Skip to content

Commit

Permalink
fix: Save properties after applying changes in Dashboard (#17570)
Browse files Browse the repository at this point in the history
* Refactor PropertiesModal

* Update json_metadata fully

* Clean up

* Verify values

* Catch changed to metadata

* Always updated dashboard info on update

* Avoid unnecessary fetches

* Formt

* Fix copy dashboards

* Fixes onUpdate onCopy handlers

* Pylint

* Update tests

* Clean up

* Handle data on show

* Change Save to Apply

* Update Cypress save test

* Update Cypress edit prop test

* Update PropertiesModal test

* Fix duplicate request with cross filters

* Improve code style

* Fix typo

* Lint
  • Loading branch information
geido authored and eschutho committed Dec 11, 2021
1 parent 8b0ab83 commit ba6d5b9
Show file tree
Hide file tree
Showing 16 changed files with 844 additions and 754 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,13 @@ describe('Dashboard edit action', () => {
.get('[data-test="dashboard-title-input"]')
.type(`{selectall}{backspace}${dashboardTitle}`);

cy.wait('@dashboardGet').then(() => {
selectColorScheme('d3Category20b');
});

// save edit changes
cy.get('.ant-modal-footer')
.contains('Save')
.contains('Apply')
.click()
.then(() => {
// assert that modal edit window has closed
cy.get('.ant-modal-body').should('not.exist');
cy.get('.ant-modal-body').should('not.be.visible');

// assert title has been updated
cy.get('.editable-title input').should('have.value', dashboardTitle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,28 +71,26 @@ describe('Dashboard save action', () => {
cy.get('[aria-label="edit-alt"]').click({ timeout: 5000 });
cy.get('[data-test="dashboard-delete-component-button"]')
.last()
.trigger('moustenter')
.trigger('mouseenter')
.click();

cy.get('[data-test="grid-container"]')
.find('.box_plot')
.should('not.exist');
cy.get('[data-test="grid-container"]').find('.treemap').should('not.exist');

cy.intercept('POST', '/superset/save_dash/**/').as('saveRequest');
cy.intercept('PUT', '/api/v1/dashboard/**').as('putDashboardRequest');
cy.get('[data-test="dashboard-header"]')
.find('[data-test="header-save-button"]')
.contains('Save')
.click();

// go back to view mode
cy.wait('@saveRequest');
cy.wait('@putDashboardRequest');
cy.get('[data-test="dashboard-header"]')
.find('[aria-label="edit-alt"]')
.click();

// deleted boxplot should still not exist
// deleted treemap should still not exist
cy.get('[data-test="grid-container"]')
.find('.box_plot', { timeout: 20000 })
.find('.treemap', { timeout: 20000 })
.should('not.exist');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ fetchMock.get('glob:*/api/v1/dashboard/*', {
},
});

describe('PropertiesModal', () => {
// all these tests need to be moved to dashboard/components/PropertiesModal/PropertiesModal.test.tsx
describe.skip('PropertiesModal', () => {
afterEach(() => {
jest.restoreAllMocks();
jest.resetAllMocks();
Expand Down
56 changes: 11 additions & 45 deletions superset-frontend/src/dashboard/actions/dashboardState.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/
/* eslint camelcase: 0 */
import { ActionCreators as UndoActionCreators } from 'redux-undo';
import { t, SupersetClient } from '@superset-ui/core';
import { ensureIsArray, t, SupersetClient } from '@superset-ui/core';
import { addChart, removeChart, refreshChart } from 'src/chart/chartAction';
import { chart as initChart } from 'src/chart/chartReducer';
import { applyDefaultFormData } from 'src/explore/store';
Expand All @@ -35,7 +35,11 @@ import { getActiveFilters } from 'src/dashboard/util/activeDashboardFilters';
import { safeStringify } from 'src/utils/safeStringify';
import { FeatureFlag, isFeatureEnabled } from 'src/featureFlags';
import { UPDATE_COMPONENTS_PARENTS_LIST } from './dashboardLayout';
import { setChartConfiguration } from './dashboardInfo';
import {
setChartConfiguration,
dashboardInfoChanged,
SET_CHART_CONFIG_COMPLETE,
} from './dashboardInfo';
import { fetchDatasourceMetadata } from './datasources';
import {
addFilter,
Expand Down Expand Up @@ -171,8 +175,6 @@ export function saveDashboardRequestSuccess(lastModifiedTime) {
}

export function saveDashboardRequest(data, id, saveType) {
const path = saveType === SAVE_TYPE_OVERWRITE ? 'save_dash' : 'copy_dash';

return (dispatch, getState) => {
dispatch({ type: UPDATE_COMPONENTS_PARENTS_LIST });

Expand Down Expand Up @@ -340,7 +342,7 @@ export function saveDashboardRequest(data, id, saveType) {
.catch(response => onError(response));
}
// changing the data as the endpoint requires
const copyData = { ...cleanedData };
const copyData = cleanedData;
if (copyData.metadata) {
delete copyData.metadata;
}
Expand All @@ -350,53 +352,17 @@ export function saveDashboardRequest(data, id, saveType) {
...(cleanedData?.metadata || {}),
};
return SupersetClient.post({
endpoint: `/superset/${path}/${id}/`,
endpoint: `/superset/copy_dash/${id}/`,
postPayload: {
data: {
...data,
...finalCopyData,
default_filters: safeStringify(serializedFilters),
filter_scopes: safeStringify(serializedFilterScopes),
},
},
})
.then(response => {
if (isFeatureEnabled(FeatureFlag.DASHBOARD_CROSS_FILTERS)) {
const {
dashboardInfo: {
metadata: { chart_configuration = {} },
},
} = getState();
const chartConfiguration = Object.values(chart_configuration).reduce(
(prev, next) => {
// If chart removed from dashboard - remove it from metadata
if (
Object.values(layout).find(
layoutItem => layoutItem?.meta?.chartId === next.id,
)
) {
return { ...prev, [next.id]: next };
}
return prev;
},
{},
);
dispatch(setChartConfiguration(chartConfiguration));
}
dispatch(saveDashboardRequestSuccess(response.json.last_modified_time));
dispatch(addSuccessToast(t('This dashboard was saved successfully.')));
return response;
})
.catch(response =>
getClientErrorObject(response).then(({ error }) =>
dispatch(
addDangerToast(
`${t(
'Sorry, there was an error saving this dashboard: ',
)} ${error}`,
),
),
),
);
.then(response => onCopySuccess(response))
.catch(response => onError(response));
};
}

Expand Down
Loading

0 comments on commit ba6d5b9

Please sign in to comment.