Skip to content

Commit 7b29b1b

Browse files
committed
add new tagCounts endpoint without top-level array type, restore but
deprecate previous `tags` endpoint, swap frontend to use new endpoint
1 parent 46a3116 commit 7b29b1b

File tree

8 files changed

+35
-16
lines changed

8 files changed

+35
-16
lines changed

backend/btrixcloud/crawlconfigs.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
CrawlConfig,
2727
CrawlConfigOut,
2828
CrawlConfigProfileOut,
29-
CrawlConfigTagCount,
29+
CrawlConfigTags,
3030
CrawlOut,
3131
UpdateCrawlConfig,
3232
Organization,
@@ -977,6 +977,10 @@ async def remove_collection_from_all_configs(
977977
)
978978

979979
async def get_crawl_config_tags(self, org):
980+
"""get distinct tags from all crawl configs for this org"""
981+
return await self.crawl_configs.distinct("tags", {"oid": org.id})
982+
983+
async def get_crawl_config_tag_counts(self, org):
980984
"""get distinct tags from all crawl configs for this org"""
981985
tags = await self.crawl_configs.aggregate(
982986
[
@@ -1409,10 +1413,17 @@ async def get_crawl_configs(
14091413
)
14101414
return paginated_format(crawl_configs, total, page, pageSize)
14111415

1412-
@router.get("/tags", response_model=List[CrawlConfigTagCount])
1416+
@router.get("/tags", response_model=List[str], deprecated=True)
14131417
async def get_crawl_config_tags(org: Organization = Depends(org_viewer_dep)):
1418+
'''
1419+
Deprecated - prefer /api/orgs/{oid}/crawlconfigs/tagCounts instead.
1420+
'''
14141421
return await ops.get_crawl_config_tags(org)
14151422

1423+
@router.get("/tagCounts", response_model=CrawlConfigTags)
1424+
async def get_crawl_config_tag_counts(org: Organization = Depends(org_viewer_dep)):
1425+
return {"tags": await ops.get_crawl_config_tag_counts(org)}
1426+
14161427
@router.get("/search-values", response_model=CrawlConfigSearchValues)
14171428
async def get_crawl_config_search_values(
14181429
org: Organization = Depends(org_viewer_dep),

backend/btrixcloud/models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,12 @@ class CrawlConfigTagCount(BaseModel):
584584
tag: str
585585
count: int
586586

587+
# ============================================================================
588+
class CrawlConfigTags(BaseModel):
589+
"""Response model for crawlconfig tags"""
590+
591+
tags: List[CrawlConfigTagCount]
592+
587593

588594
# ============================================================================
589595
class CrawlConfigSearchValues(BaseModel):

frontend/src/components/ui/tag-input.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { customElement, property, query, state } from "lit/decorators.js";
1717
import debounce from "lodash/fp/debounce";
1818

1919
import type { UnderlyingFunction } from "@/types/utils";
20-
import { type WorkflowTags } from "@/types/workflow";
20+
import { type WorkflowTag } from "@/types/workflow";
2121
import { dropdown } from "@/utils/css";
2222

2323
export type Tags = string[];
@@ -117,7 +117,7 @@ export class TagInput extends LitElement {
117117
initialTags?: Tags;
118118

119119
@property({ type: Array })
120-
tagOptions: WorkflowTags = [];
120+
tagOptions: WorkflowTag[] = [];
121121

122122
@property({ type: Boolean })
123123
disabled = false;

frontend/src/features/archived-items/file-uploader.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export class FileUploader extends BtrixElement {
7171
private collectionIds: string[] = [];
7272

7373
@state()
74-
private tagOptions: WorkflowTags = [];
74+
private tagOptions: WorkflowTag[] = [];
7575

7676
@state()
7777
private tagsToSave: Tags = [];
@@ -363,8 +363,8 @@ export class FileUploader extends BtrixElement {
363363

364364
private async fetchTags() {
365365
try {
366-
const tags = await this.api.fetch<WorkflowTags>(
367-
`/orgs/${this.orgId}/crawlconfigs/tags`,
366+
const { tags } = await this.api.fetch<WorkflowTags>(
367+
`/orgs/${this.orgId}/crawlconfigs/tagCounts`,
368368
);
369369

370370
// Update search/filter collection

frontend/src/features/archived-items/item-metadata-editor.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class CrawlMetadataEditor extends LiteElement {
4747
private includeName = false;
4848

4949
@state()
50-
private tagOptions: WorkflowTags = [];
50+
private tagOptions: WorkflowTag[] = [];
5151

5252
@state()
5353
private tagsToSave: Tags = [];
@@ -166,8 +166,8 @@ export class CrawlMetadataEditor extends LiteElement {
166166
private async fetchTags() {
167167
if (!this.crawl) return;
168168
try {
169-
const tags = await this.apiFetch<WorkflowTags>(
170-
`/orgs/${this.crawl.oid}/crawlconfigs/tags`,
169+
const { tags } = await this.apiFetch<WorkflowTags>(
170+
`/orgs/${this.crawl.oid}/crawlconfigs/tagCounts`,
171171
);
172172

173173
// Update search/filter collection

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ export class WorkflowEditor extends BtrixElement {
262262
private showCrawlerChannels = false;
263263

264264
@state()
265-
private tagOptions: WorkflowTags = [];
265+
private tagOptions: WorkflowTag[] = [];
266266

267267
@state()
268268
private isSubmitting = false;
@@ -2537,8 +2537,8 @@ https://archiveweb.page/images/${"logo.svg"}`}
25372537
private async fetchTags() {
25382538
this.tagOptions = [];
25392539
try {
2540-
const tags = await this.api.fetch<WorkflowTags>(
2541-
`/orgs/${this.orgId}/crawlconfigs/tags`,
2540+
const { tags } = await this.api.fetch<WorkflowTags>(
2541+
`/orgs/${this.orgId}/crawlconfigs/tagCounts`,
25422542
);
25432543

25442544
// Update search/filter collection

frontend/src/features/crawl-workflows/workflow-tag-filter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ export class WorkflowTagFilter extends BtrixElement {
6666

6767
private readonly orgTagsTask = new Task(this, {
6868
task: async () => {
69-
const tags = await this.api.fetch<WorkflowTags>(
70-
`/orgs/${this.orgId}/crawlconfigs/tags`,
69+
const { tags } = await this.api.fetch<WorkflowTags>(
70+
`/orgs/${this.orgId}/crawlconfigs/tagCounts`,
7171
);
7272

7373
this.fuse.setCollection(tags);

frontend/src/types/workflow.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ export type WorkflowTag = {
1111
count: number;
1212
};
1313

14-
export type WorkflowTags = WorkflowTag[];
14+
export type WorkflowTags = {
15+
tags: WorkflowTag[];
16+
};

0 commit comments

Comments
 (0)