-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathEditCollectionPanel.tsx
More file actions
74 lines (66 loc) · 2.4 KB
/
EditCollectionPanel.tsx
File metadata and controls
74 lines (66 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { Label, makeStyles, tokens } from '@fluentui/react-components';
import { translateMessage } from '../../../../utils/translate-messages';
import { useState } from 'react';
import { IResourceLink } from '../../../../../types/resources';
import { removeResourcePaths } from '../../../../services/slices/collections.slice';
import Paths from './Paths';
import { useAppDispatch, useAppSelector } from '../../../../../store';
import CommonCollectionsPanel from './CommonCollectionsPanel';
const useStyles = makeStyles({
centeredLabel: {
display: 'flex',
width: '100%',
justifyContent: 'center',
alignItems: 'center',
height: '80vh'
},
paths: {
marginBlockStart: tokens.spacingVerticalL
}
});
interface EditCollectionPanelProps {
closePopup: () => void;
}
const EditCollectionPanel: React.FC<EditCollectionPanelProps> = ({ closePopup }) => {
const dispatch = useAppDispatch();
const [selectedItems, setSelectedItems] = useState<IResourceLink[]>([]);
const { collections } = useAppSelector((state) => state.collections);
const items = collections && collections.length > 0 ? collections.find(k => k.isDefault)!.paths : [];
const columns = [
{ key: 'url', name: 'Select all', fieldName: 'url', minWidth: 300, maxWidth: 1100, isResizable: true },
{ key: 'scope', name: '', fieldName: 'scope', minWidth: 150, maxWidth: 200, isResizable: true }
];
const removeSelectedItems = () => {
dispatch(removeResourcePaths(selectedItems));
setSelectedItems([]);
};
const styles = useStyles();
return (
<CommonCollectionsPanel
messageBarText={translateMessage('edit collections')}
messageBarSpanText={translateMessage('Delete All Selected')}
primaryButtonText='Delete all selected'
primaryButtonAction={removeSelectedItems}
primaryButtonDisabled={selectedItems.length === 0}
closePopup={closePopup}
>
{items && items.length > 0 ? (
<div className={styles.paths}>
<Paths
resources={items}
columns={columns}
isSelectable={true}
onSelectionChange={(selected) => setSelectedItems(selected as IResourceLink[])}
/>
</div>
) : (
<div>
<Label className={styles.centeredLabel}>
{translateMessage('No items available')}
</Label>
</div>
)}
</CommonCollectionsPanel>
);
};
export default EditCollectionPanel;