(fix) O3-3875: JSON editor in the form builder does not show an error indicator#1085
(fix) O3-3875: JSON editor in the form builder does not show an error indicator#1085RajPrakash681 wants to merge 3 commits intoopenmrs:mainfrom
Conversation
|
Hey @ibacher, thanks for the feedback on the CDN usage completely understood. The root cause was that ace-builds/webpack-resolver (which dynamically resolves ace assets at runtime) fails in the micro-frontend deployment environment because it computes paths that don't exist in the deployed bundle. The CDN was a workaround for that, but obviously not acceptable. The proper fix: Replaced the CDN and webpack-resolver with explicit static imports ace-builds/src-noconflict/mode-json and theme-textmate are now bundled at build time, so no runtime network requests are needed |
| {!schema ? ( | ||
| {schema ? null : ( |
There was a problem hiding this comment.
I know Sonar flags this, but Sonar is wrong and this is less readable.
| onClick={handleCopySchema} | ||
| /> | ||
| <a download={`${form?.name}.json`} href={window.URL.createObjectURL(downloadableSchema)}> | ||
| <a download={`${form?.name}.json`} href={globalThis.URL.createObjectURL(downloadableSchema)}> |
There was a problem hiding this comment.
Ditto this. window.URL is fine.
| <div className={styles.backButton}> | ||
| <ConfigurableLink to={window.getOpenmrsSpaBase() + 'form-builder'}> | ||
| <ConfigurableLink | ||
| to={(globalThis as unknown as { getOpenmrsSpaBase: () => string }).getOpenmrsSpaBase() + 'form-builder'} |
There was a problem hiding this comment.
And this is why Sonar is wrong. we explicitly use window here because it's already properly typed.
| path: string, | ||
| suggestions: Array<{ name: string; type: string; path: string }>, | ||
| ) => { | ||
| if (schemaProps && typeof schemaProps === 'object') { |
There was a problem hiding this comment.
| if (schemaProps && typeof schemaProps === 'object') { | |
| if (schemaProps && typeof schemaProps === 'object' && !Array.isArray(schemaProps)) { |
There was a problem hiding this comment.
typeof blah === 'object' basically tells you that it isn't one of a handful of types. It doesn't tell you that's it's necessarily a "normal" JS object.
| const currentPath = path ? `${path}.${propertyName}` : propertyName; | ||
| const typedProperty = property as SchemaProperty; | ||
|
|
||
| if (typeof property === 'object') { |
There was a problem hiding this comment.
| if (typeof property === 'object') { | |
| if (typeof property === 'object' && !Array.isArray(property)) { |
| addCompleter({ | ||
| getCompletions: function (editor, session, pos, prefix, callback) { | ||
| getCompletions: function ( | ||
| _editor: unknown, |
There was a problem hiding this comment.
Not sure I understand why you're adding the _ prefix? Also I always think these things read better as:
function getCompletions(editor: unknown...) {
};This is, after all, just a standard JS function in a standard JS object.
| useEffect(() => { | ||
| addCompleter({ | ||
| getCompletions: function (editor, session, pos, prefix, callback) { | ||
| getCompletions: function ( |
There was a problem hiding this comment.
Incidentally, you should be able to avoid all these typings completely by just by using satisfies Completer (Completer is the Ace type this is implementing). That should give us something fully typed... I think.
| const traverse = (schemaPath) => { | ||
| const pathSegments = schemaPath.split('/').filter((segment) => segment !== '' || segment !== 'type'); | ||
| const traverse = (schemaPath: string) => { | ||
| const pathSegments = schemaPath.split('/').filter((segment) => segment !== '' && segment !== 'type'); |
There was a problem hiding this comment.
Why this change?
The original condition with || is always true, so it never actually filters anything out:
- If segment is
'':segment !== 'type'is true → condition passes - If segment is
'type':segment !== ''is true → condition passes - Any other value: both are true → condition passes
Using && correctly filters out segments that are either empty strings or equal to 'type'.
| let lineNumber = -1; | ||
|
|
||
| for (const segment of pathSegments) { | ||
| if (segment === 'properties' || segment === 'items') continue; // Skip 'properties' and 'items' |
|
|
||
| for (const segment of pathSegments) { | ||
| if (segment === 'properties' || segment === 'items') continue; // Skip 'properties' and 'items' | ||
| const match = segment.match(/^([^[\]]+)/); // Extract property key |
…tion 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.
dd3ffc5 to
1cf6e45
Compare
1cf6e45 to
dc94a88
Compare
Requirements
Summary
a fix to implement error indicators that are not being shown in dev3 or similar ones
Screenshots
Related Issue
https://issues.openmrs.org/browse/O3-3875
Other
NA