geido commented on code in PR #28046:
URL: https://github.com/apache/superset/pull/28046#discussion_r1575085804
##########
superset-frontend/src/explore/actions/saveModalActions.ts:
##########
@@ -173,10 +221,14 @@ const addToasts = (isNewSlice, sliceName,
addedToDashboard) => {
return toasts;
};
-// Update existing slice
export const updateSlice =
- (slice, sliceName, dashboards, addedToDashboard) =>
- async (dispatch, getState) => {
+ (
+ slice: Slice,
+ sliceName: string,
+ dashboards: number[],
+ addedToDashboard?: Dashboard,
+ ) =>
+ async (dispatch: Dispatch, getState: () => any) => {
Review Comment:
`any` here too
##########
superset-frontend/src/explore/actions/saveModalActions.ts:
##########
@@ -17,126 +17,174 @@
* under the License.
*/
import rison from 'rison';
+import { Dispatch } from 'redux';
import { SupersetClient, t } from '@superset-ui/core';
import { addSuccessToast } from 'src/components/MessageToasts/actions';
import { isEmpty } from 'lodash';
-import { buildV1ChartDataPayload } from '../exploreUtils';
import { Operators } from '../constants';
+export interface Dashboard {
+ title: string;
+ new?: boolean;
+}
+
+export interface Slice {
+ slice_id: number;
+ owners: string[];
+ form_data: FormData;
+}
+
+export interface FormData {
+ datasource: string;
+ viz_type: string;
+ adhoc_filters?: AdhocFilter[];
+ dashboards?: number[];
+ [key: string]: string | number | number[] | AdhocFilter[] | undefined;
+}
+
+interface AdhocFilter {
+ clause?: string;
+ subject?: string;
+ operator: string;
+ comparator?: string;
+ expressionType?: string;
+ isExtra?: boolean;
+}
+
+interface SlicePayload {
+ params: string;
+ slice_name: string;
+ viz_type: string;
+ datasource_id: number;
+ datasource_type: string;
+ dashboards: number[];
+ owners: string[];
+ query_context: string;
+}
+
const ADHOC_FILTER_REGEX = /^adhoc_filters/;
export const FETCH_DASHBOARDS_SUCCEEDED = 'FETCH_DASHBOARDS_SUCCEEDED';
-export function fetchDashboardsSucceeded(choices) {
+export function fetchDashboardsSucceeded(choices: string[]) {
return { type: FETCH_DASHBOARDS_SUCCEEDED, choices };
}
export const FETCH_DASHBOARDS_FAILED = 'FETCH_DASHBOARDS_FAILED';
-export function fetchDashboardsFailed(userId) {
+export function fetchDashboardsFailed(userId: string) {
return { type: FETCH_DASHBOARDS_FAILED, userId };
}
export const SET_SAVE_CHART_MODAL_VISIBILITY =
'SET_SAVE_CHART_MODAL_VISIBILITY';
-export function setSaveChartModalVisibility(isVisible) {
+export function setSaveChartModalVisibility(isVisible: boolean) {
return { type: SET_SAVE_CHART_MODAL_VISIBILITY, isVisible };
}
export const SAVE_SLICE_FAILED = 'SAVE_SLICE_FAILED';
export function saveSliceFailed() {
return { type: SAVE_SLICE_FAILED };
}
+
export const SAVE_SLICE_SUCCESS = 'SAVE_SLICE_SUCCESS';
-export function saveSliceSuccess(data) {
+export function saveSliceSuccess(data: any) {
return { type: SAVE_SLICE_SUCCESS, data };
}
-const extractAdhocFiltersFromFormData = formDataToHandle =>
- Object.entries(formDataToHandle).reduce(
- (acc, [key, value]) =>
- ADHOC_FILTER_REGEX.test(key)
- ? { ...acc, [key]: value?.filter(f => !f.isExtra) }
- : acc,
- {},
- );
+function extractAdhocFiltersFromFormData(
+ formDataToHandle: FormData,
+): Partial<FormData> {
+ const result: Partial<FormData> = {};
+ Object.entries(formDataToHandle).forEach(([key, value]) => {
+ if (ADHOC_FILTER_REGEX.test(key) && Array.isArray(value)) {
+ result[key] = (value as AdhocFilter[]).filter(
+ (f: AdhocFilter) => !f.isExtra,
+ );
+ }
+ });
+ return result;
+}
-const hasTemporalRangeFilter = formData =>
+const hasTemporalRangeFilter = (formData: Partial<FormData>): boolean =>
(formData?.adhoc_filters || []).some(
- filter => filter.operator === Operators.TemporalRange,
+ (filter: any) => filter.operator === Operators.TemporalRange,
Review Comment:
We need to get rid of `any`s wherever possible
##########
superset-frontend/src/explore/actions/saveModalActions.ts:
##########
@@ -17,126 +17,174 @@
* under the License.
*/
import rison from 'rison';
+import { Dispatch } from 'redux';
import { SupersetClient, t } from '@superset-ui/core';
import { addSuccessToast } from 'src/components/MessageToasts/actions';
import { isEmpty } from 'lodash';
-import { buildV1ChartDataPayload } from '../exploreUtils';
import { Operators } from '../constants';
+export interface Dashboard {
+ title: string;
+ new?: boolean;
+}
+
+export interface Slice {
+ slice_id: number;
+ owners: string[];
+ form_data: FormData;
+}
+
+export interface FormData {
+ datasource: string;
+ viz_type: string;
+ adhoc_filters?: AdhocFilter[];
+ dashboards?: number[];
+ [key: string]: string | number | number[] | AdhocFilter[] | undefined;
+}
+
+interface AdhocFilter {
+ clause?: string;
+ subject?: string;
+ operator: string;
+ comparator?: string;
+ expressionType?: string;
+ isExtra?: boolean;
+}
+
+interface SlicePayload {
+ params: string;
+ slice_name: string;
+ viz_type: string;
+ datasource_id: number;
+ datasource_type: string;
+ dashboards: number[];
+ owners: string[];
+ query_context: string;
+}
+
Review Comment:
I believe for most of these we should have types defined already. For
instance, you can find form data related types here
`superset-frontend/packages/superset-ui-core/src/query/types/QueryFormData.ts`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]