Skip to content

Commit

Permalink
chore: Add entry point for SliceHeader frontend extension (apache#25968)
Browse files Browse the repository at this point in the history
  • Loading branch information
kgabryje authored Nov 14, 2023
1 parent cd52a58 commit c22c5df
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ export interface SQLResultTableExtentionProps {
expandedColumns?: string[];
}

/**
* Interface for extensions to Slice Header
*/
export interface SliceHeaderExtension {
sliceId: number;
dashboardId: number;
}

export type Extensions = Partial<{
'alertsreports.header.icon': React.ComponentType;
'embedded.documentation.configuration_details': React.ComponentType<ConfigDetailsProps>;
Expand All @@ -147,4 +155,5 @@ export type Extensions = Partial<{
'dataset.delete.related': React.ComponentType<DatasetDeleteRelatedExtensionProps>;
'sqleditor.extension.form': React.ComponentType<SQLFormExtensionProps>;
'sqleditor.extension.resultTable': React.ComponentType<SQLResultTableExtentionProps>;
'dashboard.slice.header': React.ComponentType<SliceHeaderExtension>;
}>;
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const StyledFilterCount = styled.div`
vertical-align: middle;
color: ${theme.colors.grayscale.base};
&:hover {
color: ${theme.colors.grayscale.light1}
color: ${theme.colors.grayscale.light1};
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import React from 'react';
import { Router } from 'react-router-dom';
import { createMemoryHistory } from 'history';
import { getExtensionsRegistry } from '@superset-ui/core';
import { render, screen } from 'spec/helpers/testing-library';
import userEvent from '@testing-library/user-event';
import SliceHeader from '.';
Expand Down Expand Up @@ -472,3 +473,15 @@ test('Correct actions to "SliceHeaderControls"', () => {
userEvent.click(screen.getByTestId('handleToggleFullSize'));
expect(props.handleToggleFullSize).toBeCalledTimes(1);
});

test('Add extension to SliceHeader', () => {
const extensionsRegistry = getExtensionsRegistry();
extensionsRegistry.set('dashboard.slice.header', () => (
<div>This is an extension</div>
));

const props = createProps();
render(<SliceHeader {...props} />, { useRedux: true, useRouter: true });

expect(screen.getByText('This is an extension')).toBeInTheDocument();
});
11 changes: 10 additions & 1 deletion superset-frontend/src/dashboard/components/SliceHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import React, {
useRef,
useState,
} from 'react';
import { css, styled, t } from '@superset-ui/core';
import { css, getExtensionsRegistry, styled, t } from '@superset-ui/core';
import { useUiConfig } from 'src/components/UiConfigContext';
import { Tooltip } from 'src/components/Tooltip';
import { useSelector } from 'react-redux';
Expand All @@ -38,6 +38,8 @@ import { RootState } from 'src/dashboard/types';
import { getSliceHeaderTooltip } from 'src/dashboard/util/getSliceHeaderTooltip';
import { DashboardPageIdContext } from 'src/dashboard/containers/DashboardPage';

const extensionsRegistry = getExtensionsRegistry();

type SliceHeaderProps = SliceHeaderControlsProps & {
innerRef?: string;
updateSliceName?: (arg0: string) => void;
Expand Down Expand Up @@ -161,6 +163,7 @@ const SliceHeader: FC<SliceHeaderProps> = ({
width,
height,
}) => {
const SliceHeaderExtension = extensionsRegistry.get('dashboard.slice.header');
const uiConfig = useUiConfig();
const dashboardPageId = useContext(DashboardPageIdContext);
const [headerTooltip, setHeaderTooltip] = useState<ReactNode | null>(null);
Expand Down Expand Up @@ -239,6 +242,12 @@ const SliceHeader: FC<SliceHeaderProps> = ({
<div className="header-controls">
{!editMode && (
<>
{SliceHeaderExtension && (
<SliceHeaderExtension
sliceId={slice.slice_id}
dashboardId={dashboardId}
/>
)}
{crossFilterValue && (
<Tooltip
placement="top"
Expand Down

0 comments on commit c22c5df

Please sign in to comment.