grafana/public/app/features/manage-dashboards/components/ImportDashboardLibraryPanelsList.tsx
Josh Hunt 3c6e0e8ef8
Chore: ESlint import order (#44959)
* Add and configure eslint-plugin-import

* Fix the lint:ts npm command

* Autofix + prettier all the files

* Manually fix remaining files

* Move jquery code in jest-setup to external file to safely reorder imports

* Resolve issue caused by circular dependencies within Prometheus

* Update .betterer.results

* Fix missing // @ts-ignore

* ignore iconBundle.ts

* Fix missing // @ts-ignore
2022-04-22 14:33:13 +01:00

61 lines
1.6 KiB
TypeScript

import { css } from '@emotion/css';
import React, { ReactElement } from 'react';
import { GrafanaTheme2 } from '@grafana/data';
import { Field, useStyles2 } from '@grafana/ui';
import { LibraryPanelCard } from '../../library-panels/components/LibraryPanelCard/LibraryPanelCard';
import { LibraryPanelInput, LibraryPanelInputState } from '../state/reducers';
interface ImportDashboardLibraryPanelsListProps {
inputs: LibraryPanelInput[];
label: string;
description: string;
folderName?: string;
}
export function ImportDashboardLibraryPanelsList({
inputs,
label,
description,
folderName,
}: ImportDashboardLibraryPanelsListProps): ReactElement | null {
const styles = useStyles2(getStyles);
if (!Boolean(inputs?.length)) {
return null;
}
return (
<div className={styles.spacer}>
<Field label={label} description={description}>
<>
{inputs.map((input, index) => {
const libraryPanelIndex = `elements[${index}]`;
const libraryPanel =
input.state === LibraryPanelInputState.New
? { ...input.model, meta: { ...input.model.meta, folderName: folderName ?? 'General' } }
: { ...input.model };
return (
<div className={styles.item} key={libraryPanelIndex}>
<LibraryPanelCard libraryPanel={libraryPanel} onClick={() => undefined} />
</div>
);
})}
</>
</Field>
</div>
);
}
function getStyles(theme: GrafanaTheme2) {
return {
spacer: css`
margin-bottom: ${theme.spacing(2)};
`,
item: css`
margin-bottom: ${theme.spacing(1)};
`,
};
}