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

Add controlpanel for plone.volto block_types index (wip) #6028

Open
wants to merge 2 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
5 changes: 5 additions & 0 deletions packages/volto/locales/ca/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ msgstr "Base de cerca"
msgid "Block"
msgstr "Bloc"

#. Default: "Block Types"
#: components/manage/Controlpanels/Controlpanels
msgid "Block Types"
msgstr ""

#. Default: "Both email address and password are case sensitive, check that caps lock is not enabled."
#: components/theme/Login/Login
msgid "Both email address and password are case sensitive, check that caps lock is not enabled."
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/de/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@ msgstr "Basis Suchfilter"
msgid "Block"
msgstr "Block"

#. Default: "Block Types"
#: components/manage/Controlpanels/Controlpanels
msgid "Block Types"
msgstr "Blocktypen"

#. Default: "Both email address and password are case sensitive, check that caps lock is not enabled."
#: components/theme/Login/Login
msgid "Both email address and password are case sensitive, check that caps lock is not enabled."
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/en/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,11 @@ msgstr ""
msgid "Block"
msgstr ""

#. Default: "Block Types"
#: components/manage/Controlpanels/Controlpanels
msgid "Block Types"
msgstr ""

#. Default: "Both email address and password are case sensitive, check that caps lock is not enabled."
#: components/theme/Login/Login
msgid "Both email address and password are case sensitive, check that caps lock is not enabled."
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/es/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ msgstr "Consulta base de la búsqueda"
msgid "Block"
msgstr "Bloque"

#. Default: "Block Types"
#: components/manage/Controlpanels/Controlpanels
msgid "Block Types"
msgstr ""

#. Default: "Both email address and password are case sensitive, check that caps lock is not enabled."
#: components/theme/Login/Login
msgid "Both email address and password are case sensitive, check that caps lock is not enabled."
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/eu/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ msgstr "Oinarrizko bilaketa kontsulta"
msgid "Block"
msgstr "Blokea"

#. Default: "Block Types"
#: components/manage/Controlpanels/Controlpanels
msgid "Block Types"
msgstr ""

#. Default: "Both email address and password are case sensitive, check that caps lock is not enabled."
#: components/theme/Login/Login
msgid "Both email address and password are case sensitive, check that caps lock is not enabled."
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/fi/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@ msgstr ""
msgid "Block"
msgstr "Palikka"

#. Default: "Block Types"
#: components/manage/Controlpanels/Controlpanels
msgid "Block Types"
msgstr ""

#. Default: "Both email address and password are case sensitive, check that caps lock is not enabled."
#: components/theme/Login/Login
msgid "Both email address and password are case sensitive, check that caps lock is not enabled."
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/fr/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,11 @@ msgstr "Requête de base de la recherche"
msgid "Block"
msgstr "Bloc"

#. Default: "Block Types"
#: components/manage/Controlpanels/Controlpanels
msgid "Block Types"
msgstr ""

#. Default: "Both email address and password are case sensitive, check that caps lock is not enabled."
#: components/theme/Login/Login
msgid "Both email address and password are case sensitive, check that caps lock is not enabled."
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/it/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,11 @@ msgstr "Ricerca iniziale"
msgid "Block"
msgstr "Blocco"

#. Default: "Block Types"
#: components/manage/Controlpanels/Controlpanels
msgid "Block Types"
msgstr ""

#. Default: "Both email address and password are case sensitive, check that caps lock is not enabled."
#: components/theme/Login/Login
msgid "Both email address and password are case sensitive, check that caps lock is not enabled."
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/ja/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@ msgstr ""
msgid "Block"
msgstr "ブロック"

#. Default: "Block Types"
#: components/manage/Controlpanels/Controlpanels
msgid "Block Types"
msgstr ""

#. Default: "Both email address and password are case sensitive, check that caps lock is not enabled."
#: components/theme/Login/Login
msgid "Both email address and password are case sensitive, check that caps lock is not enabled."
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/nl/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,11 @@ msgstr ""
msgid "Block"
msgstr ""

#. Default: "Block Types"
#: components/manage/Controlpanels/Controlpanels
msgid "Block Types"
msgstr ""

#. Default: "Both email address and password are case sensitive, check that caps lock is not enabled."
#: components/theme/Login/Login
msgid "Both email address and password are case sensitive, check that caps lock is not enabled."
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/pt/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@ msgstr ""
msgid "Block"
msgstr "Bloco"

