mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
* 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
29 lines
595 B
TypeScript
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;
|
|
}
|