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(44211751): filter-sets returned from 3.0 #192

Merged
merged 13 commits into from
Feb 18, 2025
61 changes: 35 additions & 26 deletions superset-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion superset-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
"rimraf": "^3.0.2",
"rison": "^0.1.1",
"scroll-into-view-if-needed": "^3.1.0",
"shortid": "^2.2.6",
"tinycolor2": "^1.4.2",
"urijs": "^1.19.8",
"use-event-callback": "^0.1.0",
Expand Down Expand Up @@ -234,8 +235,8 @@
"@storybook/addon-essentials": "^8.1.11",
"@storybook/addon-links": "^8.1.11",
"@storybook/addon-mdx-gfm": "^8.1.11",
"@storybook/preview-api": "^8.1.11",
"@storybook/components": "^8.1.11",
"@storybook/preview-api": "^8.1.11",
"@storybook/react": "^8.1.11",
"@storybook/react-webpack5": "^8.1.11",
"@svgr/webpack": "^8.0.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
/**
* 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.
*/
// DODO was here

import { AdhocFilter, DataMask } from '@superset-ui/core';

Expand Down Expand Up @@ -54,6 +37,23 @@ export type DataMaskState = { [id: string]: DataMask };
export type DataMaskWithId = { id: string } & DataMask;
export type DataMaskStateWithId = { [filterId: string]: DataMaskWithId };

// DODO added start 44211751
type FilterSetDodoExtended = {
isPrimary: boolean;
};

export type FilterSet = {
id: number;
name: string;
nativeFilters: Filters;
dataMask: DataMaskStateWithId;
} & FilterSetDodoExtended;

export type FilterSets = {
[filtersSetId: string]: FilterSet;
};
// DODO added stop 44211751

export type Filter = {
cascadeParentIds: string[];
defaultDataMask: DataMask;
Expand Down Expand Up @@ -156,11 +156,15 @@ export type PartialFilters = {
[filterId: string]: Partial<Filters[keyof Filters]>;
};

type NativeFiltersStateDodoExtended = {
filterSets: FilterSets; // DODO added 44211751
pendingFilterSetId?: number; // DODO added 44211751
};
export type NativeFiltersState = {
filters: Filters;
focusedFilterId?: string;
hoveredFilterId?: string;
};
} & NativeFiltersStateDodoExtended;

export type DashboardComponentMetadata = {
nativeFilters: NativeFiltersState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export enum FeatureFlag {
SlackEnableAvatars = 'SLACK_ENABLE_AVATARS',
EnableDashboardScreenshotEndpoints = 'ENABLE_DASHBOARD_SCREENSHOT_ENDPOINTS',
EnableDashboardDownloadWebDriverScreenshot = 'ENABLE_DASHBOARD_DOWNLOAD_WEBDRIVER_SCREENSHOT',
DashboardNativeFiltersSet = 'DASHBOARD_NATIVE_FILTERS_SET', // DODO added 44211751
}

export type ScheduleQueriesProps = {
Expand Down
20 changes: 2 additions & 18 deletions superset-frontend/spec/fixtures/mockNativeFilters.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,4 @@
/**
* 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.
*/
// DODO was here
import {
DataMaskStateWithId,
ExtraFormData,
Expand All @@ -24,6 +7,7 @@ import {
} from '@superset-ui/core';

export const nativeFilters: NativeFiltersState = {
filterSets: {}, // DODO added 44211751
filters: {
'NATIVE_FILTER-e7Q8zKixx': {
id: 'NATIVE_FILTER-e7Q8zKixx',
Expand Down
112 changes: 112 additions & 0 deletions superset-frontend/src/DodoExtensions/FilterSets/EditSection.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/**
* 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 { render, screen } from 'spec/helpers/testing-library';
import userEvent from '@testing-library/user-event';
import { mockStore } from 'spec/fixtures/mockStore';
import { Provider } from 'react-redux';
import EditSection, { EditSectionProps } from './EditSection';

const createProps = () => ({
filterSetId: 1,
dataMaskSelected: {
DefaultsID: {
filterState: {
value: 'value',
},
},
},
onCancel: jest.fn(),
disabled: false,
});

const setup = (props: EditSectionProps) => (
<Provider store={mockStore}>
<EditSection {...props} />
</Provider>
);

test('should render', () => {
const mockedProps = createProps();
const { container } = render(setup(mockedProps));
expect(container).toBeInTheDocument();
});

test('should render the title', () => {
const mockedProps = createProps();
render(setup(mockedProps));
expect(screen.getByText('Editing filter set:')).toBeInTheDocument();
});

test('should render the set name', () => {
const mockedProps = createProps();
render(setup(mockedProps));
expect(screen.getByText('Set name')).toBeInTheDocument();
});

test('should render a textbox', () => {
const mockedProps = createProps();
render(setup(mockedProps));
expect(screen.getByRole('textbox')).toBeInTheDocument();
});

test('should change the set name', () => {
const mockedProps = createProps();
render(setup(mockedProps));
const textbox = screen.getByRole('textbox');
userEvent.clear(textbox);
userEvent.type(textbox, 'New name');
expect(textbox).toHaveValue('New name');
});

test('should render the enter icon', () => {
const mockedProps = createProps();
render(setup(mockedProps));
expect(screen.getByRole('img', { name: 'enter' })).toBeInTheDocument();
});

test('should render the Cancel button', () => {
const mockedProps = createProps();
render(setup(mockedProps));
expect(screen.getByText('Cancel')).toBeInTheDocument();
});

test('should cancel', () => {
const mockedProps = createProps();
render(setup(mockedProps));
const cancelBtn = screen.getByText('Cancel');
expect(mockedProps.onCancel).not.toHaveBeenCalled();
userEvent.click(cancelBtn);
expect(mockedProps.onCancel).toHaveBeenCalled();
});

test('should render the Save button', () => {
const mockedProps = createProps();
render(setup(mockedProps));
expect(screen.getByText('Save')).toBeInTheDocument();
});

test('should render the Save button as disabled', () => {
const mockedProps = createProps();
const saveDisabledProps = {
...mockedProps,
disabled: true,
};
render(setup(saveDisabledProps));
expect(screen.getByText('Save').parentElement).toBeDisabled();
});
Loading
Loading