mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* update eslint, tsconfig + esbuild to handle new jsx transform * remove thing that breaks the new jsx transform * remove react imports * adjust grafana-icons build * is this the correct syntax? * try this * well this was much easier than expected... * change grafana-plugin-configs webpack config * fixes * fix lockfile * fix 2 more violations * use path.resolve instead of require.resolve * remove react import * fix react imports * more fixes * remove React import * remove import React from docs * remove another react import
60 lines
1.8 KiB
TypeScript
60 lines
1.8 KiB
TypeScript
import { AnnotationQuery, getDataSourceRef, NavModelItem } from '@grafana/data';
|
|
import { getDataSourceSrv, locationService } from '@grafana/runtime';
|
|
import { Page } from 'app/core/components/Page/Page';
|
|
|
|
import { DashboardModel } from '../../state';
|
|
import { AnnotationSettingsEdit, AnnotationSettingsList, newAnnotationName } from '../AnnotationSettings';
|
|
|
|
import { SettingsPageProps } from './types';
|
|
|
|
export function AnnotationsSettings({ dashboard, editIndex, sectionNav }: SettingsPageProps) {
|
|
const onNew = () => {
|
|
const newAnnotation: AnnotationQuery = {
|
|
name: newAnnotationName,
|
|
enable: true,
|
|
datasource: getDataSourceRef(getDataSourceSrv().getInstanceSettings(null)!),
|
|
iconColor: 'red',
|
|
};
|
|
|
|
dashboard.annotations.list = [...dashboard.annotations.list, { ...newAnnotation }];
|
|
locationService.partial({ editIndex: dashboard.annotations.list.length - 1 });
|
|
};
|
|
|
|
const onEdit = (idx: number) => {
|
|
locationService.partial({ editIndex: idx });
|
|
};
|
|
|
|
const isEditing = editIndex != null && editIndex < dashboard.annotations.list.length;
|
|
|
|
return (
|
|
<Page navModel={sectionNav} pageNav={getSubPageNav(dashboard, editIndex, sectionNav.node)}>
|
|
{!isEditing && <AnnotationSettingsList dashboard={dashboard} onNew={onNew} onEdit={onEdit} />}
|
|
{isEditing && <AnnotationSettingsEdit dashboard={dashboard} editIdx={editIndex!} />}
|
|
</Page>
|
|
);
|
|
}
|
|
|
|
function getSubPageNav(
|
|
dashboard: DashboardModel,
|
|
editIndex: number | undefined,
|
|
node: NavModelItem
|
|
): NavModelItem | undefined {
|
|
const parentItem = node.parentItem;
|
|
if (editIndex == null) {
|
|
return parentItem;
|
|
}
|
|
|
|
const editItem = dashboard.annotations.list[editIndex];
|
|
if (editItem) {
|
|
return {
|
|
text: editItem.name,
|
|
parentItem: parentItem && {
|
|
...parentItem,
|
|
url: node.url,
|
|
},
|
|
};
|
|
}
|
|
|
|
return undefined;
|
|
}
|