From aa29fa1bd2992bdfec1f4dfdef7b40d76e03c7c0 Mon Sep 17 00:00:00 2001 From: Aleksei Potsetsuev Date: Thu, 12 Sep 2024 21:13:12 +0800 Subject: [PATCH] chore: review fixes --- .../src/SettingsPanel/SettingsList.tsx | 24 ++++--------------- .../src/SettingsPanel/getGroupsFromTree.ts | 21 ++++++++++++++++ 2 files changed, 26 insertions(+), 19 deletions(-) create mode 100644 webapp/packages/plugin-settings-panel/src/SettingsPanel/getGroupsFromTree.ts diff --git a/webapp/packages/plugin-settings-panel/src/SettingsPanel/SettingsList.tsx b/webapp/packages/plugin-settings-panel/src/SettingsPanel/SettingsList.tsx index 3104934c114..ccd1ea75d25 100644 --- a/webapp/packages/plugin-settings-panel/src/SettingsPanel/SettingsList.tsx +++ b/webapp/packages/plugin-settings-panel/src/SettingsPanel/SettingsList.tsx @@ -8,14 +8,10 @@ import { observer } from 'mobx-react-lite'; import { Container, TextPlaceholder, useTranslate } from '@cloudbeaver/core-blocks'; -import { - type ISettingDescription, - type ISettingsSource, - ROOT_SETTINGS_GROUP, - type SettingsGroup as SettingsGroupType, -} from '@cloudbeaver/core-settings'; +import { type ISettingDescription, type ISettingsSource, type SettingsGroup as SettingsGroupType } from '@cloudbeaver/core-settings'; import type { ITreeData, ITreeFilter } from '@cloudbeaver/plugin-navigation-tree'; +import { getGroupsFromTree } from './getGroupsFromTree'; import { SettingsGroup } from './SettingsGroup'; import { useTreeScrollSync } from './useTreeScrollSync'; @@ -29,25 +25,15 @@ interface Props { export const SettingsList = observer(function SettingsList({ treeData, treeFilter, source, settings, onSettingsOpen }) { const translate = useTranslate(); - const list = []; - const groups = [...treeData.getChildren(treeData.rootId)]; const ref = useTreeScrollSync(treeData, onSettingsOpen); - - while (groups.length) { - const groupId = groups[0]; - groups.splice(0, 1, ...treeData.getChildren(groupId)); - - const group = ROOT_SETTINGS_GROUP.get(groupId)!; - - list.push(group); - } + const groups = Array.from(getGroupsFromTree(treeData, treeData.getChildren(treeData.rootId))); return ( - {list.map(group => ( + {groups.map(group => ( ))} - {list.length === 0 && {translate('plugin_settings_panel_no_settings')}} + {groups.length === 0 && {translate('plugin_settings_panel_no_settings')}}
); diff --git a/webapp/packages/plugin-settings-panel/src/SettingsPanel/getGroupsFromTree.ts b/webapp/packages/plugin-settings-panel/src/SettingsPanel/getGroupsFromTree.ts new file mode 100644 index 00000000000..4ae28e709f3 --- /dev/null +++ b/webapp/packages/plugin-settings-panel/src/SettingsPanel/getGroupsFromTree.ts @@ -0,0 +1,21 @@ +/* + * CloudBeaver - Cloud Database Manager + * Copyright (C) 2020-2024 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 { ROOT_SETTINGS_GROUP, type SettingsGroup as SettingsGroupType } from '@cloudbeaver/core-settings'; +import type { ITreeData } from '@cloudbeaver/plugin-navigation-tree'; + +export function* getGroupsFromTree(treeData: ITreeData, groups: string[]): IterableIterator { + for (const groupId of groups) { + const group = ROOT_SETTINGS_GROUP.get(groupId); + + if (group) { + yield group; + } + + yield* getGroupsFromTree(treeData, treeData.getChildren(groupId)); + } +}