From 09eff80f83bbcd63eff2d1c820c66a94fdf09834 Mon Sep 17 00:00:00 2001 From: Viktor Rozaev Date: Wed, 30 Oct 2024 14:37:43 +0100 Subject: [PATCH] feat(PoolTreeSuggestControl): now we could select multiply pool trees on clique creation/edit [#841] --- .../PoolSuggestControl/PoolSuggestControl.tsx | 24 +++++---- .../PoolTreeSuggestControl.tsx | 14 ++++-- .../ui/components/Dialog/df-dialog-utils.ts | 50 +++++++++++++++++-- packages/ui/src/ui/hooks/global-pool-trees.ts | 2 +- .../ChytPageClique/ChytPageCliqueSpeclet.tsx | 36 +++++++++---- .../ui/src/ui/pages/chyt/ChytPageTopRow.tsx | 9 ++-- .../TableMergeSortModal/TableMergeModal.tsx | 8 +-- .../TableMergeSortModal/TableSortModal.tsx | 8 +-- 8 files changed, 109 insertions(+), 42 deletions(-) diff --git a/packages/ui/src/ui/components/Dialog/controls/PoolSuggestControl/PoolSuggestControl.tsx b/packages/ui/src/ui/components/Dialog/controls/PoolSuggestControl/PoolSuggestControl.tsx index 1d4e84094..8db8701e8 100644 --- a/packages/ui/src/ui/components/Dialog/controls/PoolSuggestControl/PoolSuggestControl.tsx +++ b/packages/ui/src/ui/components/Dialog/controls/PoolSuggestControl/PoolSuggestControl.tsx @@ -57,11 +57,13 @@ export function PoolSuggestControl(props: Props) { const [poolNames, setPoolNames] = React.useState>([]); - const loadedPools = useLoadedPools(cluster, poolTrees); + const names = useLoadedPools(cluster, poolTrees); React.useEffect( function onPoolLoaded() { - const {names} = loadedPools; + if (!names) { + return; + } const noRoot = filter_(names, (item) => '' !== item); const valueIndex = indexOf_(noRoot, value); if (value && -1 === valueIndex) { @@ -73,7 +75,7 @@ export function PoolSuggestControl(props: Props) { } }, // value should not affect the useEffect - [loadedPools, setPoolNames, onChange, calculateValueOnPoolsLoaded /*, value */], + [names && names.join(), setPoolNames, onChange, calculateValueOnPoolsLoaded /*, value */], ); const getItems = React.useCallback( @@ -121,13 +123,19 @@ PoolSuggestControl.isEmpty = (value: Props['value']) => { return !value; }; -function useLoadedPools(cluster?: string, poolTrees: string[] = []): {names: Array} { - const [poolNames, setPoolNames] = React.useState>([]); +function useLoadedPools(cluster?: string, poolTrees?: string[]): Array | null { + poolTrees = poolTrees || []; + + const [poolNames, setPoolNames] = React.useState | null>(null); const defaultPoolTree = useDefaultPoolTree(); React.useMemo(() => { - const localPoolTrees: string[] = poolTrees.length ? poolTrees : defaultPoolTree ? [defaultPoolTree] : []; + const localPoolTrees: string[] = poolTrees.length + ? poolTrees + : defaultPoolTree + ? [defaultPoolTree] + : []; if (!localPoolTrees.length) { return; @@ -150,9 +158,7 @@ function useLoadedPools(cluster?: string, poolTrees: string[] = []): {names: Arr }); }, [cluster, defaultPoolTree, poolTrees.join()]); - return { - names: poolNames, - }; + return poolNames; } function fetchPoolNamesByCluster(cluster: string, poolTrees: string[]): Promise { diff --git a/packages/ui/src/ui/components/Dialog/controls/PoolTreeSuggestControl/PoolTreeSuggestControl.tsx b/packages/ui/src/ui/components/Dialog/controls/PoolTreeSuggestControl/PoolTreeSuggestControl.tsx index 809234302..253e98bba 100644 --- a/packages/ui/src/ui/components/Dialog/controls/PoolTreeSuggestControl/PoolTreeSuggestControl.tsx +++ b/packages/ui/src/ui/components/Dialog/controls/PoolTreeSuggestControl/PoolTreeSuggestControl.tsx @@ -6,8 +6,9 @@ import {Select} from '@gravity-ui/uikit'; import {DialogControlProps} from '../../../../components/Dialog/Dialog.types'; import {getAllPoolTreeNames} from '../../../../store/selectors/global'; +import {usePoolTreesLoaded} from '../../../../hooks/global-pool-trees'; -type Props = DialogControlProps & { +type Props = DialogControlProps & { disabled?: boolean; }; @@ -15,6 +16,8 @@ export function PoolTreeSuggestControl(props: Props) { const {value, onChange, disabled, placeholder} = props; const treeNames = useSelector(getAllPoolTreeNames); + usePoolTreesLoaded(); + const items = React.useMemo(() => { return map_(treeNames, (value) => { return {value, content: value}; @@ -24,20 +27,21 @@ export function PoolTreeSuggestControl(props: Props) { return (