mirror of
https://github.com/apache/superset.git
synced 2024-09-06 22:07:34 -04:00
chore: convert chartReducer to TypeScript (#13374)
This commit is contained in:
parent
70e12ed27d
commit
f2616294e6
@ -18,11 +18,12 @@
|
|||||||
*/
|
*/
|
||||||
/* eslint camelcase: 0 */
|
/* eslint camelcase: 0 */
|
||||||
import { t } from '@superset-ui/core';
|
import { t } from '@superset-ui/core';
|
||||||
|
import { ChartState } from 'src/explore/types';
|
||||||
import { getFormDataFromControls } from 'src/explore/controlUtils';
|
import { getFormDataFromControls } from 'src/explore/controlUtils';
|
||||||
import { now } from '../modules/dates';
|
import { now } from '../modules/dates';
|
||||||
import * as actions from './chartAction';
|
import * as actions from './chartAction';
|
||||||
|
|
||||||
export const chart = {
|
export const chart: ChartState = {
|
||||||
id: 0,
|
id: 0,
|
||||||
chartAlert: null,
|
chartAlert: null,
|
||||||
chartStatus: 'loading',
|
chartStatus: 'loading',
|
||||||
@ -30,14 +31,22 @@ export const chart = {
|
|||||||
chartUpdateEndTime: null,
|
chartUpdateEndTime: null,
|
||||||
chartUpdateStartTime: 0,
|
chartUpdateStartTime: 0,
|
||||||
latestQueryFormData: {},
|
latestQueryFormData: {},
|
||||||
|
sliceFormData: null,
|
||||||
queryController: null,
|
queryController: null,
|
||||||
queriesResponse: null,
|
queriesResponse: null,
|
||||||
triggerQuery: true,
|
triggerQuery: true,
|
||||||
lastRendered: 0,
|
lastRendered: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function chartReducer(charts = {}, action) {
|
type ChartActionHandler = (state: ChartState) => ChartState;
|
||||||
const actionHandlers = {
|
|
||||||
|
type AnyChartAction = Record<string, any>;
|
||||||
|
|
||||||
|
export default function chartReducer(
|
||||||
|
charts: Record<string, ChartState> = {},
|
||||||
|
action: AnyChartAction,
|
||||||
|
) {
|
||||||
|
const actionHandlers: Record<string, ChartActionHandler> = {
|
||||||
[actions.ADD_CHART]() {
|
[actions.ADD_CHART]() {
|
||||||
return {
|
return {
|
||||||
...chart,
|
...chart,
|
||||||
@ -134,7 +143,7 @@ export default function chartReducer(charts = {}, action) {
|
|||||||
}
|
}
|
||||||
const annotationQuery = {
|
const annotationQuery = {
|
||||||
...state.annotationQuery,
|
...state.annotationQuery,
|
||||||
[action.annotation.name]: action.queryRequest,
|
[action.annotation.name]: action.queryController,
|
||||||
};
|
};
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
@ -27,11 +27,6 @@ import {
|
|||||||
QueryFormData,
|
QueryFormData,
|
||||||
DatasourceType,
|
DatasourceType,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
|
|
||||||
import Tabs from 'src/common/components/Tabs';
|
|
||||||
import Collapse from 'src/common/components/Collapse';
|
|
||||||
import { PluginContext } from 'src/components/DynamicPlugins';
|
|
||||||
import Loading from 'src/components/Loading';
|
|
||||||
import {
|
import {
|
||||||
ControlPanelSectionConfig,
|
ControlPanelSectionConfig,
|
||||||
ControlState,
|
ControlState,
|
||||||
@ -39,11 +34,21 @@ import {
|
|||||||
ExpandedControlItem,
|
ExpandedControlItem,
|
||||||
InfoTooltipWithTrigger,
|
InfoTooltipWithTrigger,
|
||||||
} from '@superset-ui/chart-controls';
|
} from '@superset-ui/chart-controls';
|
||||||
|
|
||||||
|
import Tabs from 'src/common/components/Tabs';
|
||||||
|
import Collapse from 'src/common/components/Collapse';
|
||||||
|
import { PluginContext } from 'src/components/DynamicPlugins';
|
||||||
|
import Loading from 'src/components/Loading';
|
||||||
|
|
||||||
|
import { sectionsToRender } from 'src/explore/controlUtils';
|
||||||
|
import {
|
||||||
|
ExploreActions,
|
||||||
|
exploreActions,
|
||||||
|
} from 'src/explore/actions/exploreActions';
|
||||||
|
import { ExplorePageState } from 'src/explore/reducers/getInitialState';
|
||||||
|
|
||||||
import ControlRow from './ControlRow';
|
import ControlRow from './ControlRow';
|
||||||
import Control from './Control';
|
import Control from './Control';
|
||||||
import { sectionsToRender } from '../controlUtils';
|
|
||||||
import { ExploreActions, exploreActions } from '../actions/exploreActions';
|
|
||||||
import { ExploreState } from '../reducers/getInitialState';
|
|
||||||
|
|
||||||
export type ControlPanelsContainerProps = {
|
export type ControlPanelsContainerProps = {
|
||||||
actions: ExploreActions;
|
actions: ExploreActions;
|
||||||
@ -312,8 +317,12 @@ class ControlPanelsContainer extends React.Component<ControlPanelsContainerProps
|
|||||||
export { ControlPanelsContainer };
|
export { ControlPanelsContainer };
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
function mapStateToProps({ explore }: ExploreState) {
|
function mapStateToProps(state: ExplorePageState) {
|
||||||
|
const { explore, charts } = state;
|
||||||
|
const chartKey = Object.keys(charts)[0];
|
||||||
|
const chart = charts[chartKey];
|
||||||
return {
|
return {
|
||||||
|
chart,
|
||||||
isDatasourceMetaLoading: explore.isDatasourceMetaLoading,
|
isDatasourceMetaLoading: explore.isDatasourceMetaLoading,
|
||||||
controls: explore.controls,
|
controls: explore.controls,
|
||||||
exploreState: explore,
|
exploreState: explore,
|
||||||
|
@ -23,17 +23,17 @@ import {
|
|||||||
JsonObject,
|
JsonObject,
|
||||||
QueryFormData,
|
QueryFormData,
|
||||||
} from '@superset-ui/core';
|
} from '@superset-ui/core';
|
||||||
import { Slice } from 'src/types/Chart';
|
import { ControlStateMapping } from '@superset-ui/chart-controls';
|
||||||
import { CommonBootstrapData } from 'src/types/bootstrapTypes';
|
import { CommonBootstrapData } from 'src/types/bootstrapTypes';
|
||||||
|
|
||||||
import getToastsFromPyFlashMessages from 'src/messageToasts/utils/getToastsFromPyFlashMessages';
|
import getToastsFromPyFlashMessages from 'src/messageToasts/utils/getToastsFromPyFlashMessages';
|
||||||
|
|
||||||
|
import { ChartState, Slice } from 'src/explore/types';
|
||||||
import { getChartKey } from 'src/explore/exploreUtils';
|
import { getChartKey } from 'src/explore/exploreUtils';
|
||||||
import { getControlsState } from 'src/explore/store';
|
import { getControlsState } from 'src/explore/store';
|
||||||
import {
|
import {
|
||||||
getFormDataFromControls,
|
getFormDataFromControls,
|
||||||
applyMapStateToPropsToControl,
|
applyMapStateToPropsToControl,
|
||||||
} from 'src/explore/controlUtils';
|
} from 'src/explore/controlUtils';
|
||||||
import { ControlStateMapping } from '@superset-ui/chart-controls';
|
|
||||||
|
|
||||||
export interface ExlorePageBootstrapData extends JsonObject {
|
export interface ExlorePageBootstrapData extends JsonObject {
|
||||||
can_add: boolean;
|
can_add: boolean;
|
||||||
@ -91,22 +91,24 @@ export default function getInitialState(
|
|||||||
: null;
|
: null;
|
||||||
|
|
||||||
const chartKey: number = getChartKey(bootstrapData);
|
const chartKey: number = getChartKey(bootstrapData);
|
||||||
|
const chart: ChartState = {
|
||||||
|
id: chartKey,
|
||||||
|
chartAlert: null,
|
||||||
|
chartStatus: null,
|
||||||
|
chartStackTrace: null,
|
||||||
|
chartUpdateEndTime: null,
|
||||||
|
chartUpdateStartTime: 0,
|
||||||
|
latestQueryFormData: getFormDataFromControls(exploreState.controls),
|
||||||
|
sliceFormData,
|
||||||
|
queryController: null,
|
||||||
|
queriesResponse: null,
|
||||||
|
triggerQuery: false,
|
||||||
|
lastRendered: 0,
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
charts: {
|
charts: {
|
||||||
[chartKey]: {
|
[chartKey]: chart,
|
||||||
id: chartKey,
|
|
||||||
chartAlert: null,
|
|
||||||
chartStatus: null,
|
|
||||||
chartUpdateEndTime: null,
|
|
||||||
chartUpdateStartTime: 0,
|
|
||||||
latestQueryFormData: getFormDataFromControls(exploreState.controls),
|
|
||||||
sliceFormData,
|
|
||||||
queryController: null,
|
|
||||||
queriesResponse: null,
|
|
||||||
triggerQuery: false,
|
|
||||||
lastRendered: 0,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
saveModal: {
|
saveModal: {
|
||||||
dashboards: [],
|
dashboards: [],
|
||||||
@ -120,4 +122,4 @@ export default function getInitialState(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ExploreState = ReturnType<typeof getInitialState>;
|
export type ExplorePageState = ReturnType<typeof getInitialState>;
|
||||||
|
47
superset-frontend/src/explore/types.ts
Normal file
47
superset-frontend/src/explore/types.ts
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
import { QueryData, QueryFormData, AnnotationData } from '@superset-ui/core';
|
||||||
|
|
||||||
|
export { Slice, Chart } from 'src/types/Chart';
|
||||||
|
|
||||||
|
export type ChartStatus =
|
||||||
|
| 'loading'
|
||||||
|
| 'rendered'
|
||||||
|
| 'failed'
|
||||||
|
| 'stopped'
|
||||||
|
| 'success';
|
||||||
|
|
||||||
|
export interface ChartState {
|
||||||
|
id: number;
|
||||||
|
annotationData?: AnnotationData;
|
||||||
|
annotationError?: Record<string, string>;
|
||||||
|
annotationQuery?: Record<string, AbortController>;
|
||||||
|
chartAlert: string | null;
|
||||||
|
chartStatus: ChartStatus | null;
|
||||||
|
chartStackTrace?: string | null;
|
||||||
|
chartUpdateEndTime: number | null;
|
||||||
|
chartUpdateStartTime: number;
|
||||||
|
lastRendered: number;
|
||||||
|
latestQueryFormData: Partial<QueryFormData>;
|
||||||
|
sliceFormData: QueryFormData | null;
|
||||||
|
queryController: AbortController | null;
|
||||||
|
queriesResponse: QueryData | null;
|
||||||
|
triggerQuery: boolean;
|
||||||
|
asyncJobId?: string;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user