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

chore(spa refactor): refactoring dashboard to use api's instead of bootstrapdata #13306

Merged
merged 67 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
8375446
add hook for future async api calls
pkdotson Feb 5, 2021
49d8edc
test to see conflict
pkdotson Feb 8, 2021
52731c7
add async middleware and update reducers
pkdotson Feb 9, 2021
8050697
working async dashboard load
pkdotson Feb 17, 2021
d247e96
implement getcharts api
pkdotson Feb 17, 2021
706845b
add user permissions to explore and dashboard bootstrap data
suddjian Feb 19, 2021
0010bbb
integrate api calls with getinitial state
pkdotson Feb 19, 2021
4d54bc4
Merge branch 'hook-dashboard' of https://github.com/preset-io/superse…
pkdotson Feb 19, 2021
82b6984
update namings
pkdotson Feb 23, 2021
02a2dd1
accept an id or a slug in the dashboard charts api
suddjian Feb 23, 2021
97e62b9
Merge branch 'master' into hook-dashboard
suddjian Feb 23, 2021
2450a85
add permissions function
pkdotson Feb 24, 2021
ea65d57
Merge branch 'hook-dashboard' of https://github.com/preset-io/superse…
pkdotson Feb 24, 2021
168bd0e
fix merge
pkdotson Feb 24, 2021
88b7a33
Merge branch 'master' of https://github.com/preset-io/superset into h…
pkdotson Mar 9, 2021
e9c0a74
update state
pkdotson Mar 10, 2021
96d5a82
get dashboard charts by id or slug
suddjian Mar 10, 2021
46ffec7
fix undefined states
pkdotson Mar 10, 2021
d0d3117
variable names
suddjian Mar 11, 2021
d170b79
stop using some more bootstrap data
suddjian Mar 11, 2021
ff023bc
fix metadata reference
suddjian Mar 11, 2021
8034e91
remove unused bootstrap from the template
suddjian Mar 11, 2021
23fe65b
add errorboundry to dashboard
pkdotson Mar 11, 2021
4b6d51a
Merge branch 'hook-dashboard' of https://github.com/preset-io/superse…
pkdotson Mar 11, 2021
64137af
refactoring, fixing
suddjian Mar 11, 2021
17465ee
update permissions
pkdotson Mar 11, 2021
3560dff
Merge branch 'hook-dashboard' of https://github.com/preset-io/superse…
pkdotson Mar 11, 2021
af5d24a
add just roles
pkdotson Mar 11, 2021
8691cac
id is supposed to be a string
suddjian Mar 12, 2021
b003f56
Merge branch 'master' into hook-dashboard
suddjian Mar 12, 2021
601df9b
unused vars
suddjian Mar 12, 2021
eb80636
get datasources from api
suddjian Mar 12, 2021
7ae7e54
make onError optional
suddjian Mar 12, 2021
19c6d3e
use resource hooks, better error boundary
suddjian Mar 12, 2021
d4cc924
add loading state for dashboardroute
pkdotson Mar 13, 2021
69fba28
remove console
pkdotson Mar 13, 2021
a5f0337
add conditional
pkdotson Mar 16, 2021
25c8ed6
more conditionals
pkdotson Mar 16, 2021
8528ce3
testing out a possible fix for cypress
suddjian Mar 17, 2021
de82911
Merge branch 'master' into hook-dashboard
suddjian Mar 26, 2021
fc5c1b4
convert edit/standalone test to cypress
suddjian Mar 26, 2021
291fcd3
remove bootstrappy assertions
suddjian Mar 26, 2021
9dcfc00
lint
suddjian Mar 26, 2021
1fdfe12
fix dashboard edit history issue
suddjian Mar 29, 2021
21e7848
rename stuff
suddjian Mar 30, 2021
321ad7f
address recent native filters schema change
suddjian Mar 31, 2021
5af2efa
remove unused getInitialState
suddjian Mar 31, 2021
fdf9a5b
remove .only from test
suddjian Mar 31, 2021
8e1bf02
hooksy redux usage
suddjian Mar 31, 2021
9d25042
Revert "more conditionals"
suddjian Mar 31, 2021
cc638a3
cleanup
suddjian Mar 31, 2021
09dd21b
undo unnecessary change
suddjian Mar 31, 2021
9256762
actually need conditions here
suddjian Mar 31, 2021
77dea19
certainty
suddjian Mar 31, 2021
9fe0577
Revert "certainty"
suddjian Mar 31, 2021
52b3111
more permutations (untested yolo)
suddjian Apr 1, 2021
2e5b817
Update superset-frontend/src/chart/chartReducer.ts
suddjian Apr 1, 2021
874cf20
import style
suddjian Apr 1, 2021
230bc97
comment
suddjian Apr 1, 2021
5bf69e6
cleaner dashboardInfo
suddjian Apr 2, 2021
a56d3b3
remove debug code
suddjian Apr 2, 2021
efd189c
use memo for getPermissions
pkdotson Apr 5, 2021
87b3928
fix lint
pkdotson Apr 5, 2021
2de8a79
adjust name/location of DashboardPage
suddjian Apr 7, 2021
b6247ff
move logic for REMOVE_SLICE_LEVEL_LABEL_COLORS to DAO
suddjian Apr 7, 2021
483389d
stop using full_data()
suddjian Apr 7, 2021
8f46816
remove unused (and now useless) json=true query param
suddjian Apr 7, 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
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,28 @@ import {
} from './dashboard.helper';

