Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[data view field editor] Runtime field code editor - move state out of controller #155107

Merged
merged 1 commit into from
Apr 18, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ const currentDocumentSelector = (state: PreviewState) => state.documents[state.c
const currentDocumentIsLoadingSelector = (state: PreviewState) => state.isLoadingDocuments;

const ScriptFieldComponent = ({ existingConcreteFields, links, placeholder }: Props) => {
const {
validation: { setScriptEditorValidation },
} = useFieldPreviewContext();
const monacoEditor = useRef<monaco.editor.IStandaloneCodeEditor | null>(null);
const editorValidationSubscription = useRef<Subscription>();
const fieldCurrentValue = useRef<string>('');
Expand Down Expand Up @@ -143,15 +146,15 @@ const ScriptFieldComponent = ({ existingConcreteFields, links, placeholder }: Pr

editorValidationSubscription.current = PainlessLang.validation$().subscribe(
({ isValid, isValidating, errors }) => {
controller.setScriptEditorValidation({
setScriptEditorValidation({
isValid,
isValidating,
message: errors[0]?.message ?? null,
});
}
);
},
[controller]
[setScriptEditorValidation]
);

const updateMonacoMarkers = useCallback((markers: monaco.editor.IMarkerData[]) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ const documentsSelector = (state: PreviewState) => {
};
};

const scriptEditorValidationSelector = (state: PreviewState) => state.scriptEditorValidation;

export const FieldPreviewProvider: FunctionComponent<{ controller: PreviewController }> = ({
controller,
children,
Expand Down Expand Up @@ -121,6 +119,12 @@ export const FieldPreviewProvider: FunctionComponent<{ controller: PreviewContro
/** The parameters required for the Painless _execute API */
const [params, setParams] = useState<Params>(defaultParams);

const [scriptEditorValidation, setScriptEditorValidation] = useState<{
isValidating: boolean;
isValid: boolean;
message: string | null;
}>({ isValidating: false, isValid: true, message: null });

/** Flag to show/hide the preview panel */
const [isPanelVisible, setIsPanelVisible] = useState(true);
/** Flag to indicate if we are loading document from cluster */
Expand All @@ -133,10 +137,6 @@ export const FieldPreviewProvider: FunctionComponent<{ controller: PreviewContro

const { currentDocument, currentDocIndex, currentDocId, totalDocs, currentIdx } =
useStateSelector(controller.state$, documentsSelector);
const scriptEditorValidation = useStateSelector(
controller.state$,
scriptEditorValidationSelector
);

let isPreviewAvailable = true;

Expand Down Expand Up @@ -513,6 +513,9 @@ export const FieldPreviewProvider: FunctionComponent<{ controller: PreviewContro
isVisible: isPanelVisible,
setIsVisible: setIsPanelVisible,
},
validation: {
setScriptEditorValidation,
},
reset,
}),
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ export class PreviewController {
}
};

/* disabled while investigating issues with painless script editor
setScriptEditorValidation = (scriptEditorValidation: PreviewState['scriptEditorValidation']) => {
this.updateState({ scriptEditorValidation });
};
*/

setCustomId = (customId?: string) => {
this.updateState({ customId });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ export interface Context {
isLastDoc: boolean;
};
reset: () => void;
validation: {
setScriptEditorValidation: React.Dispatch<
React.SetStateAction<{ isValid: boolean; isValidating: boolean; message: string | null }>
>;
};
}

export type PainlessExecuteContext =
Expand Down