0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

fix(console): language editor form should be dirty on clear button clicked (#2037)

This commit is contained in:
Xiao Yijun 2022-09-30 17:56:03 +08:00 committed by GitHub
parent 800ac7fcd9
commit 1223d23eb3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 5 deletions

View file

@ -66,6 +66,7 @@ const LanguageEditor = () => {
const {
handleSubmit,
reset,
setValue,
formState: { isSubmitting, isDirty, dirtyFields },
} = formMethods;
@ -159,7 +160,11 @@ const LanguageEditor = () => {
className={style.clearButton}
icon={<Delete />}
onClick={() => {
reset(emptyUiTranslation);
for (const [key, value] of Object.entries(
flattenTranslation(emptyUiTranslation)
)) {
setValue(key, value, { shouldDirty: true });
}
}}
/>
</span>

View file

@ -110,14 +110,14 @@ export const flattenTranslation = (
const unwrappedKey = `${prefix}${key}`;
const unwrapped = translation[key];
return unwrapped
? {
return unwrapped === undefined
? result
: {
...result,
...(typeof unwrapped === 'string'
? { [unwrappedKey]: unwrapped }
: flattenTranslation(unwrapped, unwrappedKey)),
}
: result;
};
}, {});
const emptyTranslation = (translation: Translation): Translation =>