Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to set limit of tags returned by TagListResource #960

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading