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

Improve loading state; prevent duplicate refresh #289

Merged
merged 2 commits into from
Aug 15, 2024
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 @@ -49,7 +49,7 @@ export function ConfigureSearchRequest(props: ConfigureSearchRequestProps) {
const { values, setFieldValue, setFieldTouched } = useFormikContext<
WorkflowFormValues
>();
const ingestEnabled = values?.ingest?.enabled || true;
const ingestEnabled = values?.ingest?.enabled;
const searchIndexNameFormPath = 'search.index.name';

// All indices state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,14 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
const dispatch = useAppDispatch();
const dataSourceId = getDataSourceId();

// Overall workspace state
// Overall form state
const { isDirty } = useSelector((state: AppState) => state.form);

// running ingest/search state
const [isRunningIngest, setIsRunningIngest] = useState<boolean>(false);
const [isRunningSearch, setIsRunningSearch] = useState<boolean>(false);
const [isRunningDelete, setIsRunningDelete] = useState<boolean>(false);

// selected step state
const [selectedStep, setSelectedStep] = useState<STEP>(STEP.INGEST);

Expand Down Expand Up @@ -465,6 +470,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
// to clean up any created resources and not have leftover / stale data in some index.
// This is propagated by passing `reprovision=false` to validateAndUpdateWorkflow()
async function validateAndRunIngestion(): Promise<boolean> {
setIsRunningIngest(true);
let success = false;
try {
let ingestDocsObjs = [] as {}[];
Expand Down Expand Up @@ -497,6 +503,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
} catch (error) {
console.error('Error ingesting documents: ', error);
}
setIsRunningIngest(false);
return success;
}

Expand All @@ -508,6 +515,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
// This logic is propagated by passing `reprovision=true/false` in the
// validateAndUpdateWorkflow() fn calls below.
async function validateAndRunQuery(): Promise<boolean> {
setIsRunningSearch(true);
let success = false;
try {
let queryObj = {};
Expand Down Expand Up @@ -551,6 +559,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
} catch (error) {
console.error('Error running query: ', error);
}
setIsRunningSearch(false);
return success;
}

Expand Down Expand Up @@ -602,7 +611,10 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
Cancel
</EuiButtonEmpty>
<EuiButton
isLoading={isRunningDelete}
disabled={isRunningDelete}
onClick={async () => {
setIsRunningDelete(true);
await dispatch(
deprovisionWorkflow({
apiBody: {
Expand All @@ -617,6 +629,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
.unwrap()
.then(async (result) => {
setFieldValue('ingest.enabled', false);
await validateAndUpdateWorkflow(false);
// @ts-ignore
await dispatch(
getWorkflow({
Expand All @@ -628,6 +641,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
.catch((error: any) => {})
.finally(() => {
setIsModalOpen(false);
setIsRunningDelete(false);
});
}}
fill={true}
Expand Down Expand Up @@ -752,6 +766,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
<EuiFlexItem grow={false}>
<EuiButton
fill={true}
disabled={false}
onClick={() => {
setSelectedStep(STEP.SEARCH);
dispatch(removeDirty());
Expand All @@ -769,6 +784,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
validateAndRunIngestion();
}}
disabled={!ingestTemplatesDifferent}
isLoading={isRunningIngest}
>
Run ingestion
</EuiButton>
Expand All @@ -779,7 +795,7 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
onClick={() => {
setSelectedStep(STEP.SEARCH);
}}
disabled={ingestTemplatesDifferent}
disabled={ingestTemplatesDifferent || isRunningIngest}
>
{`Search pipeline >`}
</EuiButton>
Expand All @@ -790,9 +806,10 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
<EuiFlexItem grow={false}>
<EuiButtonEmpty
disabled={
isProposingNoSearchResources
isRunningSearch ||
(isProposingNoSearchResources
? false
: searchTemplatesDifferent
: searchTemplatesDifferent)
}
onClick={() => setSelectedStep(STEP.INGEST)}
>
Expand All @@ -801,7 +818,10 @@ export function WorkflowInputs(props: WorkflowInputsProps) {
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
disabled={isProposingNoSearchResources}
disabled={
isRunningSearch || isProposingNoSearchResources
}
isLoading={isRunningSearch}
fill={false}
onClick={() => {
validateAndRunQuery();
Expand Down
1 change: 0 additions & 1 deletion public/pages/workflows/new_workflow/use_case.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export function UseCase(props: UseCaseProps) {
history.replace(
`${APP_PATH.WORKFLOWS}/${workflow.id}?dataSourceId=${dataSourceId}`
);
history.go(0);
})
.catch((err: any) => {
console.error(err);
Expand Down
Loading