Skip to content

Commit

Permalink
additional functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
AAfghahi committed May 6, 2022
1 parent 51455c8 commit ed88c67
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 15 deletions.
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);
});
});
10 changes: 5 additions & 5 deletions superset-frontend/src/addSlice/AddSliceContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ export default class AddSliceContainer extends React.PureComponent<
}

exploreUrl() {
const url = window.location.href;
const dashboardTitleIndex = url.search('dashboardTitle:');
const dashboardExists = dashboardTitleIndex !== -1;
const url = window.location.search;
const urlParams = new URLSearchParams(url);
const dashboardExists = urlParams.has('dashboardInfo');
const dashboardInfo = urlParams.get('dashboardInfo');
const dashboardTitle = dashboardExists
? `dashboardTitle: ${url.slice(dashboardTitleIndex + 15)}`
? `dashboardInfo=${dashboardInfo}`
: '';
// 15 is how long dashboardtitle: is//
const formData = encodeURIComponent(
JSON.stringify({
viz_type: this.state.visType,
Expand Down
14 changes: 8 additions & 6 deletions 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 @@ -168,7 +174,7 @@ class DashboardGrid extends React.PureComponent {
}
buttonAction={() => {
window.open(
`/chart/add?dashboardTitle:${this.props.dashboardTitle}`,
`/chart/add?dashboardInfo=${dashboardProps}`,
'_blank',
'noopener noreferrer',
);
Expand All @@ -190,11 +196,7 @@ class DashboardGrid extends React.PureComponent {
</>
}
buttonAction={() => {
window.open(
`/chart/add?${this.props.dashboardTitle}`,
'_blank',
'noopener noreferrer',
);
window.open('/chart/add', '_blank', 'noopener noreferrer');
}}
image="chart.svg"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function mapStateToProps({ dashboardState, dashboardInfo }) {
return {
editMode: dashboardState.editMode,
canEdit: dashboardInfo.dash_edit_perm,
dashboardTitle: dashboardInfo.dashboard_title,
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

0 comments on commit ed88c67

Please sign in to comment.