Skip to content

Commit

Permalink
Improve UDF state handling
Browse files Browse the repository at this point in the history
If a UDF validation request is in progress while the user continues
editing the definition input, the request should be aborted.

Also keep the state of the UDF editor separate from local storage to
make the data flow in only one direction.

Also changes the UDF validation fetcher to run on empty definitions.
  • Loading branch information
jbeisen committed Nov 13, 2023
1 parent bd9e895 commit d58e27f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
7 changes: 6 additions & 1 deletion arroyo-console/src/lib/data_fetching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { components, paths } from '../gen/api-types';
import createClient from 'openapi-fetch';

import { LocalUdf } from '../udf_state';
import { useRef } from 'react';

type schemas = components['schemas'];

Expand Down Expand Up @@ -121,7 +122,7 @@ const operatorErrorsKey = (pipelineId?: string, jobId?: string) => {
};

const queryValidationKey = (query?: string, localUdfs?: LocalUdf[]) => {
return query ? { key: 'PipelineGraph', query, localUdfs } : null;
return query != undefined ? { key: 'PipelineGraph', query, localUdfs } : null;
};

const udfValidationKey = (definition: string) => {
Expand Down Expand Up @@ -372,11 +373,15 @@ export const useQueryValidation = (query?: string, localUdfs?: LocalUdf[]) => {
};

const udfValidationFetcher = () => {
const controller = useRef<AbortController>();
return async (params: { key: string; definition: string }) => {
controller.current?.abort();
controller.current = new AbortController();
const { data, error } = await post('/v1/udfs/validate', {
body: {
definition: params.definition,
},
signal: controller.current?.signal,
});
return processResponse(data, error);
};
Expand Down
2 changes: 1 addition & 1 deletion arroyo-console/src/routes/pipelines/CreatePipeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function CreatePipeline() {
useOperatorErrors(pipelineId, job?.id);
const [operatorErrors, setOperatorErrors] = useState<JobLogMessage[]>([]);
const [queryInput, setQueryInput] = useState<string>('');
const [queryInputToCheck, setQueryInputToCheck] = useState<string>('');
const [queryInputToCheck, setQueryInputToCheck] = useState<string | undefined>(undefined);
const { operatorMetricGroups } = useJobMetrics(pipelineId, job?.id);
const { isOpen, onOpen, onClose } = useDisclosure();
const [options, setOptions] = useState<SqlOptions>({ parallelism: 4, checkpointMS: 5000 });
Expand Down
4 changes: 3 additions & 1 deletion arroyo-console/src/routes/udfs/UdfEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface UdfEditorProps {
const UdfEditor: React.FC<UdfEditorProps> = ({ udf }) => {
const { updateLocalUdf, isGlobal } = useContext(LocalUdfsContext);
const [definitionToCheck, setDefinitionToCheck] = useState<string>(udf.definition);
const [localDefinition, setLocalDefinition] = useState<string>(udf.definition);

const debounceSetCheck = useMemo(
() =>
Expand All @@ -30,10 +31,11 @@ const UdfEditor: React.FC<UdfEditorProps> = ({ udf }) => {

return (
<CodeEditor
code={udf.definition}
code={localDefinition}
readOnly={isGlobal(udf)}
setCode={s => {
updateLocalUdf(udf as LocalUdf, { definition: s });
setLocalDefinition(s);
debounceSetCheck(s);
}}
language="rust"
Expand Down
1 change: 0 additions & 1 deletion arroyo-console/src/udf_state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ export const getLocalUdfsContextValue = () => {
};

const deleteGlobalUdf = async (udf: GlobalUdf) => {
console.log('deleting global');
await apiDeleteGlobalUdf(udf);
setOpenedGlobalUdfs(openedGlobalUdfs.filter(u => u.id !== udf.id));
};
Expand Down

0 comments on commit d58e27f

Please sign in to comment.