#. Default: "Block Types"
#: components/manage/Controlpanels/Controlpanels
msgid "Block Types"
msgstr ""

#. Default: "Both email address and password are case sensitive, check that caps lock is not enabled."
#: components/theme/Login/Login
msgid "Both email address and password are case sensitive, check that caps lock is not enabled."
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/pt_BR/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ msgstr "Base da consulta para busca"
msgid "Block"
msgstr "Bloco"

#. Default: "Block Types"
#: components/manage/Controlpanels/Controlpanels
msgid "Block Types"
msgstr ""

#. Default: "Both email address and password are case sensitive, check that caps lock is not enabled."
#: components/theme/Login/Login
msgid "Both email address and password are case sensitive, check that caps lock is not enabled."
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/ro/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,11 @@ msgstr "Interogare căutare de bază"
msgid "Block"
msgstr "Bloc"

#. Default: "Block Types"
#: components/manage/Controlpanels/Controlpanels
msgid "Block Types"
msgstr ""

#. Default: "Both email address and password are case sensitive, check that caps lock is not enabled."
#: components/theme/Login/Login
msgid "Both email address and password are case sensitive, check that caps lock is not enabled."
Expand Down
7 changes: 6 additions & 1 deletion packages/volto/locales/volto.pot
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: Plone\n"
"POT-Creation-Date: 2024-05-03T06:54:04.407Z\n"
"POT-Creation-Date: 2024-05-17T14:50:16.752Z\n"
"Last-Translator: Plone i18n <[email protected]>\n"
"Language-Team: Plone i18n <[email protected]>\n"
"Content-Type: text/plain; charset=utf-8\n"
Expand Down Expand Up @@ -473,6 +473,11 @@ msgstr ""
msgid "Block"
msgstr ""

#. Default: "Block Types"
#: components/manage/Controlpanels/Controlpanels
msgid "Block Types"
msgstr ""

#. Default: "Both email address and password are case sensitive, check that caps lock is not enabled."
#: components/theme/Login/Login
msgid "Both email address and password are case sensitive, check that caps lock is not enabled."
Expand Down
5 changes: 5 additions & 0 deletions packages/volto/locales/zh_CN/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,11 @@ msgstr "基本搜索查询"
msgid "Block"
msgstr "块"

#. Default: "Block Types"
#: components/manage/Controlpanels/Controlpanels
msgid "Block Types"
msgstr ""

#. Default: "Both email address and password are case sensitive, check that caps lock is not enabled."
#: components/theme/Login/Login
msgid "Both email address and password are case sensitive, check that caps lock is not enabled."
Expand Down
11 changes: 11 additions & 0 deletions packages/volto/src/actions/blockTypesIndex/blockTypesIndex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { GET_BLOCKTYPES_INDEX } from '../../constants/ActionTypes';

export function getBlockTypes(blocktypes) {
return {
type: GET_BLOCKTYPES_INDEX,
request: {
op: 'get',
path: `/@blocktypes?blocktypes=${blocktypes}`,
},
};
}
1 change: 1 addition & 0 deletions packages/volto/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export {
UpgradeControlPanel,
ModerateComments,
DatabaseInformation,
BlockTypesControlpanel,
} from '@plone/volto/components/manage/Controlpanels';

export { default as Circle } from '@plone/volto/components/manage/Contents/circle';
Expand Down
114 changes: 114 additions & 0 deletions packages/volto/src/components/manage/Controlpanels/BlockTypes.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import React, { useEffect, useState } from 'react';
import { createPortal } from 'react-dom';
import { useHistory } from 'react-router';
import { Link, useLocation } from 'react-router-dom';
import { useDispatch, useSelector } from 'react-redux';
import { getBlockTypes } from '../../../actions/blockTypesIndex/blockTypesIndex';
import { UniversalLink, Icon, Toolbar } from '@plone/volto/components';
import { getParentUrl } from '@plone/volto/helpers';
import backSVG from '@plone/volto/icons/back.svg';
import { map, keys, sum } from 'lodash';
import { blocksConfig } from '@plone/volto/config/Blocks';

