Skip to content

Commit

Permalink
Merge pull request #88 from samply/feature/select_all_subcategory_opt…
Browse files Browse the repository at this point in the history
…ions_in_catalogue

Feat(catalogue): select all button for single-select elements
  • Loading branch information
MatsJohansen87 authored Apr 25, 2024
2 parents 013ee3a + 29f8d2f commit c610cdf
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/demo/public/options.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"iconOptions": {
"infoUrl": "info-circle-svgrepo-com.svg"
"infoUrl": "info-circle-svgrepo-com.svg",
"selectAll": {
"text": "Add all"
}
},
"chartOptions": {
"patients": {
Expand Down
16 changes: 16 additions & 0 deletions packages/lib/src/components/Options.wc.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@
) {
store.set("infoUrl", options.iconOptions.infoUrl);
}
if (
"selectAll" in options.iconOptions &&
typeof options.iconOptions["selectAll"] === "object" &&
options.iconOptions.selectAll
) {
// Allow for future possibility of iconUrl instead of text
if (
"text" in options.iconOptions.selectAll &&
typeof options.iconOptions.selectAll["text"] ===
"string"
)
store.set(
"selectAllText",
options.iconOptions.selectAll.text,
);
}
}
}
Expand Down
41 changes: 40 additions & 1 deletion packages/lib/src/components/catalogue/DataTreeElement.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<script lang="ts">
import { addItemToQuery, activeQueryGroupIndex } from "../../stores/query";
import type { Category } from "../../types/treeData";
import DataTreeElement from "./DataTreeElement.svelte";
import NumberInputComponent from "./NumberInputComponent.svelte";
Expand Down Expand Up @@ -37,7 +38,6 @@
* watches the open tree nodes store to update the open state of the subcategorys
*/
let open: boolean = false;
$: {
if (subCategoryName) {
open = $openTreeNodes
Expand Down Expand Up @@ -93,6 +93,13 @@
});
};
let finalParent: boolean =
!("childCategories" in element) &&
(!("fieldType" in element) ||
("fieldType" in element &&
typeof element.fieldType === "string" &&
element.fieldType == "single-select"));
/**
* watches the number input store to update the number input components
*/
Expand Down Expand Up @@ -131,6 +138,32 @@
}
return store;
});
$: selectAllText = $iconStore.get("selectAllText");
const selectAllOptions = (): void => {
if (!("criteria" in element)) return;
element.criteria.forEach((criterion) => {
const queryItem: QueryItem = {
id: uuidv4(),
key: element.key,
name: element.name,
system: "system" in element ? element.system : "",
type: "type" in element ? element.type : "",
values: [
{
name: criterion.name,
value: criterion.aggregatedValue
? criterion.aggregatedValue
: criterion.key,
queryBindId: uuidv4(),
},
],
};
addItemToQuery(queryItem, $activeQueryGroupIndex);
});
};
</script>

<div part="data-tree-element">
Expand Down Expand Up @@ -160,6 +193,12 @@
<InfoButtonComponent message={element.infoButtonText} />
{/if}

{#if finalParent && open}
<button part="add-all-options-button" on:click={selectAllOptions}>
{selectAllText ? selectAllText : "Add all"}
</button>
{/if}

{#if open}
{#if "childCategories" in element}
{#each element.childCategories as child}
Expand Down
11 changes: 11 additions & 0 deletions packages/lib/src/styles/catalogue.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ lens-catalogue::part(data-tree-element-toggle-icon) {
transition: all 0.1s ease-in-out;
}

lens-catalogue::part(add-all-options-button) {
background-color: var(--button-background-color);
border-radius: var(--border-radius-small);
color: var(--button-color);
position: relative;
padding: 3px 8px;
cursor: pointer;
border: none;
left: +15px;
}

lens-catalogue::part(data-tree-element-toggle-icon-open) {
transform: rotate(0deg);
}
Expand Down

0 comments on commit c610cdf

Please sign in to comment.