Skip to content

Commit

Permalink
rename Scope and Target
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Feb 9, 2022
1 parent b65e977 commit e5b7040
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export interface NativeFilterColumn {
displayName?: string;
}

export interface Scope {
export interface NativeFilterScope {
rootPath: string[];
excluded: number[];
}

/** The target of a filter is the datasource/column being filtered */
export interface Target {
export interface NativeFilterTarget {
datasetId: number;
column: NativeFilterColumn;

Expand Down Expand Up @@ -70,11 +70,11 @@ export interface Filter {
defaultDataMask: DataMask;
id: string; // randomly generated at filter creation
name: string;
scope: Scope;
scope: NativeFilterScope;
filterType: string;
// for now there will only ever be one target
// when multiple targets are supported, change this to Target[]
targets: [Partial<Target>];
targets: [Partial<NativeFilterTarget>];
controlValues: {
[key: string]: any;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
*/
import React, { FC } from 'react';
import { FormInstance } from 'antd/lib/form';
import { Scope } from '@superset-ui/core';
import { NativeFilterScope } from '@superset-ui/core';
import FilterScope from 'src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FilterScope/FilterScope';
import { setCrossFilterFieldValues } from 'src/dashboard/components/CrossFilterScopingModal/utils';
import { useForceUpdate } from 'src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/utils';
import { CrossFilterScopingFormType } from 'src/dashboard/components/CrossFilterScopingModal/types';

type CrossFilterScopingFormProps = {
chartId: number;
scope: Scope;
scope: NativeFilterScope;
form: FormInstance<CrossFilterScopingFormType>;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* under the License.
*/

import { Scope } from '@superset-ui/core';
import { NativeFilterScope } from '@superset-ui/core';

export type CrossFilterScopingFormType = {
scope: Scope;
scope: NativeFilterScope;
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import React, { FC, useCallback, useState } from 'react';
import { Scope, styled, t } from '@superset-ui/core';
import { NativeFilterScope, styled, t } from '@superset-ui/core';
import { Radio } from 'src/components/Radio';
import { Form, Typography } from 'src/common/components';
import { useComponentDidUpdate } from 'src/hooks/useComponentDidUpdate/useComponentDidUpdate';
Expand All @@ -29,9 +29,9 @@ import { getDefaultScopeValue, isScopingAll } from './utils';
type FilterScopeProps = {
pathToFormValue?: string[];
updateFormValues: (values: any) => void;
formFilterScope?: Scope;
formFilterScope?: NativeFilterScope;
forceUpdate: Function;
filterScope?: Scope;
filterScope?: NativeFilterScope;
formScopingType?: ScopingType;
chartId?: number;
initiallyExcludedCharts?: number[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import React, { FC, useMemo, useState } from 'react';
import { Scope } from '@superset-ui/core';
import { NativeFilterScope } from '@superset-ui/core';
import { Tree } from 'src/common/components';
import { DASHBOARD_ROOT_ID } from 'src/dashboard/util/constants';
import { Tooltip } from 'src/components/Tooltip';
Expand All @@ -29,8 +29,8 @@ import { findFilterScope, getTreeCheckedItems } from './utils';
type ScopingTreeProps = {
forceUpdate: Function;
updateFormValues: (values: any) => void;
formScope?: Scope;
initialScope: Scope;
formScope?: NativeFilterScope;
initialScope: NativeFilterScope;
chartId?: number;
initiallyExcludedCharts?: number[];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
TAB_TYPE,
} from 'src/dashboard/util/componentTypes';
import { DASHBOARD_ROOT_ID } from 'src/dashboard/util/constants';
import { Scope, t } from '@superset-ui/core';
import { NativeFilterScope, t } from '@superset-ui/core';
import { BuildTreeLeafTitle, TreeItem } from './types';

export const isShowTypeInTree = ({ type, meta }: LayoutItem, charts?: Charts) =>
Expand Down Expand Up @@ -113,7 +113,10 @@ const checkTreeItem = (
});
};

export const getTreeCheckedItems = (scope: Scope, layout: Layout) => {
export const getTreeCheckedItems = (
scope: NativeFilterScope,
layout: Layout,
) => {
const checkedItems: string[] = [];
checkTreeItem(checkedItems, layout, [...scope.rootPath], [...scope.excluded]);
return [...new Set(checkedItems)];
Expand All @@ -123,7 +126,7 @@ export const getTreeCheckedItems = (scope: Scope, layout: Layout) => {
export const findFilterScope = (
checkedKeys: string[],
layout: Layout,
): Scope => {
): NativeFilterScope => {
if (!checkedKeys.length) {
return {
rootPath: [],
Expand Down Expand Up @@ -169,14 +172,14 @@ export const findFilterScope = (
export const getDefaultScopeValue = (
chartId?: number,
initiallyExcludedCharts: number[] = [],
): Scope => ({
): NativeFilterScope => ({
rootPath: [DASHBOARD_ROOT_ID],
excluded: chartId
? [chartId, ...initiallyExcludedCharts]
: initiallyExcludedCharts,
});

export const isScopingAll = (scope: Scope, chartId?: number) =>
export const isScopingAll = (scope: NativeFilterScope, chartId?: number) =>
!scope ||
(scope.rootPath[0] === DASHBOARD_ROOT_ID &&
!scope.excluded.filter(item => item !== chartId).length);
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import {
AdhocFilter,
DataMask,
NativeFilterType,
Scope,
NativeFilterScope,
} from '@superset-ui/core';

export interface NativeFiltersFormItem {
scope: Scope;
scope: NativeFilterScope;
name: string;
filterType: string;
dataset: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
NativeFilterType,
Divider,
t,
Target,
NativeFilterTarget,
} from '@superset-ui/core';
import { DASHBOARD_ROOT_ID } from 'src/dashboard/util/constants';
import {
Expand Down Expand Up @@ -156,7 +156,7 @@ export const createHandleSave =
description: formInputs.description,
};
}
const target: Partial<Target> = {};
const target: Partial<NativeFilterTarget> = {};
if (formInputs.dataset) {
target.datasetId = formInputs.dataset.value;
}
Expand Down
4 changes: 2 additions & 2 deletions superset-frontend/src/dashboard/reducers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

import componentTypes from 'src/dashboard/util/componentTypes';
import { Scope, JsonObject } from '@superset-ui/core';
import { NativeFilterScope, JsonObject } from '@superset-ui/core';

export enum Scoping {
All = 'All',
Expand All @@ -29,7 +29,7 @@ export type ChartConfiguration = {
[chartId: number]: {
id: number;
crossFilters: {
scope: Scope;
scope: NativeFilterScope;
};
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
DataMaskStateWithId,
Filters,
JsonObject,
Scope,
NativeFilterScope,
} from '@superset-ui/core';
import { CHART_TYPE } from './componentTypes';
import { ActiveFilters, Layout, LayoutItem } from '../types';
Expand All @@ -38,7 +38,7 @@ export const findAffectedCharts = ({
}: {
child: string;
layout: { [key: string]: LayoutItem };
scope: Scope;
scope: NativeFilterScope;
activeFilters: ActiveFilters;
filterId: string;
extraFormData: any;
Expand Down

0 comments on commit e5b7040

Please sign in to comment.