2022-09-22 09:35:04 -03:00
|
|
|
import React from 'react';
|
2022-12-14 09:12:09 -03:00
|
|
|
import { UseFormRegister } from 'react-hook-form';
|
2022-09-22 09:35:04 -03:00
|
|
|
|
2023-07-25 13:17:39 +03:00
|
|
|
import { TimeRange } from '@grafana/data/src';
|
2022-09-22 09:35:04 -03:00
|
|
|
import { selectors as e2eSelectors } from '@grafana/e2e-selectors/src';
|
2023-07-25 13:17:39 +03:00
|
|
|
import { FieldSet, Label, Switch, TimeRangeInput, VerticalGroup } from '@grafana/ui/src';
|
2022-09-22 09:35:04 -03:00
|
|
|
import { Layout } from '@grafana/ui/src/components/Layout/Layout';
|
2023-02-24 12:36:29 -03:00
|
|
|
|
2023-08-03 16:41:26 +03:00
|
|
|
import { trackDashboardSharingActionPerType } from '../../analytics';
|
|
|
|
|
import { shareDashboardType } from '../../utils';
|
|
|
|
|
|
2023-03-22 10:49:34 -03:00
|
|
|
import { ConfigPublicDashboardForm } from './ConfigPublicDashboard';
|
2023-02-24 12:36:29 -03:00
|
|
|
|
|
|
|
|
const selectors = e2eSelectors.pages.ShareDashboardModal.PublicDashboard;
|
2022-12-14 09:12:09 -03:00
|
|
|
|
2022-09-22 09:35:04 -03:00
|
|
|
export const Configuration = ({
|
|
|
|
|
disabled,
|
2023-02-24 12:36:29 -03:00
|
|
|
onChange,
|
2022-12-14 09:12:09 -03:00
|
|
|
register,
|
2023-07-25 13:17:39 +03:00
|
|
|
timeRange,
|
2022-09-22 09:35:04 -03:00
|
|
|
}: {
|
|
|
|
|
disabled: boolean;
|
2023-03-22 10:49:34 -03:00
|
|
|
onChange: (name: keyof ConfigPublicDashboardForm, value: boolean) => void;
|
|
|
|
|
register: UseFormRegister<ConfigPublicDashboardForm>;
|
2023-07-25 13:17:39 +03:00
|
|
|
timeRange: TimeRange;
|
2022-09-22 09:35:04 -03:00
|
|
|
}) => {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2023-07-25 13:17:39 +03:00
|
|
|
<FieldSet disabled={disabled}>
|
2022-09-22 09:35:04 -03:00
|
|
|
<VerticalGroup spacing="md">
|
2023-02-24 12:36:29 -03:00
|
|
|
<Layout orientation={1} spacing="xs" justify="space-between">
|
|
|
|
|
<Label description="The public dashboard uses the default time range settings of the dashboard">
|
2023-01-18 10:54:19 -03:00
|
|
|
Default time range
|
|
|
|
|
</Label>
|
2022-09-22 09:35:04 -03:00
|
|
|
<TimeRangeInput value={timeRange} disabled onChange={() => {}} />
|
|
|
|
|
</Layout>
|
2023-02-24 12:36:29 -03:00
|
|
|
<Layout orientation={0} spacing="sm">
|
|
|
|
|
<Switch
|
|
|
|
|
{...register('isTimeSelectionEnabled')}
|
|
|
|
|
data-testid={selectors.EnableTimeRangeSwitch}
|
2023-03-22 10:49:34 -03:00
|
|
|
onChange={(e) => {
|
2023-08-03 16:41:26 +03:00
|
|
|
trackDashboardSharingActionPerType(
|
|
|
|
|
e.currentTarget.checked ? 'enable_time' : 'disable_time',
|
|
|
|
|
shareDashboardType.publicDashboard
|
|
|
|
|
);
|
2023-03-22 10:49:34 -03:00
|
|
|
onChange('isTimeSelectionEnabled', e.currentTarget.checked);
|
|
|
|
|
}}
|
2023-02-24 12:36:29 -03:00
|
|
|
/>
|
2023-01-18 10:54:19 -03:00
|
|
|
<Label description="Allow viewers to change time range">Time range picker enabled</Label>
|
|
|
|
|
</Layout>
|
2023-02-24 12:36:29 -03:00
|
|
|
<Layout orientation={0} spacing="sm">
|
2022-10-21 13:42:14 -06:00
|
|
|
<Switch
|
2022-12-14 09:12:09 -03:00
|
|
|
{...register('isAnnotationsEnabled')}
|
|
|
|
|
onChange={(e) => {
|
2023-08-03 16:41:26 +03:00
|
|
|
trackDashboardSharingActionPerType(
|
|
|
|
|
e.currentTarget.checked ? 'enable_annotations' : 'disable_annotations',
|
|
|
|
|
shareDashboardType.publicDashboard
|
|
|
|
|
);
|
2023-02-24 12:36:29 -03:00
|
|
|
onChange('isAnnotationsEnabled', e.currentTarget.checked);
|
2022-10-21 13:42:14 -06:00
|
|
|
}}
|
2022-12-14 09:12:09 -03:00
|
|
|
data-testid={selectors.EnableAnnotationsSwitch}
|
2022-10-21 13:42:14 -06:00
|
|
|
/>
|
2023-02-24 12:36:29 -03:00
|
|
|
<Label description="Show annotations on public dashboard">Show annotations</Label>
|
2022-09-22 09:35:04 -03:00
|
|
|
</Layout>
|
|
|
|
|
</VerticalGroup>
|
|
|
|
|
</FieldSet>
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|