Files
grafana/public/app/features/support-bundles/SupportBundlesCreate.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

100 lines
3.4 KiB
TypeScript

import { useEffect } from 'react';
import { connect, ConnectedProps } from 'react-redux';
import { Button, Field, Checkbox, LinkButton, Stack, Alert } from '@grafana/ui';
import { Form } from 'app/core/components/Form/Form';
import { Page } from 'app/core/components/Page/Page';
import { StoreState } from 'app/types';
import { loadSupportBundleCollectors, createSupportBundle } from './state/actions';
const subTitle = (
<span>
Choose the components for the support bundle. The support bundle will be available for 3 days after creation.
</span>
);
const mapStateToProps = (state: StoreState) => {
return {
collectors: state.supportBundles.supportBundleCollectors,
isLoading: state.supportBundles.createBundlePageLoading,
loadCollectorsError: state.supportBundles.loadBundlesError,
createBundleError: state.supportBundles.createBundleError,
};
};
const mapDispatchToProps = {
loadSupportBundleCollectors,
createSupportBundle,
};
const connector = connect(mapStateToProps, mapDispatchToProps);
type Props = ConnectedProps<typeof connector>;
export const SupportBundlesCreateUnconnected = ({
collectors,
isLoading,
loadCollectorsError,
createBundleError,
loadSupportBundleCollectors,
createSupportBundle,
}: Props): JSX.Element => {
const onSubmit = (data: Record<string, boolean>) => {
const selectedLabelsArray = Object.keys(data).filter((key) => data[key]);
createSupportBundle({ collectors: selectedLabelsArray });
};
useEffect(() => {
loadSupportBundleCollectors();
}, [loadSupportBundleCollectors]);
// turn components into a uuid -> enabled map
const values: Record<string, boolean> = collectors.reduce((acc, curr) => {
return { ...acc, [curr.uid]: curr.default };
}, {});
return (
<Page navId="support-bundles" pageNav={{ text: 'Create support bundle' }} subTitle={subTitle}>
<Page.Contents isLoading={isLoading}>
{loadCollectorsError && <Alert title={loadCollectorsError} severity="error" />}
{createBundleError && <Alert title={createBundleError} severity="error" />}
{!!collectors.length && (
<Form defaultValues={values} onSubmit={onSubmit} validateOn="onSubmit">
{({ register }) => {
return (
<>
{[...collectors]
.sort((a, b) => a.displayName.localeCompare(b.displayName))
.map((component) => {
return (
<Field key={component.uid}>
<Checkbox
{...register(component.uid)}
label={component.displayName}
id={component.uid}
description={component.description}
defaultChecked={component.default}
disabled={component.includedByDefault}
/>
</Field>
);
})}
<Stack>
<Button type="submit">Create</Button>
<LinkButton href="/support-bundles" variant="secondary">
Cancel
</LinkButton>
</Stack>
</>
);
}}
</Form>
)}
</Page.Contents>
</Page>
);
};
export default connector(SupportBundlesCreateUnconnected);