Skip to content

Commit

Permalink
fix(tags): Improve support for tags with colons (#26965)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitor-Avila authored Feb 7, 2024
1 parent d8e26cf commit e437356
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
9 changes: 5 additions & 4 deletions superset-frontend/src/components/Tags/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ export const loadTags = async (
) => {
const searchColumn = 'name';
const query = rison.encode({
filters: [{ col: searchColumn, opr: 'ct', value: search }],
filters: [
{ col: searchColumn, opr: 'ct', value: search },
{ col: 'type', opr: 'custom_tag', value: true },
],
page,
page_size: pageSize,
order_column: searchColumn,
Expand All @@ -78,9 +81,7 @@ export const loadTags = async (
const data: {
label: string;
value: string | number;
}[] = response.json.result
.filter((item: Tag & { table_name: string }) => item.type === 1)
.map(tagToSelectOption);
}[] = response.json.result.map(tagToSelectOption);
return {
data,
totalCount: response.json.count,
Expand Down
16 changes: 7 additions & 9 deletions superset-frontend/src/features/tags/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ const map_object_type_to_id = (objectType: string) => {
};

export function fetchAllTags(
// fetch all tags (excluding system tags)
callback: (json: JsonObject) => void,
error: (response: Response) => void,
) {
SupersetClient.get({ endpoint: `/api/v1/tag` })
SupersetClient.get({
endpoint: `/api/v1/tag/?q=${rison.encode({
filters: [{ col: 'type', opr: 'custom_tag', value: true }],
})}`,
})
.then(({ json }) => callback(json))
.catch(response => error(response));
}
Expand Down Expand Up @@ -89,11 +94,7 @@ export function fetchTags(
endpoint: `/api/v1/${objectType}/${objectId}`,
})
.then(({ json }) =>
callback(
json.result.tags.filter(
(tag: Tag) => tag.name.indexOf(':') === -1 || includeTypes,
),
),
callback(json.result.tags.filter((tag: Tag) => tag.type === 1)),
)
.catch(response => error(response));
}
Expand Down Expand Up @@ -163,9 +164,6 @@ export function addTag(
if (objectType === undefined || objectId === undefined) {
throw new Error('Need to specify objectType and objectId');
}
if (tag.indexOf(':') !== -1 && !includeTypes) {
return;
}
const objectTypeId = map_object_type_to_id(objectType);
SupersetClient.post({
endpoint: `/api/v1/tag/${objectTypeId}/${objectId}/`,
Expand Down

0 comments on commit e437356

Please sign in to comment.