Skip to content

Commit

Permalink
chore: Add an extension for Home submenu (apache#27480)
Browse files Browse the repository at this point in the history
(cherry picked from commit a75bb76)
  • Loading branch information
kgabryje authored and sadpandajoe committed Mar 26, 2024
1 parent 8e462ed commit 9ccf369
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import React from 'react';
import React, { ReactNode, MouseEventHandler } from 'react';

/**
* A function which returns text (or marked-up text)
Expand Down Expand Up @@ -144,13 +144,34 @@ export interface DashboardEmbedModalExtensions {
onHide: () => void;
}

export interface ButtonProps {
name: ReactNode;
onClick?: MouseEventHandler<HTMLElement>;
'data-test'?: string;
buttonStyle:
| 'primary'
| 'secondary'
| 'dashed'
| 'link'
| 'warning'
| 'success'
| 'tertiary';
}

export interface SubMenuProps {
buttons?: Array<ButtonProps>;
name?: string | ReactNode;
activeChild?: string;
}

export type Extensions = Partial<{
'alertsreports.header.icon': React.ComponentType;
'embedded.documentation.configuration_details': React.ComponentType<ConfigDetailsProps>;
'embedded.documentation.description': ReturningDisplayable;
'embedded.documentation.url': string;
'embedded.modal': React.ComponentType<DashboardEmbedModalExtensions>;
'dashboard.nav.right': React.ComponentType;
'home.submenu': React.ComponentType<SubMenuProps>;
'navbar.right-menu.item.icon': React.ComponentType<RightMenuItemIconProps>;
'navbar.right': React.ComponentType;
'report-modal.dropdown.item.icon': React.ComponentType;
Expand Down
16 changes: 16 additions & 0 deletions superset-frontend/src/pages/Home/Home.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,19 @@ test('should render an extension component if one is supplied', () => {
screen.getByText('welcome.banner extension component'),
).toBeInTheDocument();
});

test('should render a submenu extension component if one is supplied', () => {
const extensionsRegistry = getExtensionsRegistry();

extensionsRegistry.set('home.submenu', () => <>submenu extension</>);

setupExtensions();

render(
<Provider store={store}>
<Welcome {...mockedProps} />
</Provider>,
);

expect(screen.getByText('submenu extension')).toBeInTheDocument();
});
7 changes: 6 additions & 1 deletion superset-frontend/src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ function Welcome({ user, addDangerToast }: WelcomeProps) {
setItem(LocalStorageKeys.HomepageCollapseState, state);
};

const SubmenuExtension = extensionsRegistry.get('home.submenu');
const WelcomeMessageExtension = extensionsRegistry.get('welcome.message');
const WelcomeTopExtension = extensionsRegistry.get('welcome.banner');
const WelcomeMainExtension = extensionsRegistry.get(
Expand Down Expand Up @@ -352,7 +353,11 @@ function Welcome({ user, addDangerToast }: WelcomeProps) {

return (
<>
<SubMenu {...menuData} />
{SubmenuExtension ? (
<SubmenuExtension {...menuData} />
) : (
<SubMenu {...menuData} />
)}
<WelcomeContainer>
{WelcomeMessageExtension && <WelcomeMessageExtension />}
{WelcomeTopExtension && <WelcomeTopExtension />}
Expand Down

0 comments on commit 9ccf369

Please sign in to comment.