0
Fork 0
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:
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 { 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>

View file

@ -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 =>