Skip to content

Commit a70c40e

Browse files
committed
ensure max collection name
1 parent f97ed5c commit a70c40e

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

frontend/src/components/ui/search-combobox.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ export class SearchCombobox<T> extends TailwindElement {
5858
@property({ type: String })
5959
name?: string;
6060

61+
@property({ type: Number })
62+
maxlength?: number;
63+
6164
@property({ type: Boolean })
6265
required?: boolean;
6366

@@ -149,6 +152,7 @@ export class SearchCombobox<T> extends TailwindElement {
149152
placeholder=${this.placeholder}
150153
label=${ifDefined(this.label)}
151154
size=${ifDefined(this.size)}
155+
maxlength=${ifDefined(this.maxlength)}
152156
?disabled=${this.disabled}
153157
clearable
154158
value=${this.searchByValue}

frontend/src/features/collections/collection-create-dialog.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ import { BtrixElement } from "@/classes/BtrixElement";
1717
import type { Dialog } from "@/components/ui/dialog";
1818
import type { SelectCollectionAccess } from "@/features/collections/select-collection-access";
1919
import { alerts } from "@/strings/collections/alerts";
20-
import { CollectionAccess, type Collection } from "@/types/collection";
20+
import {
21+
COLLECTION_CAPTION_MAX_LENGTH,
22+
COLLECTION_NAME_MAX_LENGTH,
23+
CollectionAccess,
24+
type Collection,
25+
} from "@/types/collection";
2126
import { isApiError } from "@/utils/api";
2227
import { maxLengthValidator } from "@/utils/form";
2328

@@ -49,8 +54,12 @@ export class CollectionCreateDialog extends BtrixElement {
4954
@queryAsync("#collectionForm")
5055
private readonly form!: Promise<HTMLFormElement>;
5156

52-
private readonly validateNameMax = maxLengthValidator(50);
53-
private readonly validateCaptionMax = maxLengthValidator(150);
57+
private readonly validateNameMax = maxLengthValidator(
58+
COLLECTION_NAME_MAX_LENGTH,
59+
);
60+
private readonly validateCaptionMax = maxLengthValidator(
61+
COLLECTION_CAPTION_MAX_LENGTH,
62+
);
5463

5564
protected firstUpdated(): void {
5665
if (this.open) {

frontend/src/features/collections/collection-name-input.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ import type { BtrixChangeEvent } from "@/events/btrix-change";
1616
import { FormControl } from "@/mixins/FormControl";
1717
import { validationMessageFor } from "@/strings/validation";
1818
import type { APIPaginatedList } from "@/types/api";
19-
import type { Collection } from "@/types/collection";
19+
import {
20+
COLLECTION_NAME_MAX_LENGTH,
21+
type Collection,
22+
} from "@/types/collection";
2023
import appState from "@/utils/state";
2124

2225
export type CollectionNameInputChangeEvent = BtrixChangeEvent<{
@@ -42,8 +45,9 @@ export class CollectionNameInput extends WithSearchOrgContext(
4245
collectionId = "";
4346

4447
placeholder = msg("Enter existing or new collection name");
45-
searchKeys = searchQueryKeys;
4648
createNew = true;
49+
readonly searchKeys = searchQueryKeys;
50+
readonly maxlength = COLLECTION_NAME_MAX_LENGTH;
4751

4852
#collection?: Collection;
4953

frontend/src/features/crawl-workflows/workflow-editor.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,13 +2427,19 @@ https://archiveweb.page/images/${"logo.svg"}`}
24272427
${when(
24282428
this.formState.dedupeCollectionName &&
24292429
!this.formState.dedupeCollectionId,
2430-
() => html`
2431-
<div class="form-help-text">
2432-
${msg(
2433-
"A new collection will be created when this workflow is saved.",
2434-
)}
2435-
</div>
2436-
`,
2430+
() => {
2431+
const workflow_name = html`<strong class="font-medium"
2432+
>${this.formState.dedupeCollectionName}</strong
2433+
>`;
2434+
return html`
2435+
<div class="form-help-text">
2436+
${msg(
2437+
html`A new collection named “${workflow_name}” will be created
2438+
when this workflow is saved.`,
2439+
)}
2440+
</div>
2441+
`;
2442+
},
24372443
)}
24382444
`)}
24392445
${this.renderHelpTextCol(

frontend/src/types/collection.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { z } from "zod";
22

33
import { storageFileSchema } from "./storage";
44

5+
export const COLLECTION_NAME_MAX_LENGTH = 50;
6+
export const COLLECTION_CAPTION_MAX_LENGTH = 150;
7+
58
export enum CollectionAccess {
69
Private = "private",
710
Public = "public",

0 commit comments

Comments
 (0)