Fix download conversion change detection
The setting was considered to have always been modified. This resulted in the save button never being disabled.
This commit is contained in:
@@ -74,6 +74,7 @@ const maybeAddDefault = (conversions: SettingsDownloadConversion[]) => {
|
|||||||
{
|
{
|
||||||
mimeType: DEFAULT_MIME_TYPE,
|
mimeType: DEFAULT_MIME_TYPE,
|
||||||
target: '',
|
target: '',
|
||||||
|
compressionLevel: null,
|
||||||
},
|
},
|
||||||
]),
|
]),
|
||||||
...conversions,
|
...conversions,
|
||||||
@@ -247,7 +248,7 @@ export const DownloadConversionSetting = ({
|
|||||||
updateSetting,
|
updateSetting,
|
||||||
}: {
|
}: {
|
||||||
conversions: SettingsDownloadConversion[];
|
conversions: SettingsDownloadConversion[];
|
||||||
updateSetting: (conversions: SettingsDownloadConversion[]) => void;
|
updateSetting: (conversions: SettingsDownloadConversion[]) => Promise<void>;
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
@@ -257,13 +258,17 @@ export const DownloadConversionSetting = ({
|
|||||||
|
|
||||||
const hasInvalidConversion = containsInvalidConversion(tmpConversions);
|
const hasInvalidConversion = containsInvalidConversion(tmpConversions);
|
||||||
|
|
||||||
const hasChanged = didUpdateConversions(conversions, tmpConversions);
|
const hasChanged = didUpdateConversions(normalizeConversions(maybeAddDefault(conversions)), tmpConversions);
|
||||||
|
|
||||||
const onClose = () => {
|
const onClose = (newConversions: SettingsDownloadConversion[] = conversions) => {
|
||||||
setTmpConversions(normalizeConversions(maybeAddDefault(conversions)));
|
setTmpConversions(normalizeConversions(maybeAddDefault(newConversions)));
|
||||||
setIsDialogOpen(false);
|
setIsDialogOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onCancel = () => {
|
||||||
|
onClose(conversions);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<ListItemButton disabled={false} onClick={() => setIsDialogOpen(true)}>
|
<ListItemButton disabled={false} onClick={() => setIsDialogOpen(true)}>
|
||||||
@@ -275,7 +280,7 @@ export const DownloadConversionSetting = ({
|
|||||||
secondaryTypographyProps={{ style: { display: 'flex', flexDirection: 'column' } }}
|
secondaryTypographyProps={{ style: { display: 'flex', flexDirection: 'column' } }}
|
||||||
/>
|
/>
|
||||||
</ListItemButton>
|
</ListItemButton>
|
||||||
<Dialog open={isDialogOpen} onClose={onClose}>
|
<Dialog open={isDialogOpen} onClose={onCancel}>
|
||||||
<DialogTitle>{t('download.settings.conversion.title')}</DialogTitle>
|
<DialogTitle>{t('download.settings.conversion.title')}</DialogTitle>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
<DialogContentText sx={{ mb: 2 }}>
|
<DialogContentText sx={{ mb: 2 }}>
|
||||||
@@ -322,16 +327,23 @@ export const DownloadConversionSetting = ({
|
|||||||
<Button
|
<Button
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setTmpConversions((prev) => [...prev, { mimeType: '', target: '' }]);
|
setTmpConversions((prev) => [
|
||||||
|
...prev,
|
||||||
|
{ mimeType: '', target: '', compressionLevel: null },
|
||||||
|
]);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{t('global.button.add')}
|
{t('global.button.add')}
|
||||||
</Button>
|
</Button>
|
||||||
<Stack direction="row">
|
<Stack direction="row">
|
||||||
<Button onClick={onClose}>{t('global.button.cancel')}</Button>
|
<Button onClick={onCancel}>{t('global.button.cancel')}</Button>
|
||||||
<Button
|
<Button
|
||||||
disabled={hasInvalidConversion || !hasChanged}
|
disabled={hasInvalidConversion || !hasChanged}
|
||||||
onClick={() => updateSetting(toValidServerConversions(tmpConversions))}
|
onClick={() =>
|
||||||
|
updateSetting(toValidServerConversions(tmpConversions)).then(() =>
|
||||||
|
onClose(toValidServerConversions(tmpConversions)),
|
||||||
|
)
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{t('global.button.ok')}
|
{t('global.button.ok')}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -108,10 +108,11 @@ export const DownloadSettings = () => {
|
|||||||
const updateSetting = <Setting extends keyof DownloadSettingsType>(
|
const updateSetting = <Setting extends keyof DownloadSettingsType>(
|
||||||
setting: Setting,
|
setting: Setting,
|
||||||
value: DownloadSettingsType[Setting],
|
value: DownloadSettingsType[Setting],
|
||||||
) => {
|
): Promise<any> => {
|
||||||
mutateSettings({ variables: { input: { settings: { [setting]: value } } } }).catch((e) =>
|
const mutation = mutateSettings({ variables: { input: { settings: { [setting]: value } } } });
|
||||||
makeToast(t('global.error.label.failed_to_save_changes'), 'error', getErrorMessage(e)),
|
mutation.catch((e) => makeToast(t('global.error.label.failed_to_save_changes'), 'error', getErrorMessage(e)));
|
||||||
);
|
|
||||||
|
return mutation;
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateMetadataSetting = createUpdateMetadataServerSettings<keyof MetadataDownloadSettings>((e) =>
|
const updateMetadataSetting = createUpdateMetadataServerSettings<keyof MetadataDownloadSettings>((e) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user