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

refactor: Migration publishedStatus to typescript #30653

Merged
Merged
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
4 changes: 2 additions & 2 deletions superset-frontend/src/dashboard/components/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,8 @@ class Header extends PureComponent {
dashboardId={dashboardInfo.id}
isPublished={isPublished}
savePublished={this.props.savePublished}
canEdit={userCanEdit}
canSave={userCanSaveAs}
userCanEdit={userCanEdit}
userCanSave={userCanSaveAs}
visible={!editMode}
/>
),
Expand Down
2 changes: 1 addition & 1 deletion superset-frontend/src/dashboard/components/Header/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export interface HeaderProps {
onSave: () => void;
fetchFaveStar: () => void;
saveFaveStar: () => void;
savePublished: () => void;
savePublished: (dashboardId: number, isPublished: boolean) => void;
updateDashboardTitle: () => void;
editMode: boolean;
setEditMode: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ const defaultProps = {
dashboardId: 1,
isPublished: false,
savePublished: jest.fn(),
canEdit: false,
canSave: false,
userCanEdit: false,
userCanSave: false,
};

test('renders with unpublished status and readonly permissions', async () => {
Expand All @@ -44,8 +44,8 @@ test('renders with unpublished status and write permissions', async () => {
render(
<PublishedStatus
{...defaultProps}
canEdit
canSave
userCanEdit
userCanSave
savePublished={savePublished}
/>,
);
Expand All @@ -69,8 +69,8 @@ test('renders with published status and write permissions', async () => {
<PublishedStatus
{...defaultProps}
isPublished
canEdit
canSave
userCanEdit
userCanSave
savePublished={savePublished}
/>,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
* under the License.
*/
import { Component } from 'react';
import PropTypes from 'prop-types';
import { t } from '@superset-ui/core';
import { Tooltip } from 'src/components/Tooltip';
import Label from 'src/components/Label';
import { HeaderProps, HeaderDropdownProps } from '../Header/types';

const propTypes = {
dashboardId: PropTypes.number,
isPublished: PropTypes.bool.isRequired,
savePublished: PropTypes.func.isRequired,
canEdit: PropTypes.bool,
canSave: PropTypes.bool,
export type DashboardPublishedStatusType = {
dashboardId: HeaderDropdownProps['dashboardId'];
userCanEdit: HeaderDropdownProps['userCanEdit'];
userCanSave: HeaderDropdownProps['userCanSave'];
isPublished: HeaderProps['isPublished'];
savePublished: HeaderProps['savePublished'];
};

const draftButtonTooltip = t(
Expand All @@ -44,8 +44,9 @@ const publishedTooltip = t(
'This dashboard is published. Click to make it a draft.',
);

export default class PublishedStatus extends Component {
componentDidMount() {
export default class PublishedStatus extends Component<DashboardPublishedStatusType> {
constructor(props: DashboardPublishedStatusType) {
super(props);
this.togglePublished = this.togglePublished.bind(this);
}

Expand All @@ -54,10 +55,12 @@ export default class PublishedStatus extends Component {
}

render() {
const { isPublished, userCanEdit, userCanSave } = this.props;

// Show everybody the draft badge
if (!this.props.isPublished) {
if (!isPublished) {
// if they can edit the dash, make the badge a button
if (this.props.canEdit && this.props.canSave) {
if (userCanEdit && userCanSave) {
return (
<Tooltip
id="unpublished-dashboard-tooltip"
Expand Down Expand Up @@ -86,7 +89,7 @@ export default class PublishedStatus extends Component {
}

// Show the published badge for the owner of the dashboard to toggle
if (this.props.canEdit && this.props.canSave) {
if (userCanEdit && userCanSave) {
return (
<Tooltip
id="published-dashboard-tooltip"
Expand All @@ -108,5 +111,3 @@ export default class PublishedStatus extends Component {
return null;
}
}

PublishedStatus.propTypes = propTypes;
Loading