Skip to content

Commit

Permalink
Fix useSelector is returned a different result when called with the s… (
Browse files Browse the repository at this point in the history
  • Loading branch information
iFlameing authored Oct 29, 2024
1 parent e5b8a40 commit ec89ad8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
1 change: 1 addition & 0 deletions packages/volto/news/6449.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix useSelector is returned a different result when called with the same parameters in IdWidget. @iFlameing
13 changes: 6 additions & 7 deletions packages/volto/src/components/manage/Widgets/IdWidget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useState, useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import { useSelector, useDispatch } from 'react-redux';
import { Input } from 'semantic-ui-react';
import { compact, concat, keys, map, union, uniq } from 'lodash';
import { compact, concat, map, union, uniq } from 'lodash';

import { defineMessages, useIntl } from 'react-intl';
import { Icon } from '@plone/volto/components';
Expand Down Expand Up @@ -46,8 +46,7 @@ const IdWidget = (props) => {
const intl = useIntl();
const dispatch = useDispatch();
const ref = useRef();

const indexes = useSelector((state) => keys(state.querystring.indexes));
const indexes = useSelector((state) => state.querystring.indexes);

const [errors, setError] = useState([]);
const [reservedIds] = useState(
Expand All @@ -62,26 +61,26 @@ const IdWidget = (props) => {
),
),
);
const fieldValidation = (values) => {
const fieldValidation = (value) => {
const error = [];

// Check reserved id's
if (reservedIds.indexOf(values) !== -1) {
if (reservedIds.indexOf(value) !== -1) {
error.push(intl.formatMessage(messages.reservedId));
}

// Check invalid characters
if (
// eslint-disable-next-line no-control-regex
!/^(?!.*\\)(?!\+\+)(?!@@)(?!.*request)(?!.*contributors)(?!aq_)(?!.*__)(?!_)(?!((^|\/)\.\.?($|\/)|^"\s*"$))(?!.*[A-Z])(?:(?![\r\n<>/?&#\x00-\x1F\x7F])['\x00-\x7F\u0080-\uFFFF. _])*$/.test(
values,
value,
)
) {
error.push(intl.formatMessage(messages.invalidCharacters));
}

// Check indexes
if (indexes.indexOf(values) !== -1) {
if (value in indexes) {
error.push(intl.formatMessage(messages.reservedId));
}

Expand Down

0 comments on commit ec89ad8

Please sign in to comment.