Skip to content

Commit

Permalink
chore: rename "uiOverrideRegistry" -> "extensionsRegistry" (apache#20628
Browse files Browse the repository at this point in the history
)

* uiOverrideRegistry -> extensionsRegistry

* better comments

* missed a spot

* missed another spot

* url
  • Loading branch information
suddjian authored and akshatsri committed Jul 19, 2022
1 parent 301ad62 commit beb5545
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,37 @@ import React from 'react';
import { TypedRegistry } from '../models';
import { makeSingleton } from '../utils';

/** A function (or component) which returns text (or marked-up text) */
type UiGeneratorText<P = void> = (props: P) => string | React.ReactElement;
/**
* A function which returns text (or marked-up text)
* If what you want is a react component, don't use this. Use React.ComponentType instead.
*/
type ReturningDisplayable<P = void> = (props: P) => string | React.ReactElement;

/**
* This type defines all the UI override options which replace elements of Superset's default UI.
* Idea with the keys here is generally to namespace following the form of 'domain.functonality.item'
* This type defines all available extensions of Superset's default UI.
* Namespace the keys here to follow the form of 'some_domain.functonality.item'.
* Take care to name your keys well, as the name describes what this extension point's role is in Superset.
*
* When defining a new option here, take care to keep any parameters to functions (or components) minimal.
* Any removal or alteration to a parameter will be considered a breaking change.
*/
export type UiOverrides = Partial<{
'embedded.documentation.description': UiGeneratorText;
export type Extensions = Partial<{
'embedded.documentation.description': ReturningDisplayable;
'embedded.documentation.url': string;
'navbar.right': React.ComponentType;
'welcome.banner': React.ComponentType;
}>;

/**
* A registry containing UI customizations to replace elements of Superset's default UI.
* A registry containing extensions which can alter Superset's UI at specific points defined by Superset.
* See SIP-87: https://github.com/apache/superset/issues/20615
*/
class UiOverrideRegistry extends TypedRegistry<UiOverrides> {
name = 'UiOverrideRegistry';
class ExtensionsRegistry extends TypedRegistry<Extensions> {
name = 'ExtensionsRegistry';
}

export const getUiOverrideRegistry = makeSingleton(UiOverrideRegistry, {});
export const getExtensionsRegistry = makeSingleton(ExtensionsRegistry, {});

// Exporting this under the old name for backwards compatibility.
// After downstream folks have migrated to `getExtensionsRegistry`, we should remove this.
export const getUiOverrideRegistry = getExtensionsRegistry;
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* under the License.
*/

export * from './UiOverrideRegistry';
export * from './ExtensionsRegistry';
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
import { getUiOverrideRegistry } from '@superset-ui/core';
import { getExtensionsRegistry } from '@superset-ui/core';

test('should get instance of getUiOverrideRegistry', () => {
expect(getUiOverrideRegistry().name).toBe('UiOverrideRegistry');
test('should get instance of getExtensionsRegistry', () => {
expect(getExtensionsRegistry().name).toBe('ExtensionsRegistry');
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
styled,
SupersetApiError,
t,
getUiOverrideRegistry,
getExtensionsRegistry,
} from '@superset-ui/core';
import { InfoTooltipWithTrigger } from '@superset-ui/chart-controls';
import Modal from 'src/components/Modal';
Expand All @@ -33,7 +33,7 @@ import { useToasts } from 'src/components/MessageToasts/withToasts';
import { FormItem } from 'src/components/Form';
import { EmbeddedDashboard } from '../types';

const uiOverrideRegistry = getUiOverrideRegistry();
const extensionsRegistry = getExtensionsRegistry();

type Props = {
dashboardId: string;
Expand Down Expand Up @@ -148,11 +148,11 @@ export const DashboardEmbedControls = ({ dashboardId, onHide }: Props) => {
return <Loading />;
}

const docsDescription = uiOverrideRegistry.get(
const docsDescription = extensionsRegistry.get(
'embedded.documentation.description',
);
const docsUrl =
uiOverrideRegistry.get('embedded.documentation.url') ??
extensionsRegistry.get('embedded.documentation.url') ??
'https://www.npmjs.com/package/@superset-ui/embedded-sdk';

return (
Expand Down
6 changes: 3 additions & 3 deletions superset-frontend/src/views/CRUD/welcome/Welcome.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ 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 { getExtensionsRegistry } from '@superset-ui/core';
import setupExtensions from 'src/setup/setupExtensions';

const mockStore = configureStore([thunk]);
Expand Down Expand Up @@ -184,9 +184,9 @@ describe('Welcome page with toggle switch', () => {
});

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

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

Expand Down
6 changes: 3 additions & 3 deletions 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, getUiOverrideRegistry } from '@superset-ui/core';
import { styled, t, getExtensionsRegistry } 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,7 +46,7 @@ import ChartTable from './ChartTable';
import SavedQueries from './SavedQueries';
import DashboardTable from './DashboardTable';

const uiOverrideRegistry = getUiOverrideRegistry();
const extensionsRegistry = getExtensionsRegistry();

interface WelcomeProps {
user: User;
Expand Down Expand Up @@ -179,7 +179,7 @@ function Welcome({ user, addDangerToast }: WelcomeProps) {
setItem(LocalStorageKeys.homepage_collapse_state, state);
};

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

useEffect(() => {
const activeTab = getItem(LocalStorageKeys.homepage_activity_filter, null);
Expand Down
6 changes: 3 additions & 3 deletions superset-frontend/src/views/components/Menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import fetchMock from 'fetch-mock';
import { render, screen } from 'spec/helpers/testing-library';
import setupExtensions from 'src/setup/setupExtensions';
import userEvent from '@testing-library/user-event';
import { getUiOverrideRegistry } from '@superset-ui/core';
import { getExtensionsRegistry } from '@superset-ui/core';
import { Menu } from './Menu';

const dropdownItems = [
Expand Down Expand Up @@ -486,9 +486,9 @@ test('should render without QueryParamProvider', () => {
});

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

uiOverrideRegistry.set('navbar.right', () => (
extensionsRegistry.set('navbar.right', () => (
<>navbar.right extension component</>
));

Expand Down
6 changes: 3 additions & 3 deletions superset-frontend/src/views/components/RightMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
css,
SupersetTheme,
SupersetClient,
getUiOverrideRegistry,
getExtensionsRegistry,
} from '@superset-ui/core';
import { MainNav as Menu } from 'src/components/Menu';
import { Tooltip } from 'src/components/Tooltip';
Expand All @@ -47,7 +47,7 @@ import {
} from './types';
import { MenuObjectProps } from './Menu';

const uiOverrideRegistry = getUiOverrideRegistry();
const extensionsRegistry = getExtensionsRegistry();

const versionInfoStyles = (theme: SupersetTheme) => css`
padding: ${theme.gridUnit * 1.5}px ${theme.gridUnit * 4}px
Expand Down Expand Up @@ -258,7 +258,7 @@ const RightMenu = ({
}
return null;
};
const RightMenuExtension = uiOverrideRegistry.get('navbar.right');
const RightMenuExtension = extensionsRegistry.get('navbar.right');

const handleDatabaseAdd = () => setQuery({ databaseAdded: true });

Expand Down

0 comments on commit beb5545

Please sign in to comment.