fix: plugin locale merge re-runs on HMR; API Key form allows Personal
- locale-merger: drop the module-level dedup Set. addLocale is idempotent, and the guard made HMR-added plugin locale keys silently skipped — strings like organizations.members.selectUsers stayed unresolved until a full dev-server restart. - api-keys form: pass allowPersonal: true to CreateOrgScopeField so admin in Platform-wide mode can target their own Personal Org when creating a key (unlike infra resources where Personal doesn't fit).
This commit is contained in:
@@ -45,7 +45,10 @@ const APIKeyForm: React.FC<{
|
|||||||
></CInput.Input>
|
></CInput.Input>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
<PluginExtraFields name="CreateOrgScopeField" context={{ action }} />
|
<PluginExtraFields
|
||||||
|
name="CreateOrgScopeField"
|
||||||
|
context={{ action, allowPersonal: true }}
|
||||||
|
/>
|
||||||
|
|
||||||
<Form.Item<FormData>
|
<Form.Item<FormData>
|
||||||
name="expires_in"
|
name="expires_in"
|
||||||
|
|||||||
@@ -1,32 +1,27 @@
|
|||||||
import { addLocale } from '@umijs/max';
|
import { addLocale } from '@umijs/max';
|
||||||
|
|
||||||
const mergedLocales = new Set<string>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge enterprise plugin locales into the main application
|
* Merge enterprise plugin locales into the main application.
|
||||||
|
*
|
||||||
|
* `addLocale` is idempotent: re-calling with the latest message dict
|
||||||
|
* overwrites previous entries, so we always pass the freshest plugin
|
||||||
|
* locales through. A previous version deduped via a module-level Set
|
||||||
|
* and that broke HMR — newly added keys in plugin locale files were
|
||||||
|
* skipped on the second merge, leaving the placeholder/validation
|
||||||
|
* strings unresolved until a full server restart.
|
||||||
*/
|
*/
|
||||||
export function mergeEnterpriseLocales(locales: Record<string, any> = {}) {
|
export function mergeEnterpriseLocales(locales: Record<string, any> = {}) {
|
||||||
if (!locales) {
|
if (!locales) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Merging enterprise plugin locales:', Object.keys(locales));
|
|
||||||
|
|
||||||
// Iterate over all locale configurations of the enterprise plugin
|
|
||||||
Object.entries(locales).forEach(([locale, messages]) => {
|
Object.entries(locales).forEach(([locale, messages]) => {
|
||||||
try {
|
try {
|
||||||
if (mergedLocales.has(locale)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Merge the enterprise locale into the main application
|
|
||||||
addLocale(locale, messages, {
|
addLocale(locale, messages, {
|
||||||
momentLocale: '',
|
momentLocale: '',
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
antd: locale
|
antd: locale
|
||||||
});
|
});
|
||||||
mergedLocales.add(locale);
|
|
||||||
console.log(`✓ Merged enterprise locale: ${locale}`, messages);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Failed to merge enterprise locale ${locale}:`, error);
|
console.error(`Failed to merge enterprise locale ${locale}:`, error);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user