Skip to content

Commit

Permalink
Allow to set limit of tags returned by TagListResource (#960)
Browse files Browse the repository at this point in the history
  • Loading branch information
psrok1 authored Jul 12, 2024
1 parent 416ab4b commit db068aa
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
11 changes: 11 additions & 0 deletions mwdb/resources/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def get(self):
type: string
description: Tag prefix
required: false
- in: query
name: count
schema:
type: integer
description: Number of objects to return
required: false
responses:
200:
description: List of tags
Expand All @@ -67,6 +73,11 @@ def get(self):
tag_prefix = obj["query"]
if tag_prefix:
tags = tags.filter(Tag.tag.startswith(tag_prefix, autoescape=True))

tag_count = obj.get("count")
if tag_count:
tags = tags.limit(tag_count)

tags = tags.all()
schema = TagItemResponseSchema(many=True)
return schema.dump(tags)
Expand Down
1 change: 1 addition & 0 deletions mwdb/schema/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def validate_tag(self, value):

class TagListRequestSchema(Schema):
query = fields.Str(missing="")
count = fields.Int()


class TagRequestSchema(TagSchemaBase):
Expand Down
4 changes: 2 additions & 2 deletions mwdb/web/src/commons/api/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ function getObjectCount(
});
}

function getTags(query: string): GetTagsResponse {
function getTags(query: string, count: number): GetTagsResponse {
return axios.get(`/tag`, {
params: { query },
params: { query, count },
});
}

Expand Down
2 changes: 1 addition & 1 deletion mwdb/web/src/components/ShowObject/common/TagForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function TagForm(props: Props) {
return;
}
try {
const response = await api.getTags(value);
const response = await api.getTags(value, 20);
setTags(response.data.map((t) => t.tag));
} catch (error) {
context.setObjectError(error);
Expand Down

0 comments on commit db068aa

Please sign in to comment.