Skip to content
Merged
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
9 changes: 5 additions & 4 deletions src/hooks/useGetSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,20 @@ export const useGetSchema = ({ schemaId, skip, resource }) => {
const isWorkerOkay = isWorkerAvailable && !schemasError;
const [schema, setSchema] = useState(null);
const [error, setError] = useState(null);
const [loading, setLoading] = useState(!isWorkerOkay ? false : !skip);

const [loading, setLoading] = useState(true);
useEffect(() => {
setSchema(null);
setError(null);
setLoading(!isWorkerOkay ? false : !skip);
setLoading(true);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [schemaId]);

useEffect(() => {
if (!areSchemasComputed || schema || skip || !isWorkerOkay) {
if (schema || skip || !isWorkerOkay) {
setLoading(false);
return;
}
if (!areSchemasComputed) return;
sendWorkerMessage('getSchema', schemaId);

addWorkerListener(`schemaComputed:${schemaId}`, ({ schema }) => {
Expand Down
1 change: 1 addition & 0 deletions src/shared/ResourceForm/components/ResourceForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export function ResourceForm({
schemaId={resourceSchemaId}
updateValueOnParentChange={true}
setEditorError={setEditorError}
schema={schema}
/>
);
editor = renderEditor
Expand Down
2 changes: 2 additions & 0 deletions src/shared/ResourceForm/fields/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export function Editor({
convert = true,
schemaId,
setEditorError,
schema,
...props
}) {
const { t } = useTranslation();
Expand Down Expand Up @@ -85,6 +86,7 @@ export function Editor({
error={error}
schemaId={schemaId}
placeholder={t('clusters.wizard.editor-placeholder')}
schema={schema}
/>
);
}
Expand Down
7 changes: 4 additions & 3 deletions src/shared/components/MonacoEditorESM/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function Editor({
onFocus,
options = {}, // IEditorOptions, check Monaco API for the list of options
placeholder = null,
...rest
schema,
}) {
const { t } = useTranslation();
const prevValueRef = useRef(value);
Expand All @@ -45,6 +45,7 @@ export function Editor({
autocompletionDisabled,
readOnly,
language,
schema,
});

// set autocompletion global context to the current editor and initialize an editor instance
Expand Down Expand Up @@ -90,11 +91,11 @@ export function Editor({
className="resource-form__wrapper"
style={{ height, minHeight: height }}
>
{loading ? (
{loading && (
<div className="resource-form__overlay">
<Spinner />
</div>
) : null}
)}
<div ref={divRef} className="resource-form__editor" />
{placeholder && !!!value && (
<div className="resource-form__placeholder">{placeholder}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function useAutocompleteWorker({
autocompletionDisabled,
readOnly,
language,
schema: predefinedSchema,
}) {
const [schemaId] = useState(predefinedSchemaId || Math.random().toString());

Expand All @@ -42,11 +43,12 @@ export function useAutocompleteWorker({
autocompletionDisabled = true;
}

const { schema, loading, error } = useGetSchema({
const { schemas: fetchedSchema, loading, error } = useGetSchema({
schemaId,
skip: autocompletionDisabled,
skip: autocompletionDisabled || !!predefinedSchema,
});

const schema = predefinedSchema || fetchedSchema;
/**
* Call this before initializing Monaco. This function alters Monaco global config to set up JSON-based
* autocompletion.
Expand Down
Loading