const BlockTypesControlpanel = () => {
const history = useHistory();
const location = useLocation();
const dispatch = useDispatch();

const [isClient, setIsClient] = useState(false);
const [displayingType, setDisplayingType] = useState('');

useEffect(() => {
const allBlockTypes = Object.keys(blocksConfig).join(',');
dispatch(getBlockTypes(`${allBlockTypes}`));
}, [dispatch]);

useEffect(() => {
setIsClient(true);
}, []);

const toggleTable = (id) => {
setDisplayingType(id);
};

const blocktypes = useSelector((state) => state.blocktypes?.items) || {};

const result = map(keys(blocktypes), (type) =>
// console.log(blocktypes[type]),
({
type,
total_sum: sum(
map(keys(blocktypes[type]), (url) => blocktypes[type][url]),
),
info: map(Object.entries(blocktypes[type])),
}),
);

return (
<>
<div id="page-controlpanel" className="ui container">
{displayingType === '' ? (
<table>
<tr>
<th>Type</th>
<th>Total</th>
</tr>
{result.map((blocktype) => {
return (
<tr>
<td onClick={() => toggleTable(blocktype.type)}>
{blocktype.type}
</td>
<td>{blocktype.total_sum}</td>
</tr>
);
})}
</table>
) : (
<table>
<tr>
<th>Location</th>
<th>Total</th>
</tr>
{result
.find((item) => item.type === displayingType)
?.info.map(([url, amount]) => {
return (
<tr>
<td>
<UniversalLink href={url}>{url}</UniversalLink>
</td>
<td>{amount}</td>
</tr>
);
})}
</table>
)}
</div>

{isClient &&
createPortal(
<Toolbar
pathname={location.pathname}
hideDefaultViewButtons
inner={
<Link
className="item"
to="#"
onClick={() => {
displayingType === ''
? history.push(getParentUrl(location.pathname))
: setDisplayingType('');
}}
>
<Icon name={backSVG} className="contents circled" size="30px" />
</Link>
}
/>,
document.getElementById('toolbar'),
)}
</>
);
};

export default BlockTypesControlpanel;
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ const messages = defineMessages({
id: 'Relations',
defaultMessage: 'Relations',
},
blocktypes: {
id: 'Block Types',
defaultMessage: 'Block Types',
},
});

/**
Expand Down Expand Up @@ -168,6 +172,11 @@ export default function Controlpanels({ location }) {
group: intl.formatMessage(messages.content),
title: intl.formatMessage(messages.moderatecomments),
},
{
'@id': '/blocktypes',
group: intl.formatMessage(messages.content),
title: intl.formatMessage(messages.blocktypes),
},
{
'@id': '/users',
group: intl.formatMessage(messages.usersControlPanelCategory),
Expand Down
6 changes: 6 additions & 0 deletions packages/volto/src/components/manage/Controlpanels/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,9 @@ export const DatabaseInformation = loadable(
() =>
import('@plone/volto/components/manage/Controlpanels/DatabaseInformation'),
);

// BLOCKTYPES CONTROLPANEL

export const BlockTypesControlpanel = loadable(
() => import('@plone/volto/components/manage/Controlpanels/BlockTypes'),
);
2 changes: 2 additions & 0 deletions packages/volto/src/config/ControlPanels.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import rulesSVG from '@plone/volto/icons/content-existing.svg';
import undoControlPanelSVG from '@plone/volto/icons/undo-control-panel.svg';
import linkSVG from '@plone/volto/icons/link.svg';
import relationsSVG from '@plone/volto/icons/ahead.svg';
import contentListingSVG from '@plone/volto/icons/content-listing.svg';

export const controlPanelsIcons = {
default: settingsSVG,
Expand All @@ -42,6 +43,7 @@ export const controlPanelsIcons = {
undo: undoControlPanelSVG,
aliases: linkSVG,
relations: relationsSVG,
blocktypes: contentListingSVG,
};

export const filterControlPanels = (controlpanels = []) => {
Expand Down
1 change: 1 addition & 0 deletions packages/volto/src/constants/ActionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,4 @@ export const GET_SITE = 'GET_SITE';
export const GET_NAVROOT = 'GET_NAVROOT';
export const SET_FORM_DATA = 'SET_FORM_DATA';
export const UPDATE_UPLOADED_FILES = 'UPDATE_UPLOADED_FILES';
export const GET_BLOCKTYPES_INDEX = 'GET_BLOCKTYPES_INDEX';
Loading
Loading