From 78a26aa7355e67c04a80e92f89a74334f83fca30 Mon Sep 17 00:00:00 2001 From: Giulia Ghisini <51911425+giuliaghisini@users.noreply.github.com> Date: Wed, 2 Oct 2024 13:46:18 +0200 Subject: [PATCH 1/7] fix: build_classnames in edit mode (#6259) Co-authored-by: ichim-david --- packages/volto/news/6259.bugfix | 1 + .../components/manage/Blocks/Block/EditBlockWrapper.jsx | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 packages/volto/news/6259.bugfix diff --git a/packages/volto/news/6259.bugfix b/packages/volto/news/6259.bugfix new file mode 100644 index 0000000000..9a9158fcc6 --- /dev/null +++ b/packages/volto/news/6259.bugfix @@ -0,0 +1 @@ +- Fixed build style classnames in edit mode. Also use buildStyleClassNamesExtenders. @giuliaghisini diff --git a/packages/volto/src/components/manage/Blocks/Block/EditBlockWrapper.jsx b/packages/volto/src/components/manage/Blocks/Block/EditBlockWrapper.jsx index 31508127bf..5fd3ab2adb 100644 --- a/packages/volto/src/components/manage/Blocks/Block/EditBlockWrapper.jsx +++ b/packages/volto/src/components/manage/Blocks/Block/EditBlockWrapper.jsx @@ -6,6 +6,7 @@ import { blockHasValue, buildStyleClassNamesFromData, buildStyleObjectFromData, + buildStyleClassNamesExtenders, } from '@plone/volto/helpers'; import dragSVG from '@plone/volto/icons/drag.svg'; import { Button } from 'semantic-ui-react'; @@ -61,7 +62,12 @@ const EditBlockWrapper = (props) => { ? data.required : includes(config.blocks.requiredBlocks, type); - const classNames = buildStyleClassNamesFromData(data.styles); + let classNames = buildStyleClassNamesFromData(data.styles); + classNames = buildStyleClassNamesExtenders({ + block, + data, + classNames, + }); const style = buildStyleObjectFromData(data.styles); // We need to merge the StyleWrapper styles with the draggable props from b-D&D From 1af4acef91e10604a782bbcc874dfe2468819065 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Wed, 2 Oct 2024 08:50:54 -0700 Subject: [PATCH 2/7] Fix spelling of prerequisites (#6362) --- docs/source/contributing/developing-core.md | 4 ++-- packages/volto/news/6362.documentation | 1 + styles/Vocab/Plone/reject.txt | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 packages/volto/news/6362.documentation diff --git a/docs/source/contributing/developing-core.md b/docs/source/contributing/developing-core.md index c00abaa0f1..44b387b761 100644 --- a/docs/source/contributing/developing-core.md +++ b/docs/source/contributing/developing-core.md @@ -71,9 +71,9 @@ Volto has the following folder structure. ``` -## Development pre-requisites +## Development prerequisites -To set up a Volto core development environment, your system must satisfy the following pre-requisites. +To set up a Volto core development environment, your system must satisfy the following prerequisites. ```{include} ./install-operating-system.md ``` diff --git a/packages/volto/news/6362.documentation b/packages/volto/news/6362.documentation new file mode 100644 index 0000000000..c37ab93222 --- /dev/null +++ b/packages/volto/news/6362.documentation @@ -0,0 +1 @@ +Fixed spelling of prerequisites. @stevepiercy diff --git a/styles/Vocab/Plone/reject.txt b/styles/Vocab/Plone/reject.txt index 1cefa812f0..81510d55a8 100644 --- a/styles/Vocab/Plone/reject.txt +++ b/styles/Vocab/Plone/reject.txt @@ -1,2 +1,3 @@ [^.]js NodeJS +[Pp]re-requisite From c3e5be1db26f7865e3777cca4210a21bfd39f4b2 Mon Sep 17 00:00:00 2001 From: peralta <129250086+aadityaforwork@users.noreply.github.com> Date: Wed, 2 Oct 2024 22:28:37 +0530 Subject: [PATCH 3/7] vscode/settings.json markdown added (#6357) Co-authored-by: Steve Piercy --- packages/scripts/news/6354.documentation | 1 + packages/scripts/vscodesettings.js | 16 ++++++++++++---- pnpm-lock.yaml | 2 +- 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 packages/scripts/news/6354.documentation diff --git a/packages/scripts/news/6354.documentation b/packages/scripts/news/6354.documentation new file mode 100644 index 0000000000..b643f0ac32 --- /dev/null +++ b/packages/scripts/news/6354.documentation @@ -0,0 +1 @@ +Added the configuration for VSCode not to reformat Markdown and MyST files. @aadityaforwork \ No newline at end of file diff --git a/packages/scripts/vscodesettings.js b/packages/scripts/vscodesettings.js index ebcc8cec08..2df03c41b8 100644 --- a/packages/scripts/vscodesettings.js +++ b/packages/scripts/vscodesettings.js @@ -13,9 +13,17 @@ if (fs.existsSync('.vscode')) { if (!vscodeSettingsJSON['eslint.workingDirectories']) { vscodeSettingsJSON['eslint.workingDirectories'] = [{ mode: 'auto' }]; +} - fs.writeFileSync( - '.vscode/settings.json', - `${stringify(vscodeSettingsJSON, null, 2)}`, - ); +if (!vscodeSettingsJSON['[markdown]']) { + vscodeSettingsJSON['[markdown]'] = { + 'editor.formatOnSave': false, + }; +} else { + vscodeSettingsJSON['[markdown]']['editor.formatOnSave'] = false; } + +fs.writeFileSync( + '.vscode/settings.json', + `${stringify(vscodeSettingsJSON, null, 2)}`, +); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 013c2c131a..21d9875b8e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -44371,4 +44371,4 @@ snapshots: zod@3.22.5: {} - zwitch@2.0.4: {} + zwitch@2.0.4: {} \ No newline at end of file From 913a084ffb9ec62fc8559cbad0035afc9ca97a73 Mon Sep 17 00:00:00 2001 From: Jefferson Bledsoe Date: Wed, 2 Oct 2024 21:10:25 +0100 Subject: [PATCH 4/7] Add outline to toolbar buttons (#6313) Co-authored-by: Piero Nicolli --- packages/volto/news/6313.bugfix | 1 + .../theme/themes/pastanaga/extras/toolbar.less | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 packages/volto/news/6313.bugfix diff --git a/packages/volto/news/6313.bugfix b/packages/volto/news/6313.bugfix new file mode 100644 index 0000000000..134d5727c5 --- /dev/null +++ b/packages/volto/news/6313.bugfix @@ -0,0 +1 @@ +Fixed toolbar buttons not having a focus outline. @JeffersonBledsoe diff --git a/packages/volto/theme/themes/pastanaga/extras/toolbar.less b/packages/volto/theme/themes/pastanaga/extras/toolbar.less index 0d25297239..9b1d5e6f03 100644 --- a/packages/volto/theme/themes/pastanaga/extras/toolbar.less +++ b/packages/volto/theme/themes/pastanaga/extras/toolbar.less @@ -283,16 +283,28 @@ body:not(.has-sidebar):not(.has-sidebar-collapsed) { .toolbar-content, .toolbar { - button { + button, + a { // Default reset for button padding: 0; border: 0; background: transparent; + box-shadow: unset !important; // Some buttons have double outlines due to default styles. Safely disable those styles here. cursor: pointer; text-align: initial; + svg { + display: block; // SVGs are inline by default, causing the spacing to be odd + margin: 0; // Some SVGs have margin set by default styles. + } + &:focus-visible { - outline: 1px auto; + outline: 2px solid black; + outline-offset: 2px; + + &:has(.circled) { + border-radius: 50%; + } } } } From ff84416d69d89bb86fd36e378a52f27be31f2c40 Mon Sep 17 00:00:00 2001 From: Piero Nicolli Date: Wed, 2 Oct 2024 22:11:56 +0200 Subject: [PATCH 5/7] Fixed client copy mutation, cleanup up move mutation for consistency (#6349) --- packages/client/news/6349.bugfix | 1 + .../client/src/restapi/copymove/copy.test.tsx | 4 +-- packages/client/src/restapi/copymove/copy.ts | 28 +++++++++---------- packages/client/src/restapi/copymove/move.ts | 22 +++++---------- packages/client/src/validation/copymove.ts | 5 +++- 5 files changed, 27 insertions(+), 33 deletions(-) create mode 100644 packages/client/news/6349.bugfix diff --git a/packages/client/news/6349.bugfix b/packages/client/news/6349.bugfix new file mode 100644 index 0000000000..47f5249e59 --- /dev/null +++ b/packages/client/news/6349.bugfix @@ -0,0 +1 @@ +Fixed client copy mutation, cleanup up move mutation for consistency @pnicolli diff --git a/packages/client/src/restapi/copymove/copy.test.tsx b/packages/client/src/restapi/copymove/copy.test.tsx index e278ad3d88..0c79277546 100644 --- a/packages/client/src/restapi/copymove/copy.test.tsx +++ b/packages/client/src/restapi/copymove/copy.test.tsx @@ -43,7 +43,7 @@ describe('[POST] Copy', () => { }); act(() => { - result.current.mutate({ data: copyData }); + result.current.mutate({ path: '/', data: copyData }); }); await waitFor(() => expect(result.current.isSuccess).toBe(true)); @@ -80,7 +80,7 @@ describe('[POST] Copy', () => { }); act(() => { - result.current.mutate({ data: copyMultipleData }); + result.current.mutate({ path: '/', data: copyMultipleData }); }); await waitFor(() => expect(result.current.isSuccess).toBe(true)); diff --git a/packages/client/src/restapi/copymove/copy.ts b/packages/client/src/restapi/copymove/copy.ts index 3935275dd5..bf300f958f 100644 --- a/packages/client/src/restapi/copymove/copy.ts +++ b/packages/client/src/restapi/copymove/copy.ts @@ -1,37 +1,35 @@ import { z } from 'zod'; import { ApiRequestParams, apiRequest } from '../../API'; -import { - PloneClientConfig, - PloneClientConfigSchema, -} from '../../validation/config'; +import { PloneClientConfig } from '../../validation/config'; import { copyMoveDataSchema as copyDataSchema } from '../../validation/copymove'; import { CopyMoveResponse as CopyResponse } from '@plone/types'; -export const copyArgsSchema = z.object({ - data: copyDataSchema, - config: PloneClientConfigSchema, -}); - -export type CopyArgs = z.infer; +export type CopyArgs = z.infer & { + config: PloneClientConfig; +}; export const copy = async ({ + path, data, config, }: CopyArgs): Promise => { - const validatedArgs = copyArgsSchema.parse({ + const validatedArgs = copyDataSchema.parse({ + path, data, - config, }); const options: ApiRequestParams = { + config, data: validatedArgs.data, - config: validatedArgs.config, }; - return apiRequest('post', '/@copy', options); + const copyPath = `${validatedArgs.path}/@copy`; + + return apiRequest('post', copyPath, options); }; export const copyMutation = ({ config }: { config: PloneClientConfig }) => ({ mutationKey: ['post', 'copy'], - mutationFn: ({ data }: Omit) => copy({ data, config }), + mutationFn: ({ path, data }: Omit) => + copy({ path, data, config }), }); diff --git a/packages/client/src/restapi/copymove/move.ts b/packages/client/src/restapi/copymove/move.ts index 3f9e3ceea7..6f1015caad 100644 --- a/packages/client/src/restapi/copymove/move.ts +++ b/packages/client/src/restapi/copymove/move.ts @@ -1,37 +1,29 @@ import { z } from 'zod'; import { ApiRequestParams, apiRequest } from '../../API'; -import { - PloneClientConfig, - PloneClientConfigSchema, -} from '../../validation/config'; +import { PloneClientConfig } from '../../validation/config'; import { copyMoveDataSchema as moveDataSchema } from '../../validation/copymove'; import { CopyMoveResponse as MoveResponse } from '@plone/types'; -export const MoveArgsSchema = z.object({ - path: z.string(), - data: moveDataSchema, - config: PloneClientConfigSchema, -}); - -export type MoveArgs = z.infer; +export type MoveArgs = z.infer & { + config: PloneClientConfig; +}; export const move = async ({ path, data, config, }: MoveArgs): Promise => { - const validatedArgs = MoveArgsSchema.parse({ + const validatedArgs = moveDataSchema.parse({ path, data, - config, }); const options: ApiRequestParams = { + config, data: validatedArgs.data, - config: validatedArgs.config, }; - const movePath = `/${validatedArgs.path}/@move`; + const movePath = `${validatedArgs.path}/@move`; return apiRequest('post', movePath, options); }; diff --git a/packages/client/src/validation/copymove.ts b/packages/client/src/validation/copymove.ts index ee27382a81..f712bd708a 100644 --- a/packages/client/src/validation/copymove.ts +++ b/packages/client/src/validation/copymove.ts @@ -1,5 +1,8 @@ import { z } from 'zod'; export const copyMoveDataSchema = z.object({ - source: z.union([z.string(), z.array(z.string())]), + path: z.string(), + data: z.object({ + source: z.union([z.string(), z.array(z.string())]), + }), }); From 6e498dec450ffe747b5bae7308362d879e7e59f4 Mon Sep 17 00:00:00 2001 From: Wesley Barroso Lopes Date: Thu, 3 Oct 2024 03:51:55 -0300 Subject: [PATCH 6/7] Fetch user before pass it to the restricted function (#6293) --- packages/volto-slate/news/6293.bugfix | 1 + .../volto-slate/src/blocks/Text/SlashMenu.jsx | 4 ++-- packages/volto/news/6293.bugfix | 1 + .../manage/BlockChooser/BlockChooser.jsx | 4 ++-- .../manage/BlockChooser/BlockChooser.test.jsx | 4 ++++ packages/volto/src/hooks/index.js | 1 + packages/volto/src/hooks/user/useUser.js | 23 +++++++++++++++++++ 7 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 packages/volto-slate/news/6293.bugfix create mode 100644 packages/volto/news/6293.bugfix create mode 100644 packages/volto/src/hooks/user/useUser.js diff --git a/packages/volto-slate/news/6293.bugfix b/packages/volto-slate/news/6293.bugfix new file mode 100644 index 0000000000..ea8503c548 --- /dev/null +++ b/packages/volto-slate/news/6293.bugfix @@ -0,0 +1 @@ +Fetch `user` before pass it to the `restricted` function of the block settings. @wesleybl diff --git a/packages/volto-slate/src/blocks/Text/SlashMenu.jsx b/packages/volto-slate/src/blocks/Text/SlashMenu.jsx index 2a26c39cfe..9ec1612304 100644 --- a/packages/volto-slate/src/blocks/Text/SlashMenu.jsx +++ b/packages/volto-slate/src/blocks/Text/SlashMenu.jsx @@ -4,7 +4,7 @@ import { filter, isEmpty } from 'lodash'; import { Menu } from 'semantic-ui-react'; import { useIntl, FormattedMessage } from 'react-intl'; import { Icon } from '@plone/volto/components'; -import { useSelector } from 'react-redux'; +import { useUser } from '@plone/volto/hooks'; const emptySlateBlock = () => ({ value: [ @@ -111,7 +111,7 @@ const PersistentSlashMenu = ({ editor }) => { } = props; const disableNewBlocks = data?.disableNewBlocks || detached; - const user = useSelector((state) => state.users?.user); + const user = useUser(); const [slashMenuSelected, setSlashMenuSelected] = React.useState(0); diff --git a/packages/volto/news/6293.bugfix b/packages/volto/news/6293.bugfix new file mode 100644 index 0000000000..ea8503c548 --- /dev/null +++ b/packages/volto/news/6293.bugfix @@ -0,0 +1 @@ +Fetch `user` before pass it to the `restricted` function of the block settings. @wesleybl diff --git a/packages/volto/src/components/manage/BlockChooser/BlockChooser.jsx b/packages/volto/src/components/manage/BlockChooser/BlockChooser.jsx index 80c5142e81..2ae878e5ba 100644 --- a/packages/volto/src/components/manage/BlockChooser/BlockChooser.jsx +++ b/packages/volto/src/components/manage/BlockChooser/BlockChooser.jsx @@ -1,5 +1,5 @@ import React from 'react'; -import { useSelector } from 'react-redux'; +import { useUser } from '@plone/volto/hooks'; import PropTypes from 'prop-types'; import { filter, map, groupBy, isEmpty } from 'lodash'; import { Accordion, Button } from 'semantic-ui-react'; @@ -36,7 +36,7 @@ const BlockChooser = ({ contentType, }) => { const intl = useIntl(); - const user = useSelector((state) => state.users?.user); + const user = useUser(); const hasAllowedBlocks = !isEmpty(allowedBlocks); const filteredBlocksConfig = filter(blocksConfig, (item) => { diff --git a/packages/volto/src/components/manage/BlockChooser/BlockChooser.test.jsx b/packages/volto/src/components/manage/BlockChooser/BlockChooser.test.jsx index 447c20f61d..d2bd1bbe5a 100644 --- a/packages/volto/src/components/manage/BlockChooser/BlockChooser.test.jsx +++ b/packages/volto/src/components/manage/BlockChooser/BlockChooser.test.jsx @@ -4,6 +4,7 @@ import { Provider } from 'react-intl-redux'; import configureStore from 'redux-mock-store'; import BlockChooser from './BlockChooser'; import config from '@plone/volto/registry'; +import jwt from 'jsonwebtoken'; const blockSVG = {}; @@ -121,6 +122,9 @@ const store = mockStore({ locale: 'en', messages: {}, }, + userSession: { + token: jwt.sign({ fullname: 'John Doe' }, 'secret'), + }, }); describe('BlocksChooser', () => { diff --git a/packages/volto/src/hooks/index.js b/packages/volto/src/hooks/index.js index a955aa8285..f8e327c0e6 100644 --- a/packages/volto/src/hooks/index.js +++ b/packages/volto/src/hooks/index.js @@ -1,2 +1,3 @@ export { default as useClipboard } from '@plone/volto/hooks/clipboard/useClipboard'; export { useClient } from '@plone/volto/hooks/client/useClient'; +export { default as useUser } from '@plone/volto/hooks/user/useUser'; diff --git a/packages/volto/src/hooks/user/useUser.js b/packages/volto/src/hooks/user/useUser.js new file mode 100644 index 0000000000..3232ed0a8e --- /dev/null +++ b/packages/volto/src/hooks/user/useUser.js @@ -0,0 +1,23 @@ +import { useEffect } from 'react'; +import { useDispatch, useSelector } from 'react-redux'; +import jwtDecode from 'jwt-decode'; +import { getUser } from '@plone/volto/actions'; + +const useUser = () => { + const users = useSelector((state) => state.users); + const user = users?.user; + const userId = useSelector((state) => + state.userSession.token ? jwtDecode(state.userSession.token).sub : '', + ); + const dispatch = useDispatch(); + + useEffect(() => { + if (!user?.id && users?.get.loading === false) { + dispatch(getUser(userId)); + } + }, [dispatch, userId, user, users?.get.loading]); + + return user; +}; + +export default useUser; From 52a23bd2de3ad671975f5db5778f6f0ccdabf3a2 Mon Sep 17 00:00:00 2001 From: Steve Piercy Date: Wed, 2 Oct 2024 23:54:19 -0700 Subject: [PATCH 7/7] =?UTF-8?q?Fix=20lexer=20language=20in=20upgrade=20gui?= =?UTF-8?q?de=20for=20Field=20validation=20in=20blocks=20ex=E2=80=A6=20(#6?= =?UTF-8?q?367)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/source/upgrade-guide/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/upgrade-guide/index.md b/docs/source/upgrade-guide/index.md index ddea900417..407cf8fe48 100644 --- a/docs/source/upgrade-guide/index.md +++ b/docs/source/upgrade-guide/index.md @@ -395,7 +395,7 @@ If you shadowed the module {file}`packages/volto/src/helpers/FormValidation/Form This prop must be assigned with the new prop passed down from the blocks engine `blocksErrors`. If not passed down, the block can't display any field validation error. -```tsx +```jsx // More component code above here const {