From 9b14ba2a3aea4eb425b0b1ea78bcf66876f94556 Mon Sep 17 00:00:00 2001 From: marlon-erler Date: Thu, 25 Jul 2024 16:57:51 +0200 Subject: [PATCH] make PropertyValueList dynamically add and remove values --- dist/index.js | 13 ++++++++++--- src/View/ChatPages/boardKanbanPage.tsx | 2 +- src/View/ChatPages/boardStatusGridPage.tsx | 2 +- .../{propertyList.tsx => propertyValueList.tsx} | 12 ++++++++++-- 4 files changed, 22 insertions(+), 7 deletions(-) rename src/View/Components/{propertyList.tsx => propertyValueList.tsx} (68%) diff --git a/dist/index.js b/dist/index.js index 574caec0..638300ea 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2533,17 +2533,24 @@ return viewBuilder(matchingObjects); } - // src/View/Components/propertyList.tsx + // src/View/Components/propertyValueList.tsx function PropertyValueList(propertyKey, stringEntryObjectConverter, objects, viewBuilder) { const propertyValues = new ListState(); function collectValues() { - propertyValues.clear(); const values = collectObjectValuesForKey( propertyKey, stringEntryObjectConverter, [...objects.value.values()] ); - propertyValues.add(...values); + for (const existingValue of values) { + if (propertyValues.value.has(existingValue)) continue; + propertyValues.add(existingValue); + } + for (const displayedValue of propertyValues.value.values()) { + if (values.includes(displayedValue) == false) { + propertyValues.remove(displayedValue); + } + } } objects.subscribe(() => { collectValues(); diff --git a/src/View/ChatPages/boardKanbanPage.tsx b/src/View/ChatPages/boardKanbanPage.tsx index ac3d019b..e7ab9d5b 100644 --- a/src/View/ChatPages/boardKanbanPage.tsx +++ b/src/View/ChatPages/boardKanbanPage.tsx @@ -2,7 +2,7 @@ import * as React from "bloatless-react"; import BoardViewModel from "../../ViewModel/Pages/boardViewModel"; import { FilteredList } from "../Components/filteredList"; -import { PropertyValueList } from "../Components/propertyList"; +import { PropertyValueList } from "../Components/propertyValueList"; import { TaskCategoryBulkChangeViewModel } from "../../ViewModel/Utility/taskPropertyBulkChangeViewModel"; import TaskViewModel from "../../ViewModel/Pages/taskViewModel"; import { TaskViewModelToEntry } from "../Components/taskEntry"; diff --git a/src/View/ChatPages/boardStatusGridPage.tsx b/src/View/ChatPages/boardStatusGridPage.tsx index c55d9954..515d087e 100644 --- a/src/View/ChatPages/boardStatusGridPage.tsx +++ b/src/View/ChatPages/boardStatusGridPage.tsx @@ -7,7 +7,7 @@ import { import BoardViewModel from "../../ViewModel/Pages/boardViewModel"; import { FilteredList } from "../Components/filteredList"; -import { PropertyValueList } from "../Components/propertyList"; +import { PropertyValueList } from "../Components/propertyValueList"; import TaskViewModel from "../../ViewModel/Pages/taskViewModel"; import { TaskViewModelToEntry } from "../Components/taskEntry"; import { allowDrop } from "../utility"; diff --git a/src/View/Components/propertyList.tsx b/src/View/Components/propertyValueList.tsx similarity index 68% rename from src/View/Components/propertyList.tsx rename to src/View/Components/propertyValueList.tsx index b5551d43..b36fa38a 100644 --- a/src/View/Components/propertyList.tsx +++ b/src/View/Components/propertyValueList.tsx @@ -14,13 +14,21 @@ export function PropertyValueList( const propertyValues: React.ListState = new React.ListState(); function collectValues() { - propertyValues.clear(); const values: string[] = collectObjectValuesForKey( propertyKey, stringEntryObjectConverter, [...objects.value.values()] ); - propertyValues.add(...values); + for (const existingValue of values) { + if (propertyValues.value.has(existingValue)) continue; + propertyValues.add(existingValue); + } + + for (const displayedValue of propertyValues.value.values()) { + if (values.includes(displayedValue) == false) { + propertyValues.remove(displayedValue); + } + } } objects.subscribe(() => {