@firecms/core 3.0.0-beta.13 → 3.0.0-beta.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ArrayContainer.d.ts +7 -12
- package/dist/components/EntityCollectionTable/EntityCollectionRowActions.d.ts +2 -1
- package/dist/components/EntityPreview.d.ts +4 -2
- package/dist/components/HomePage/DefaultHomePage.d.ts +2 -15
- package/dist/components/HomePage/HomePageDnD.d.ts +76 -0
- package/dist/components/HomePage/NavigationCard.d.ts +3 -1
- package/dist/components/HomePage/NavigationCardBinding.d.ts +3 -2
- package/dist/components/HomePage/NavigationGroup.d.ts +7 -1
- package/dist/components/HomePage/RenameGroupDialog.d.ts +9 -0
- package/dist/components/SelectableTable/SelectableTable.d.ts +1 -1
- package/dist/components/VirtualTable/VirtualTableProps.d.ts +0 -4
- package/dist/components/index.d.ts +1 -0
- package/dist/core/EntityEditView.d.ts +3 -0
- package/dist/core/EntityEditViewFormActions.d.ts +1 -1
- package/dist/core/field_configs.d.ts +1 -1
- package/dist/form/EntityForm.d.ts +2 -1
- package/dist/form/EntityFormActions.d.ts +6 -2
- package/dist/form/field_bindings/MapFieldBinding.d.ts +1 -1
- package/dist/form/field_bindings/ReferenceAsStringFieldBinding.d.ts +9 -0
- package/dist/form/field_bindings/StorageUploadFieldBinding.d.ts +3 -9
- package/dist/form/index.d.ts +1 -0
- package/dist/hooks/useBuildNavigationController.d.ts +50 -8
- package/dist/index.es.js +3259 -1649
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +3265 -1658
- package/dist/index.umd.js.map +1 -1
- package/dist/types/analytics.d.ts +1 -1
- package/dist/types/collections.d.ts +28 -4
- package/dist/types/customization_controller.d.ts +8 -0
- package/dist/types/entity_actions.d.ts +46 -6
- package/dist/types/firecms.d.ts +10 -1
- package/dist/types/navigation.d.ts +26 -5
- package/dist/types/plugins.d.ts +32 -1
- package/dist/types/properties.d.ts +7 -0
- package/dist/types/property_config.d.ts +1 -1
- package/dist/types/side_entity_controller.d.ts +8 -0
- package/dist/util/callbacks.d.ts +2 -0
- package/dist/util/icons.d.ts +2 -2
- package/dist/util/index.d.ts +1 -0
- package/dist/util/navigation_from_path.d.ts +4 -0
- package/dist/util/resolutions.d.ts +2 -1
- package/package.json +8 -6
- package/src/components/ArrayContainer.tsx +409 -294
- package/src/components/ClearFilterSortButton.tsx +1 -1
- package/src/components/ConfirmationDialog.tsx +10 -9
- package/src/components/EntityCollectionTable/EntityCollectionRowActions.tsx +6 -0
- package/src/components/EntityCollectionTable/PropertyTableCell.tsx +26 -4
- package/src/components/EntityCollectionTable/internal/CollectionTableToolbar.tsx +3 -3
- package/src/components/EntityCollectionTable/internal/EntityTableCell.tsx +13 -2
- package/src/components/EntityCollectionTable/internal/popup_field/PopupFormField.tsx +53 -27
- package/src/components/EntityCollectionTable/internal/popup_field/useDraggable.tsx +9 -9
- package/src/components/EntityCollectionView/EntityCollectionView.tsx +11 -4
- package/src/components/EntityCollectionView/EntityCollectionViewActions.tsx +3 -2
- package/src/components/EntityPreview.tsx +18 -14
- package/src/components/ErrorView.tsx +1 -1
- package/src/components/FireCMSLogo.tsx +7 -51
- package/src/components/HomePage/DefaultHomePage.tsx +491 -156
- package/src/components/HomePage/FavouritesView.tsx +3 -3
- package/src/components/HomePage/HomePageDnD.tsx +599 -0
- package/src/components/HomePage/NavigationCard.tsx +47 -38
- package/src/components/HomePage/NavigationCardBinding.tsx +13 -7
- package/src/components/HomePage/NavigationGroup.tsx +63 -29
- package/src/components/HomePage/RenameGroupDialog.tsx +117 -0
- package/src/components/SelectableTable/SelectableTable.tsx +140 -143
- package/src/components/UnsavedChangesDialog.tsx +6 -2
- package/src/components/VirtualTable/VirtualTable.tsx +8 -30
- package/src/components/VirtualTable/VirtualTableProps.tsx +0 -5
- package/src/components/VirtualTable/fields/VirtualTableInput.tsx +0 -1
- package/src/components/common/default_entity_actions.tsx +25 -9
- package/src/components/common/useDataSourceTableController.tsx +2 -2
- package/src/components/index.tsx +2 -0
- package/src/core/DefaultDrawer.tsx +8 -8
- package/src/core/DrawerNavigationItem.tsx +1 -1
- package/src/core/EntityEditView.tsx +65 -18
- package/src/core/EntityEditViewFormActions.tsx +154 -29
- package/src/core/EntitySidePanel.tsx +19 -21
- package/src/core/FireCMS.tsx +9 -1
- package/src/core/field_configs.tsx +15 -1
- package/src/form/EntityForm.tsx +37 -5
- package/src/form/EntityFormActions.tsx +51 -9
- package/src/form/PropertyFieldBinding.tsx +0 -1
- package/src/form/components/CustomIdField.tsx +3 -1
- package/src/form/components/LabelWithIcon.tsx +1 -1
- package/src/form/components/StorageItemPreview.tsx +1 -1
- package/src/form/components/StorageUploadProgress.tsx +3 -3
- package/src/form/field_bindings/ArrayOfReferencesFieldBinding.tsx +3 -2
- package/src/form/field_bindings/MapFieldBinding.tsx +5 -4
- package/src/form/field_bindings/MarkdownEditorFieldBinding.tsx +4 -2
- package/src/form/field_bindings/MultiSelectFieldBinding.tsx +1 -1
- package/src/form/field_bindings/ReferenceAsStringFieldBinding.tsx +135 -0
- package/src/form/field_bindings/SelectFieldBinding.tsx +2 -1
- package/src/form/field_bindings/StorageUploadFieldBinding.tsx +216 -153
- package/src/form/index.tsx +1 -0
- package/src/hooks/data/save.ts +0 -6
- package/src/hooks/useBuildNavigationController.tsx +299 -96
- package/src/internal/useBuildSideEntityController.tsx +8 -5
- package/src/preview/PropertyPreview.tsx +14 -0
- package/src/preview/components/ImagePreview.tsx +2 -2
- package/src/preview/components/ReferencePreview.tsx +1 -1
- package/src/preview/property_previews/ArrayOfMapsPreview.tsx +1 -1
- package/src/preview/property_previews/MapPropertyPreview.tsx +1 -1
- package/src/preview/property_previews/SkeletonPropertyComponent.tsx +1 -1
- package/src/preview/property_previews/StringPropertyPreview.tsx +1 -1
- package/src/routes/FireCMSRoute.tsx +3 -3
- package/src/types/analytics.ts +3 -0
- package/src/types/collections.ts +32 -4
- package/src/types/customization_controller.tsx +9 -0
- package/src/types/entity_actions.tsx +57 -6
- package/src/types/firecms.tsx +11 -2
- package/src/types/navigation.ts +34 -6
- package/src/types/plugins.tsx +40 -1
- package/src/types/properties.ts +8 -0
- package/src/types/property_config.tsx +1 -0
- package/src/types/side_entity_controller.tsx +10 -5
- package/src/util/callbacks.ts +119 -0
- package/src/util/icons.tsx +22 -7
- package/src/util/index.ts +1 -0
- package/src/util/join_collections.ts +3 -1
- package/src/util/navigation_from_path.ts +15 -5
- package/src/util/navigation_utils.ts +72 -57
- package/src/util/objects.ts +53 -20
- package/src/util/resolutions.ts +13 -1
- package/dist/components/EntityCollectionTable/internal/popup_field/ElementResizeListener.d.ts +0 -5
- package/src/components/EntityCollectionTable/internal/popup_field/ElementResizeListener.tsx +0 -59
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ArrowForwardIcon, Card, cls, Markdown, Typography, } from "@firecms/ui";
|
|
2
|
+
import React from "react"; // Import React
|
|
2
3
|
|
|
3
4
|
export type NavigationCardProps = {
|
|
4
5
|
name: string,
|
|
@@ -6,64 +7,72 @@ export type NavigationCardProps = {
|
|
|
6
7
|
actions: React.ReactNode;
|
|
7
8
|
icon: React.ReactNode;
|
|
8
9
|
onClick?: () => void,
|
|
10
|
+
shrink?: boolean
|
|
9
11
|
};
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
// Wrap the component with React.memo
|
|
14
|
+
export const NavigationCard = React.memo(function NavigationCard({
|
|
12
15
|
name,
|
|
13
16
|
description,
|
|
14
17
|
icon,
|
|
15
18
|
actions,
|
|
16
19
|
onClick,
|
|
20
|
+
shrink
|
|
17
21
|
}: NavigationCardProps) {
|
|
18
22
|
|
|
19
|
-
return (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
return (
|
|
24
|
+
<Card
|
|
25
|
+
className={cls(
|
|
26
|
+
"h-full p-4 cursor-pointer min-h-[230px] transition-all duration-200 ease-in-out",
|
|
27
|
+
shrink && "w-full max-w-full min-h-0 scale-75"
|
|
28
|
+
)}
|
|
29
|
+
onClick={() => {
|
|
30
|
+
onClick?.();
|
|
31
|
+
}}
|
|
32
|
+
>
|
|
33
|
+
|
|
34
|
+
<div className="flex flex-col items-start h-full">
|
|
35
|
+
<div
|
|
36
|
+
className="flex-grow w-full">
|
|
24
37
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
className="flex-grow w-full">
|
|
38
|
+
<div
|
|
39
|
+
className="h-10 flex items-center w-full justify-between text-surface-300 dark:text-surface-600">
|
|
28
40
|
|
|
29
|
-
|
|
30
|
-
className="h-10 flex items-center w-full justify-between text-surface-300 dark:text-surface-600">
|
|
41
|
+
{icon}
|
|
31
42
|
|
|
32
|
-
|
|
43
|
+
<div
|
|
44
|
+
className="flex items-center gap-1"
|
|
45
|
+
onClick={(event: React.MouseEvent) => {
|
|
46
|
+
event.preventDefault();
|
|
47
|
+
event.stopPropagation();
|
|
48
|
+
}}>
|
|
33
49
|
|
|
34
|
-
|
|
35
|
-
className="flex items-center gap-1"
|
|
36
|
-
onClick={(event: React.MouseEvent) => {
|
|
37
|
-
event.preventDefault();
|
|
38
|
-
event.stopPropagation();
|
|
39
|
-
}}>
|
|
50
|
+
{actions}
|
|
40
51
|
|
|
41
|
-
|
|
52
|
+
</div>
|
|
42
53
|
|
|
43
54
|
</div>
|
|
44
55
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
{name}
|
|
50
|
-
</Typography>
|
|
56
|
+
<Typography gutterBottom variant="h5"
|
|
57
|
+
component="h2">
|
|
58
|
+
{name}
|
|
59
|
+
</Typography>
|
|
51
60
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
{description && <Typography variant="body2"
|
|
62
|
+
color="secondary"
|
|
63
|
+
component="div">
|
|
64
|
+
<Markdown source={description} size={"small"}/>
|
|
65
|
+
</Typography>}
|
|
66
|
+
</div>
|
|
58
67
|
|
|
59
|
-
|
|
68
|
+
<div style={{ alignSelf: "flex-end" }}>
|
|
60
69
|
|
|
61
|
-
|
|
62
|
-
|
|
70
|
+
<div className={"p-4"}>
|
|
71
|
+
<ArrowForwardIcon className="text-primary"/>
|
|
72
|
+
</div>
|
|
63
73
|
</div>
|
|
64
|
-
</div>
|
|
65
74
|
|
|
66
|
-
|
|
75
|
+
</div>
|
|
67
76
|
|
|
68
|
-
|
|
69
|
-
}
|
|
77
|
+
</Card>)
|
|
78
|
+
});
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { useNavigate } from "react-router-dom";
|
|
2
2
|
|
|
3
3
|
import { useCustomizationController, useFireCMSContext } from "../../hooks";
|
|
4
|
-
import {
|
|
4
|
+
import { NavigationEntry, PluginHomePageActionsProps } from "../../types";
|
|
5
5
|
import { IconForView } from "../../util";
|
|
6
6
|
import { useUserConfigurationPersistence } from "../../hooks/useUserConfigurationPersistence";
|
|
7
7
|
import { IconButton, StarIcon } from "@firecms/ui";
|
|
8
8
|
import { NavigationCard } from "./NavigationCard";
|
|
9
9
|
import { SmallNavigationCard } from "./SmallNavigationCard";
|
|
10
|
+
import React from "react";
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* This is the component used in the home page to render a card for each
|
|
@@ -29,9 +30,11 @@ export function NavigationCardBinding({
|
|
|
29
30
|
name,
|
|
30
31
|
description,
|
|
31
32
|
onClick,
|
|
32
|
-
type
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
type,
|
|
34
|
+
shrink
|
|
35
|
+
}: NavigationEntry & {
|
|
36
|
+
onClick?: () => void,
|
|
37
|
+
shrink?: boolean // <-- add shrink prop type
|
|
35
38
|
}) {
|
|
36
39
|
|
|
37
40
|
const userConfigurationPersistence = useUserConfigurationPersistence();
|
|
@@ -47,6 +50,7 @@ export function NavigationCardBinding({
|
|
|
47
50
|
? [
|
|
48
51
|
<IconButton
|
|
49
52
|
key={"favourite"}
|
|
53
|
+
size={"small"}
|
|
50
54
|
onClick={(e) => {
|
|
51
55
|
e.preventDefault();
|
|
52
56
|
e.stopPropagation();
|
|
@@ -61,7 +65,7 @@ export function NavigationCardBinding({
|
|
|
61
65
|
}
|
|
62
66
|
}}>
|
|
63
67
|
<StarIcon
|
|
64
|
-
size={
|
|
68
|
+
size={"small"}
|
|
65
69
|
className={favourite ? "text-secondary" : "text-surface-400 dark:text-surface-500"}/>
|
|
66
70
|
</IconButton>
|
|
67
71
|
]
|
|
@@ -91,7 +95,7 @@ export function NavigationCardBinding({
|
|
|
91
95
|
if (type === "admin") {
|
|
92
96
|
return <SmallNavigationCard icon={collectionIcon}
|
|
93
97
|
name={name}
|
|
94
|
-
url={url}
|
|
98
|
+
url={url}/>;
|
|
95
99
|
}
|
|
96
100
|
|
|
97
101
|
return <NavigationCard
|
|
@@ -107,5 +111,7 @@ export function NavigationCardBinding({
|
|
|
107
111
|
[path, ...(userConfigurationPersistence.recentlyVisitedPaths ?? []).filter(p => p !== path)]
|
|
108
112
|
);
|
|
109
113
|
}
|
|
110
|
-
}}
|
|
114
|
+
}}
|
|
115
|
+
shrink={shrink}
|
|
116
|
+
/>;
|
|
111
117
|
}
|
|
@@ -1,39 +1,73 @@
|
|
|
1
|
-
import { PropsWithChildren } from "react";
|
|
2
|
-
import {
|
|
3
|
-
import { ExpandablePanel, Typography } from "@firecms/ui";
|
|
1
|
+
import React, { PropsWithChildren, useState } from "react";
|
|
2
|
+
import { cls, EditIcon, IconButton, Typography } from "@firecms/ui";
|
|
4
3
|
|
|
5
4
|
export function NavigationGroup({
|
|
6
5
|
children,
|
|
7
|
-
group
|
|
6
|
+
group,
|
|
7
|
+
minimised,
|
|
8
|
+
isPreview,
|
|
9
|
+
isPotentialCardDropTarget,
|
|
10
|
+
onEditGroup, // New prop to handle editing
|
|
11
|
+
dndDisabled // New prop to disable editing when D&D is off
|
|
8
12
|
}: PropsWithChildren<{
|
|
9
|
-
group: string | undefined
|
|
13
|
+
group: string | undefined,
|
|
14
|
+
minimised?: boolean,
|
|
15
|
+
isPreview?: boolean,
|
|
16
|
+
isPotentialCardDropTarget?: boolean,
|
|
17
|
+
onEditGroup?: (groupName: string) => void; // Callback to open dialog
|
|
18
|
+
dndDisabled?: boolean; // Added dndDisabled prop
|
|
10
19
|
}>) {
|
|
11
|
-
const userConfigurationPersistence = useUserConfigurationPersistence();
|
|
12
|
-
return (
|
|
13
|
-
<ExpandablePanel
|
|
14
|
-
invisible={true}
|
|
15
|
-
titleClassName={"font-medium text-sm text-surface-600 dark:text-surface-400"}
|
|
16
|
-
innerClassName={"py-4"}
|
|
17
|
-
initiallyExpanded={!(userConfigurationPersistence?.collapsedGroups ?? []).includes(group ?? "ungrouped")}
|
|
18
|
-
onExpandedChange={expanded => {
|
|
19
|
-
if (userConfigurationPersistence) {
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
{group?.toUpperCase() ?? "Views".toUpperCase()}
|
|
32
|
-
</Typography>}>
|
|
21
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
22
|
+
const currentGroupName = group ?? "Views";
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<div className={cls(
|
|
26
|
+
!isPotentialCardDropTarget ? "my-10" : "my-6",
|
|
27
|
+
"transition-all duration-200 ease-in-out"
|
|
28
|
+
)}
|
|
29
|
+
>
|
|
30
|
+
<div className={`flex items-center ${isPreview ? "px-1 py-0.5 m-0" : "ml-3.5 mt-6"} `}
|
|
33
31
|
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
onMouseEnter={() => setIsHovered(true)}
|
|
33
|
+
onMouseLeave={() => setIsHovered(false)}>
|
|
34
|
+
<Typography
|
|
35
|
+
variant={isPreview ? "body2" : "caption"}
|
|
36
|
+
component={"h2"}
|
|
37
|
+
color="secondary"
|
|
38
|
+
// Minimal padding and no margin for preview title
|
|
39
|
+
className={`${isPreview ? "px-1 py-0.5" : "ml-3.5"} font-medium uppercase text-sm text-surface-600 dark:text-surface-400`}
|
|
40
|
+
>
|
|
41
|
+
{currentGroupName}
|
|
42
|
+
</Typography>
|
|
43
|
+
{!isPreview && onEditGroup && !dndDisabled && (
|
|
44
|
+
<IconButton
|
|
45
|
+
size="smallest"
|
|
46
|
+
onClick={(e) => {
|
|
47
|
+
e.stopPropagation(); // Prevent other click events
|
|
48
|
+
onEditGroup(currentGroupName);
|
|
49
|
+
}}
|
|
50
|
+
className={cls("ml-2 ", isHovered ? "opacity-100" : "opacity-0", "transition-opacity duration-100")}
|
|
51
|
+
>
|
|
52
|
+
<EditIcon size="smallest"/>
|
|
53
|
+
</IconButton>
|
|
54
|
+
)}
|
|
36
55
|
</div>
|
|
37
|
-
|
|
56
|
+
|
|
57
|
+
{isPreview ? (
|
|
58
|
+
children
|
|
59
|
+
) : minimised ? (
|
|
60
|
+
// For minimised view in the main list
|
|
61
|
+
<div className={cls("mt-4 p-8 bg-surface-accent-200 dark:bg-surface-accent-800 rounded-lg")}
|
|
62
|
+
style={{ minHeight: "50px" }}>
|
|
63
|
+
</div>
|
|
64
|
+
) : (
|
|
65
|
+
// If highlighted, the parent div already has padding, so children (NavigationGroupDroppable) don't need extra margin top as much.
|
|
66
|
+
// The inner content of NavigationGroupDroppable will define its own padding if needed when active.
|
|
67
|
+
<div className={cls("mt-4", !minimised ? "pt-0" : "")}>
|
|
68
|
+
{children}
|
|
69
|
+
</div>
|
|
70
|
+
)}
|
|
71
|
+
</div>
|
|
38
72
|
);
|
|
39
73
|
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import React, { useState, useEffect, useRef } from "react";
|
|
2
|
+
import { Button, Dialog, DialogActions, DialogContent, DialogTitle, TextField } from "@firecms/ui";
|
|
3
|
+
|
|
4
|
+
interface RenameGroupDialogProps {
|
|
5
|
+
open: boolean;
|
|
6
|
+
initialName: string;
|
|
7
|
+
existingGroupNames: string[]; // Names of other existing groups to check for duplicates
|
|
8
|
+
onClose: () => void;
|
|
9
|
+
onRename: (newName: string) => void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function RenameGroupDialog({ open, initialName, existingGroupNames, onClose, onRename }: RenameGroupDialogProps) {
|
|
13
|
+
const [name, setName] = useState(initialName);
|
|
14
|
+
const [error, setError] = useState<string | null>(null);
|
|
15
|
+
const inputRef = useRef<HTMLInputElement | HTMLTextAreaElement | null>(null); // Create a ref for the input
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (open) {
|
|
19
|
+
setName(initialName);
|
|
20
|
+
setError(null);
|
|
21
|
+
// Focus and select text when dialog opens
|
|
22
|
+
setTimeout(() => { // setTimeout to ensure the input is rendered and focusable
|
|
23
|
+
if (inputRef.current) {
|
|
24
|
+
inputRef.current.focus();
|
|
25
|
+
inputRef.current.select();
|
|
26
|
+
}
|
|
27
|
+
}, 100);
|
|
28
|
+
}
|
|
29
|
+
}, [initialName, open]);
|
|
30
|
+
|
|
31
|
+
const handleNameChange = (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
|
32
|
+
const newName = event.target.value;
|
|
33
|
+
setName(newName);
|
|
34
|
+
if (!newName.trim()) {
|
|
35
|
+
setError("Group name cannot be empty.");
|
|
36
|
+
} else if (existingGroupNames.includes(newName.trim())) {
|
|
37
|
+
setError("This group name already exists.");
|
|
38
|
+
} else {
|
|
39
|
+
setError(null);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const handleSave = () => {
|
|
44
|
+
const trimmedName = name.trim();
|
|
45
|
+
if (!trimmedName) {
|
|
46
|
+
setError("Group name cannot be empty.");
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (existingGroupNames.includes(trimmedName)) {
|
|
50
|
+
setError("This group name already exists.");
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (!error) {
|
|
54
|
+
onRename(trimmedName);
|
|
55
|
+
onClose();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
|
60
|
+
if (event.key === "Enter") {
|
|
61
|
+
event.preventDefault(); // Prevent default form submission behavior
|
|
62
|
+
const trimmedName = name.trim();
|
|
63
|
+
// We need to check the error state directly as well,
|
|
64
|
+
// because the error state might not have updated if the user types and immediately hits enter.
|
|
65
|
+
let currentError = null;
|
|
66
|
+
if (!trimmedName) {
|
|
67
|
+
currentError = "Group name cannot be empty.";
|
|
68
|
+
} else if (existingGroupNames.includes(trimmedName)) {
|
|
69
|
+
currentError = "This group name already exists.";
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!currentError && trimmedName) {
|
|
73
|
+
handleSave();
|
|
74
|
+
} else if (currentError) {
|
|
75
|
+
setError(currentError); // Ensure error is displayed if trying to submit with Enter
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const handleClose = () => {
|
|
81
|
+
setName(initialName);
|
|
82
|
+
setError(null);
|
|
83
|
+
onClose();
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
if (!open) return null;
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<Dialog open={open} onOpenChange={onClose}>
|
|
90
|
+
<DialogTitle>Rename Group</DialogTitle>
|
|
91
|
+
<DialogContent>
|
|
92
|
+
<TextField
|
|
93
|
+
inputRef={inputRef} // Pass the ref to the TextField
|
|
94
|
+
label="Group Name"
|
|
95
|
+
value={name}
|
|
96
|
+
onChange={handleNameChange}
|
|
97
|
+
onKeyDown={handleKeyDown} // Added onKeyDown handler
|
|
98
|
+
error={!!error}
|
|
99
|
+
aria-describedby={error ? "group-name-error" : undefined}
|
|
100
|
+
/>
|
|
101
|
+
{error && <p id="group-name-error" style={{ display: "none" }}>{error}</p>}
|
|
102
|
+
</DialogContent>
|
|
103
|
+
<DialogActions>
|
|
104
|
+
<Button onClick={onClose}
|
|
105
|
+
color={"primary"}
|
|
106
|
+
variant="text">
|
|
107
|
+
Cancel
|
|
108
|
+
</Button>
|
|
109
|
+
<Button onClick={handleSave}
|
|
110
|
+
color={"primary"}
|
|
111
|
+
disabled={!!error || !name.trim()}>
|
|
112
|
+
Save
|
|
113
|
+
</Button>
|
|
114
|
+
</DialogActions>
|
|
115
|
+
</Dialog>
|
|
116
|
+
);
|
|
117
|
+
}
|