Fix exclusion dropdown & removal in crawl config edit (#372)

* fix dialog closing on regex

* fix unable to delete regex with same text
This commit is contained in:
sua yoo 2022-11-18 14:47:40 -08:00 committed by GitHub
parent 4d4ce40443
commit 13d5ab7d2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 8 deletions

View File

@ -81,6 +81,8 @@ export class QueueExclusionForm extends LiteElement {
placeholder=${msg("Select Type")}
size="small"
.value=${this.selectValue}
@sl-hide=${this.stopProp}
@sl-after-hide=${this.stopProp}
@sl-select=${(e: any) => {
this.selectValue = e.target.value;
}}
@ -223,4 +225,13 @@ export class QueueExclusionForm extends LiteElement {
}) as ExclusionAddEvent
);
}
/**
* Stop propgation of sl-select events.
* Prevents bug where sl-dialog closes when dropdown closes
* https://github.com/shoelace-style/shoelace/issues/170
*/
private stopProp(e: CustomEvent) {
e.stopPropagation();
}
}

View File

@ -9,7 +9,7 @@ import { regexEscape } from "../utils/string";
import type { Exclusion } from "./queue-exclusion-form";
export type ExclusionRemoveEvent = CustomEvent<{
value: string;
regex: string;
}>;
/**
@ -205,12 +205,14 @@ export class QueueExclusionTable extends LiteElement {
return [typeColClass, valueColClass, actionColClass];
}
private removeExclusion(exclusion: Exclusion) {
this.exclusionToRemove = exclusion.value;
private removeExclusion({ value, type }: Exclusion) {
this.exclusionToRemove = value;
this.dispatchEvent(
new CustomEvent("on-remove", {
detail: exclusion,
detail: {
regex: type == "text" ? regexEscape(value) : value,
},
}) as ExclusionRemoveEvent
);
}

View File

@ -1062,7 +1062,7 @@ export class CrawlTemplatesDetail extends LiteElement {
editable
@on-remove=${(e: ExclusionRemoveEvent) => {
if (!this.exclusions) return;
const { value } = e.detail;
const { regex: value } = e.detail;
this.exclusions = this.exclusions.filter((v) => v !== value);
}}
></btrix-queue-exclusion-table>

View File

@ -537,9 +537,9 @@ export class CrawlTemplatesNew extends LiteElement {
}
private handleRemoveRegex(e: ExclusionRemoveEvent) {
const { value } = e.detail;
if (!this.exclusions || !value) return;
this.exclusions = this.exclusions.filter((v) => v !== value);
const { regex } = e.detail;
if (!this.exclusions || !regex) return;
this.exclusions = this.exclusions.filter((v) => v !== regex);
}
private handleAddRegex(e: ExclusionAddEvent) {