2024-06-25 06:43:47 -05:00
|
|
|
import { useMemo } from 'react';
|
2023-05-24 04:41:03 -05:00
|
|
|
|
|
|
|
import { Page } from 'app/core/components/Page/Page';
|
|
|
|
import { GrafanaRouteComponentProps } from 'app/core/navigation/types';
|
|
|
|
import { buildNavModel, getAlertingTabID } from 'app/features/folders/state/navModel';
|
|
|
|
import { useSelector } from 'app/types';
|
|
|
|
|
|
|
|
import { AlertsFolderView } from '../alerting/unified/AlertsFolderView';
|
|
|
|
|
2023-05-31 11:03:54 -05:00
|
|
|
import { useGetFolderQuery, useSaveFolderMutation } from './api/browseDashboardsAPI';
|
2023-05-24 04:41:03 -05:00
|
|
|
import { FolderActionsButton } from './components/FolderActionsButton';
|
|
|
|
|
|
|
|
export interface OwnProps extends GrafanaRouteComponentProps<{ uid: string }> {}
|
|
|
|
|
|
|
|
export function BrowseFolderAlertingPage({ match }: OwnProps) {
|
|
|
|
const { uid: folderUID } = match.params;
|
2023-05-31 11:03:54 -05:00
|
|
|
const { data: folderDTO } = useGetFolderQuery(folderUID);
|
2023-05-24 04:41:03 -05:00
|
|
|
const folder = useSelector((state) => state.folder);
|
2023-05-31 11:03:54 -05:00
|
|
|
const [saveFolder] = useSaveFolderMutation();
|
2023-05-24 04:41:03 -05:00
|
|
|
|
|
|
|
const navModel = useMemo(() => {
|
|
|
|
if (!folderDTO) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
const model = buildNavModel(folderDTO);
|
|
|
|
|
|
|
|
// Set the "Alerting" tab to active
|
|
|
|
const alertingTabID = getAlertingTabID(folderDTO.uid);
|
|
|
|
const alertingTab = model.children?.find((child) => child.id === alertingTabID);
|
|
|
|
if (alertingTab) {
|
|
|
|
alertingTab.active = true;
|
|
|
|
}
|
|
|
|
return model;
|
|
|
|
}, [folderDTO]);
|
|
|
|
|
2023-05-31 11:03:54 -05:00
|
|
|
const onEditTitle = folderUID
|
|
|
|
? async (newValue: string) => {
|
|
|
|
if (folderDTO) {
|
|
|
|
const result = await saveFolder({
|
|
|
|
...folderDTO,
|
|
|
|
title: newValue,
|
|
|
|
});
|
|
|
|
if ('error' in result) {
|
|
|
|
throw result.error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
: undefined;
|
|
|
|
|
2023-05-24 04:41:03 -05:00
|
|
|
return (
|
|
|
|
<Page
|
|
|
|
navId="dashboards/browse"
|
|
|
|
pageNav={navModel}
|
2023-05-31 11:03:54 -05:00
|
|
|
onEditTitle={onEditTitle}
|
2023-05-24 04:41:03 -05:00
|
|
|
actions={<>{folderDTO && <FolderActionsButton folder={folderDTO} />}</>}
|
|
|
|
>
|
2023-05-31 11:03:54 -05:00
|
|
|
<Page.Contents>
|
2023-05-24 04:41:03 -05:00
|
|
|
<AlertsFolderView folder={folder} />
|
|
|
|
</Page.Contents>
|
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default BrowseFolderAlertingPage;
|