mirror of
https://github.com/logto-io/logto.git
synced 2025-01-06 20:40:08 -05:00
fix(console): language editor form should be dirty on clear button clicked (#2037)
This commit is contained in:
parent
800ac7fcd9
commit
1223d23eb3
2 changed files with 10 additions and 5 deletions
|
@ -66,6 +66,7 @@ const LanguageEditor = () => {
|
||||||
const {
|
const {
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
reset,
|
reset,
|
||||||
|
setValue,
|
||||||
formState: { isSubmitting, isDirty, dirtyFields },
|
formState: { isSubmitting, isDirty, dirtyFields },
|
||||||
} = formMethods;
|
} = formMethods;
|
||||||
|
|
||||||
|
@ -159,7 +160,11 @@ const LanguageEditor = () => {
|
||||||
className={style.clearButton}
|
className={style.clearButton}
|
||||||
icon={<Delete />}
|
icon={<Delete />}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
reset(emptyUiTranslation);
|
for (const [key, value] of Object.entries(
|
||||||
|
flattenTranslation(emptyUiTranslation)
|
||||||
|
)) {
|
||||||
|
setValue(key, value, { shouldDirty: true });
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -110,14 +110,14 @@ export const flattenTranslation = (
|
||||||
const unwrappedKey = `${prefix}${key}`;
|
const unwrappedKey = `${prefix}${key}`;
|
||||||
const unwrapped = translation[key];
|
const unwrapped = translation[key];
|
||||||
|
|
||||||
return unwrapped
|
return unwrapped === undefined
|
||||||
? {
|
? result
|
||||||
|
: {
|
||||||
...result,
|
...result,
|
||||||
...(typeof unwrapped === 'string'
|
...(typeof unwrapped === 'string'
|
||||||
? { [unwrappedKey]: unwrapped }
|
? { [unwrappedKey]: unwrapped }
|
||||||
: flattenTranslation(unwrapped, unwrappedKey)),
|
: flattenTranslation(unwrapped, unwrappedKey)),
|
||||||
}
|
};
|
||||||
: result;
|
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
const emptyTranslation = (translation: Translation): Translation =>
|
const emptyTranslation = (translation: Translation): Translation =>
|
||||||
|
|
Loading…
Reference in a new issue