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: render Ordertab only when it is active #6583

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions packages/volto/news/6492.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Order side panel now renders only when the "Order" tab is active. Previously, the panel would render unnecessarily even when inactive. @Abhishek-17h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ const BlocksForm = (props) => {
<>
{isMainForm &&
isClient &&
document.getElementById('sidebar-order') &&
createPortal(
<div>
<Order
Expand Down Expand Up @@ -355,7 +356,6 @@ const BlocksForm = (props) => {
editable,
showBlockChooser: selectedBlock === childId,
detached: isContainer,
// Properties to pass to the BlocksForm to match the View ones
content: properties,
history,
location,
Expand All @@ -375,5 +375,4 @@ const BlocksForm = (props) => {
</>
);
};

export default BlocksForm;
29 changes: 16 additions & 13 deletions packages/volto/src/components/manage/Sidebar/Sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import BodyClass from '@plone/volto/helpers/BodyClass/BodyClass';
import { getCookieOptions } from '@plone/volto/helpers/Cookies/cookies';
import Icon from '@plone/volto/components/theme/Icon/Icon';
import forbiddenSVG from '@plone/volto/icons/forbidden.svg';
import loaderSVG from '@plone/volto/icons/loader.svg';
import { setSidebarTab } from '@plone/volto/actions/sidebar/sidebar';
import expandSVG from '@plone/volto/icons/left-key.svg';
import collapseSVG from '@plone/volto/icons/right-key.svg';
Expand Down Expand Up @@ -57,6 +58,7 @@ const Sidebar = (props) => {
);
const [size] = useState(0);
const [showFull, setshowFull] = useState(true);
const [isOrderTabRendered, setIsOrderTabRendered] = useState(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like it can cause unnecessary rerenders. The active index tab is an information we already have two lines below with the tab variable. In other words, isOrderTabRendered can simply be something like this, moved after const tab = ...

  const isOrderTabRendered = tab === 2;

Is this state needed for some other case I might be missing at this time?


const tab = useSelector((state) => state.sidebar.tab);
const toolbarExpanded = useSelector((state) => state.toolbar.expanded);
Expand Down Expand Up @@ -101,6 +103,10 @@ const Sidebar = (props) => {
const onTabChange = (event, data) => {
event.nativeEvent.stopImmediatePropagation();
dispatch(setSidebarTab(data.activeIndex));

if (data.activeIndex === 2) {
setIsOrderTabRendered(true);
}
Comment on lines +107 to +109
Copy link
Contributor

Choose a reason for hiding this comment

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

If my assumptions above are correct, this should be removed

};

return (
Expand Down Expand Up @@ -186,19 +192,16 @@ const Sidebar = (props) => {
},
!!orderTab && {
menuItem: intl.formatMessage(messages.order),
pane: (
<Tab.Pane
key="order"
className="tab-wrapper"
id="sidebar-order"
>
<Icon
className="tab-forbidden"
name={forbiddenSVG}
size="48px"
/>
</Tab.Pane>
),
pane:
isOrderTabRendered || tab === 2 ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

If my assumptions above are correct, this can simply be

Suggested change
isOrderTabRendered || tab === 2 ? (
tab === 2 ? (

<Tab.Pane
key="order"
className="tab-wrapper"
id="sidebar-order"
>
<Icon className="tab-loader" name={loaderSVG} size="60px" />
</Tab.Pane>
) : null,
},
!!settingsTab && {
menuItem: intl.formatMessage(messages.settings),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,29 +87,6 @@ Array [
xmlns=""
/>
</div>
<div
className="ui bottom attached segment tab tab-wrapper"
id="sidebar-order"
>
<svg
className="icon tab-forbidden"
dangerouslySetInnerHTML={
Object {
"__html": undefined,
}
}
onClick={null}
style={
Object {
"fill": "currentColor",
"height": "48px",
"width": "auto",
}
}
viewBox=""
xmlns=""
/>
</div>
</div>
</div>,
<div
Expand Down
43 changes: 43 additions & 0 deletions packages/volto/src/icons/loader.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions packages/volto/theme/themes/pastanaga/extras/sidebar.less
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@
color: #bac5c7;
}

.tab-loader {
margin: calc(50% - 24px) auto;
color: #bac5c7;
}

header {
display: flex;
height: 60px;
Expand Down