Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(native-filters): Add defaultValue for Native filters modal #12199

Merged
merged 23 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
ff3a06b
refactor: sync Scoping tree with Forms data
simcha90 Dec 22, 2020
540db22
refactor: update scoping tree
simcha90 Dec 22, 2020
e85b8c7
refactor: update scope tree logic to be more UX friendly
simcha90 Dec 23, 2020
da9887f
test: fix tests
simcha90 Dec 23, 2020
4ea8525
lint: fix lin CR notes
simcha90 Dec 23, 2020
829cdb2
chore: temp
simcha90 Dec 23, 2020
a5c3467
fix: fix jsx
simcha90 Dec 23, 2020
03e6d82
Merge branch 'sync-scoping' of github.com:simchaNielsen/incubator-sup…
simcha90 Dec 23, 2020
d20dca0
feat: Init value
simcha90 Dec 24, 2020
f154f49
refactor: move effect to utils
simcha90 Dec 24, 2020
7c851e7
chore: add comments
simcha90 Dec 24, 2020
b0f70be
Merge branch 'master' of github.com:apache/superset into filter_type
simcha90 Jan 20, 2021
1f7861e
Merge branch 'master' of github.com:apache/superset into filter_type
simcha90 Jan 27, 2021
33400b6
feat: updates for default value in native filters
simcha90 Jan 28, 2021
057a6cc
refactor: move multi values management to Modal
simcha90 Jan 28, 2021
7edf5be
Merge branch 'master' of github.com:apache/superset into filter_type
simcha90 Jan 31, 2021
51818e6
feat: added currentState to filterState
simcha90 Jan 31, 2021
b91b3f1
style: update filter styles
simcha90 Jan 31, 2021
eab3d19
fix: process selection of same filter
simcha90 Feb 1, 2021
0b6b82a
fix: fix double choose select
simcha90 Feb 1, 2021
9d2677c
fix: fix order of cascading filters
simcha90 Feb 1, 2021
50f812c
fix: fix CR comments
simcha90 Feb 2, 2021
10529e9
fix: fix CR comments
simcha90 Feb 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions superset-frontend/spec/fixtures/mockNativeFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
* specific language governing permissions and limitations
* under the License.
*/
import { NativeFiltersState } from 'src/dashboard/components/nativeFilters/types';
import {
FilterType,
NativeFiltersState,
} from 'src/dashboard/components/nativeFilters/types';

export const nativeFilters: NativeFiltersState = {
filters: {
'NATIVE_FILTER-e7Q8zKixx': {
id: 'NATIVE_FILTER-e7Q8zKixx',
name: 'region',
type: 'text',
filterType: FilterType.filter_select,
targets: [
{
datasetId: 2,
Expand All @@ -46,7 +49,7 @@ export const nativeFilters: NativeFiltersState = {
'NATIVE_FILTER-x9QPw0so1': {
id: 'NATIVE_FILTER-x9QPw0so1',
name: 'country_code',
type: 'text',
filterType: FilterType.filter_select,
targets: [
{
datasetId: 2,
Expand Down
5 changes: 5 additions & 0 deletions superset-frontend/src/dashboard/actions/nativeFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import { ExtraFormData, makeApi } from '@superset-ui/core';
import { Dispatch } from 'redux';
import {
CurrentFilterState,
Filter,
FilterConfiguration,
SelectedValues,
Expand Down Expand Up @@ -99,6 +100,7 @@ export interface SetExtraFormData {
type: typeof SET_EXTRA_FORM_DATA;
filterId: string;
extraFormData: ExtraFormData;
currentState: CurrentFilterState;
}

export function setFilterState(
Expand All @@ -117,15 +119,18 @@ export function setFilterState(
* Sets the selected option(s) for a given filter
* @param filterId the id of the native filter
* @param extraFormData the selection translated into extra form data
* @param currentState
*/
export function setExtraFormData(
filterId: string,
extraFormData: ExtraFormData,
currentState: CurrentFilterState,
): SetExtraFormData {
return {
type: SET_EXTRA_FORM_DATA,
filterId,
extraFormData,
currentState,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ import Popover from 'src/common/components/Popover';
import Icon from 'src/components/Icon';
import { Pill } from 'src/dashboard/components/FiltersBadge/Styles';
import { CascadeFilterControl, FilterControl } from './FilterBar';
import { Filter, CascadeFilter } from './types';
import { Filter, CascadeFilter, CurrentFilterState } from './types';
import { useFilterState } from './state';

interface CascadePopoverProps {
filter: CascadeFilter;
visible: boolean;
directPathToChild?: string[];
onVisibleChange: (visible: boolean) => void;
onExtraFormDataChange: (filter: Filter, extraFormData: ExtraFormData) => void;
onFilterSelectionChange: (
filter: Filter,
extraFormData: ExtraFormData,
currentState: CurrentFilterState,
) => void;
}

const StyledTitleBox = styled.div`
Expand Down Expand Up @@ -73,10 +78,11 @@ const CascadePopover: React.FC<CascadePopoverProps> = ({
filter,
visible,
onVisibleChange,
onExtraFormDataChange,
onFilterSelectionChange,
directPathToChild,
}) => {
const [currentPathToChild, setCurrentPathToChild] = useState<string[]>();
const filterState = useFilterState(filter.id);

useEffect(() => {
setCurrentPathToChild(directPathToChild);
Expand All @@ -86,26 +92,27 @@ const CascadePopover: React.FC<CascadePopoverProps> = ({
return () => clearTimeout(timeout);
}, [directPathToChild, setCurrentPathToChild]);

const getActiveChildren = useCallback((filter: CascadeFilter):
| CascadeFilter[]
| null => {
const children = filter.cascadeChildren || [];
const currentValue = filter.currentValue || [];
const getActiveChildren = useCallback(
(filter: CascadeFilter): CascadeFilter[] | null => {
const children = filter.cascadeChildren || [];
const currentValue = filterState.currentState?.value;

const activeChildren = children.flatMap(
childFilter => getActiveChildren(childFilter) || [],
);
const activeChildren = children.flatMap(
childFilter => getActiveChildren(childFilter) || [],
);

if (activeChildren.length > 0) {
return activeChildren;
}
if (activeChildren.length > 0) {
return activeChildren;
}

if (currentValue.length > 0) {
return [filter];
}
if (currentValue) {
return [filter];
}

return null;
}, []);
return null;
},
[filterState],
);

const getAllFilters = (filter: CascadeFilter): CascadeFilter[] => {
const children = filter.cascadeChildren || [];
Expand Down Expand Up @@ -139,7 +146,7 @@ const CascadePopover: React.FC<CascadePopoverProps> = ({
<FilterControl
filter={filter}
directPathToChild={directPathToChild}
onExtraFormDataChange={onExtraFormDataChange}
onFilterSelectionChange={onFilterSelectionChange}
/>
);
}
Expand All @@ -160,7 +167,7 @@ const CascadePopover: React.FC<CascadePopoverProps> = ({
key={filter.id}
filter={filter}
directPathToChild={visible ? currentPathToChild : undefined}
onExtraFormDataChange={onExtraFormDataChange}
onFilterSelectionChange={onFilterSelectionChange}
/>
);

Expand All @@ -180,7 +187,7 @@ const CascadePopover: React.FC<CascadePopoverProps> = ({
<FilterControl
key={activeFilter.id}
filter={activeFilter}
onExtraFormDataChange={onExtraFormDataChange}
onFilterSelectionChange={onFilterSelectionChange}
directPathToChild={currentPathToChild}
icon={
<>
Expand Down
Loading