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: (Explore) Pre-populate dashboard in Explore #19964

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion superset-frontend/src/addSlice/AddSliceContainer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('AddSliceContainer', () => {
visType: 'table',
});
const formattedUrl =
'/superset/explore/?form_data=%7B%22viz_type%22%3A%22table%22%2C%22datasource%22%3A%221%22%7D';
'/superset/explore/?form_data=%7B%22viz_type%22%3A%22table%22%2C%22datasource%22%3A%221%22%7D&';
expect(wrapper.instance().exploreUrl()).toBe(formattedUrl);
});
});
9 changes: 8 additions & 1 deletion superset-frontend/src/addSlice/AddSliceContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,20 @@ export default class AddSliceContainer extends React.PureComponent<
}

exploreUrl() {
const url = window.location.search;
const urlParams = new URLSearchParams(url);
const dashboardExists = urlParams.has('dashboardInfo');
const dashboardInfo = urlParams.get('dashboardInfo');
const dashboardTitle = dashboardExists
? `dashboardInfo=${dashboardInfo}`
: '';
const formData = encodeURIComponent(
JSON.stringify({
viz_type: this.state.visType,
datasource: this.state.datasource?.value,
}),
);
return `/superset/explore/?form_data=${formData}`;
return `/superset/explore/?form_data=${formData}&${dashboardTitle}`;
}

gotoSlice() {
Expand Down
12 changes: 11 additions & 1 deletion superset-frontend/src/dashboard/components/DashboardGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ class DashboardGrid extends React.PureComponent {
const shouldDisplayTopLevelTabEmptyState =
shouldDisplayEmptyState && gridComponent.type === TAB_TYPE;

const dashboardProps = encodeURIComponent(
JSON.stringify({
value: this.props.dashboardId,
}),
);

const dashboardEmptyState = editMode && (
<EmptyStateBig
title={t('Drag and drop components and charts to the dashboard')}
Expand All @@ -167,7 +173,11 @@ class DashboardGrid extends React.PureComponent {
</>
}
buttonAction={() => {
window.open('/chart/add', '_blank', 'noopener noreferrer');
window.open(
`/chart/add?dashboardInfo=${dashboardProps}`,
'_blank',
'noopener noreferrer',
);
}}
image="chart.svg"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function mapStateToProps({ dashboardState, dashboardInfo }) {
return {
editMode: dashboardState.editMode,
canEdit: dashboardInfo.dash_edit_perm,
dashboardId: dashboardInfo.id,
};
}

Expand Down
18 changes: 16 additions & 2 deletions superset-frontend/src/explore/components/SaveModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ import { connect } from 'react-redux';

// Session storage key for recent dashboard
const SK_DASHBOARD_ID = 'save_chart_recent_dashboard';
const SELECT_PLACEHOLDER = t('**Select** a dashboard OR **create** a new one');
const SELECT_PLACEHOLDER = t(
'**Select** a dashboard OR type in a title to **create** a new one',
);

type SaveModalProps = {
onHide: () => void;
Expand All @@ -55,6 +57,7 @@ type SaveModalState = {
newDashboardName?: string;
alert: string | null;
action: ActionType;
newlyCreatedDashboard?: number;
};

export const StyledModal = styled(Modal)`
Expand Down Expand Up @@ -174,9 +177,20 @@ class SaveModal extends React.Component<SaveModalProps, SaveModalState> {
this.setState({ alert: null });
}

newlyCreatedDashboardName(): number | null {
const url = window.location.search;
const urlParams = new URLSearchParams(url);
const dashInfoExists = urlParams.has('dashboardInfo');
const stringifiedDash = dashInfoExists && urlParams.get('dashboardInfo');
const dashboardInfo = stringifiedDash && JSON.parse(stringifiedDash);
return dashboardInfo.value;
}

render() {
const dashboardSelectValue =
this.state.saveToDashboardId || this.state.newDashboardName;
this.state.saveToDashboardId ||
this.state.newDashboardName ||
this.newlyCreatedDashboardName();
return (
<StyledModal
show
Expand Down