Files
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

48 lines
1.3 KiB
TypeScript

import { useState } from 'react';
import { arrayUtils } from '@grafana/data';
import { DashboardLink } from '@grafana/schema';
import { DashboardLinkList } from 'app/features/dashboard-scene/settings/links/DashboardLinkList';
import { DashboardModel } from '../../state/DashboardModel';
type LinkSettingsListProps = {
dashboard: DashboardModel;
onNew: () => void;
onEdit: (idx: number) => void;
};
/**
* Used in DashboardSettings to display the list of links.
* It updates the DashboardModel instance when links are added, edited, duplicated or deleted.
*/
export const LinkSettingsList = ({ dashboard, onNew, onEdit }: LinkSettingsListProps) => {
const [links, setLinks] = useState(dashboard.links);
const moveLink = (idx: number, direction: number) => {
dashboard.links = arrayUtils.moveItemImmutably(links, idx, idx + direction);
setLinks(dashboard.links);
};
const duplicateLink = (link: DashboardLink) => {
dashboard.links = [...links, { ...link }];
setLinks(dashboard.links);
};
const deleteLink = (idx: number) => {
dashboard.links = [...links.slice(0, idx), ...links.slice(idx + 1)];
setLinks(dashboard.links);
};
return (
<DashboardLinkList
links={links}
onNew={onNew}
onEdit={onEdit}
onDuplicate={duplicateLink}
onDelete={deleteLink}
onOrderChange={moveLink}
/>
);
};