Skip to content

Commit

Permalink
Revert "chore(spa refactor): refactoring dashboard to use api's inste…
Browse files Browse the repository at this point in the history
…ad of bootstrapdata (apache#13306)"

This reverts commit 4bb29b6.
  • Loading branch information
henryyeh committed Apr 23, 2021
1 parent 068165f commit e26e198
Show file tree
Hide file tree
Showing 32 changed files with 183 additions and 537 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,12 @@ import {
} from './dashboard.helper';

describe('Dashboard load', () => {
beforeEach(() => {
before(() => {
cy.login();
cy.visit(WORLD_HEALTH_DASHBOARD);
});

it('should load dashboard', () => {
cy.visit(WORLD_HEALTH_DASHBOARD);
WORLD_HEALTH_CHARTS.forEach(waitForChartLoad);
});

it('should load in edit mode', () => {
cy.visit(`${WORLD_HEALTH_DASHBOARD}?edit=true&standalone=true`);
cy.get('[data-test="discard-changes-button"]').should('be.visible');
});

it('should load in standalone mode', () => {
cy.visit(`${WORLD_HEALTH_DASHBOARD}?edit=true&standalone=true`);
cy.get('#app-menu').should('not.exist');
});

it('should load in edit/standalone mode', () => {
cy.visit(`${WORLD_HEALTH_DASHBOARD}?edit=true&standalone=true`);
cy.get('[data-test="discard-changes-button"]').should('be.visible');
cy.get('#app-menu').should('not.exist');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,9 @@ describe('Nativefilters', () => {
.click()
.type('Country name');

cy.get('.ant-modal')
.find('[data-test="datasource-input"]')
.click()
.type('wb_health_population');
cy.get('.ant-modal').find('[data-test="datasource-input"]').click();

cy.get('.ant-modal [data-test="datasource-input"] .Select__menu')
cy.get('[data-test="datasource-input"]')
.contains('wb_health_population')
.click();

Expand Down Expand Up @@ -158,12 +155,9 @@ describe('Nativefilters', () => {
.click()
.type('Country name');

cy.get('.ant-modal')
.find('[data-test="datasource-input"]')
.click()
.type('wb_health_population');
cy.get('.ant-modal').find('[data-test="datasource-input"]').click();

cy.get('.ant-modal [data-test="datasource-input"] .Select__menu')
cy.get('[data-test="datasource-input"]')
.contains('wb_health_population')
.click();

Expand Down Expand Up @@ -193,10 +187,9 @@ describe('Nativefilters', () => {
cy.get('.ant-modal')
.find('[data-test="datasource-input"]')
.last()
.click()
.type('wb_health_population');
.click();

cy.get('.ant-modal [data-test="datasource-input"] .Select__menu')
cy.get('[data-test="datasource-input"]')
.last()
.contains('wb_health_population')
.click();
Expand Down
7 changes: 2 additions & 5 deletions superset-frontend/src/chart/chartReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
*/
/* eslint camelcase: 0 */
import { t } from '@superset-ui/core';
import { HYDRATE_DASHBOARD } from 'src/dashboard/actions/hydrate';
import { ChartState } from 'src/explore/types';
import { getFormDataFromControls } from 'src/explore/controlUtils';
import { now } from 'src/modules/dates';
import { now } from '../modules/dates';
import * as actions from './chartAction';

export const chart: ChartState = {
Expand Down Expand Up @@ -193,9 +192,7 @@ export default function chartReducer(
delete charts[key];
return charts;
}
if (action.type === HYDRATE_DASHBOARD) {
return { ...action.data.charts };
}

if (action.type in actionHandlers) {
return {
...charts,
Expand Down
41 changes: 0 additions & 41 deletions superset-frontend/src/common/hooks/apiResources/dashboards.ts

This file was deleted.

3 changes: 1 addition & 2 deletions superset-frontend/src/common/hooks/apiResources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ export {
// A central catalog of API Resource hooks.
// Add new API hooks here, organized under
// different files for different resource types.
export * from './charts';
export * from './dashboards';
export { useChartOwnerNames } from './charts';
2 changes: 1 addition & 1 deletion superset-frontend/src/components/ErrorBoundary/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class ErrorBoundary extends React.Component {
}

componentDidCatch(error, info) {
if (this.props.onError) this.props.onError(error, info);
this.props.onError(error, info);
this.setState({ error, info });
}

Expand Down
30 changes: 12 additions & 18 deletions superset-frontend/src/dashboard/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,22 @@ import { HTML5Backend } from 'react-dnd-html5-backend';
import { DynamicPluginProvider } from 'src/components/DynamicPlugins';
import setupApp from '../setup/setupApp';
import setupPlugins from '../setup/setupPlugins';
import DashboardPage from './containers/DashboardPage';
import DashboardContainer from './containers/Dashboard';
import { theme } from '../preamble';

setupApp();
setupPlugins();

const App = ({ store }) => {
const dashboardIdOrSlug = window.location.pathname.split('/')[3];
return (
<Provider store={store}>
<DndProvider backend={HTML5Backend}>
<ThemeProvider theme={theme}>
<DynamicPluginProvider>
<DashboardPage
store={store}
dashboardIdOrSlug={dashboardIdOrSlug}
/>
</DynamicPluginProvider>
</ThemeProvider>
</DndProvider>
</Provider>
);
};
const App = ({ store }) => (
<Provider store={store}>
<DndProvider backend={HTML5Backend}>
<ThemeProvider theme={theme}>
<DynamicPluginProvider>
<DashboardContainer />
</DynamicPluginProvider>
</ThemeProvider>
</DndProvider>
</Provider>
);

export default hot(App);
21 changes: 2 additions & 19 deletions superset-frontend/src/dashboard/actions/nativeFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@

import { makeApi } from '@superset-ui/core';
import { Dispatch } from 'redux';
import {
Filter,
FilterConfiguration,
} from 'src/dashboard/components/nativeFilters/types';
import { FilterConfiguration } from 'src/dashboard/components/nativeFilters/types';
import { DataMaskType, DataMaskStateWithId } from 'src/dataMask/types';
import {
SET_DATA_MASK_FOR_FILTER_CONFIG_COMPLETE,
SET_DATA_MASK_FOR_FILTER_CONFIG_FAIL,
} from 'src/dataMask/actions';
import { HYDRATE_DASHBOARD } from './hydrate';
import { dashboardInfoChanged } from './dashboardInfo';
import { DashboardInfo, FilterSet } from '../reducers/types';

Expand Down Expand Up @@ -109,18 +105,6 @@ export const setFilterConfiguration = (
}
};

type BootstrapData = {
nativeFilters: {
filters: Filter;
filtersState: object;
};
};

export interface SetBooststapData {
type: typeof HYDRATE_DASHBOARD;
data: BootstrapData;
}

export const setFilterSetsConfiguration = (
filterSetsConfig: FilterSet[],
) => async (dispatch: Dispatch, getState: () => any) => {
Expand Down Expand Up @@ -189,5 +173,4 @@ export type AnyFilterAction =
| SetFilterSetsConfigBegin
| SetFilterSetsConfigComplete
| SetFilterSetsConfigFail
| SaveFilterSets
| SetBooststapData;
| SaveFilterSets;
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class DashboardGrid extends React.PureComponent {
width,
isComponentVisible,
} = this.props;

const columnPlusGutterWidth =
(width + GRID_GUTTER_SIZE) / GRID_COLUMN_COUNT;

Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/dashboard/components/SaveModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class SaveModal extends React.PureComponent<SaveModalProps, SaveModalState> {
// check refresh frequency is for current session or persist
const refreshFrequency = shouldPersistRefreshFrequency
? currentRefreshFrequency
: dashboardInfo.metadata?.refresh_frequency; // eslint-disable camelcase
: dashboardInfo.metadata.refresh_frequency; // eslint-disable camelcase

const data = {
positions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function mapStateToProps({
maxUndoHistoryExceeded: !!dashboardState.maxUndoHistoryExceeded,
lastModifiedTime: Math.max(
dashboardState.lastModifiedTime,
dashboardInfo.last_modified_time,
dashboardInfo.lastModifiedTime,
),
editMode: !!dashboardState.editMode,
slug: dashboardInfo.slug,
Expand Down
90 changes: 0 additions & 90 deletions superset-frontend/src/dashboard/containers/DashboardPage.tsx

This file was deleted.

11 changes: 3 additions & 8 deletions superset-frontend/src/dashboard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,18 @@ import thunk from 'redux-thunk';
import { createStore, applyMiddleware, compose } from 'redux';
import { initFeatureFlags } from 'src/featureFlags';
import { initEnhancer } from '../reduxUtils';
import getInitialState from './reducers/getInitialState';
import rootReducer from './reducers/index';
import logger from '../middleware/loggerMiddleware';
import App from './App';

const appContainer = document.getElementById('app');
const bootstrapData = JSON.parse(appContainer.getAttribute('data-bootstrap'));
initFeatureFlags(bootstrapData.common.feature_flags);

const initialState = {
user: bootstrapData.user,
common: bootstrapData.common,
datasources: bootstrapData.datasources,
};

const initState = getInitialState(bootstrapData);
const store = createStore(
rootReducer,
initialState,
initState,
compose(applyMiddleware(thunk, logger), initEnhancer(false)),
);

Expand Down
Loading

0 comments on commit e26e198

Please sign in to comment.