grafana/public/app/features/browse-dashboards/state/utils.ts
Ashley Harrison 02086e843f
Nested folders: hook up move/delete logic properly (#67648)
* clear selection post move/delete

* move actions out of rtk-query

* move findItems, create selectors, refetch children when moving/deleting

* cleaner syntax

* remove unnecessary function, just put logic in the selector

* handle moving/deleting from the root

* slightly cleaner

* handle when rootItems are undefined

* handle 'general' in the fetchChildren reducer

* only refresh at the end

* don't need thunk api
2023-05-02 17:22:51 +01:00

29 lines
595 B
TypeScript

import { DashboardViewItem } from 'app/features/search/types';
export function findItem(
rootItems: DashboardViewItem[],
childrenByUID: Record<string, DashboardViewItem[] | undefined>,
uid: string
): DashboardViewItem | undefined {
for (const item of rootItems) {
if (item.uid === uid) {
return item;
}
}
for (const parentUID in childrenByUID) {
const children = childrenByUID[parentUID];
if (!children) {
continue;
}
for (const child of children) {
if (child.uid === uid) {
return child;
}
}
}
return undefined;
}