Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defineEmits<{
>
<i class="pi pi-filter idle-info-tile-icon" />
<span class="idle-info-tile-title">
{{ $gettext("Facets") }}
{{ $gettext("Filters") }}
</span>
<span class="idle-info-tile-desc">
{{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ defineEmits<{
<div class="toolbar-right">
<Button
v-if="!hideFiltersButton"
:label="$gettext('Facets')"
:label="$gettext('Filters')"
icon="pi pi-filter"
icon-pos="left"
size="small"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ function componentFor(node: NodeFilterConfigNode): Component | null {
gap: 1.6rem;
}

.attribute-filters :deep(.p-accordioncontent-wrapper) {
min-inline-size: 0;
}

.attribute-filters-header {
display: flex;
align-items: center;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<script setup lang="ts">
import { computed, ref, watch } from "vue";
import { useGettext } from "vue3-gettext";

import arches from "arches";
import MultiSelect from "openvue/multiselect";

import { fetchControlledListItems } from "@/arches_search/SimpleSearch/api.ts";

import type { Language } from "@/arches_controlled_lists/types.ts";
import type { NodeFilterConfigNode } from "@/arches_search/SimpleSearch/types.ts";
import type {
ReferenceFilterOption,
ReferenceFilterValue,
} from "@/arches_search/SimpleSearch/components/attribute-filters/types.ts";

const DEFAULT_LANGUAGE_CODE = "en";

const { $gettext } = useGettext();

const language = arches.activeLanguage;
const systemLanguage =
arches.languages.find((lang: Language) => lang.isdefault)?.code ??
DEFAULT_LANGUAGE_CODE;

const { node, modelValue } = defineProps<{
node: NodeFilterConfigNode;
modelValue: ReferenceFilterValue | null;
}>();

const emit = defineEmits<{
(event: "update:modelValue", value: ReferenceFilterValue): void;
}>();

const options = ref<ReferenceFilterOption[]>([]);
const isLoading = ref(false);

const controlledListId = computed<string | null>(() => {
const listId = node.config?.controlledList;
return typeof listId === "string" ? listId : null;
});

watch(
controlledListId,
async (listId) => {
if (!listId) {
options.value = [];
return;
}
isLoading.value = true;
try {
const items = await fetchControlledListItems(
listId,
language,
systemLanguage,
);
options.value = items.map((item) => ({
id: item.uri,
label: item.label,
}));
} catch (error) {
console.error(
"[ReferenceFilterMultiSelect] failed to load controlled list items:",
error,
);
options.value = [];
} finally {
isLoading.value = false;
}
},
{ immediate: true },
);

function onSelectionChange(value: ReferenceFilterValue): void {
emit("update:modelValue", value);
}
</script>

<template>
<div class="reference-filter">
<MultiSelect
class="reference-filter-select"
data-key="id"
:input-id="node.node_alias"
:model-value="modelValue ?? []"
:options="options"
option-label="label"
:loading="isLoading"
:filter="true"
:filter-placeholder="$gettext('Search options...')"
:placeholder="$gettext('Select options...')"
:show-clear="true"
:fluid="true"
:disabled="options.length === 0 && !isLoading"
:aria-label="node.label"
@update:model-value="onSelectionChange"
/>
<span
v-if="options.length === 0 && !isLoading"
class="status"
>
{{ $gettext("No options available.") }}
</span>
</div>
</template>

<style scoped>
.reference-filter {
padding: 0.4rem 0 0.8rem 0;
}

.reference-filter .reference-filter-select {
padding-block: 0.4rem;
padding-inline: 0.8rem;
}

.reference-filter :deep(.p-multiselect-label) {
font-size: var(--p-arches-search-font-size);
}

.reference-filter .status {
display: block;
font-size: var(--p-arches-search-font-size);
color: var(--p-text-muted-color);
padding: 0.4rem 0 0 0;
line-height: 1.5;
}
</style>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import NumericFilter from "@/arches_search/SimpleSearch/components/attribute-filters/NumericFilter.vue";
import ReferenceFilter from "@/arches_search/SimpleSearch/components/attribute-filters/ReferenceFilter.vue";
import ReferenceFilterMultiSelect from "@/arches_search/SimpleSearch/components/attribute-filters/ReferenceFilterMultiSelect.vue";

import {
ClauseSubjectTypeToken,
Expand Down Expand Up @@ -126,7 +126,7 @@ function formatNumericValue(value: unknown): string {
// datatype by registering one entry here and dropping in its widget component.
const ATTRIBUTE_FILTER_REGISTRY: Record<string, AttributeFilterEntry> = {
reference: {
component: ReferenceFilter,
component: ReferenceFilterMultiSelect,
buildQuery: buildReferenceQuery,
formatValue: formatReferenceValue,
},
Expand Down
Loading