Files
grafana/public/app/features/dashboard/components/DashboardSettings/LinksSettings.tsx
Ashley Harrison 47f8717149 React: Use new JSX transform (#88802)
* 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
2024-06-25 12:43:47 +01:00

58 lines
1.7 KiB
TypeScript

import { useState } from 'react';
import { locationService } from '@grafana/runtime';
import { Page } from 'app/core/components/Page/Page';
import { NEW_LINK } from 'app/features/dashboard-scene/settings/links/utils';
import { LinkSettingsEdit, LinkSettingsList } from '../LinksSettings';
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, { ...NEW_LINK }];
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 = sectionNav.node.parentItem;
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,
};
const parentUrl = sectionNav.node.url;
pageNav.parentItem = sectionNav.node.parentItem && {
...sectionNav.node.parentItem,
url: parentUrl,
};
}
return (
<Page navModel={sectionNav} pageNav={pageNav}>
{!isEditing && <LinkSettingsList dashboard={dashboard} onNew={onNew} onEdit={onEdit} />}
{isEditing && <LinkSettingsEdit dashboard={dashboard} editLinkIdx={editIndex} onGoBack={onGoBack} />}
</Page>
);
}