From d08674187f3554ccccb574895f38af881a409017 Mon Sep 17 00:00:00 2001 From: "ryota.sasazawa" Date: Mon, 16 Dec 2024 19:23:33 +0900 Subject: [PATCH] feat: Add hiddenNodes store and related actions and hooks --- .../erd-core/src/stores/hiddenNodes/actions.ts | 14 ++++++++++++++ .../erd-core/src/stores/hiddenNodes/hooks.ts | 7 +++++++ .../erd-core/src/stores/hiddenNodes/index.ts | 3 +++ .../erd-core/src/stores/hiddenNodes/store.ts | 9 +++++++++ 4 files changed, 33 insertions(+) create mode 100644 frontend/packages/erd-core/src/stores/hiddenNodes/actions.ts create mode 100644 frontend/packages/erd-core/src/stores/hiddenNodes/hooks.ts create mode 100644 frontend/packages/erd-core/src/stores/hiddenNodes/index.ts create mode 100644 frontend/packages/erd-core/src/stores/hiddenNodes/store.ts diff --git a/frontend/packages/erd-core/src/stores/hiddenNodes/actions.ts b/frontend/packages/erd-core/src/stores/hiddenNodes/actions.ts new file mode 100644 index 000000000..e4f6b8f4e --- /dev/null +++ b/frontend/packages/erd-core/src/stores/hiddenNodes/actions.ts @@ -0,0 +1,14 @@ +import { hiddenNodesStore } from './store' + +export const addHiddenNode = (nodeId: string) => { + if (!hiddenNodesStore.nodes.includes(nodeId)) { + hiddenNodesStore.nodes.push(nodeId) + } +} + +export const removeHiddenNode = (nodeId: string) => { + const index = hiddenNodesStore.nodes.indexOf(nodeId) + if (index !== -1) { + hiddenNodesStore.nodes.splice(index, 1) + } +} diff --git a/frontend/packages/erd-core/src/stores/hiddenNodes/hooks.ts b/frontend/packages/erd-core/src/stores/hiddenNodes/hooks.ts new file mode 100644 index 000000000..85957af1c --- /dev/null +++ b/frontend/packages/erd-core/src/stores/hiddenNodes/hooks.ts @@ -0,0 +1,7 @@ +import { useSnapshot } from 'valtio' +import { hiddenNodesStore } from './store' + +export const useHiddenNodesStore = () => { + const { nodes } = useSnapshot(hiddenNodesStore) + return nodes +} diff --git a/frontend/packages/erd-core/src/stores/hiddenNodes/index.ts b/frontend/packages/erd-core/src/stores/hiddenNodes/index.ts new file mode 100644 index 000000000..5d8918fa2 --- /dev/null +++ b/frontend/packages/erd-core/src/stores/hiddenNodes/index.ts @@ -0,0 +1,3 @@ +export * from './store' +export * from './actions' +export * from './hooks' diff --git a/frontend/packages/erd-core/src/stores/hiddenNodes/store.ts b/frontend/packages/erd-core/src/stores/hiddenNodes/store.ts new file mode 100644 index 000000000..6a7e59e74 --- /dev/null +++ b/frontend/packages/erd-core/src/stores/hiddenNodes/store.ts @@ -0,0 +1,9 @@ +import { proxy } from 'valtio' + +type HiddenNodesStore = { + nodes: string[] +} + +export const hiddenNodesStore = proxy({ + nodes: [], +})