Skip to content

Commit

Permalink
feat-issueresolve-1
Browse files Browse the repository at this point in the history
  • Loading branch information
githubering182 committed Mar 14, 2024
1 parent 8f169f4 commit 1ac187c
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 21 deletions.
11 changes: 10 additions & 1 deletion backend-app/file/file_tests/services_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from project.models import Project
from user.models import CustomUser
from uuid import uuid4
from datetime import datetime as dt, timedelta as td


class ViewServicesTest(TestCase, ViewSetServices):
Expand Down Expand Up @@ -199,6 +200,12 @@ def test_form_query(self):
query["author"] = self.admin
self._form_query_mixin(query)

query["from_"] = dt.now().strftime("%Y-%m-%d")
self._form_query_mixin(query)

query["to"] = (dt.now() + td(days=1)).strftime("%Y-%m-%d")
self._form_query_mixin(query)

def _form_query_mixin(self, data={}):
query, filter = self._get_query(**data)
res = self._form_query(
Expand All @@ -215,7 +222,9 @@ def _get_query(
status="",
downloaded=False,
author=[],
user=None
user=None,
from_="",
to=""
):
request_query = type(
"query",
Expand Down
20 changes: 15 additions & 5 deletions backend-app/file/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
from rest_framework.views import Request
from django.db import connection
from django.db.models import Count, Subquery, QuerySet
from django.utils import timezone as tz
from attribute.models import Level, AttributeGroup as AGroup
from user.models import CustomUser
from json import loads
from typing import Any
from uuid import UUID
from datetime import datetime as dt
from .serializers import File, FileSerializer


Expand All @@ -28,7 +30,9 @@ class ViewSetServices:
("file_type__in", "type[]", True),
("status", "status", False),
("is_downloaded", "downloaded", False),
("author__in", "author[]", True)
("author__in", "author[]", True),
("upload_date__gte", "from", False),
("upload_date__lte", "to", False)
)

def _patch_file(
Expand Down Expand Up @@ -87,13 +91,19 @@ def _form_query(
else request_query.get(param)
)

if query_param: query[filter_name] = (
False if filter_name == "is_downloaded"
else query_param
)
if query_param:
query[filter_name] = self._get_param(filter_name, query_param)

return query

def _get_param(self, filter_name: str, query_param: Any) -> Any:
date_from_str = lambda d: tz.make_aware(dt.strptime(d, "%Y-%m-%d"))
match filter_name:
case "is_downloaded": return False
case "upload_date__gte": return date_from_str(query_param)
case "upload_date__lte": return date_from_str(query_param)
case _: return query_param

def _get_files(
self,
project_id: int,
Expand Down
2 changes: 1 addition & 1 deletion frontend-app/src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/* --issLightGreen: #99ff62; */
/* --issBrand: #004077; */
/* --issLightBrand: #01a4e0; */
--maxWidth: 1320px;
--maxWidth: 1920px;
}

* {
Expand Down
20 changes: 14 additions & 6 deletions frontend-app/src/components/FilesValidate/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,23 @@ export default function FilesValidation({ pathID, attributes, canValidate }) {

function handleChange(filterType, query) {
var { card, attr, type, author, date } = getPageQuery();

setPageQuery({
var preparedQuery = {
'card[]': filterType === 'card' ? query : card,
'attr[]': filterType === 'attr' ? query : attr,
'type[]': filterType === 'type' ? query : type,
'author[]': filterType === 'author' ? query : author,
"date_from": filterType === "date" ? query.from : date.from,
"date_to": filterType === "date" ? query.to : date.to,
});
};

if (filterType === "date" || date?.from) {
let value = filterType === "date" ? query?.from : date?.from;
if (value) preparedQuery.date_from = value;
}
if (filterType === "date" || date?.to) {
let value = filterType === "date" ? query?.to : date?.to;
if (value) preparedQuery.date_to = value;
}

setPageQuery(preparedQuery);
}

useEffect(() => {
Expand All @@ -72,7 +80,7 @@ export default function FilesValidation({ pathID, attributes, canValidate }) {
// TODO: query collectors depend on uploads to project by users
Promise.allSettled([
api.get(`/api/files/project/${pathID}/`, {
params: { card, attr, type, author },
params: { card, attr, type, author, from: date?.from, to: date?.to },
headers: { "Authorization": "Bearer " + localStorage.getItem("dtcAccess") }
}),
canValidate && api.get(`api/users/collectors/${pathID}/`, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import ValidationFilterGroup from '.';

test("validation filter group form component test", () => {
const filterData = [
{ prettryName: "sel1", name: "sel1name", selected: [], attributes: true, data: [] },
{ prettryName: "sel2", name: "sek2name", selected: [], data: [] },
{ prettryName: "sel1", name: "sel1name", selected: [], type: "attr", data: [] },
{ prettryName: "sel2", name: "sel2name", selected: [], type: "date", data: [] },
{ prettryName: "sel3", name: "sek3name", selected: [], data: [] },
];
var changed = false;
const { container } = render(
Expand All @@ -16,6 +17,7 @@ test("validation filter group form component test", () => {

expect(container.querySelectorAll(".iss__filterSelector")).toHaveLength(1);
expect(container.querySelectorAll(".iss__manualSelector")).toHaveLength(1);
expect(container.querySelectorAll(".iss__dateSelector")).toHaveLength(1);
expect(changed).toBeFalsy();
fireEvent.click(
container.querySelector(".iss__filterSelector")
Expand Down
38 changes: 36 additions & 2 deletions frontend-app/src/components/ui/DateSelector/component.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,37 @@
import { fireEvent, act, render, renderHook, screen } from '@testing-library/react';
import { fireEvent, render, screen } from '@testing-library/react';
import DateSelector from '.';

test("date selector test", () => {});
test("date selector test", () => {
const containerClass = ".iss__dateSelector__options";
const parentClass = ".iss__dateSelector__selected";

const toggler = () => {
var opened = false;
return (set) => {
if (set) return opened = !opened;
var className = containerClass.slice(1);
fireEvent.click(container.querySelector(parentClass));
opened = !opened;
if (opened) className += " options--open";
expect(container.querySelector(containerClass).className).toBe(className);
return opened;
};
};

const { container } = render(
<DateSelector onChange={(e) => e} defaultSelected={{}} />
);

var toggle = toggler();

screen.getByText("clear dates");
expect(toggle()).toBeTruthy();
expect(toggle()).toBeFalsy();
expect(toggle()).toBeTruthy();
expect(container.querySelector(".off--title")).not.toBeNull();

fireEvent.click(screen.getByRole("button"));
toggle(true);

expect(container.querySelector(containerClass).className).toBe(containerClass.slice(1));
});
5 changes: 1 addition & 4 deletions frontend-app/src/components/ui/DateSelector/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import './styles.css';
* @param {{ from: string, to: string }} [props.defaultSelected]
* @returns {ReactElement}
*/
export default function DateSelector({
onChange,
defaultSelected,
}) {
export default function DateSelector({ onChange, defaultSelected }) {
const [isOpen, setIsOpen] = useState(false);
const [from, setFrom] = useState("");
const [to, setTo] = useState("");
Expand Down

0 comments on commit 1ac187c

Please sign in to comment.