mirror of
https://github.com/apache/superset.git
synced 2024-09-06 13:57:40 -04:00
chore: cleanup as unknown conversion (#19587)
This commit is contained in:
parent
d6d2777ada
commit
761d5c4208
@ -22,7 +22,7 @@
|
|||||||
export default function parsePostForm(requestBody: ArrayBuffer) {
|
export default function parsePostForm(requestBody: ArrayBuffer) {
|
||||||
type ParsedFields = Record<string, string[] | string>;
|
type ParsedFields = Record<string, string[] | string>;
|
||||||
if (requestBody.constructor.name !== 'ArrayBuffer') {
|
if (requestBody.constructor.name !== 'ArrayBuffer') {
|
||||||
return requestBody as unknown as ParsedFields;
|
return requestBody;
|
||||||
}
|
}
|
||||||
const lines = new TextDecoder('utf-8').decode(requestBody).split('\n');
|
const lines = new TextDecoder('utf-8').decode(requestBody).split('\n');
|
||||||
const fields: ParsedFields = {};
|
const fields: ParsedFields = {};
|
||||||
|
@ -75,7 +75,14 @@ export function getAnalogousColors(colors: string[], results: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function addAlpha(color: string, opacity: number): string {
|
export function addAlpha(color: string, opacity: number): string {
|
||||||
// coerce values so ti is between 0 and 1.
|
// opacity value should be between 0 and 1.
|
||||||
const rounded = Math.round(Math.min(Math.max(opacity || 1, 0), 1) * 255);
|
if (opacity > 1 || opacity < 0) {
|
||||||
return color + rounded.toString(16).toUpperCase();
|
throw new Error(`The opacity should between 0 and 1, but got: ${opacity}`);
|
||||||
|
}
|
||||||
|
// the alpha value is between 00 - FF
|
||||||
|
const alpha = `0${Math.round(opacity * 255)
|
||||||
|
.toString(16)
|
||||||
|
.toUpperCase()}`.slice(-2);
|
||||||
|
|
||||||
|
return `${color}${alpha}`;
|
||||||
}
|
}
|
||||||
|
@ -67,5 +67,19 @@ describe('color utils', () => {
|
|||||||
it('adds 50% opacity to white', () => {
|
it('adds 50% opacity to white', () => {
|
||||||
expect(addAlpha('#FFFFFF', 0.5)).toBe('#FFFFFF80');
|
expect(addAlpha('#FFFFFF', 0.5)).toBe('#FFFFFF80');
|
||||||
});
|
});
|
||||||
|
it('should apply transparent alpha', () => {
|
||||||
|
expect(addAlpha('#000000', 0)).toBe('#00000000');
|
||||||
|
});
|
||||||
|
it('should apply fully opaque', () => {
|
||||||
|
expect(addAlpha('#000000', 1)).toBe('#000000FF');
|
||||||
|
});
|
||||||
|
it('opacity should be between 0 and 1', () => {
|
||||||
|
expect(() => {
|
||||||
|
addAlpha('#000000', 2);
|
||||||
|
}).toThrow();
|
||||||
|
expect(() => {
|
||||||
|
addAlpha('#000000', -1);
|
||||||
|
}).toThrow();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -55,7 +55,7 @@ describe('ExtensibleFunction', () => {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
super(function customName() {
|
super(function customName() {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return customName.x as unknown;
|
return customName.x;
|
||||||
}); // named function
|
}); // named function
|
||||||
this.x = x;
|
this.x = x;
|
||||||
}
|
}
|
||||||
|
@ -285,7 +285,8 @@ describe('buildQueryObject', () => {
|
|||||||
datasource: '5__table',
|
datasource: '5__table',
|
||||||
granularity_sqla: 'ds',
|
granularity_sqla: 'ds',
|
||||||
viz_type: 'table',
|
viz_type: 'table',
|
||||||
url_params: null as unknown as undefined,
|
// @ts-expect-error
|
||||||
|
url_params: null,
|
||||||
}).url_params,
|
}).url_params,
|
||||||
).toBeUndefined();
|
).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
@ -25,7 +25,7 @@ import {
|
|||||||
// eslint-disable-next-line import/extensions
|
// eslint-disable-next-line import/extensions
|
||||||
import birthNamesJson from './birthNames.json';
|
import birthNamesJson from './birthNames.json';
|
||||||
|
|
||||||
export const birthNames = birthNamesJson as unknown as TableChartProps;
|
export const birthNames = birthNamesJson as TableChartProps;
|
||||||
|
|
||||||
export const basicFormData: TableChartFormData = {
|
export const basicFormData: TableChartFormData = {
|
||||||
datasource: '1__table',
|
datasource: '1__table',
|
||||||
|
@ -357,7 +357,7 @@ export function transformEventAnnotation(
|
|||||||
const eventData: MarkLine1DDataItemOption[] = [
|
const eventData: MarkLine1DDataItemOption[] = [
|
||||||
{
|
{
|
||||||
name: label,
|
name: label,
|
||||||
xAxis: time as unknown as number,
|
xAxis: time,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -226,7 +226,7 @@ function QuerySearch({ actions, displayLimit }: QuerySearchProps) {
|
|||||||
value: xt,
|
value: xt,
|
||||||
label: xt,
|
label: xt,
|
||||||
}))}
|
}))}
|
||||||
value={from as unknown as undefined}
|
value={{ value: from, label: from }}
|
||||||
autosize={false}
|
autosize={false}
|
||||||
onChange={(selected: any) => setFrom(selected?.value)}
|
onChange={(selected: any) => setFrom(selected?.value)}
|
||||||
/>
|
/>
|
||||||
@ -235,7 +235,7 @@ function QuerySearch({ actions, displayLimit }: QuerySearchProps) {
|
|||||||
name="select-to"
|
name="select-to"
|
||||||
placeholder={t('[To]-')}
|
placeholder={t('[To]-')}
|
||||||
options={TIME_OPTIONS.map(xt => ({ value: xt, label: xt }))}
|
options={TIME_OPTIONS.map(xt => ({ value: xt, label: xt }))}
|
||||||
value={to as unknown as undefined}
|
value={{ value: to, label: to }}
|
||||||
autosize={false}
|
autosize={false}
|
||||||
onChange={(selected: any) => setTo(selected?.value)}
|
onChange={(selected: any) => setTo(selected?.value)}
|
||||||
/>
|
/>
|
||||||
@ -247,7 +247,7 @@ function QuerySearch({ actions, displayLimit }: QuerySearchProps) {
|
|||||||
value: s,
|
value: s,
|
||||||
label: s,
|
label: s,
|
||||||
}))}
|
}))}
|
||||||
value={status as unknown as undefined}
|
value={{ value: status, label: status }}
|
||||||
isLoading={false}
|
isLoading={false}
|
||||||
autosize={false}
|
autosize={false}
|
||||||
onChange={(selected: any) => setStatus(selected?.value)}
|
onChange={(selected: any) => setStatus(selected?.value)}
|
||||||
|
@ -16,13 +16,9 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
import { Filter } from '@superset-ui/core';
|
|
||||||
import getFormDataWithExtraFilters, {
|
import getFormDataWithExtraFilters, {
|
||||||
GetFormDataWithExtraFiltersArguments,
|
GetFormDataWithExtraFiltersArguments,
|
||||||
} from 'src/dashboard/util/charts/getFormDataWithExtraFilters';
|
} from 'src/dashboard/util/charts/getFormDataWithExtraFilters';
|
||||||
import { DASHBOARD_ROOT_ID } from 'src/dashboard/util/constants';
|
|
||||||
import { LayoutItem } from 'src/dashboard/types';
|
|
||||||
import { dashboardLayout } from 'spec/fixtures/mockDashboardLayout';
|
|
||||||
import { sliceId as chartId } from 'spec/fixtures/mockChartQueries';
|
import { sliceId as chartId } from 'spec/fixtures/mockChartQueries';
|
||||||
|
|
||||||
describe('getFormDataWithExtraFilters', () => {
|
describe('getFormDataWithExtraFilters', () => {
|
||||||
@ -63,16 +59,8 @@ describe('getFormDataWithExtraFilters', () => {
|
|||||||
},
|
},
|
||||||
sliceId: chartId,
|
sliceId: chartId,
|
||||||
nativeFilters: {
|
nativeFilters: {
|
||||||
|
filters: {},
|
||||||
filterSets: {},
|
filterSets: {},
|
||||||
filters: {
|
|
||||||
[filterId]: {
|
|
||||||
id: filterId,
|
|
||||||
scope: {
|
|
||||||
rootPath: [DASHBOARD_ROOT_ID],
|
|
||||||
excluded: [],
|
|
||||||
},
|
|
||||||
} as unknown as Filter,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
dataMask: {
|
dataMask: {
|
||||||
[filterId]: {
|
[filterId]: {
|
||||||
@ -82,9 +70,7 @@ describe('getFormDataWithExtraFilters', () => {
|
|||||||
ownState: {},
|
ownState: {},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
layout: dashboardLayout.present as unknown as {
|
layout: {},
|
||||||
[key: string]: LayoutItem;
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
it('should include filters from the passed filters', () => {
|
it('should include filters from the passed filters', () => {
|
||||||
|
@ -40,7 +40,7 @@ export default function injectCustomCss(css: string) {
|
|||||||
document.querySelector(`.${className}`) || createStyleElement(className);
|
document.querySelector(`.${className}`) || createStyleElement(className);
|
||||||
|
|
||||||
if ('styleSheet' in style) {
|
if ('styleSheet' in style) {
|
||||||
(style as unknown as MysteryStyleElement).styleSheet.cssText = css;
|
(style as HTMLStyleElement & MysteryStyleElement).styleSheet.cssText = css;
|
||||||
} else {
|
} else {
|
||||||
style.innerHTML = css;
|
style.innerHTML = css;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Slice } from 'src/types/Chart';
|
|
||||||
import { render, screen } from 'spec/helpers/testing-library';
|
import { render, screen } from 'spec/helpers/testing-library';
|
||||||
import userEvent from '@testing-library/user-event';
|
import userEvent from '@testing-library/user-event';
|
||||||
import ExploreHeader from '.';
|
import ExploreHeader from '.';
|
||||||
@ -80,7 +79,7 @@ const createProps = () => ({
|
|||||||
slice_id: 318,
|
slice_id: 318,
|
||||||
slice_name: 'Age distribution of respondents',
|
slice_name: 'Age distribution of respondents',
|
||||||
slice_url: '/superset/explore/?form_data=%7B%22slice_id%22%3A%20318%7D',
|
slice_url: '/superset/explore/?form_data=%7B%22slice_id%22%3A%20318%7D',
|
||||||
} as unknown as Slice,
|
},
|
||||||
slice_name: 'Age distribution of respondents',
|
slice_name: 'Age distribution of respondents',
|
||||||
actions: {
|
actions: {
|
||||||
postChartFormData: () => null,
|
postChartFormData: () => null,
|
||||||
|
@ -18,57 +18,27 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Slice } from 'src/types/Chart';
|
|
||||||
import { render, screen, waitFor } from 'spec/helpers/testing-library';
|
import { render, screen, waitFor } from 'spec/helpers/testing-library';
|
||||||
import fetchMock from 'fetch-mock';
|
import fetchMock from 'fetch-mock';
|
||||||
import userEvent from '@testing-library/user-event';
|
import userEvent from '@testing-library/user-event';
|
||||||
import PropertiesModal, { PropertiesModalProps } from '.';
|
import PropertiesModal, { PropertiesModalProps } from '.';
|
||||||
|
|
||||||
const createProps = () => ({
|
const createProps = () =>
|
||||||
|
({
|
||||||
slice: {
|
slice: {
|
||||||
cache_timeout: null,
|
cache_timeout: null,
|
||||||
certified_by: 'John Doe',
|
certified_by: 'John Doe',
|
||||||
certification_details: 'Sample certification',
|
certification_details: 'Sample certification',
|
||||||
changed_on: '2021-03-19T16:30:56.750230',
|
|
||||||
changed_on_humanized: '7 days ago',
|
|
||||||
datasource: 'FCC 2018 Survey',
|
|
||||||
description: null,
|
description: null,
|
||||||
description_markeddown: '',
|
|
||||||
edit_url: '/chart/edit/318',
|
|
||||||
form_data: {
|
|
||||||
adhoc_filters: [],
|
|
||||||
all_columns_x: ['age'],
|
|
||||||
color_scheme: 'supersetColors',
|
|
||||||
datasource: '49__table',
|
|
||||||
granularity_sqla: 'time_start',
|
|
||||||
groupby: null,
|
|
||||||
label_colors: {},
|
|
||||||
link_length: '25',
|
|
||||||
queryFields: { groupby: 'groupby' },
|
|
||||||
row_limit: 10000,
|
|
||||||
slice_id: 318,
|
|
||||||
time_range: 'No filter',
|
|
||||||
url_params: {},
|
|
||||||
viz_type: 'histogram',
|
|
||||||
x_axis_label: 'age',
|
|
||||||
y_axis_label: 'count',
|
|
||||||
},
|
|
||||||
modified: '<span class="no-wrap">7 days ago</span>',
|
|
||||||
owners: [
|
|
||||||
{
|
|
||||||
text: 'Superset Admin',
|
|
||||||
value: 1,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
slice_id: 318,
|
slice_id: 318,
|
||||||
slice_name: 'Age distribution of respondents',
|
slice_name: 'Age distribution of respondents',
|
||||||
slice_url: '/superset/explore/?form_data=%7B%22slice_id%22%3A%20318%7D',
|
is_managed_externally: false,
|
||||||
} as unknown as Slice,
|
},
|
||||||
show: true,
|
show: true,
|
||||||
onHide: jest.fn(),
|
onHide: jest.fn(),
|
||||||
onSave: jest.fn(),
|
onSave: jest.fn(),
|
||||||
addSuccessToast: jest.fn(),
|
addSuccessToast: jest.fn(),
|
||||||
});
|
} as PropertiesModalProps);
|
||||||
|
|
||||||
fetchMock.get('glob:*/api/v1/chart/318', {
|
fetchMock.get('glob:*/api/v1/chart/318', {
|
||||||
body: {
|
body: {
|
||||||
|
@ -16,12 +16,15 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
import { getChartControlPanelRegistry, t } from '@superset-ui/core';
|
import {
|
||||||
|
DatasourceType,
|
||||||
|
getChartControlPanelRegistry,
|
||||||
|
t,
|
||||||
|
} from '@superset-ui/core';
|
||||||
import {
|
import {
|
||||||
ControlConfig,
|
ControlConfig,
|
||||||
ControlPanelState,
|
ControlPanelState,
|
||||||
CustomControlItem,
|
CustomControlItem,
|
||||||
DatasourceMeta,
|
|
||||||
} from '@superset-ui/chart-controls';
|
} from '@superset-ui/chart-controls';
|
||||||
import {
|
import {
|
||||||
getControlConfig,
|
getControlConfig,
|
||||||
@ -44,9 +47,16 @@ const getKnownControlState = (...args: Parameters<typeof getControlState>) =>
|
|||||||
describe('controlUtils', () => {
|
describe('controlUtils', () => {
|
||||||
const state: ControlPanelState = {
|
const state: ControlPanelState = {
|
||||||
datasource: {
|
datasource: {
|
||||||
|
id: 1,
|
||||||
|
type: DatasourceType.Table,
|
||||||
columns: [{ column_name: 'a' }],
|
columns: [{ column_name: 'a' }],
|
||||||
metrics: [{ metric_name: 'first' }, { metric_name: 'second' }],
|
metrics: [{ metric_name: 'first' }, { metric_name: 'second' }],
|
||||||
} as unknown as DatasourceMeta,
|
column_format: {},
|
||||||
|
verbose_map: {},
|
||||||
|
main_dttm_col: '',
|
||||||
|
datasource_name: '1__table',
|
||||||
|
description: null,
|
||||||
|
},
|
||||||
controls: {},
|
controls: {},
|
||||||
form_data: { datasource: '1__table', viz_type: 'table' },
|
form_data: { datasource: '1__table', viz_type: 'table' },
|
||||||
};
|
};
|
||||||
|
@ -371,11 +371,11 @@ function dbReducer(
|
|||||||
action.payload.configuration_method ===
|
action.payload.configuration_method ===
|
||||||
CONFIGURATION_METHOD.DYNAMIC_FORM
|
CONFIGURATION_METHOD.DYNAMIC_FORM
|
||||||
) {
|
) {
|
||||||
const engineParamsCatalog = Object.keys(
|
const engineParamsCatalog = Object.entries(
|
||||||
extra_json?.engine_params?.catalog || {},
|
extra_json?.engine_params?.catalog || {},
|
||||||
).map(e => ({
|
).map(([key, value]) => ({
|
||||||
name: e,
|
name: key,
|
||||||
value: extra_json?.engine_params?.catalog[e],
|
value,
|
||||||
}));
|
}));
|
||||||
return {
|
return {
|
||||||
...action.payload,
|
...action.payload,
|
||||||
@ -418,9 +418,7 @@ const serializeExtra = (extraJson: DatabaseObject['extra_json']) =>
|
|||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
...extraJson,
|
...extraJson,
|
||||||
metadata_params: JSON.parse((extraJson?.metadata_params as string) || '{}'),
|
metadata_params: JSON.parse((extraJson?.metadata_params as string) || '{}'),
|
||||||
engine_params: JSON.parse(
|
engine_params: JSON.parse((extraJson?.engine_params as string) || '{}'),
|
||||||
(extraJson?.engine_params as unknown as string) || '{}',
|
|
||||||
),
|
|
||||||
schemas_allowed_for_file_upload: (
|
schemas_allowed_for_file_upload: (
|
||||||
extraJson?.schemas_allowed_for_file_upload || []
|
extraJson?.schemas_allowed_for_file_upload || []
|
||||||
).filter(schema => schema !== ''),
|
).filter(schema => schema !== ''),
|
||||||
|
@ -79,7 +79,7 @@ export type DatabaseObject = {
|
|||||||
// Extra
|
// Extra
|
||||||
extra_json?: {
|
extra_json?: {
|
||||||
engine_params?: {
|
engine_params?: {
|
||||||
catalog: Record<any, any> | string;
|
catalog?: Record<any, any> | string;
|
||||||
};
|
};
|
||||||
metadata_params?: {} | string;
|
metadata_params?: {} | string;
|
||||||
metadata_cache_timeout?: {
|
metadata_cache_timeout?: {
|
||||||
|
Loading…
Reference in New Issue
Block a user