Skip to content

Commit dd3ffc5

Browse files
committed
(fix) O3-3875: remove CDN dependency from schema editor ace configuration
Replace runtime CDN asset loading with bundled imports for ace-builds mode, theme, and language tools. Set useWorker: false to prevent ace from fetching the JSON worker file at runtime. Add gutter annotations alongside existing markers so error icons render correctly in production. Also remove unused isLoading prop, fix pre-existing logic bug in traverse filter (|| -> &&), extract sub-components outside SchemaEditor, and resolve SonarQube warnings in both schema-editor and form-editor.
1 parent 4e2b5f9 commit dd3ffc5

File tree

2 files changed

+158
-127
lines changed

2 files changed

+158
-127
lines changed

src/components/form-editor/form-editor.component.tsx

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ interface ErrorProps {
4646
}
4747

4848
interface TranslationFnProps {
49-
t: TFunction;
49+
readonly t: TFunction;
5050
}
5151

5252
interface MarkerProps extends IMarker {
@@ -223,15 +223,13 @@ const FormEditorContent: React.FC<TranslationFnProps> = ({ t }) => {
223223

224224
const renderSchemaChanges = useCallback(() => {
225225
resetErrorMessage();
226-
{
227-
try {
228-
const parsedJson: Schema = JSON.parse(stringifiedSchema);
229-
updateSchema(parsedJson);
230-
setStringifiedSchema(JSON.stringify(parsedJson, null, 2));
231-
} catch (e) {
232-
if (e instanceof Error) {
233-
setInvalidJsonErrorMessage(e.message);
234-
}
226+
try {
227+
const parsedJson: Schema = JSON.parse(stringifiedSchema);
228+
updateSchema(parsedJson);
229+
setStringifiedSchema(JSON.stringify(parsedJson, null, 2));
230+
} catch (e) {
231+
if (e instanceof Error) {
232+
setInvalidJsonErrorMessage(e.message);
235233
}
236234
}
237235
}, [stringifiedSchema, updateSchema, resetErrorMessage]);
@@ -258,25 +256,11 @@ const FormEditorContent: React.FC<TranslationFnProps> = ({ t }) => {
258256
}
259257
}, [blockRenderingWithErrors, errors.length, renderSchemaChanges, selectedLanguageCode]);
260258

261-
const handleSchemaImport = (event: React.ChangeEvent<HTMLInputElement>) => {
259+
const handleSchemaImport = async (event: React.ChangeEvent<HTMLInputElement>) => {
262260
const file = event.target.files[0];
263-
const reader = new FileReader();
264-
265-
reader.onload = (e) => {
266-
const result = e.target?.result;
267-
if (typeof result === 'string') {
268-
const fileContent: string = result;
269-
const parsedJson: Schema = JSON.parse(fileContent);
270-
setSchema(parsedJson);
271-
} else if (result instanceof ArrayBuffer) {
272-
const decoder = new TextDecoder();
273-
const fileContent: string = decoder.decode(result);
274-
const parsedJson: Schema = JSON.parse(fileContent);
275-
setSchema(parsedJson);
276-
}
277-
};
278-
279-
reader.readAsText(file);
261+
const fileContent = await file.text();
262+
const parsedJson: Schema = JSON.parse(fileContent);
263+
setSchema(parsedJson);
280264
};
281265

282266
const downloadableSchema = useMemo(
@@ -316,7 +300,7 @@ const FormEditorContent: React.FC<TranslationFnProps> = ({ t }) => {
316300
<div className={styles.heading}>
317301
<span className={styles.tabHeading}>{t('schemaEditor', 'Schema editor')}</span>
318302
<div className={styles.topBtns}>
319-
{!schema ? (
303+
{schema ? null : (
320304
<FileUploader
321305
onChange={handleSchemaImport}
322306
labelTitle=""
@@ -331,7 +315,7 @@ const FormEditorContent: React.FC<TranslationFnProps> = ({ t }) => {
331315
iconDescription={t('importSchema', 'Import schema')}
332316
name="form-import"
333317
/>
334-
) : null}
318+
)}
335319
{isNewSchema && !schema ? (
336320
<Button kind="ghost" onClick={inputDummySchema}>
337321
{t('inputDummySchema', 'Input dummy schema')}
@@ -376,7 +360,7 @@ const FormEditorContent: React.FC<TranslationFnProps> = ({ t }) => {
376360
kind="ghost"
377361
onClick={handleCopySchema}
378362
/>
379-
<a download={`${form?.name}.json`} href={window.URL.createObjectURL(downloadableSchema)}>
363+
<a download={`${form?.name}.json`} href={globalThis.URL.createObjectURL(downloadableSchema)}>
380364
<IconButton
381365
enterDelayInMs={defaultEnterDelayInMs}
382366
kind="ghost"
@@ -398,7 +382,6 @@ const FormEditorContent: React.FC<TranslationFnProps> = ({ t }) => {
398382
<div className={styles.editorContainer}>
399383
<SchemaEditor
400384
errors={errors}
401-
isLoading={isLoadingFormOrSchema}
402385
onSchemaChange={handleSchemaChange}
403386
setErrors={setErrors}
404387
setValidationOn={setValidationOn}
@@ -460,7 +443,9 @@ const FormEditorContent: React.FC<TranslationFnProps> = ({ t }) => {
460443
function BackButton({ t }: TranslationFnProps) {
461444
return (
462445
<div className={styles.backButton}>
463-
<ConfigurableLink to={window.getOpenmrsSpaBase() + 'form-builder'}>
446+
<ConfigurableLink
447+
to={(globalThis as unknown as { getOpenmrsSpaBase: () => string }).getOpenmrsSpaBase() + 'form-builder'}
448+
>
464449
<Button
465450
kind="ghost"
466451
renderIcon={(props) => <ArrowLeft size={24} {...props} />}

0 commit comments

Comments
 (0)