describe('Dashboard load', () => {
before(() => {
beforeEach(() => {
rusackas marked this conversation as resolved.
Show resolved Hide resolved
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`);
suddjian marked this conversation as resolved.
Show resolved Hide resolved
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,9 +61,12 @@ describe('Nativefilters', () => {
.click()
.type('Country name');

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

cy.get('[data-test="datasource-input"]')
cy.get('.ant-modal [data-test="datasource-input"] .Select__menu')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a problem, but I'm curious why we need the .ant-modal selector here. Mainly wondering if our data-test attribute is too general and should just be made more specific.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I think that's a copy-paste artifact

.contains('wb_health_population')
.click();

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

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

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

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

cy.get('[data-test="datasource-input"]')
cy.get('.ant-modal [data-test="datasource-input"] .Select__menu')
.last()
.contains('wb_health_population')
.click();
Expand Down
7 changes: 5 additions & 2 deletions superset-frontend/src/chart/chartReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
*/
/* 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 '../modules/dates';
import { now } from 'src/modules/dates';
import * as actions from './chartAction';

export const chart: ChartState = {
Expand Down Expand Up @@ -192,7 +193,9 @@ 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: 41 additions & 0 deletions superset-frontend/src/common/hooks/apiResources/dashboards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* 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 Dashboard from 'src/types/Dashboard';
import { useApiV1Resource, useTransformedResource } from './apiResources';
rusackas marked this conversation as resolved.
Show resolved Hide resolved

export const useDashboard = (idOrSlug: string | number) =>
useTransformedResource(
useApiV1Resource<Dashboard>(`/api/v1/dashboard/${idOrSlug}`),
dashboard => ({
...dashboard,
metadata: JSON.parse(dashboard.json_metadata),
position_data: JSON.parse(dashboard.position_json),
}),
);

// gets the chart definitions for a dashboard
export const useDashboardCharts = (idOrSlug: string | number) =>
useApiV1Resource(`/api/v1/dashboard/${idOrSlug}/charts`);

// gets the datasets for a dashboard
// important: this endpoint only returns the fields in the dataset
// that are necessary for rendering the given dashboard
export const useDashboardDatasets = (idOrSlug: string | number) =>
useApiV1Resource(`/api/v1/dashboard/${idOrSlug}/datasets`);
3 changes: 2 additions & 1 deletion superset-frontend/src/common/hooks/apiResources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ export {
// A central catalog of API Resource hooks.
// Add new API hooks here, organized under
// different files for different resource types.
export { useChartOwnerNames } from './charts';
export * from './charts';
export * from './dashboards';
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) {
this.props.onError(error, info);
if (this.props.onError) this.props.onError(error, info);
this.setState({ error, info });
}

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

setupApp();
setupPlugins();

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

export default hot(App);
Loading