/
vshmidt
/
cloudbeaver
Обзор
Документация
Войти
/
vshmidt
/
cloudbeaver
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
devel
webapp/packages/plugin-navigation-tree/src/TreeNew/useTreeState.ts
58 строк
2 KB
Sychev Andrey
dbeaver/pro#7667 feat: add tree toolbar functionality to new tree (#3981)
24 дек 2025, 16:04
Не верифицирован
24 дек 2025, 16:04
cd3cc2e
Код
Авторство
О чём код?
/* * CloudBeaver - Cloud Database Manager * Copyright (C) 2020-2025 DBeaver Corp and others * * Licensed under the Apache License, Version 2.0. * you may not use this file except in compliance with the License. */ import { action, observable } from 'mobx'; import { useState } from 'react'; import { useObservableRef } from '@cloudbeaver/core-blocks'; import { MetadataMap } from '@cloudbeaver/core-utils'; import type { INodeState } from './INodeState.js'; import type { TreeState } from './TreeState.js'; export interface ITreeState { getState(id: string): Readonly<INodeState>; updateState(id: string, state: Partial<INodeState>): void; updateAllState(state: Partial<INodeState>): void; } export function useTreeState(externalState?: TreeState): ITreeState { const [innerState] = useState( () => new MetadataMap<string, INodeState>(() => observable({ expanded: false, selected: false, showInFilter: false, }), ), ); const state = externalState ?? innerState; return useObservableRef( () => ({ getState(id: string): Readonly<INodeState> { return state.get(id); }, updateState(id: string, stateUpdate: Partial<INodeState>): void { Object.assign(this.getState(id), stateUpdate); }, updateAllState(stateUpdate: Partial<INodeState>): void { for (const nodeState of state.values()) { Object.assign(nodeState, stateUpdate); } }, }), { state: observable.ref, updateState: action.bound, updateAllState: action.bound, }, { state }, ); }