@craftercms/studio-ui
Version:
Services, components, models & utils to build CrafterCMS authoring extensions.
91 lines (89 loc) • 3.6 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 LauncherTile from '../LauncherTile';
import React from 'react';
import { useDispatch } from 'react-redux';
import { closeLauncher, showWidgetDialog } from '../../state/actions/dialogs';
import { batchActions } from '../../state/actions/misc';
import { useActiveSiteId } from '../../hooks/useActiveSiteId';
import { useEnv } from '../../hooks/useEnv';
import { usePossibleTranslation } from '../../hooks/usePossibleTranslation';
import { getSystemLink } from '../../utils/system';
const LauncherLinkTile = (props) => {
var _a;
const { icon, systemLinkId, title: propTitle } = props;
const { authoringBase } = useEnv();
const site = useActiveSiteId();
const dispatch = useDispatch();
const title = usePossibleTranslation(propTitle);
const isDialog = ['siteDashboardDialog', 'siteToolsDialog', 'siteSearchDialog'].includes(systemLinkId);
const onClick = isDialog
? (e) => {
if (!e.metaKey) {
e.preventDefault();
// TODO: Re-id craftercms.components.Dashboard => craftercms.components.SiteDashboard when switching to new dashboard
// prettier-ignore
const id = systemLinkId === 'siteDashboardDialog' ? 'craftercms.components.Dashboard' : (systemLinkId === 'siteToolsDialog'
? 'craftercms.components.EmbeddedSiteTools'
: 'craftercms.components.Search');
dispatch(
batchActions([
closeLauncher(),
showWidgetDialog({
id: systemLinkId,
title,
widget: Object.assign(
{ id },
systemLinkId === 'siteSearchDialog' && { configuration: { embedded: true } }
)
})
])
);
}
}
: null;
const link = isDialog
? getSystemLink({
systemLinkId: systemLinkId.replace(/Dialog$/, ''),
authoringBase,
site
})
: (_a = props.link) !== null && _a !== void 0
? _a
: getSystemLink({ systemLinkId, authoringBase, site });
return React.createElement(LauncherTile, {
icon: icon,
onClick: onClick,
title: usePossibleTranslation(title),
link: link
});
};
export default LauncherLinkTile;