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

fix: move menu reorg logic from crud app into Menu component #10717

Merged
merged 1 commit into from
Aug 28, 2020
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 @@ -22,7 +22,7 @@ import { Nav, MenuItem } from 'react-bootstrap';
import NavDropdown from 'src/components/NavDropdown';
import { supersetTheme, ThemeProvider } from '@superset-ui/style';

import Menu from 'src/components/Menu/Menu';
import { Menu } from 'src/components/Menu/Menu';

const defaultProps = {
data: {
Expand Down
66 changes: 64 additions & 2 deletions superset-frontend/src/components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import { t } from '@superset-ui/translation';
import { Nav, Navbar, NavItem, MenuItem } from 'react-bootstrap';
import NavDropdown from 'src/components/NavDropdown';
import styled from '@superset-ui/style';
import MenuObject, { MenuObjectProps } from './MenuObject';
import MenuObject, {
MenuObjectProps,
MenuObjectChildProps,
} from './MenuObject';
import NewMenu from './NewMenu';
import UserMenu from './UserMenu';
import LanguagePicker, { Languages } from './LanguagePicker';
Expand Down Expand Up @@ -128,7 +131,7 @@ const StyledHeader = styled.header`
}
`;

export default function Menu({
export function Menu({
data: { menu, brand, navbar_right: navbarRight, settings },
}: MenuProps) {
// Flatten settings
Expand Down Expand Up @@ -254,3 +257,62 @@ export default function Menu({
</StyledHeader>
);
}

// transform the menu data to reorganize components
export default function MenuWrapper({ data }: MenuProps) {
const newMenuData = {
...data,
};
// Menu items that should go into settings dropdown
const settingsMenus = {
Security: true,
Manage: true,
};

// Menu items that should be ignored
const ignore = {
'Import Dashboards': true,
};

// Cycle through menu.menu to build out cleanedMenu and settings
const cleanedMenu: MenuObjectProps[] = [];
const settings: MenuObjectProps[] = [];

newMenuData.menu.forEach((item: any) => {
if (!item) {
return;
}

const children: (MenuObjectProps | string)[] = [];
const newItem = {
...item,
};

// Filter childs
if (item.childs) {
item.childs.forEach((child: MenuObjectChildProps | string) => {
if (typeof child === 'string') {
children.push(child);
} else if (
(child as MenuObjectChildProps).label &&
!ignore.hasOwnProperty(child.label)
) {
children.push(child);
}
});

newItem.childs = children;
}

if (!settingsMenus.hasOwnProperty(item.name)) {
cleanedMenu.push(newItem);
} else {
settings.push(newItem);
}
});

newMenuData.menu = cleanedMenu;
newMenuData.settings = settings;

return <Menu data={newMenuData} />;
}
55 changes: 0 additions & 55 deletions superset-frontend/src/views/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ import setupApp from '../setup/setupApp';
import setupPlugins from '../setup/setupPlugins';
import Welcome from './CRUD/welcome/Welcome';
import ToastPresenter from '../messageToasts/containers/ToastPresenter';
import {
MenuObjectProps,
MenuObjectChildProps,
} from '../components/Menu/MenuObject';

setupApp();
setupPlugins();
Expand All @@ -62,57 +58,6 @@ const store = createStore(
compose(applyMiddleware(thunk), initEnhancer(false)),
);

// Menu items that should go into settings dropdown
const settingsMenus = {
Security: true,
Manage: true,
};

// Menu items that should be ignored
const ignore = {
'Import Dashboards': true,
};

// Cycle through menu.menu to build out cleanedMenu and settings
const cleanedMenu: object[] = [];
const settings: object[] = [];

menu.menu.forEach((item: any) => {
if (!item) {
return;
}

const children: (MenuObjectProps | string)[] = [];
const newItem = {
...item,
};

// Filter childs
if (item.childs) {
item.childs.forEach((child: MenuObjectChildProps | string) => {
if (typeof child === 'string') {
children.push(child);
} else if (
(child as MenuObjectChildProps).label &&
!ignore.hasOwnProperty(child.label)
) {
children.push(child);
}
});

newItem.childs = children;
}

if (!settingsMenus.hasOwnProperty(item.name)) {
cleanedMenu.push(newItem);
} else {
settings.push(newItem);
}
});

menu.menu = cleanedMenu;
menu.settings = settings;

const App = () => (
<Provider store={store}>
<ThemeProvider theme={supersetTheme}>
Expand Down