-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'fix/issues-layout-mobx' into chore/issue-properties-mobx
- Loading branch information
Showing
16 changed files
with
279 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
web/components/issues/issue-layouts/filters/applied-filters/root.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { useRouter } from "next/router"; | ||
import { observer } from "mobx-react-lite"; | ||
|
||
// mobx store | ||
import { useMobxStore } from "lib/mobx/store-provider"; | ||
// components | ||
import { AppliedFiltersList } from "components/issues"; | ||
// types | ||
import { IIssueFilterOptions } from "types"; | ||
|
||
export const AppliedFiltersRoot: React.FC = observer(() => { | ||
const router = useRouter(); | ||
const { workspaceSlug, projectId } = router.query; | ||
|
||
const { issueFilter: issueFilterStore, project: projectStore } = useMobxStore(); | ||
|
||
const userFilters = issueFilterStore.userFilters; | ||
|
||
// filters whose value not null or empty array | ||
const appliedFilters: IIssueFilterOptions = {}; | ||
Object.entries(userFilters).forEach(([key, value]) => { | ||
if (!value) return; | ||
|
||
if (Array.isArray(value) && value.length === 0) return; | ||
|
||
appliedFilters[key as keyof IIssueFilterOptions] = value; | ||
}); | ||
|
||
const handleRemoveFilter = (key: keyof IIssueFilterOptions, value: string | null) => { | ||
if (!workspaceSlug || !projectId) return; | ||
|
||
// remove all values of the key if value is null | ||
if (!value) { | ||
issueFilterStore.updateUserFilters(workspaceSlug.toString(), projectId.toString(), { | ||
filters: { | ||
[key]: null, | ||
}, | ||
}); | ||
return; | ||
} | ||
|
||
// remove the passed value from the key | ||
let newValues = issueFilterStore.userFilters?.[key] ?? []; | ||
newValues = newValues.filter((val) => val !== value); | ||
|
||
issueFilterStore.updateUserFilters(workspaceSlug.toString(), projectId.toString(), { | ||
filters: { | ||
[key]: newValues, | ||
}, | ||
}); | ||
}; | ||
|
||
const handleClearAllFilters = () => { | ||
if (!workspaceSlug || !projectId) return; | ||
|
||
const newFilters: IIssueFilterOptions = {}; | ||
Object.keys(userFilters).forEach((key) => { | ||
newFilters[key as keyof IIssueFilterOptions] = null; | ||
}); | ||
|
||
issueFilterStore.updateUserFilters(workspaceSlug.toString(), projectId.toString(), { | ||
filters: { ...newFilters }, | ||
}); | ||
}; | ||
|
||
// return if no filters are applied | ||
if (Object.keys(appliedFilters).length === 0) return null; | ||
|
||
return ( | ||
<AppliedFiltersList | ||
appliedFilters={appliedFilters} | ||
handleClearAllFilters={handleClearAllFilters} | ||
handleRemoveFilter={handleRemoveFilter} | ||
labels={projectStore.labels?.[projectId?.toString() ?? ""] ?? []} | ||
members={projectStore.members?.[projectId?.toString() ?? ""]?.map((m) => m.member)} | ||
states={projectStore.states?.[projectId?.toString() ?? ""]} | ||
/> | ||
); | ||
}); |
Oops, something went wrong.