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

feat: add extension point to the top of welcome page #20575

Merged
merged 7 commits into from
Jul 1, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type UiOverrides = Partial<{
'embedded.documentation.description': UiGeneratorText;
'embedded.documentation.url': string;
'navbar.right': React.ComponentType;
'welcome.banner': React.ComponentType;
}>;

/**
Expand Down
4 changes: 4 additions & 0 deletions superset-frontend/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export const URL_PARAMS = {
name: 'viz_type',
type: 'string',
},
showDatabaseModal: {
Copy link
Member

Choose a reason for hiding this comment

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

why is this added?

Copy link
Member Author

Choose a reason for hiding this comment

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

one of the setup guide step is to redirect to database list view and pop open the database modal

name: 'show_database_modal',
type: 'boolean',
},
} as const;

export const RESERVED_CHART_URL_PARAMS: string[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import { createErrorHandler, uploadUserPerms } from 'src/views/CRUD/utils';
import withToasts from 'src/components/MessageToasts/withToasts';
import SubMenu, { SubMenuProps } from 'src/views/components/SubMenu';
import DeleteModal from 'src/components/DeleteModal';
import { getUrlParam } from 'src/utils/urlUtils';
import { URL_PARAMS } from 'src/constants';
import { Tooltip } from 'src/components/Tooltip';
import Icons from 'src/components/Icons';
import { isUserAdmin } from 'src/dashboard/util/permissionUtils';
Expand Down Expand Up @@ -92,12 +94,15 @@ function DatabaseList({ addDangerToast, addSuccessToast }: DatabaseListProps) {
const user = useSelector<any, UserWithPermissionsAndRoles>(
state => state.user,
);
const showDatabaseModal = getUrlParam(URL_PARAMS.showDatabaseModal);

const [query, setQuery] = useQueryParams({
databaseAdded: BooleanParam,
});

const [databaseModalOpen, setDatabaseModalOpen] = useState<boolean>(false);
const [databaseModalOpen, setDatabaseModalOpen] = useState<boolean>(
showDatabaseModal || false,
);
const [databaseCurrentlyDeleting, setDatabaseCurrentlyDeleting] =
useState<DatabaseDeleteObject | null>(null);
const [currentDatabase, setCurrentDatabase] = useState<DatabaseObject | null>(
Expand Down
23 changes: 23 additions & 0 deletions superset-frontend/src/views/CRUD/welcome/Welcome.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import * as featureFlags from 'src/featureFlags';
import Welcome from 'src/views/CRUD/welcome/Welcome';
import { ReactWrapper } from 'enzyme';
import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint';
import { render, screen } from 'spec/helpers/testing-library';
import { getUiOverrideRegistry } from '@superset-ui/core';
import setupExtensions from 'src/setup/setupExtensions';

const mockStore = configureStore([thunk]);
const store = mockStore({});
Expand Down Expand Up @@ -179,3 +182,23 @@ describe('Welcome page with toggle switch', () => {
expect(wrapper.find('ImageLoader')).not.toExist();
});
});

test('should render an extension component if one is supplied', () => {
const uiOverrideRegistry = getUiOverrideRegistry();

uiOverrideRegistry.set('welcome.banner', () => (
<>welcome.banner extension component</>
));

setupExtensions();

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

expect(
screen.getByText('welcome.banner extension component'),
).toBeInTheDocument();
});
7 changes: 6 additions & 1 deletion superset-frontend/src/views/CRUD/welcome/Welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import React, { useEffect, useState } from 'react';
import { styled, t } from '@superset-ui/core';
import { styled, t, getUiOverrideRegistry } from '@superset-ui/core';
import Collapse from 'src/components/Collapse';
import { User } from 'src/types/bootstrapTypes';
import { reject } from 'lodash';
Expand Down Expand Up @@ -46,6 +46,8 @@ import ChartTable from './ChartTable';
import SavedQueries from './SavedQueries';
import DashboardTable from './DashboardTable';

const uiOverrideRegistry = getUiOverrideRegistry();

interface WelcomeProps {
user: User;
addDangerToast: (arg0: string) => void;
Expand Down Expand Up @@ -177,6 +179,8 @@ function Welcome({ user, addDangerToast }: WelcomeProps) {
setItem(LocalStorageKeys.homepage_collapse_state, state);
};

const WelcomeTopExtension = uiOverrideRegistry.get('welcome.banner');

useEffect(() => {
const activeTab = getItem(LocalStorageKeys.homepage_activity_filter, null);
setActiveState(collapseState.length > 0 ? collapseState : DEFAULT_TAB_ARR);
Expand Down Expand Up @@ -278,6 +282,7 @@ function Welcome({ user, addDangerToast }: WelcomeProps) {
!activityData?.Examples && !activityData?.Viewed;
return (
<WelcomeContainer>
{WelcomeTopExtension && <WelcomeTopExtension />}
<WelcomeNav>
<h1 className="welcome-header">Home</h1>
{isFeatureEnabled(FeatureFlag.THUMBNAILS) ? (
Expand Down