diff --git a/web/client/selectors/__tests__/dashboard-test.js b/web/client/selectors/__tests__/dashboard-test.js index 0f56500a6f..45b1ff2e50 100644 --- a/web/client/selectors/__tests__/dashboard-test.js +++ b/web/client/selectors/__tests__/dashboard-test.js @@ -97,6 +97,13 @@ describe('dashboard selectors', () => { } } })).toBe(false); + expect(buttonCanEdit({ + router: { + location: { + pathname: '/dashboard/1' + } + } + })).toBe(false); }); it("test dashboardServicesSelector", () => { diff --git a/web/client/selectors/dashboard.js b/web/client/selectors/dashboard.js index 1deeb28447..6d5cc0a092 100644 --- a/web/client/selectors/dashboard.js +++ b/web/client/selectors/dashboard.js @@ -21,7 +21,9 @@ export const isDashboardLoading = state => state && state.dashboard && state.das export const getDashboardSaveErrors = state => state && state.dashboard && state.dashboard.saveErrors; export const isBrowserMobile = state => state && state.browser && state.browser.mobile; export const buttonCanEdit = createSelector(pathnameSelector, dashboardResource, isBrowserMobile, - (path, resource, isMobile) => isMobile ? !isMobile : (resource && resource.canEdit || isNaN(path.substr(-4)))); + // can edit only on desktop, when the resource is saved and editable by the user or when we are editing a new dashboard + // in that case the `path` ends with a number. Like `dashboard/1` or `dashboard/1234`. + (path, resource, isMobile) => isMobile ? !isMobile : (resource && resource.canEdit || isNaN(path.substr(-1)))); export const originalDataSelector = state => state?.dashboard?.originalData; export const dashboardServicesSelector = state => state && state.dashboard && state.dashboard.services;