fix(tags): Improve support for tags with colons (#26965)

This commit is contained in:
Vitor Avila 2024-02-07 13:20:28 -03:00 committed by GitHub
parent d8e26cfff1
commit e437356013
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 13 deletions

View File

@ -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,

View File

@ -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}/`,