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

chore: Add entry point for SliceHeader frontend extension #25968

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@ export interface SQLResultTableExtentionProps {
expandedColumns?: string[];
}

/**
* Interface for extensions to Slice Header
*/
export interface SliceHeaderExtension {
slice: {
description: string;
viz_type: string;
slice_name: string;
slice_id: number;
slice_description: string;
datasource: string;
};
dashboardId: number;
}

export type Extensions = Partial<{
'alertsreports.header.icon': React.ComponentType;
'embedded.documentation.configuration_details': React.ComponentType<ConfigDetailsProps>;
Expand All @@ -147,4 +162,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();
});
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,9 @@ const SliceHeader: FC<SliceHeaderProps> = ({
<div className="header-controls">
{!editMode && (
<>
{SliceHeaderExtension && (

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a test for when the extension is provided?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, done

<SliceHeaderExtension slice={slice} dashboardId={dashboardId} />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need the entire slice or just the id?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, if an extension needs entire slice, it can be pulled from redux store using just the id. Updated

)}
{crossFilterValue && (
<Tooltip
placement="top"
Expand Down
Loading