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

feat(ingestion) Add Save & Run button to managed ingestion builder #5579

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
88 changes: 50 additions & 38 deletions datahub-web-react/src/app/ingest/source/IngestionSourceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,47 @@ export const IngestionSourceList = () => {
const focusSource =
(focusSourceUrn && filteredSources.find((source) => source.urn === focusSourceUrn)) || undefined;

const onRefresh = () => {
refetch();
// Used to force a re-render of the child execution request list.
setLastRefresh(new Date().getMilliseconds());
};

const executeIngestionSource = (urn: string) => {
createExecutionRequestMutation({
variables: {
input: {
ingestionSourceUrn: urn,
},
},
})
.then(() => {
message.success({
content: `Successfully submitted ingestion execution request!`,
duration: 3,
});
setInterval(() => onRefresh(), 3000);
})
.catch((e) => {
message.destroy();
message.error({
content: `Failed to submit ingestion execution request!: \n ${e.message || ''}`,
duration: 3,
});
});
};

const onCreateOrUpdateIngestionSourceSuccess = () => {
setTimeout(() => refetch(), 2000);
setIsBuildingSource(false);
setFocusSourceUrn(undefined);
};

const createOrUpdateIngestionSource = (input: UpdateIngestionSourceInput, resetState: () => void) => {
const createOrUpdateIngestionSource = (
input: UpdateIngestionSourceInput,
resetState: () => void,
shouldRun?: boolean,
) => {
if (focusSourceUrn) {
// Update:
updateIngestionSource({ variables: { urn: focusSourceUrn as string, input } })
Expand All @@ -128,6 +162,7 @@ export const IngestionSourceList = () => {
});
onCreateOrUpdateIngestionSourceSuccess();
resetState();
if (shouldRun) executeIngestionSource(focusSourceUrn);
})
.catch((e) => {
message.destroy();
Expand All @@ -139,15 +174,21 @@ export const IngestionSourceList = () => {
} else {
// Create
createIngestionSource({ variables: { input } })
.then(() => {
setTimeout(() => refetch(), 2000);
.then((result) => {
message.loading({ content: 'Loading...', duration: 2 });
setTimeout(() => {
refetch();
message.success({
content: `Successfully created ingestion source!`,
duration: 3,
});
if (shouldRun && result.data?.createIngestionSource) {
executeIngestionSource(result.data.createIngestionSource);
}
}, 2000);
setIsBuildingSource(false);
setFocusSourceUrn(undefined);
resetState();
message.success({
content: `Successfully created ingestion source!`,
duration: 3,
});
// onCreateOrUpdateIngestionSourceSuccess();
})
.catch((e) => {
Expand All @@ -164,36 +205,6 @@ export const IngestionSourceList = () => {
setPage(newPage);
};

const onRefresh = () => {
refetch();
// Used to force a re-render of the child execution request list.
setLastRefresh(new Date().getMilliseconds());
};

const executeIngestionSource = (urn: string) => {
createExecutionRequestMutation({
variables: {
input: {
ingestionSourceUrn: urn,
},
},
})
.then(() => {
message.success({
content: `Successfully submitted ingestion execution request!`,
duration: 3,
});
setInterval(() => onRefresh(), 3000);
})
.catch((e) => {
message.destroy();
message.error({
content: `Failed to submit ingestion execution request!: \n ${e.message || ''}`,
duration: 3,
});
});
};

const deleteIngestionSource = async (urn: string) => {
removeIngestionSourceMutation({
variables: { urn },
Expand All @@ -214,7 +225,7 @@ export const IngestionSourceList = () => {
});
};

const onSubmit = (recipeBuilderState: SourceBuilderState, resetState: () => void) => {
const onSubmit = (recipeBuilderState: SourceBuilderState, resetState: () => void, shouldRun?: boolean) => {
createOrUpdateIngestionSource(
{
type: recipeBuilderState.type as string,
Expand All @@ -236,6 +247,7 @@ export const IngestionSourceList = () => {
},
},
resetState,
shouldRun,
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export enum IngestionSourceBuilderStep {
type Props = {
initialState?: SourceBuilderState;
visible: boolean;
onSubmit?: (input: SourceBuilderState, resetState: () => void) => void;
onSubmit?: (input: SourceBuilderState, resetState: () => void, shouldRun?: boolean) => void;
onCancel?: () => void;
};

Expand Down Expand Up @@ -98,11 +98,15 @@ export const IngestionSourceBuilderModal = ({ initialState, visible, onSubmit, o
onCancel?.();
};

const submit = () => {
onSubmit?.(ingestionBuilderState, () => {
setStepStack([initialStep]);
setIngestionBuilderState({});
});
const submit = (shouldRun?: boolean) => {
onSubmit?.(
ingestionBuilderState,
() => {
setStepStack([initialStep]);
setIngestionBuilderState({});
},
shouldRun,
);
};

const currentStep = stepStack[stepStack.length - 1];
Expand Down
25 changes: 20 additions & 5 deletions datahub-web-react/src/app/ingest/source/builder/NameSourceStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const ControlsContainer = styled.div`
margin-top: 8px;
`;

const SaveRunButton = styled(Button)`
margin-right: 15px;
`;

export const NameSourceStep = ({ state, updateState, prev, submit }: StepProps) => {
const setName = (stagedName: string) => {
const newState: SourceBuilderState = {
Expand Down Expand Up @@ -40,9 +44,9 @@ export const NameSourceStep = ({ state, updateState, prev, submit }: StepProps)
updateState(newState);
};

const onClickCreate = () => {
const onClickCreate = (shouldRun?: boolean) => {
if (state.name !== undefined && state.name.length > 0) {
submit();
submit(shouldRun);
}
};

Expand Down Expand Up @@ -93,9 +97,20 @@ export const NameSourceStep = ({ state, updateState, prev, submit }: StepProps)
</Form>
<ControlsContainer>
<Button onClick={prev}>Previous</Button>
<Button disabled={!(state.name !== undefined && state.name.length > 0)} onClick={onClickCreate}>
Done
</Button>
<div>
<SaveRunButton
disabled={!(state.name !== undefined && state.name.length > 0)}
onClick={() => onClickCreate(true)}
>
Save & Run
</SaveRunButton>
<Button
disabled={!(state.name !== undefined && state.name.length > 0)}
onClick={() => onClickCreate(false)}
>
Save
</Button>
</div>
</ControlsContainer>
</>
);
Expand Down
2 changes: 1 addition & 1 deletion datahub-web-react/src/app/ingest/source/builder/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export type StepProps = {
updateState: (newState: SourceBuilderState) => void;
goTo: (step: IngestionSourceBuilderStep) => void;
prev?: () => void;
submit: () => void;
submit: (shouldRun?: boolean) => void;
cancel: () => void;
};

Expand Down