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

Feat/improve search options #26

Merged
merged 2 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
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
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 @@
<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
Loading