@craftercms/studio-ui
Version:
Services, components, models & utils to build CrafterCMS authoring extensions.
164 lines (162 loc) • 5.57 kB
JavaScript
/*
* Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import React from 'react';
import TreeView from '@mui/lab/TreeView';
import { makeStyles } from 'tss-react/mui';
import Accordion from '@mui/material/Accordion';
import Header from '../PathNavigator/PathNavigatorHeader';
import AccordionDetails from '@mui/material/AccordionDetails';
import PathNavigatorTreeItem from './PathNavigatorTreeItem';
import RefreshRounded from '@mui/icons-material/RefreshRounded';
import { FormattedMessage } from 'react-intl';
import { ErrorState } from '../ErrorState';
const useStyles = makeStyles()(() => ({
root: {},
accordion: {
boxShadow: 'none',
backgroundColor: 'inherit',
'&.Mui-expanded': {
margin: 'inherit'
}
},
accordionDetails: {
padding: 0,
flexDirection: 'column'
},
loading: {
display: 'flex',
alignItems: 'center',
padding: '2px',
marginLeft: '5px',
'& p': {
marginLeft: '10px'
}
}
}));
export function PathNavigatorTreeUI(props) {
var _a, _b, _c;
const { classes, cx } = useStyles();
// region const { ... } = props
const {
icon,
container,
title,
rootPath,
isRootPathMissing,
itemsByPath,
keywordByPath,
childrenByParentPath,
totalByPath,
onIconClick,
onLabelClick,
onChangeCollapsed,
onOpenItemMenu,
onHeaderButtonClick,
onFilterChange,
onMoreClick,
isCollapsed,
expandedNodes,
active,
showNavigableAsLinks,
showPublishingTarget,
showWorkflowState,
showItemMenu
} = props;
// endregion
return React.createElement(
Accordion,
{
square: true,
disableGutters: true,
elevation: 0,
TransitionProps: { unmountOnExit: true },
expanded: !isCollapsed,
onChange: () => onChangeCollapsed(!isCollapsed),
className: cx(
classes.accordion,
(_a = props.classes) === null || _a === void 0 ? void 0 : _a.root,
container === null || container === void 0 ? void 0 : container.baseClass,
container ? (isCollapsed ? container.collapsedClass : container.expandedClass) : void 0
),
style: Object.assign(
Object.assign({}, container === null || container === void 0 ? void 0 : container.baseStyle),
container ? (isCollapsed ? container.collapsedStyle : container.expandedStyle) : void 0
)
},
React.createElement(Header, {
icon: icon,
title: title,
locale: null,
// @see https://github.com/craftercms/craftercms/issues/5360
menuButtonIcon: React.createElement(RefreshRounded, null),
collapsed: isCollapsed,
onMenuButtonClick: onHeaderButtonClick,
className: (_b = props.classes) === null || _b === void 0 ? void 0 : _b.header
}),
isRootPathMissing
? React.createElement(ErrorState, {
styles: { image: { display: 'none' } },
title: React.createElement(FormattedMessage, {
id: 'pathNavigatorTree.missingRootPath',
defaultMessage: `The path "{path}" doesn't exist`,
values: { path: rootPath }
})
})
: React.createElement(
AccordionDetails,
{
className: cx(classes.accordionDetails, (_c = props.classes) === null || _c === void 0 ? void 0 : _c.body)
},
React.createElement(
TreeView,
{ className: classes.root, expanded: expandedNodes, disableSelection: true },
React.createElement(PathNavigatorTreeItem, {
path: rootPath,
active: active,
itemsByPath: itemsByPath,
keywordByPath: keywordByPath,
totalByPath: totalByPath,
childrenByParentPath: childrenByParentPath,
onIconClick: onIconClick,
onLabelClick: onLabelClick,
onFilterChange: onFilterChange,
onOpenItemMenu: onOpenItemMenu,
onMoreClick: onMoreClick,
showNavigableAsLinks: showNavigableAsLinks,
showPublishingTarget: showPublishingTarget,
showWorkflowState: showWorkflowState,
showItemMenu: showItemMenu
})
)
)
);
}
export default PathNavigatorTreeUI;