0
- ) {
- const linkintegrityInfo = await this.props.linkIntegrityCheck(
- map(this.state.itemsToDelete, (item) => this.getFieldById(item, 'UID')),
- );
- const containedItems = linkintegrityInfo
- .map((result) => result.items_total ?? 0)
- .reduce((acc, value) => acc + value, 0);
- const breaches = linkintegrityInfo.flatMap((result) =>
- result.breaches.map((source) => ({
- source: source,
- target: result,
- })),
- );
- const source_by_uid = breaches.reduce(
- (acc, value) => acc.set(value.source.uid, value.source),
- new Map(),
- );
- const by_source = breaches.reduce((acc, value) => {
- if (acc.get(value.source.uid) === undefined) {
- acc.set(value.source.uid, new Set());
- }
- acc.get(value.source.uid).add(value.target);
- return acc;
- }, new Map());
-
- this.setState({
- containedItemsToDelete: containedItems,
- brokenReferences: by_source.size,
- linksAndReferencesViewLink: linkintegrityInfo.length
- ? linkintegrityInfo[0]['@id'] + '/links-to-item'
- : null,
- breaches: Array.from(by_source, (entry) => ({
- source: source_by_uid.get(entry[0]),
- targets: Array.from(entry[1]),
- })),
- showAllItemsToDelete:
- this.state.itemsToDelete.length < this.deleteItemsToShowThreshold,
- });
- }
- }
/**
* Component will receive props
@@ -1209,298 +1149,12 @@ class Contents extends Component {
/>
-
- {this.state.itemsToDelete.length > 1 ? (
- this.state.containedItemsToDelete > 0 ? (
- <>
-
- {this.state.containedItemsToDelete}
-
- ),
- variation: (
-
- {this.state.containedItemsToDelete ===
- 1 ? (
-
- ) : (
-
- )}
-
- ),
- }}
- />
- {this.state.brokenReferences > 0 && (
- <>
-
-
- {this.state.brokenReferences}
-
- ),
- variation: (
-
- {this.state.brokenReferences === 1 ? (
-
- ) : (
-
- )}
-
- ),
- }}
- />
- >
- )}
- >
- ) : (
- <>
- {this.state.brokenReferences > 0 && (
- <>
-
- {this.state.brokenReferences}
-
- ),
- variation: (
-
- {this.state.brokenReferences === 1 ? (
-
- ) : (
-
- )}
-
- ),
- }}
- />
- >
- )}
- >
- )
- ) : this.state.containedItemsToDelete > 0 ? (
- <>
-
- {this.state.containedItemsToDelete}
-
- ),
- variation: (
-
- {this.state.containedItemsToDelete === 1 ? (
-
- ) : (
-
- )}
-
- ),
- }}
- />
- {this.state.brokenReferences > 0 && (
- <>
-
- {this.state.brokenReferences}
- ),
- variation: (
-
- {this.state.brokenReferences === 1 ? (
-
- ) : (
-
- )}
-
- ),
- }}
- />
-
-
-
- {this.state.breaches.map((breach) => (
- -
-
- {breach.source.title}
- {' '}
- refers to{' '}
- {breach.targets
- .map((target) => (
-
- {target.title}
-
- ))
- .reduce((result, item) => (
- <>
- {result}, {item}
- >
- ))}
-
- ))}
-
- {this.state.linksAndReferencesViewLink && (
-
-
-
- )}
-
- >
- )}
- >
- ) : this.state.brokenReferences > 0 ? (
- <>
- {this.state.brokenReferences}
- ),
- variation: (
-
- {this.state.brokenReferences === 1 ? (
-
- ) : (
-
- )}
-
- ),
- }}
- />
-
-
-
- {this.state.breaches.map((breach) => (
- -
-
- {breach.source.title}
- {' '}
- refers to{' '}
- {breach.targets
- .map((target) => (
-
- {target.title}
-
- ))
- .reduce((result, item) => (
- <>
- {result}, {item}
- >
- ))}
-
- ))}
-
- {this.state.linksAndReferencesViewLink && (
-
-
-
- )}
-
- >
- ) : null}
-
- }
onCancel={this.onDeleteCancel}
- onConfirm={this.onDeleteOk}
- size="medium"
+ onOk={this.onDeleteOk}
+ items={this.state.items}
+ itemsToDelete={this.state.itemsToDelete}
/>
{
+ const { itemsToDelete = [], open, onCancel, onOk, items } = props;
+ const intl = useIntl();
+ const dispatch = useDispatch();
+ const linkintegrityInfo = useSelector((state) => state.linkIntegrity?.result);
+ const loading = useSelector((state) => state.linkIntegrity?.loading);
+
+ const [brokenReferences, setBrokenReferences] = useState(0);
+ const [containedItemsToDelete, setContainedItemsToDelete] = useState([]);
+ const [breaches, setBreaches] = useState([]);
+
+ const [linksAndReferencesViewLink, setLinkAndReferencesViewLink] =
+ useState(null);
+
+ useEffect(() => {
+ const getFieldById = (id, field) => {
+ const item = find(items, { '@id': id });
+ return item ? item[field] : '';
+ };
+
+ if (itemsToDelete.length > 0 && open) {
+ dispatch(
+ linkIntegrityCheck(
+ map(itemsToDelete, (item) => getFieldById(item, 'UID')),
+ ),
+ );
+ }
+ }, [itemsToDelete, items, open, dispatch]);
+
+ useEffect(() => {
+ if (linkintegrityInfo) {
+ const containedItems = linkintegrityInfo
+ .map((result) => result.items_total ?? 0)
+ .reduce((acc, value) => acc + value, 0);
+ const breaches = linkintegrityInfo.flatMap((result) =>
+ result.breaches.map((source) => ({
+ source: source,
+ target: result,
+ })),
+ );
+ const source_by_uid = breaches.reduce(
+ (acc, value) => acc.set(value.source.uid, value.source),
+ new Map(),
+ );
+ const by_source = breaches.reduce((acc, value) => {
+ if (acc.get(value.source.uid) === undefined) {
+ acc.set(value.source.uid, new Set());
+ }
+ acc.get(value.source.uid).add(value.target);
+ return acc;
+ }, new Map());
+
+ setContainedItemsToDelete(containedItems);
+ setBrokenReferences(by_source.size);
+ setLinkAndReferencesViewLink(
+ linkintegrityInfo.length
+ ? linkintegrityInfo[0]['@id'] + '/links-to-item'
+ : null,
+ );
+ setBreaches(
+ Array.from(by_source, (entry) => ({
+ source: source_by_uid.get(entry[0]),
+ targets: Array.from(entry[1]),
+ })),
+ );
+ } else {
+ setContainedItemsToDelete([]);
+ setBrokenReferences(0);
+ setLinkAndReferencesViewLink(null);
+ setBreaches([]);
+ }
+ }, [linkintegrityInfo]);
+
+ return (
+ open && (
+
+
+
+ {intl.formatMessage(messages.loading)}
+
+
+
+ {itemsToDelete.length > 1 ? (
+ containedItemsToDelete > 0 ? (
+ <>
+ {containedItemsToDelete}
+ ),
+ variation: (
+
+ {containedItemsToDelete === 1 ? (
+
+ ) : (
+
+ )}
+
+ ),
+ }}
+ />
+ {brokenReferences > 0 && (
+ <>
+
+ {brokenReferences},
+ variation: (
+
+ {brokenReferences === 1 ? (
+
+ ) : (
+
+ )}
+
+ ),
+ }}
+ />
+ >
+ )}
+ >
+ ) : (
+ <>
+ {brokenReferences > 0 && (
+ <>
+ {brokenReferences},
+ variation: (
+
+ {brokenReferences === 1 ? (
+
+ ) : (
+
+ )}
+
+ ),
+ }}
+ />
+ >
+ )}
+ >
+ )
+ ) : containedItemsToDelete > 0 ? (
+ <>
+ {containedItemsToDelete}
+ ),
+ variation: (
+
+ {containedItemsToDelete === 1 ? (
+
+ ) : (
+
+ )}
+
+ ),
+ }}
+ />
+ {brokenReferences > 0 && (
+ <>
+
+ {brokenReferences},
+ variation: (
+
+ {brokenReferences === 1 ? (
+
+ ) : (
+
+ )}
+
+ ),
+ }}
+ />
+
+ >
+ )}
+ >
+ ) : brokenReferences > 0 ? (
+ <>
+ {brokenReferences},
+ variation: (
+
+ {brokenReferences === 1 ? (
+
+ ) : (
+
+ )}
+
+ ),
+ }}
+ />
+
+ >
+ ) : null}
+
+ }
+ onCancel={onCancel}
+ onConfirm={onOk}
+ size="medium"
+ />
+ )
+ );
+};
+
+const BrokenLinksList = ({ intl, breaches, linksAndReferencesViewLink }) => {
+ return (
+
+
+ :
+
+
+ {breaches.map((breach) => (
+
+
+
+ {breach.source.title}
+
+
+
+ :
+
+
+
+ {breach.targets.map((target) => (
+ -
+
+ {target.title}
+
+
+ ))}
+
+
+
+ ))}
+
+
+ {linksAndReferencesViewLink && (
+
+
+
+ )}
+
+ );
+};
+ContentsDeleteModal.propTypes = {
+ itemsToDelete: PropTypes.arrayOf(
+ PropTypes.shape({
+ UID: PropTypes.string,
+ }),
+ ).isRequired,
+ open: PropTypes.bool.isRequired,
+ onOk: PropTypes.func.isRequired,
+ onCancel: PropTypes.func.isRequired,
+};
+export default ContentsDeleteModal;
diff --git a/packages/volto/src/components/manage/Rules/Rules.jsx b/packages/volto/src/components/manage/Rules/Rules.jsx
index e8b4837aa4..2a07bf0ca6 100644
--- a/packages/volto/src/components/manage/Rules/Rules.jsx
+++ b/packages/volto/src/components/manage/Rules/Rules.jsx
@@ -76,6 +76,10 @@ const messages = defineMessages({
id: 'Unassigned',
defaultMessage: 'Unassigned',
},
+ select_rule: {
+ id: 'Select rule',
+ defaultMessage: 'Select rule',
+ },
});
/**
@@ -366,7 +370,9 @@ class Rules extends Component {
/>