Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] [Share] Cleanup share model UI and warning logic (#196401) #197532

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -237,18 +237,6 @@ export const reportingExportModalProvider = ({
generateExportUrl: generateExportUrlPDF,
reportType: 'printablePdfV2',
requiresSavedState,
helpText: (
<FormattedMessage
id="reporting.printablePdfV2.helpText"
defaultMessage="Select the file type you would like to export for this visualization."
/>
),
generateExportButton: (
<FormattedMessage
id="reporting.printablePdfV2.generateButtonLabel"
defaultMessage="Export file"
/>
),
layoutOption: objectType === 'dashboard' ? ('print' as const) : undefined,
renderLayoutOptionSwitch: objectType === 'dashboard',
renderCopyURLButton: true,
Expand All @@ -268,15 +256,6 @@ export const reportingExportModalProvider = ({
generateExportUrl: generateExportUrlPNG,
reportType: 'pngV2',
requiresSavedState,
helpText: (
<FormattedMessage
id="reporting.pngV2.helpText"
defaultMessage="Select the file type you would like to export for this visualization."
/>
),
generateExportButton: (
<FormattedMessage id="reporting.pngV2.generateButtonLabel" defaultMessage="Export file" />
),
layoutOption: objectType === 'dashboard' ? ('print' as const) : undefined,
renderCopyURLButton: true,
});
Expand Down
98 changes: 67 additions & 31 deletions src/plugins/share/public/components/tabs/export/export_content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,16 @@ const ExportContentUi = ({
const [usePrintLayout, setPrintLayout] = useState(false);

const radioOptions = useMemo(() => {
return aggregateReportTypes
.filter(({ reportType }) => reportType)
.map(({ reportType, label }) => {
return { id: reportType, label, 'data-test-subj': `${reportType}-radioOption` };
}) as EuiRadioGroupOption[];
return aggregateReportTypes.reduce<EuiRadioGroupOption[]>((acc, { reportType, label }) => {
if (reportType) {
acc.push({
id: reportType,
label,
'data-test-subj': `${reportType}-radioOption`,
});
}
return acc;
}, []);
}, [aggregateReportTypes]);

const [selectedRadio, setSelectedRadio] = useState<SupportedExportTypes>(
Expand All @@ -62,6 +67,7 @@ const ExportContentUi = ({
const {
generateExportButton,
helpText,
warnings = [],
renderCopyURLButton,
generateExport,
generateExportUrl,
Expand Down Expand Up @@ -168,42 +174,56 @@ const ExportContentUi = ({
return (
<EuiButton
fill
color={isDirty ? 'warning' : 'primary'}
color={(isDirty && renderCopyURLButton) || warnings.length > 0 ? 'warning' : 'primary'}
onClick={getReport}
data-test-subj="generateReportButton"
isLoading={isCreatingExport}
>
{generateExportButton}
{generateExportButton ?? (
<FormattedMessage id="share.export.generateButtonLabel" defaultMessage="Export file" />
)}
</EuiButton>
);
}, [generateExportButton, getReport, isCreatingExport, isDirty]);
}, [
generateExportButton,
getReport,
isCreatingExport,
isDirty,
renderCopyURLButton,
warnings.length,
]);

const renderRadioOptions = () => {
if (radioOptions.length > 1) {
return (
<EuiFlexGroup direction="row" justifyContent={'spaceBetween'}>
<EuiRadioGroup
options={radioOptions}
onChange={(id) => setSelectedRadio(id as SupportedExportTypes)}
name="image reporting radio group"
idSelected={selectedRadio}
legend={{
children: <FormattedMessage id="share.fileType" defaultMessage="File type" />,
}}
/>
</EuiFlexGroup>
<>
<EuiSpacer size="m" />
<EuiFlexGroup direction="row" justifyContent={'spaceBetween'}>
<EuiRadioGroup
options={radioOptions}
onChange={(id) => setSelectedRadio(id as SupportedExportTypes)}
name="image reporting radio group"
idSelected={selectedRadio}
legend={{
children: <FormattedMessage id="share.fileType" defaultMessage="File type" />,
}}
/>
</EuiFlexGroup>
</>
);
}
};

const renderHelpText = () => {
const showHelpText = publicAPIEnabled && isDirty;
const renderDirtyWarning = () => {
return (
showHelpText && (
renderCopyURLButton &&
publicAPIEnabled &&
isDirty && (
<>
<EuiSpacer size="s" />
<EuiSpacer size="m" />
<EuiCallOut
color="warning"
iconType="warning"
title={
<FormattedMessage id="share.link.warning.title" defaultMessage="Unsaved changes" />
}
Expand All @@ -218,19 +238,35 @@ const ExportContentUi = ({
);
};

const renderWarnings = (warning: { title: string; message: string }) => (
<>
<EuiSpacer size="m" />
<EuiCallOut color="warning" iconType="warning" title={warning.title}>
{warning.message}
</EuiCallOut>
</>
);

return (
<>
<EuiForm>
<>{helpText}</>
<EuiSpacer size="m" />
<>{renderRadioOptions()}</>
{renderHelpText()}
<EuiSpacer size="xl" />
<EuiText size="s">
{helpText ?? (
<FormattedMessage
id="share.export.helpText"
defaultMessage="Select the file type you would like to export for this visualization."
/>
)}
</EuiText>
{renderRadioOptions()}
{renderDirtyWarning()}
{warnings.map(renderWarnings)}
<EuiSpacer size="l" />
</EuiForm>
<EuiFlexGroup justifyContent="flexEnd" responsive={false} gutterSize="m">
<>{renderLayoutOptionsSwitch()}</>
<>{showCopyURLButton()}</>
<>{renderGenerateReportButton()}</>
{renderLayoutOptionsSwitch()}
{showCopyURLButton()}
{renderGenerateReportButton()}
</EuiFlexGroup>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export const LinkContent = ({
<EuiSpacer size="m" />
<EuiCallOut
color="warning"
iconType="warning"
title={
<FormattedMessage id="share.link.warning.title" defaultMessage="Unsaved changes" />
}
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/share/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,12 @@ export interface ShareMenuItemV2 extends ShareMenuItemBase {
layoutOption?: 'print';
generateCopyUrl?: URL;
renderCopyURLButton?: boolean;
warnings?: Array<{ title: string; message: string }>;
}

export interface ShareMenuProviderV2 {
readonly id: string;
getShareMenuItems: (context: ShareContext) => Array<Omit<ShareMenuItemV2, 'intl'>>;
getShareMenuItems: (context: ShareContext) => ShareMenuItemV2[];
}
export interface ShareMenuProviderLegacy {
readonly id: string;
Expand Down

This file was deleted.

This file was deleted.

Loading