mirror of
https://github.com/LukeHagar/sveltesociety.dev.git
synced 2025-12-10 12:47:45 +00:00
Fix category (unclassified) facet
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
export type Facet = {
|
type Facet = {
|
||||||
identifier: string;
|
identifier: string;
|
||||||
title: string;
|
title: string;
|
||||||
isMulti?: boolean;
|
isMulti?: boolean;
|
||||||
@@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
export let facetsConfig: Array<Facet> = [];
|
export let facetsConfig: Array<Facet> = [];
|
||||||
export let data;
|
export let data;
|
||||||
|
export let dataDefault = {};
|
||||||
let sort = { value: 'stars_desc' };
|
let sort = { value: 'stars_desc' };
|
||||||
export let searchableFields: Array<string> = [];
|
export let searchableFields: Array<string> = [];
|
||||||
export let sortableFields: Array<SortField> = [];
|
export let sortableFields: Array<SortField> = [];
|
||||||
@@ -49,8 +50,10 @@
|
|||||||
),
|
),
|
||||||
searchableFields
|
searchableFields
|
||||||
};
|
};
|
||||||
|
const searcher = itemsjs(
|
||||||
const searcher = itemsjs(data, configurations as Configuration<string, string, string>);
|
data.map((line) => ({ ...dataDefault, ...line })),
|
||||||
|
configurations as Configuration<string, string, string>
|
||||||
|
);
|
||||||
|
|
||||||
export function search() {
|
export function search() {
|
||||||
const results = searcher.search({
|
const results = searcher.search({
|
||||||
@@ -62,9 +65,9 @@
|
|||||||
let filterValue;
|
let filterValue;
|
||||||
const facetValue = facet.value;
|
const facetValue = facet.value;
|
||||||
if (Array.isArray(facetValue)) {
|
if (Array.isArray(facetValue)) {
|
||||||
filterValue = facetValue.map((value) => value.value);
|
filterValue = facetValue.map((value) => revertDefaultValue(value.value));
|
||||||
} else {
|
} else {
|
||||||
filterValue = [facetValue.value];
|
filterValue = [revertDefaultValue(facetValue.value)];
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
...object,
|
...object,
|
||||||
@@ -86,10 +89,22 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$: query, facets, sort, search();
|
$: query, facets, sort, search();
|
||||||
|
|
||||||
|
function defaultEmpty(values: Array<string>, defaultValue = 'Unclassified'): Array<string> {
|
||||||
|
return values.map((value) => value || defaultValue);
|
||||||
|
}
|
||||||
|
function revertDefaultValue(value: string, defaultValue = 'Unclassified'): string {
|
||||||
|
return value === defaultValue ? '' : value;
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#each facets as facet (facet.identifier)}
|
{#each facets as facet (facet.identifier)}
|
||||||
<Select {...facet} bind:value={facet.value} items={facet.values} label={facet.title} />
|
<Select
|
||||||
|
{...facet}
|
||||||
|
bind:value={facet.value}
|
||||||
|
items={defaultEmpty(facet.values)}
|
||||||
|
label={facet.title}
|
||||||
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
|
|
||||||
<Select
|
<Select
|
||||||
|
|||||||
@@ -46,6 +46,7 @@
|
|||||||
<div class="inputs">
|
<div class="inputs">
|
||||||
<Search
|
<Search
|
||||||
data={components}
|
data={components}
|
||||||
|
dataDefault={{ category: '' }}
|
||||||
bind:query={searchValue}
|
bind:query={searchValue}
|
||||||
sortableFields={[
|
sortableFields={[
|
||||||
{ identifier: 'addedOn', title: 'Last added first', ascending: false },
|
{ identifier: 'addedOn', title: 'Last added first', ascending: false },
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
<div class="inputs">
|
<div class="inputs">
|
||||||
<Search
|
<Search
|
||||||
data={templates}
|
data={templates}
|
||||||
|
dataDefault={{ category: '' }}
|
||||||
bind:query={searchValue}
|
bind:query={searchValue}
|
||||||
sortableFields={[
|
sortableFields={[
|
||||||
{ identifier: 'addedOn', title: 'Last added first', ascending: false },
|
{ identifier: 'addedOn', title: 'Last added first', ascending: false },
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
<div class="inputs">
|
<div class="inputs">
|
||||||
<Search
|
<Search
|
||||||
data={tools}
|
data={tools}
|
||||||
|
dataDefault={{ category: '' }}
|
||||||
bind:query={searchValue}
|
bind:query={searchValue}
|
||||||
sortableFields={[
|
sortableFields={[
|
||||||
{ identifier: 'addedOn', title: 'Last added first', ascending: false },
|
{ identifier: 'addedOn', title: 'Last added first', ascending: false },
|
||||||
|
|||||||
Reference in New Issue
Block a user