From e437356013adc8beb2eca39a31beca6ba56f4c23 Mon Sep 17 00:00:00 2001 From: Vitor Avila <96086495+Vitor-Avila@users.noreply.github.com> Date: Wed, 7 Feb 2024 13:20:28 -0300 Subject: [PATCH] fix(tags): Improve support for tags with colons (#26965) --- superset-frontend/src/components/Tags/utils.tsx | 9 +++++---- superset-frontend/src/features/tags/tags.ts | 16 +++++++--------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/superset-frontend/src/components/Tags/utils.tsx b/superset-frontend/src/components/Tags/utils.tsx index 2dd38e6236911..ec08a3b126a32 100644 --- a/superset-frontend/src/components/Tags/utils.tsx +++ b/superset-frontend/src/components/Tags/utils.tsx @@ -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, @@ -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, diff --git a/superset-frontend/src/features/tags/tags.ts b/superset-frontend/src/features/tags/tags.ts index db172681cb90f..c1f5c3815106c 100644 --- a/superset-frontend/src/features/tags/tags.ts +++ b/superset-frontend/src/features/tags/tags.ts @@ -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)); } @@ -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)); } @@ -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}/`,