Skip to content

Catalogue props cleanup #427

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

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- [Styling](development/styling.md)
- [Making a release](development/releasing.md)
- [Release notes](releases/README.md)
- [Version 0.5.4](releases/v0.5.4.md)
- [Version 0.5.3](releases/v0.5.3.md)
- [Version 0.5.2](releases/v0.5.2.md)
- [Version 0.5.1](releases/v0.5.1.md)
Expand Down
28 changes: 28 additions & 0 deletions book/src/releases/v0.5.4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Version 0.5.4

## Migration guide

If you are using the collapsible catalogue feature, the texts for the expand/collapse button are now no longer specified as props:

```diff
<lens-catalogue
- texts={{
- collapseButtonTitle: 'My custom expand text',
- expandButtonTitle: 'My custom collapse text',
- }}
toggle={{ collapsable: true }}
></lens-catalogue>
```

If you specified any other texts in the `texts` prop you can remove them as well as they are no longer used. The expand/collapse button texts are now specified in the Lens options [as translations](../guide/translations.md):

```json
"texts": {
"catalogue_expand": {
"en": "My custom expand text"
},
"catalogue_collapse": {
"en": "My custom collapse text"
},
}
```
58 changes: 18 additions & 40 deletions src/components/catalogue/Catalogue.wc.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,37 @@
/>

<script lang="ts">
import { catalogueTextStore } from "../../stores/texts";
import { catalogue } from "../../stores/catalogue";
import type { ToggleAttribute } from "../../types/helpers";
import type { CatalogueText } from "../../types/texts";
import type { Catalogue } from "../../types/catalogue";
import DataTreeElement from "./DataTreeElement.svelte";
import { onMount } from "svelte";
import { lensOptions } from "../../stores/options";
import { fetchFacetCounts } from "../../stores/facetCounts";
import { translate } from "../../helpers/translations";

interface Props {
treeData?: Catalogue;

texts?: CatalogueText;
/**
* handle the toggle of the catalogue
*/
toggle?: ToggleAttribute;
toggle?: {
collapsable?: boolean;
open?: boolean;
};
}

let {
treeData = [],
texts = {},
toggle = {
collapsable: true,
open: false,
},
}: Props = $props();

let toggleTree = $state(toggle.open);
let isOpen = $state(toggle.open);

const handleToggle = (): void => {
toggleTree = !toggleTree;
};

/**
* Initialize the catalogue text store with the given texts
*/
let initializedTexts = {
group: texts.group || "Group",
collapseButtonTitle: texts.collapseButtonTitle || "Collapse Tree",
expandButtonTitle: texts.expandButtonTitle || "Expand Tree",
numberInput: {
labelFrom: texts.numberInput?.labelFrom || "From",
labelTo: texts.numberInput?.labelTo || "to",
},
isOpen = !isOpen;
};

/**
Expand All @@ -63,13 +48,6 @@
}
});

/**
* Initialize the text store with the given texts
*/
$effect(() => {
$catalogueTextStore = initializedTexts;
});

onMount(() => {
let didRun = false;
lensOptions.subscribe((opts) => {
Expand All @@ -86,34 +64,34 @@
<div part="lens-catalogue">
{#if toggle.collapsable}
<button
part="lens-catalogue-toggle-button {toggle.open
part="lens-catalogue-toggle-button {isOpen
? 'lens-catalogue-button-open'
: ''}"
onclick={handleToggle}
>
<div
part="toggle-button-icon {toggle.open
? 'toggle-button-open-icon'
: ''}"
part="toggle-button-icon {isOpen
? ''
: 'lens-catalogue-toggle-button-closed-icon'}"
>
&#9660;
</div>
<div
part="toggle-button-text {toggle.open
part="toggle-button-text {isOpen
? 'toggle-button-open-text'
: ''}"
>
{toggle.open
? $catalogueTextStore.collapseButtonTitle
: $catalogueTextStore.expandButtonTitle}
{isOpen
? translate("catalogue_collapse")
: translate("catalogue_expand")}
</div>
</button>
{/if}
{#if toggleTree || !toggle.collapsable}
{#if isOpen || !toggle.collapsable}
<div part="lens-catalogue-wrapper">
<!-- eslint-disable-next-line svelte/require-each-key -->
{#each $catalogue as Category}
<DataTreeElement element={Category} treeOpen={toggle.open} />
<DataTreeElement element={Category} treeOpen={isOpen} />
{/each}
</div>
{/if}
Expand All @@ -138,7 +116,7 @@
background-color: var(--button-background-color-hover);
}

[part~="toggle-button-open-icon"] {
[part~="lens-catalogue-toggle-button-closed-icon"] {
transform: rotate(180deg);
}

Expand Down
8 changes: 8 additions & 0 deletions src/helpers/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,12 @@ const lensTranslations: Texts = {
en: "One of the search fields is empty. Please delete empty search fields or enter search criteria.",
de: "Eine der Suchleisten ist leer. Löschen Sie leere Suchleisten oder fügen Sie Suchkriterien ein.",
},
catalogue_expand: {
en: "Expand Catalogue",
de: "Katalog ausklappen",
},
catalogue_collapse: {
en: "Collapse Catalogue",
de: "Katalog einklappen",
},
};
10 changes: 0 additions & 10 deletions src/stores/texts.ts

This file was deleted.

5 changes: 0 additions & 5 deletions src/types/helpers.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/types/texts.ts

This file was deleted.