Skip to content

Commit

Permalink
Feat/improve search options (#26)
Browse files Browse the repository at this point in the history
Resolves https://redmine.openatlas.eu/issues/2427 by reducing the search
categories to:

- Name
- ID
- Before (Begin before)
- After (Begin after)
- Type name
- Description
  • Loading branch information
katharinawuensche authored Jan 27, 2025
2 parents 941e942 + b67d6d4 commit 54dbe48
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
6 changes: 2 additions & 4 deletions components/data-map-view.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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()), []),
});
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions components/data-view.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -40,8 +40,6 @@ const searchFiltersSchema = v.object({
),
});
const idCategories = ["entityID", "typeID", "valueTypeID", "typeIDWithSubs"];
const searchFilters = computed(() => {
return v.parse(searchFiltersSchema, route.query);
});
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion components/search-form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>

Check warning on line 49 in components/search-form.vue

View workflow job for this annotation

GitHub Actions / Validate (20.x, ubuntu-latest)

Variable 'category' is already declared in the upper scope
t(`SearchForm.filters.${a}`).localeCompare(t(`SearchForm.filters.${b}`)),
)"
:key="category"
:value="category"
>
{{ t(`SearchForm.filters.${category}`) }}
</SelectItem>
</SelectContent>
Expand Down
18 changes: 9 additions & 9 deletions composables/use-get-search-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions messages/de/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions messages/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 54dbe48

Please sign in to comment.