mirror of
https://github.com/apache/superset.git
synced 2026-06-01 05:39:17 +00:00
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:
@@ -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,
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user