From ca3811a48b240128cd5c13551c3268b3f818423c Mon Sep 17 00:00:00 2001 From: Bhasher Date: Wed, 10 Jan 2024 17:56:31 +0100 Subject: [PATCH] Frontend filter menu --- frontend/src/lib/api/filtersApi.ts | 4 +- .../src/lib/components/menu/FilterMenu.svelte | 18 ++ .../lib/components/menu/FilterMenuItem.svelte | 155 ++++++++++++++++++ .../src/lib/components/project/Header.svelte | 7 +- frontend/src/lib/types/Filter.ts | 64 ++++++-- frontend/src/lib/types/View.ts | 14 +- 6 files changed, 246 insertions(+), 16 deletions(-) create mode 100644 frontend/src/lib/components/menu/FilterMenu.svelte create mode 100644 frontend/src/lib/components/menu/FilterMenuItem.svelte diff --git a/frontend/src/lib/api/filtersApi.ts b/frontend/src/lib/api/filtersApi.ts index c26e040..3284b99 100644 --- a/frontend/src/lib/api/filtersApi.ts +++ b/frontend/src/lib/api/filtersApi.ts @@ -5,7 +5,7 @@ async function create( viewId: number, projectTagId: number, filterType: number, - tagOptionId: number + tagOptionId: number | null ): Promise { const response = await api.post(`/v1/filters`, { view_id: viewId, @@ -27,7 +27,7 @@ async function update( viewId: number, projectTagId: number, filterType: number, - tagOptionId: number + tagOptionId: number | null ): Promise { const response = await api.put(`/v1/filters/${filterId}`, { view_id: viewId, diff --git a/frontend/src/lib/components/menu/FilterMenu.svelte b/frontend/src/lib/components/menu/FilterMenu.svelte new file mode 100644 index 0000000..423d56c --- /dev/null +++ b/frontend/src/lib/components/menu/FilterMenu.svelte @@ -0,0 +1,18 @@ + + + + {#each filters as filter} + + {/each} + + + + diff --git a/frontend/src/lib/components/menu/FilterMenuItem.svelte b/frontend/src/lib/components/menu/FilterMenuItem.svelte new file mode 100644 index 0000000..a171c75 --- /dev/null +++ b/frontend/src/lib/components/menu/FilterMenuItem.svelte @@ -0,0 +1,155 @@ + + +
+
+
(isProjectTagOpen = !isProjectTagOpen)} + on:keydown={(e) => { + if (e.key === 'Enter') isProjectTagOpen = !isProjectTagOpen; + }} + tabindex="0" + role="button" + > + {#if filter} + {filter.projectTag.title} + {/if} +
+ + {#each $projectTags as projectTag} + + {/each} + +
+
+
(isFilterTypeOpen = !isFilterTypeOpen)} + on:keydown={(e) => { + if (e.key === 'Enter') isFilterTypeOpen = !isFilterTypeOpen; + }} + tabindex="0" + role="button" + > + {#if filter} + {filter.filterType} + {/if} +
+ {#if filter} + + + + + {/if} +
+
+
(isOptionOpen = !isOptionOpen)} + on:keydown={(e) => { + if (e.key === 'Enter') isOptionOpen = !isOptionOpen; + }} + tabindex="0" + role="button" + > + {#if filter && filter.tagOption} + {filter.tagOption.value} + {/if} +
+ {#if filter && filter.projectTag} + + {#each filter.projectTag.options as option} + + {/each} + + {/if} +
+
+ + diff --git a/frontend/src/lib/components/project/Header.svelte b/frontend/src/lib/components/project/Header.svelte index 32720bf..30adbf6 100644 --- a/frontend/src/lib/components/project/Header.svelte +++ b/frontend/src/lib/components/project/Header.svelte @@ -7,10 +7,12 @@ import type ProjectTag from '$lib/types/ProjectTag'; import { projectTags } from '$lib/types/ProjectTag'; import { get } from 'svelte/store'; + import FilterMenu from '../menu/FilterMenu.svelte'; export let project: Project; let groupMenuOpen = false; let sortMenuOpen = false; + let filterMenuOpen = false; async function setGroup(projectTag: ProjectTag): Promise { const view = get(currentView); @@ -54,7 +56,10 @@ /> - +
+ + +