2020-11-12 03:01:04 -05:00
|
|
|
/**
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
2020-11-16 02:08:35 -05:00
|
|
|
|
2020-11-12 03:01:04 -05:00
|
|
|
const V1_PLUGINS = ['box_plot', 'echarts_timeseries', 'word_cloud', 'pie'];
|
2020-11-24 06:09:57 -05:00
|
|
|
export const DASHBOARD_CHART_ALIAS_PREFIX = 'getJson_';
|
2020-11-12 03:01:04 -05:00
|
|
|
|
|
|
|
export function isLegacyChart(vizType: string): boolean {
|
|
|
|
return !V1_PLUGINS.includes(vizType);
|
|
|
|
}
|
2021-01-25 18:05:43 -05:00
|
|
|
|
2020-11-16 02:08:35 -05:00
|
|
|
export function isLegacyResponse(response: any): boolean {
|
|
|
|
return !response.result;
|
|
|
|
}
|
2021-01-25 18:05:43 -05:00
|
|
|
|
|
|
|
export function getSliceIdFromRequestUrl(url: string) {
|
2020-11-16 02:08:35 -05:00
|
|
|
const address = new URL(url);
|
|
|
|
const query = address.searchParams.get('form_data');
|
2021-01-25 18:05:43 -05:00
|
|
|
return query?.match(/\d+/)?.[0];
|
2020-11-16 02:08:35 -05:00
|
|
|
}
|
2021-01-25 18:05:43 -05:00
|
|
|
|
2020-11-16 02:08:35 -05:00
|
|
|
export function getChartAliases(slices: any[]): string[] {
|
|
|
|
const aliases: string[] = [];
|
|
|
|
Array.from(slices).forEach(slice => {
|
|
|
|
const vizType = slice.form_data.viz_type;
|
|
|
|
const isLegacy = isLegacyChart(vizType);
|
2020-11-24 06:09:57 -05:00
|
|
|
const alias = `${DASHBOARD_CHART_ALIAS_PREFIX}${slice.slice_id}`;
|
2021-01-25 18:05:43 -05:00
|
|
|
const formData = encodeURIComponent(`{"slice_id":${slice.slice_id}}`);
|
2020-11-16 02:08:35 -05:00
|
|
|
if (isLegacy) {
|
|
|
|
const route = `/superset/explore_json/?*${formData}*`;
|
2021-01-25 18:05:43 -05:00
|
|
|
cy.intercept('POST', `${route}`).as(alias);
|
2020-11-16 02:08:35 -05:00
|
|
|
aliases.push(`@${alias}`);
|
|
|
|
} else {
|
|
|
|
const route = `/api/v1/chart/data?*${formData}*`;
|
2021-01-25 18:05:43 -05:00
|
|
|
cy.intercept('POST', `${route}`).as(alias);
|
2020-11-16 02:08:35 -05:00
|
|
|
aliases.push(`@${alias}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return aliases;
|
|
|
|
}
|
2021-01-25 18:05:43 -05:00
|
|
|
|
|
|
|
export function interceptChart(sliceId: number, isLegacy = true) {
|
|
|
|
const formData = { slice_id: sliceId };
|
|
|
|
const encodedFormData = encodeURIComponent(JSON.stringify(formData));
|
|
|
|
const url = isLegacy
|
|
|
|
? `**/superset/explore_json/?form_data=${encodedFormData}*`
|
|
|
|
: `**/api/v1/chart/data?form_data=${encodedFormData}*`;
|
|
|
|
return cy.intercept('POST', url);
|
|
|
|
}
|