NestedFolderPicker: Allow for excluding certain uids (#72019)

* exclude some uids from nested folder picker so you can't move a folder to itself

* rename excludedUids to excludeUIDs
This commit is contained in:
Ashley Harrison
2023-07-21 13:10:23 +01:00
committed by GitHub
parent 8f464ac66e
commit f078a0bb40
3 changed files with 19 additions and 8 deletions

View File

@@ -61,7 +61,7 @@ export const MoveModal = ({ onConfirm, onDismiss, selectedItems, ...props }: Pro
<Field label={t('browse-dashboards.action.move-modal-field-label', 'Folder name')}>
{config.featureToggles.nestedFolderPicker ? (
<NestedFolderPicker value={moveTarget} onChange={handleFolderChange} />
<NestedFolderPicker value={moveTarget} onChange={handleFolderChange} excludeUIDs={selectedFolders} />
) : (
<FolderPicker allowEmpty onChange={handleFolderChange} />
)}

View File

@@ -144,10 +144,11 @@ export function createFlatTree(
childrenByUID: BrowseDashboardsState['childrenByParentUID'],
openFolders: Record<string, boolean>,
level = 0,
excludeKinds: Array<DashboardViewItemWithUIItems['kind'] | UIDashboardViewItem['uiKind']> = []
excludeKinds: Array<DashboardViewItemWithUIItems['kind'] | UIDashboardViewItem['uiKind']> = [],
excludeUIDs: string[] = []
): DashboardsTreeItem[] {
function mapItem(item: DashboardViewItem, parentUID: string | undefined, level: number): DashboardsTreeItem[] {
if (excludeKinds.includes(item.kind)) {
if (excludeKinds.includes(item.kind) || excludeUIDs.includes(item.uid)) {
return [];
}
@@ -157,7 +158,8 @@ export function createFlatTree(
childrenByUID,
openFolders,
level + 1,
excludeKinds
excludeKinds,
excludeUIDs
);
const isOpen = Boolean(openFolders[item.uid]);