Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WEB-537] fix: issue in all-issue create view modal, filter needs to disappear when filter is de selected. #3781

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions web/components/workspace/views/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { AppliedFiltersList, FilterSelection, FiltersDropdown } from "components
// ui
import { Button, Input, TextArea } from "@plane/ui";
// types
import { IWorkspaceView } from "@plane/types";
import { IIssueFilterOptions, IWorkspaceView } from "@plane/types";
// constants
import { ISSUE_DISPLAY_FILTERS_BY_LAYOUT } from "constants/issue";

Expand Down Expand Up @@ -39,7 +39,7 @@ export const WorkspaceViewForm: React.FC<Props> = observer((props) => {
reset,
setValue,
watch,
} = useForm({
} = useForm<IWorkspaceView>({
defaultValues,
});

Expand All @@ -59,7 +59,35 @@ export const WorkspaceViewForm: React.FC<Props> = observer((props) => {
});
}, [data, preLoadedData, reset]);

const selectedFilters = watch("filters");
const selectedFilters: IIssueFilterOptions = watch("filters");

// filters whose value not null or empty array
let appliedFilters: IIssueFilterOptions | undefined = undefined;
Object.entries(selectedFilters ?? {}).forEach(([key, value]) => {
if (!value) return;
if (Array.isArray(value) && value.length === 0) return;
if (!appliedFilters) appliedFilters = {};
appliedFilters[key as keyof IIssueFilterOptions] = value;
});

const handleRemoveFilter = (key: keyof IIssueFilterOptions, value: string | null) => {
// To clear all filters of any particular filter key.
if (!value) {
setValue("filters", {
...selectedFilters,
[key]: [],
});
return;
}

let newValues = selectedFilters?.[key] ?? [];
newValues = newValues.filter((val) => val !== value);

setValue("filters", {
...selectedFilters,
[key]: newValues,
});
};

const clearAllFilters = () => {
if (!selectedFilters) return;
Expand Down Expand Up @@ -151,11 +179,12 @@ export const WorkspaceViewForm: React.FC<Props> = observer((props) => {
{selectedFilters && Object.keys(selectedFilters).length > 0 && (
<div>
<AppliedFiltersList
appliedFilters={selectedFilters}
appliedFilters={appliedFilters ?? {}}
handleClearAllFilters={clearAllFilters}
handleRemoveFilter={() => {}}
handleRemoveFilter={handleRemoveFilter}
labels={workspaceLabels ?? undefined}
states={undefined}
alwaysAllowEditing
/>
</div>
)}
Expand Down
Loading