mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* remove old page component * add test to check initDashboard is only called once (prevent variables loading twice) * add help node * update unit tests * remove last mentions of topnav * fix unit tests * remove unused props from ButtonRow interface * remove prop from test
52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import React, { useState } from 'react';
|
|
|
|
import { NavModelItem } from '@grafana/data';
|
|
import { locationService } from '@grafana/runtime';
|
|
import { Page } from 'app/core/components/Page/Page';
|
|
|
|
import { LinkSettingsEdit, LinkSettingsList } from '../LinksSettings';
|
|
import { newLink } from '../LinksSettings/LinkSettingsEdit';
|
|
|
|
import { SettingsPageProps } from './types';
|
|
|
|
export type LinkSettingsMode = 'list' | 'new' | 'edit';
|
|
|
|
export function LinksSettings({ dashboard, sectionNav, editIndex }: SettingsPageProps) {
|
|
const [isNew, setIsNew] = useState<boolean>(false);
|
|
|
|
const onGoBack = () => {
|
|
setIsNew(false);
|
|
locationService.partial({ editIndex: undefined });
|
|
};
|
|
|
|
const onNew = () => {
|
|
dashboard.links = [...dashboard.links, { ...newLink }];
|
|
setIsNew(true);
|
|
locationService.partial({ editIndex: dashboard.links.length - 1 });
|
|
};
|
|
|
|
const onEdit = (idx: number) => {
|
|
setIsNew(false);
|
|
locationService.partial({ editIndex: idx });
|
|
};
|
|
|
|
const isEditing = editIndex !== undefined;
|
|
|
|
let pageNav: NavModelItem | undefined;
|
|
if (isEditing) {
|
|
const title = isNew ? 'New link' : 'Edit link';
|
|
const description = isNew ? 'Create a new link on your dashboard' : 'Edit a specific link of your dashboard';
|
|
pageNav = {
|
|
text: title,
|
|
subTitle: description,
|
|
};
|
|
}
|
|
|
|
return (
|
|
<Page navModel={sectionNav} pageNav={pageNav}>
|
|
{!isEditing && <LinkSettingsList dashboard={dashboard} onNew={onNew} onEdit={onEdit} />}
|
|
{isEditing && <LinkSettingsEdit dashboard={dashboard} editLinkIdx={editIndex} onGoBack={onGoBack} />}
|
|
</Page>
|
|
);
|
|
}
|