Skip to content

Commit afcc5fb

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 35812a4 commit afcc5fb

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,
@@ -986,6 +986,10 @@ async def remove_collection_from_all_configs(
986986
)
987987

988988
async def get_crawl_config_tags(self, org):
989+
"""get distinct tags from all crawl configs for this org"""
990+
return await self.crawl_configs.distinct("tags", {"oid": org.id})
991+
992+
async def get_crawl_config_tag_counts(self, org):
989993
"""get distinct tags from all crawl configs for this org"""
990994
tags = await self.crawl_configs.aggregate(
991995
[
@@ -1416,10 +1420,17 @@ async def get_crawl_configs(
14161420
)
14171421
return paginated_format(crawl_configs, total, page, pageSize)
14181422

1419-
@router.get("/tags", response_model=List[CrawlConfigTagCount])
1423+
@router.get("/tags", response_model=List[str], deprecated=True)
14201424
async def get_crawl_config_tags(org: Organization = Depends(org_viewer_dep)):
1425+
'''
1426+
Deprecated - prefer /api/orgs/{oid}/crawlconfigs/tagCounts instead.
1427+
'''
14211428
return await ops.get_crawl_config_tags(org)
14221429

1430+
@router.get("/tagCounts", response_model=CrawlConfigTags)
1431+
async def get_crawl_config_tag_counts(org: Organization = Depends(org_viewer_dep)):
1432+
return {"tags": await ops.get_crawl_config_tag_counts(org)}
1433+
14231434
@router.get("/search-values", response_model=CrawlConfigSearchValues)
14241435
async def get_crawl_config_search_values(
14251436
org: Organization = Depends(org_viewer_dep),

backend/btrixcloud/models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,12 @@ class CrawlConfigTagCount(BaseModel):
593593
tag: str
594594
count: int
595595

596+
# ============================================================================
597+
class CrawlConfigTags(BaseModel):
598+
"""Response model for crawlconfig tags"""
599+
600+
tags: List[CrawlConfigTagCount]
601+
596602

597603
# ============================================================================
598604
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
@@ -65,8 +65,8 @@ export class WorkflowTagFilter extends BtrixElement {
6565

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

7272
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)