Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import { useState, Fragment, useCallback, useMemo } from 'react';
import { useState, Fragment, useCallback } from 'react';
import PropTypes from 'prop-types';
import {
ActionButton,
Button,
Flex,
Item,
TabList,
TabPanels,
Tabs,
} from '@adobe/react-spectrum';
import { Button, Tab } from 'semantic-ui-react';
import { useDispatch, useSelector } from 'react-redux';
import { compose } from 'redux';
import { withCookies } from 'react-cookie';
Expand All @@ -17,22 +9,24 @@ import cx from 'classnames';
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 { 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';
import { useClient } from '@plone/volto/hooks/client/useClient';
import { createPortal } from 'react-dom';
import WorkflowTab from './WorkflowTab';
import State from '../States/State';
import Transition from '../Transitions/Transition';
import type { GlobalRootState } from 'volto-workflow-manager/types';

const messages = defineMessages({
document: {
id: 'Document',
defaultMessage: 'Document',
workflow: {
id: 'Workflow',
defaultMessage: 'Workflow',
},
block: {
id: 'Block',
defaultMessage: 'Block',
state: {
id: 'State',
defaultMessage: 'State',
},
settings: {
id: 'Settings',
Expand All @@ -46,18 +40,6 @@ const messages = defineMessages({
id: 'Expand sidebar',
defaultMessage: 'Expand sidebar',
},
order: {
id: 'Order',
defaultMessage: 'Order',
},
workflow: {
id: 'Workflow',
defaultMessage: 'Workflow',
},
states: {
id: 'States',
defaultMessage: 'States',
},
transitions: {
id: 'Transitions',
defaultMessage: 'Transitions',
Expand All @@ -66,28 +48,24 @@ const messages = defineMessages({

const Sidebar = (props) => {
const dispatch = useDispatch();
const { currentWorkflow, onDataChange, isDisabled } = props;
const selectedItem = useSelector(
(state: GlobalRootState) => state.workflow.selectedItem,
);

const intl = useIntl();
const {
cookies,
content,
workflowTab = true,
statesTab = true,
stateTab = true,
transitionsTab = true,
} = props;
const [expanded, setExpanded] = useState(
cookies.get('sidebar_expanded') !== 'false',
);
const [size] = useState(0);
const [showFull, setshowFull] = useState(true);

const tabIndex = useSelector((state) => state?.sidebar.tab);
const toolbarExpanded = useSelector((state) => state?.toolbar.expanded);

const isClient = useClient();
const tab = useSelector((state) => state.sidebar.tab);
const toolbarExpanded = useSelector((state) => state.toolbar.expanded);
const type = useSelector((state) => state.schema?.schema?.title);
const { currentWorkflow, onDataChange, isDisabled } = props;
const onToggleExpanded = () => {
cookies.set('sidebar_expanded', !expanded, getCookieOptions());
setExpanded(!expanded);
Expand Down Expand Up @@ -124,65 +102,9 @@ const Sidebar = (props) => {
setshowFull(!showFull);
}, [showFull, toolbarExpanded]);

const workflowTabs = useMemo(
() =>
[
workflowTab && {
key: 'workflow',
title: intl.formatMessage(messages.workflow),
content: (
<WorkflowTab
workflowId={currentWorkflow.id}
onDataChange={(payload) => onDataChange(payload, 'workflow')}
isDisabled={isDisabled}
/>
),
},
statesTab && {
key: 'states',
title: intl.formatMessage(messages.states),
content: (
<State
workflowId={currentWorkflow.id}
workflow={currentWorkflow}
onDataChange={(payload) => onDataChange(payload, 'state')}
isDisabled={isDisabled}
/>
),
},
transitionsTab && {
key: 'transitions',
title: intl.formatMessage(messages.transitions),
content: (
<Transition
workflowId={currentWorkflow.id}
workflow={currentWorkflow}
onDataChange={(payload) => onDataChange(payload, 'transition')}
isDisabled={isDisabled}
/>
),
},
].filter(Boolean),
// eslint-disable-next-line react-hooks/exhaustive-deps
[
onDataChange,
workflowTab,
statesTab,
transitionsTab,
intl,
currentWorkflow,
isDisabled,
selectedItem,
],
);

const selectedKey = workflowTabs[tabIndex]?.key;

const handleTabChange = (key) => {
const newIndex = workflowTabs.findIndex((tab) => tab.key === key);
if (newIndex > -1) {
dispatch(setSidebarTab(newIndex));
}
const onTabChange = (event, data) => {
event.nativeEvent.stopImmediatePropagation();
dispatch(setSidebarTab(data.activeIndex));
};

return (
Expand All @@ -195,67 +117,135 @@ const Sidebar = (props) => {
style={size > 0 ? { width: size } : null}
>
<Button
variant="primary"
UNSAFE_className={
content && content.review_state
? `${content.review_state} trigger`
: 'trigger'
}
type="button"
aria-label={
expanded
? intl.formatMessage(messages.shrinkSidebar)
: intl.formatMessage(messages.expandSidebar)
}
onPress={onToggleExpanded}
className={
content && content.review_state
? `${content.review_state} trigger`
: 'trigger'
}
onClick={onToggleExpanded}
/>

<Tabs
aria-label="Workflow Manager Sidebar"
selectedKey={selectedKey}
onSelectionChange={handleTabChange}
isQuiet
height="100%"
<Button
type="button"
className="full-size-sidenav-btn"
onClick={onToggleFullSize}
aria-label="full-screen-sidenav"
>
<Flex
direction="row"
alignItems="center"
gap="size-100"
UNSAFE_className="sidebar-tabs-header"
>
<ActionButton
UNSAFE_className="full-size-sidenav-btn"
aria-label="full-screen-sidenav"
onPress={onToggleFullSize}
>
<Icon
className="full-size-icon"
name={showFull ? expandSVG : collapseSVG}
/>
</ActionButton>

<TabList flex="1">
{workflowTabs.map((tab) => (
<Item key={tab.key}>{tab.title}</Item>
))}
</TabList>
</Flex>

<TabPanels flex="1" UNSAFE_className="sidebar-tab-panels">
{workflowTabs.map((tab) => (
<Item key={tab.key}>{tab.content}</Item>
))}
</TabPanels>
</Tabs>
<Icon
className="full-size-icon"
name={showFull ? expandSVG : collapseSVG}
/>
</Button>
<Tab
menu={{
secondary: true,
pointing: true,
attached: true,
tabular: true,
className: 'formtabs',
}}
className="tabs-wrapper"
renderActiveOnly={false}
activeIndex={tab}
onTabChange={onTabChange}
panes={[
!!workflowTab && {
menuItem: {
key: 'workflowTab',
as: 'button',
className: 'ui button',
content: type || intl.formatMessage(messages.workflow),
},
pane: (
<Tab.Pane
key="metadata"
className="tab-wrapper"
id="sidebar-workflow"
/>
),
},
!!stateTab && {
menuItem: {
key: 'stateTab',
as: 'button',
className: 'ui button',
content: intl.formatMessage(messages.state),
},
pane: (
<Tab.Pane
key="properties"
className="tab-wrapper"
id="sidebar-state"
>
<Icon
className="tab-forbidden"
name={forbiddenSVG}
size="48px"
/>
</Tab.Pane>
),
},
!!transitionsTab && {
menuItem: intl.formatMessage(messages.transitions),
pane: (
<Tab.Pane
key="transitions"
className="tab-wrapper"
id="sidebar-transition"
>
<Icon
className="tab-forbidden"
name={forbiddenSVG}
size="48px"
/>
</Tab.Pane>
),
},
].filter((tab) => tab)}
/>
</div>
<div className={expanded ? 'pusher expanded' : 'pusher'} />
{isClient &&
createPortal(
<WorkflowTab
workflowId={currentWorkflow.id}
onDataChange={(payload) => {
onDataChange(payload, 'workflow');
}}
isDisabled={isDisabled}
/>,
document.getElementById('sidebar-workflow'),
)}
{isClient &&
createPortal(
<State
workflowId={currentWorkflow.id}
workflow={currentWorkflow}
onDataChange={(payload) => onDataChange(payload, 'state')}
isDisabled={isDisabled}
/>,
document.getElementById('sidebar-state'),
)}
{isClient &&
createPortal(
<Transition
workflowId={currentWorkflow.id}
workflow={currentWorkflow}
onDataChange={(payload) => onDataChange(payload, 'transition')}
isDisabled={isDisabled}
/>,
document.getElementById('sidebar-transition'),
)}
</Fragment>
);
};

Sidebar.propTypes = {
currentWorkflow: PropTypes.object.isRequired,
onDataChange: PropTypes.func.isRequired,
isDisabled: PropTypes.bool.isRequired,
documentTab: PropTypes.bool,
blockTab: PropTypes.bool,
settingsTab: PropTypes.bool,
Expand Down
Loading
Loading