diff --git a/packages/app/src/components/Layout/sidebar/index.jsx b/packages/app/src/components/Layout/sidebar/index.jsx index 42684428..b8644966 100755 --- a/packages/app/src/components/Layout/sidebar/index.jsx +++ b/packages/app/src/components/Layout/sidebar/index.jsx @@ -107,6 +107,13 @@ const CustomRender = (props) => { } +const handleRenderIcon = (icon) => { + if (typeof icon === "undefined") { + return null + } + return createIconRender(icon) +} + export default class Sidebar extends React.Component { constructor(props) { super(props) @@ -119,32 +126,54 @@ export default class Sidebar extends React.Component { isExpanded: () => this.state.expanded, setCustomRender: this.setRender, closeCustomRender: this.closeRender, - updateBackgroundItem: (children, props) => { - let updatedValue = this.state.backgroundItem + updateBottomItemProps: (id, newProps) => { + let updatedValue = this.state.bottomItems - if (typeof children !== "undefined") { - updatedValue.children = children - } - - if (typeof props !== "undefined") { - updatedValue.props = props - } + updatedValue = updatedValue.map((item) => { + if (item.id === id) { + item.props = { + ...item.props, + ...newProps, + } + } + }) this.setState({ - backgroundItem: updatedValue + bottomItems: updatedValue }) }, - setBackgroundItem: (children, props) => { + attachBottomItem: (id, children, options) => { + if (!id) { + throw new Error("ID is required") + } + + if (!children) { + throw new Error("Children is required") + } + + if (this.state.bottomItems.find((item) => item.id === id)) { + throw new Error("Item already exists") + } + + let updatedValue = this.state.bottomItems + + updatedValue.push({ + id, + children, + ...options + }) + this.setState({ - backgroundItem: { - children: children, - props: props, - }, + bottomItems: updatedValue }) }, - clearBackgroundItem: () => { + removeBottomItem: (id) => { + let updatedValue = this.state.bottomItems + + updatedValue = updatedValue.filter((item) => item.id !== id) + this.setState({ - backgroundItem: null, + bottomItems: updatedValue }) } } @@ -158,7 +187,8 @@ export default class Sidebar extends React.Component { customRenderTitle: null, customRender: null, - backgroundItem: null, + + bottomItems: [], } // handle sidedrawer open/close @@ -225,13 +255,6 @@ export default class Sidebar extends React.Component { } renderMenuItems(items) { - const handleRenderIcon = (icon) => { - if (typeof icon === "undefined") { - return null - } - return createIconRender(icon) - } - return items.map((item) => { if (Array.isArray(item.children)) { return