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(catalogue): select all button for single-select elements #88

Merged
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
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
Loading