Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions specifyweb/frontend/js_src/lib/components/DataModel/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,21 @@ const processFields = <FIELD_TYPE extends LiteralField | Relationship>(
let schemaLocalization: IR<SchemaLocalization> = undefined!;
const fetchSchemaLocalization = f.store(async () =>
import('../Preferences/userPreferences').then(async ({ userPreferences }) =>
load<IR<SchemaLocalization>>(
formatUrl('/context/schema_localization.json', {
lang: userPreferences.get('form', 'schema', 'language'),
}),
'application/json'
)
// Preferences are fetched independently of the initial context. Reading
// the schema language before that fetch completes can request the default
// language, and f.store() would then keep that localization for the life
// of the page.
userPreferences
.fetch()
.catch(() => undefined)
.then(() =>
load<IR<SchemaLocalization>>(
formatUrl('/context/schema_localization.json', {
lang: userPreferences.get('form', 'schema', 'language'),
}),
'application/json'
)
)
)
);
export const getSchemaLocalization = (): IR<SchemaLocalization> =>
Expand Down
32 changes: 21 additions & 11 deletions specifyweb/frontend/js_src/lib/components/SchemaConfig/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
useSchemaConfig,
} from './Store';
import { dialogIcons } from '../Atoms/Icons';
import { raise } from '../Errors/Crash';
import { raise } from '../Errors/Crash';

export function SchemaConfigLayout(): JSX.Element {
const schemaData = useOutletContext<SchemaData>();
Expand Down Expand Up @@ -94,20 +94,30 @@ function SchemaConfigLayoutContent(): JSX.Element {
method: 'POST',
headers: { Accept: 'application/json' },
body: { schema, language: rawLanguage },
expectedErrors: [400, 500, 504]
expectedErrors: [400, 500, 504],
})
)
.then(
(response) => {
setImportStatus(response.status);
if (response.status !== 200)
raise({name: schemaText.importSchemaError({schemaConfig: schemaText.schemaConfig()}), message:
response.status === 504 ? schemaText.importSchemaErrorTimeout({schemaConfig: schemaText.schemaConfig()}) :
response.status === 400 ? schemaText.importSchemaErrorBadRequest({schemaConfig: schemaText.schemaConfig()}) :
schemaText.importSchemaErrorInternalError()
})
},
(err) => raise(err)
setImportStatus(response.status);
if (response.status !== 200)
raise({
name: schemaText.importSchemaError({
schemaConfig: schemaText.schemaConfig(),
}),
message:
response.status === 504
? schemaText.importSchemaErrorTimeout({
schemaConfig: schemaText.schemaConfig(),
})
: response.status === 400
? schemaText.importSchemaErrorBadRequest({
schemaConfig: schemaText.schemaConfig(),
})
: schemaText.importSchemaErrorInternalError(),
});
},
(err) => raise(err)
)
);
};
Expand Down
Loading