Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
SuaYoo committed Jan 23, 2025
1 parent 72d80fe commit 6606398
Showing 1 changed file with 38 additions and 23 deletions.
61 changes: 38 additions & 23 deletions frontend/src/features/crawl-workflows/workflow-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ const DEFAULT_BEHAVIORS = [
];
const formName = "newJobConfig" as const;
const panelSuffix = "--panel" as const;
const saveRunButtonName = "saveRun--button" as const;
const saveButtonName = "save--button" as const;

const getDefaultProgressState = (hasConfigId = false): ProgressState => {
let activeTab: StepName = "crawlSetup";
Expand Down Expand Up @@ -450,10 +448,17 @@ export class WorkflowEditor extends BtrixElement {
});
}}
@sl-hide=${(e: SlHideEvent) => {
const el = e.currentTarget as SlDetails;
// Check if there's any invalid elements before hiding
const invalidEl = (
e.currentTarget as SlDetails
).querySelector<SlInput>("[data-user-invalid]");
let invalidEl: SlInput | null = null;
if (required) {
invalidEl = el.querySelector<SlInput>("[required][data-invalid]");
}
invalidEl =
invalidEl || el.querySelector<SlInput>("[data-user-invalid]");
if (invalidEl) {
e.preventDefault();
Expand Down Expand Up @@ -490,13 +495,16 @@ export class WorkflowEditor extends BtrixElement {
></sl-icon>
</sl-tooltip>
`,
() => html`
<sl-icon
name="chevron-up"
class="size-5"
label=${msg("Collapse section")}
></sl-icon>
`,
() =>
!required || this.configId
? html`
<sl-icon
name="chevron-up"
class="size-5"
label=${msg("Collapse section")}
></sl-icon>
`
: nothing,
)}
</div>
Expand Down Expand Up @@ -554,7 +562,6 @@ export class WorkflowEditor extends BtrixElement {
`
: nothing}
<sl-button
name=${saveRunButtonName}
size="small"
variant="primary"
type="submit"
Expand All @@ -564,11 +571,11 @@ export class WorkflowEditor extends BtrixElement {
${msg(html`Save & Run Crawl`)}
</sl-button>
<sl-button
name=${saveButtonName}
size="small"
type="submit"
type="button"
?disabled=${this.isSubmitting}
?loading=${this.isSubmitting}
@click=${this.save}
>
${msg("Save")}
</sl-button>
Expand Down Expand Up @@ -602,6 +609,7 @@ export class WorkflowEditor extends BtrixElement {
name="scopeType"
label=${msg("Crawl Scope")}
value=${this.formState.scopeType}
hoist
@sl-change=${(e: Event) =>
this.changeScopeType(
(e.target as HTMLSelectElement).value as FormState["scopeType"],
Expand Down Expand Up @@ -1717,7 +1725,6 @@ https://archiveweb.page/images/${"logo.svg"}`}
const panelEl = el.closest<HTMLElement>(`.${formName}${panelSuffix}`);

if (!panelEl) {
console.debug("no panel for element:", el);
return;
}

Expand Down Expand Up @@ -1841,17 +1848,20 @@ https://archiveweb.page/images/${"logo.svg"}`}
private async onSubmit(event: SubmitEvent) {
event.preventDefault();

if (!this.formElem) return;
this.updateFormState({
runNow: true,
});

if (event.submitter?.getAttribute("name") === saveRunButtonName) {
this.updateFormState({
runNow: true,
});
}
void this.save();
}

private async save() {
if (!this.formElem) return;

const isValid = await this.checkFormValidity(this.formElem);

if (!isValid || this.formHasError) {
this.formElem.reportValidity();
return;
}

Expand Down Expand Up @@ -1923,7 +1933,12 @@ https://archiveweb.page/images/${"logo.svg"}`}
}
}
} else {
this.serverError = msg("Something unexpected went wrong");
this.notify.toast({
message: msg("Sorry, couldn't save workflow at this time."),
variant: "danger",
icon: "exclamation-octagon",
id: "workflow-created-status",
});
}
}

Expand Down

0 comments on commit 6606398

Please sign in to comment.