Skip to content

Commit

Permalink
feat: add 'dashboard.nav.right' extension to registry (#20835)
Browse files Browse the repository at this point in the history
* add 'dashboard.nav.right' extension to registry

* add test
  • Loading branch information
samtfm authored Aug 4, 2022
1 parent e350823 commit 226712d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type ReturningDisplayable<P = void> = (props: P) => string | React.ReactElement;
export type Extensions = Partial<{
'embedded.documentation.description': ReturningDisplayable;
'embedded.documentation.url': string;
'dashboard.nav.right': React.ComponentType;
'navbar.right': React.ComponentType;
'welcome.banner': React.ComponentType;
}>;
Expand Down
16 changes: 16 additions & 0 deletions superset-frontend/src/dashboard/components/Header/Header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import React from 'react';
import { render, screen, fireEvent } from 'spec/helpers/testing-library';
import userEvent from '@testing-library/user-event';
import fetchMock from 'fetch-mock';
import { getExtensionsRegistry } from '@superset-ui/core';
import setupExtensions from 'src/setup/setupExtensions';
import { HeaderProps } from './types';
import Header from '.';

Expand Down Expand Up @@ -327,3 +329,17 @@ test('should refresh the charts', async () => {
userEvent.click(screen.getByText('Refresh dashboard'));
expect(mockedProps.onRefresh).toHaveBeenCalledTimes(1);
});

test('should render an extension component if one is supplied', () => {
const extensionsRegistry = getExtensionsRegistry();
extensionsRegistry.set('dashboard.nav.right', () => (
<>dashboard.nav.right extension component</>
));
setupExtensions();

const mockedProps = createProps();
setup(mockedProps);
expect(
screen.getByText('dashboard.nav.right extension component'),
).toBeInTheDocument();
});
13 changes: 12 additions & 1 deletion superset-frontend/src/dashboard/components/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
import moment from 'moment';
import React from 'react';
import PropTypes from 'prop-types';
import { styled, css, t, getSharedLabelColor } from '@superset-ui/core';
import {
styled,
css,
t,
getSharedLabelColor,
getUiOverrideRegistry,
} from '@superset-ui/core';
import { Global } from '@emotion/react';
import { isFeatureEnabled, FeatureFlag } from 'src/featureFlags';
import {
Expand Down Expand Up @@ -53,6 +59,8 @@ import { FILTER_BOX_MIGRATION_STATES } from 'src/explore/constants';
import { PageHeaderWithActions } from 'src/components/PageHeaderWithActions';
import { DashboardEmbedModal } from '../DashboardEmbedControls';

const uiOverrideRegistry = getUiOverrideRegistry();

const propTypes = {
addSuccessToast: PropTypes.func.isRequired,
addDangerToast: PropTypes.func.isRequired,
Expand Down Expand Up @@ -483,6 +491,8 @@ class Header extends React.PureComponent {
dashboardTitleChanged(updates.title);
};

const NavExtension = uiOverrideRegistry.get('dashboard.nav.right');

return (
<div
css={headerContainerStyle}
Expand Down Expand Up @@ -602,6 +612,7 @@ class Header extends React.PureComponent {
/>
) : (
<div css={actionButtonsStyle}>
{NavExtension && <NavExtension />}
{userCanEdit && (
<Button
buttonStyle="secondary"
Expand Down

0 comments on commit 226712d

Please sign in to comment.