chore: Migrate /superset/user_slices and /superset/fave_slices to API v1 (#22964)

Co-authored-by: hughhhh <hughmil3s@gmail.com>
This commit is contained in:
Diego Medina
2023-04-03 14:29:02 -03:00
committed by GitHub
parent 13ffb4b7c2
commit cdc7af11bf
14 changed files with 208 additions and 43 deletions

View File

@@ -17,6 +17,7 @@
* under the License.
*/
import React from 'react';
import rison from 'rison';
import PropTypes from 'prop-types';
import { CompactPicker } from 'react-color';
import Button from 'src/components/Button';
@@ -315,34 +316,45 @@ class AnnotationLayer extends React.PureComponent {
});
});
} else if (requiresQuery(sourceType)) {
SupersetClient.get({ endpoint: '/superset/user_slices' }).then(
({ json }) => {
const registry = getChartMetadataRegistry();
this.setState({
isLoadingOptions: false,
valueOptions: json
.filter(x => {
const metadata = registry.get(x.viz_type);
return (
metadata && metadata.canBeAnnotationType(annotationType)
);
})
.map(x => ({
value: x.id,
label: x.title,
slice: {
...x,
data: {
...x.data,
groupby: x.data.groupby?.map(column =>
getColumnLabel(column),
),
},
const queryParams = rison.encode({
filters: [
{
col: 'id',
opr: 'chart_owned_created_favored_by_me',
value: true,
},
],
order_column: 'slice_name',
order_direction: 'asc',
page: 0,
page_size: 25,
});
SupersetClient.get({
endpoint: `/api/v1/chart/?q=${queryParams}`,
}).then(({ json }) => {
const registry = getChartMetadataRegistry();
this.setState({
isLoadingOptions: false,
valueOptions: json.result
.filter(x => {
const metadata = registry.get(x.viz_type);
return metadata && metadata.canBeAnnotationType(annotationType);
})
.map(x => ({
value: x.id,
label: x.slice_name,
slice: {
...x,
data: {
...x.form_data,
groupby: x.form_data.groupby?.map(column =>
getColumnLabel(column),
),
},
})),
});
},
);
},
})),
});
});
} else {
this.setState({
isLoadingOptions: false,

View File

@@ -40,9 +40,11 @@ beforeAll(() => {
result: [{ label: 'Chart A', value: 'a' }],
});
fetchMock.get('glob:*/superset/user_slices*', [
{ id: 'a', title: 'Chart A', viz_type: 'table', data: {} },
]);
fetchMock.get('glob:*/api/v1/chart/*', {
result: [
{ id: 'a', slice_name: 'Chart A', viz_type: 'table', form_data: {} },
],
});
setupColors();