From d3e65ffcd52989ffb4ba523eb3cfb853c8c8c0a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Katharina=20W=C3=BCnsche?= <katharina_wunsche@yahoo.de> Date: Mon, 27 Jan 2025 10:26:09 +0100 Subject: [PATCH 1/2] chore: reduce search categories and add operators --- components/data-map-view.vue | 6 ++---- components/data-view.vue | 6 ++---- composables/use-get-search-results.ts | 18 +++++++++--------- messages/de/common.json | 4 ++-- messages/en/common.json | 4 ++-- 5 files changed, 17 insertions(+), 21 deletions(-) diff --git a/components/data-map-view.vue b/components/data-map-view.vue index 95515ded..85b763b4 100644 --- a/components/data-map-view.vue +++ b/components/data-map-view.vue @@ -6,7 +6,7 @@ import * as v from "valibot"; import type { SearchFormData } from "@/components/search-form.vue"; import type { EntityFeature } from "@/composables/use-create-entity"; -import { categories } from "@/composables/use-get-search-results"; +import { categories, operatorMap } from "@/composables/use-get-search-results"; import type { GeoJsonFeature } from "@/utils/create-geojson-feature"; import { project } from "../config/project.config"; @@ -22,8 +22,6 @@ const searchFiltersSchema = v.object({ search: v.fallback(v.string(), ""), }); -const idCategories = ["entityID", "typeID", "valueTypeID", "typeIDWithSubs"]; - const entitySelectionSchema = v.object({ selection: v.fallback(v.array(v.string()), []), }); @@ -60,7 +58,7 @@ const { data, isPending, isPlaceholderData } = useGetSearchResults( computed(() => { const { search, category, ...params } = searchFilters.value; - const operator = idCategories.includes(category) ? "equal" : "like"; + const operator = operatorMap[category]; return { ...params, diff --git a/components/data-view.vue b/components/data-view.vue index e30af284..d1a8b68f 100644 --- a/components/data-view.vue +++ b/components/data-view.vue @@ -12,7 +12,7 @@ import { PaginationListItem, PaginationNext, } from "@/components/ui/pagination"; -import { categories, columns, isColumn } from "@/composables/use-get-search-results"; +import { categories, columns, isColumn, operatorMap } from "@/composables/use-get-search-results"; const router = useRouter(); const route = useRoute(); @@ -40,8 +40,6 @@ const searchFiltersSchema = v.object({ ), }); -const idCategories = ["entityID", "typeID", "valueTypeID", "typeIDWithSubs"]; - const searchFilters = computed(() => { return v.parse(searchFiltersSchema, route.query); }); @@ -84,7 +82,7 @@ const { data, isPending, isPlaceholderData } = useGetSearchResults( computed(() => { const { search, category, ...params } = searchFilters.value; - const operator = idCategories.includes(category) ? "equal" : "like"; + const operator = operatorMap[category]; const searchQuery = search && search.length > 0 diff --git a/composables/use-get-search-results.ts b/composables/use-get-search-results.ts index e316ec9b..c3b5bcba 100644 --- a/composables/use-get-search-results.ts +++ b/composables/use-get-search-results.ts @@ -8,21 +8,21 @@ import type { LinkedPlace } from "@/types/api"; export const categories = [ "beginFrom", "beginTo", - "endFrom", - "endTo", - "entityAliases", - "entityCidocClass", "entityDescription", "entityID", "entityName", - "entitySystemClass", - "relationToID", - "typeID", - "typeIDWithSubs", "typeName", - "valueTypeID", ] as const; +export const operatorMap = { + beginFrom: "greaterThanEqual", + beginTo: "lesserThanEqual", + entityDescription: "like", + entityID: "equal", + entityName: "like", + typeName: "like", +} as const; + /** * The columns that can be sorted on. * @id apiColumns diff --git a/messages/de/common.json b/messages/de/common.json index 97bee6bb..4f8b1ef1 100644 --- a/messages/de/common.json +++ b/messages/de/common.json @@ -155,8 +155,8 @@ "SearchForm": { "filter": "Filter", "filters": { - "beginFrom": "Beginn von", - "beginTo": "Beginn bis", + "beginFrom": "Beginn nach", + "beginTo": "Beginn vor", "endFrom": "Ende von", "endTo": "Ende bis", "entityAliases": "Alias", diff --git a/messages/en/common.json b/messages/en/common.json index a353d0e8..1f5eb722 100644 --- a/messages/en/common.json +++ b/messages/en/common.json @@ -155,8 +155,8 @@ "SearchForm": { "filter": "Filter", "filters": { - "beginFrom": "Begin from", - "beginTo": "Begin to", + "beginFrom": "Begin before", + "beginTo": "Begin after", "endFrom": "End from", "endTo": "End to", "entityAliases": "Alias", From b67d6d4f08e298c60ebb67066abeb5275bc4439a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Katharina=20W=C3=BCnsche?= <katharina_wunsche@yahoo.de> Date: Mon, 27 Jan 2025 10:33:55 +0100 Subject: [PATCH 2/2] chore: sort search categories alphabetically --- components/search-form.vue | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/search-form.vue b/components/search-form.vue index 91a4a380..2dce96c8 100644 --- a/components/search-form.vue +++ b/components/search-form.vue @@ -45,7 +45,13 @@ const searchLabelId = "search-field"; <SelectValue :placeholder="t('SearchForm.select-filter')" /> </SelectTrigger> <SelectContent> - <SelectItem v-for="category of categories" :key="category" :value="category"> + <SelectItem + v-for="category of categories.toSorted((a, b) => + t(`SearchForm.filters.${a}`).localeCompare(t(`SearchForm.filters.${b}`)), + )" + :key="category" + :value="category" + > {{ t(`SearchForm.filters.${category}`) }} </SelectItem> </SelectContent>