Skip to content

Commit

Permalink
feat(FiltersPanel): add projects filter
Browse files Browse the repository at this point in the history
  • Loading branch information
awinogradov committed Apr 4, 2023
1 parent a9e044b commit 6ad298e
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 117 deletions.
12 changes: 12 additions & 0 deletions graphql/queries/goals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const goalsFilter = (
tags: string[];
estimates: string[];
owner: string[];
projects: number[];
},
extra: any = {},
): any => {
Expand Down Expand Up @@ -62,6 +63,16 @@ export const goalsFilter = (
}
: {};

const projectFilter = data.projects?.length
? {
project: {
id: {
in: data.projects,
},
},
}
: {};

return {
where: {
archived: false,
Expand Down Expand Up @@ -116,6 +127,7 @@ export const goalsFilter = (
...tagsFilter,
...estimateFilter,
...ownerFilter,
...projectFilter,
...extra,
},
orderBy: {
Expand Down
1 change: 1 addition & 0 deletions graphql/resolvers/Team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const goalsQuery = async (
tags: string[];
estimates: string[];
owner: string[];
projects: number[];
},
) => {
const uniqGoals = new Map();
Expand Down
3 changes: 3 additions & 0 deletions graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ input ProjectGoalsInput {
key: String!
owner: [String!]!
priority: [String!]!
projects: [Int!]!
query: String!
states: [String!]!
tags: [String!]!
Expand Down Expand Up @@ -421,6 +422,7 @@ input TeamGoalsInput {
key: String!
owner: [String!]!
priority: [String!]!
projects: [Int!]!
query: String!
states: [String!]!
tags: [String!]!
Expand Down Expand Up @@ -461,6 +463,7 @@ input UserGoalsInput {
estimates: [String!]!
owner: [String!]!
priority: [String!]!
projects: [Int!]!
query: String!
states: [String!]!
tags: [String!]!
Expand Down
3 changes: 3 additions & 0 deletions graphql/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ export const ProjectGoalsInput = inputObjectType({
t.nonNull.list.nonNull.string('tags');
t.nonNull.list.nonNull.string('estimates');
t.nonNull.list.nonNull.string('owner');
t.nonNull.list.nonNull.int('projects');
t.nonNull.string('query');
},
});
Expand All @@ -483,6 +484,7 @@ export const UserGoalsInput = inputObjectType({
t.nonNull.list.nonNull.string('tags');
t.nonNull.list.nonNull.string('estimates');
t.nonNull.list.nonNull.string('owner');
t.nonNull.list.nonNull.int('projects');
t.nonNull.string('query');
},
});
Expand Down Expand Up @@ -529,6 +531,7 @@ export const TeamGoalsInput = inputObjectType({
t.nonNull.list.nonNull.string('tags');
t.nonNull.list.nonNull.string('estimates');
t.nonNull.list.nonNull.string('owner');
t.nonNull.list.nonNull.int('projects');
t.nonNull.string('query');
},
});
Expand Down
3 changes: 2 additions & 1 deletion i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@
"Limit": "Limit",
"Tags": "Tags",
"Priority": "Priority",
"Estimate": "Estimate"
"Estimate": "Estimate",
"Project": "Project"
},
"GoalParentComboBox": {
"project": "Project",
Expand Down
3 changes: 2 additions & 1 deletion i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,8 @@
"Limit": "Лимит",
"Tags": "Теги",
"Priority": "Приоритет",
"Estimate": "Срок"
"Estimate": "Срок",
"Project": "Проект"
},
"GoalParentComboBox": {
"project": "Project",
Expand Down
28 changes: 25 additions & 3 deletions src/components/FiltersPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,25 @@ import { LimitFilterDropdown } from './LimitFilterDropdown';
import { PriorityFilterDropdown } from './PriorityFilterDropdown';
import { EstimateFilterDropdown } from './EstimateFilterDropdown';
import { Text } from './Text';
import { ProjectFilterDropdown } from './ProjectFilterDropdown';

interface FiltersPanelProps {
count?: number;
filteredCount?: number;
priority?: React.ComponentProps<typeof PriorityFilterDropdown>['priority'];
states?: React.ComponentProps<typeof StateFilterDropdown>['states'];
users?: React.ComponentProps<typeof UserFilterDropdown>['activity'];
projects?: React.ComponentProps<typeof ProjectFilterDropdown>['projects'];
tags?: React.ComponentProps<typeof TagsFilterDropdown>['tags'];
estimates?: React.ComponentProps<typeof EstimateFilterDropdown>['estimates'];
filterValues: [string[], string[], string[], string[], string[], string, number];
filterValues: [string[], string[], string[], string[], string[], number[], string, number];
children?: React.ReactNode;

onSearchChange: (search: string) => void;
onPriorityChange?: React.ComponentProps<typeof PriorityFilterDropdown>['onChange'];
onStateChange?: React.ComponentProps<typeof StateFilterDropdown>['onChange'];
onUserChange?: React.ComponentProps<typeof UserFilterDropdown>['onChange'];
onProjectChange?: React.ComponentProps<typeof ProjectFilterDropdown>['onChange'];
onTagChange?: React.ComponentProps<typeof TagsFilterDropdown>['onChange'];
onEstimateChange?: React.ComponentProps<typeof EstimateFilterDropdown>['onChange'];
onLimitChange?: React.ComponentProps<typeof LimitFilterDropdown>['onChange'];
Expand Down Expand Up @@ -68,22 +71,32 @@ export const FiltersPanel: React.FC<FiltersPanelProps> = ({
states,
priority,
users,
projects,
tags,
estimates,
filterValues,
onPriorityChange,
onSearchChange,
onStateChange,
onUserChange,
onProjectChange,
onTagChange,
onEstimateChange,
onLimitChange,
children,
}) => {
const t = useTranslations('FiltersPanel');

const [priorityFilter, stateFilter, tagsFilter, estimateFilter, ownerFilter, searchFilter, limitFilter] =
filterValues;
const [
priorityFilter,
stateFilter,
tagsFilter,
estimateFilter,
ownerFilter,
projectFilter,
searchFilter,
limitFilter,
] = filterValues;

const onSearchInputChange = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
Expand Down Expand Up @@ -141,6 +154,15 @@ export const FiltersPanel: React.FC<FiltersPanelProps> = ({
/>
))}

{nullable(projects, (pr) => (
<ProjectFilterDropdown
text={t('Project')}
projects={pr}
value={projectFilter}
onChange={onProjectChange}
/>
))}

{nullable(tags, (ta) => (
<TagsFilterDropdown text={t('Tags')} tags={ta} value={tagsFilter} onChange={onTagChange} />
))}
Expand Down
66 changes: 66 additions & 0 deletions src/components/ProjectFilterDropdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React, { useCallback, useEffect, useState } from 'react';
import dynamic from 'next/dynamic';

import { Project } from '../../graphql/@generated/genql';

import { FiltersMenuItem } from './FiltersMenuItem';
import { MenuItem } from './MenuItem';

const Dropdown = dynamic(() => import('./Dropdown'));

interface ProjectFilterDropdownProps {
text: React.ComponentProps<typeof Dropdown>['text'];
projects: Project[];
value?: number[];
disabled?: React.ComponentProps<typeof Dropdown>['disabled'];

onChange?: (selected: number[]) => void;
}

export const ProjectFilterDropdown: React.FC<ProjectFilterDropdownProps> = React.forwardRef<
HTMLDivElement,
ProjectFilterDropdownProps
>(({ text, projects, value, disabled, onChange }, ref) => {
const [selected, setSelected] = useState(new Set(value));

useEffect(() => {
setSelected(new Set(value));
}, [value]);

const onProjectClick = useCallback(
(p: Project) => {
selected.has(p.id) ? selected.delete(p.id) : selected.add(p.id);
const newSelected = new Set(selected);
setSelected(newSelected);

onChange?.(Array.from(newSelected));
},
[onChange, selected],
);

return (
<Dropdown
ref={ref}
text={text}
value={value}
onChange={onProjectClick}
items={projects}
disabled={disabled}
renderTrigger={(props) => (
<FiltersMenuItem
ref={props.ref}
active={Boolean(Array.from(selected).length)}
disabled={props.disabled}
onClick={props.onClick}
>
{props.text}
</FiltersMenuItem>
)}
renderItem={(props) => (
<MenuItem ghost key={props.item.id} selected={selected.has(props.item.id)} onClick={props.onClick}>
{props.item.title}
</MenuItem>
)}
/>
);
});
Loading

0 comments on commit 6ad298e

Please sign in to comment.