Skip to content

Commit fe9dbc8

Browse files
committed
Add validation for duplicate workspace names
Prevent users from creating workspaces with duplicate names in the same plugin. When duplicate names are detected: - Display an error alert showing which names are duplicated - Disable the Save button until duplicates are resolved - Update validation in real-time as user types Added getDuplicateWorkspaceNames helper function to detect duplicates, and integrated it into the validation logic.
1 parent 0048957 commit fe9dbc8

File tree

1 file changed

+32
-5
lines changed

1 file changed

+32
-5
lines changed

exec/java-exec/src/main/resources/webapp/src/components/datasource/FileSystemForm.tsx

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -941,22 +941,40 @@ export default function FileSystemForm({ config, onChange, onValidationChange, p
941941
return ws.filter(w => w.name && w.name.trim()).length > 0;
942942
}, []);
943943

944+
const getDuplicateWorkspaceNames = useCallback((ws: WorkspaceRow[]): string[] => {
945+
const names = ws
946+
.map(w => w.name.trim())
947+
.filter(name => name); // Filter out empty names
948+
const seen = new Set<string>();
949+
const duplicates = new Set<string>();
950+
for (const name of names) {
951+
if (seen.has(name)) {
952+
duplicates.add(name);
953+
}
954+
seen.add(name);
955+
}
956+
return Array.from(duplicates);
957+
}, []);
958+
944959
const handleWorkspaceChange = useCallback(
945960
(newWorkspaces: WorkspaceRow[]) => {
946961
setWorkspaces(newWorkspaces);
947962
// Classpath plugin doesn't support workspaces, so it's always valid
948-
const isValid = fsType === 'classpath' || hasValidWorkspaces(newWorkspaces);
963+
// For other plugins, check that we have valid workspaces and no duplicates
964+
const hasDuplicates = getDuplicateWorkspaceNames(newWorkspaces).length > 0;
965+
const isValid = fsType === 'classpath' || (hasValidWorkspaces(newWorkspaces) && !hasDuplicates);
949966
onValidationChange?.(isValid);
950967
emitChange(connection, authMode, newWorkspaces, formatsJson);
951968
},
952-
[fsType, connection, authMode, formatsJson, emitChange, onValidationChange, hasValidWorkspaces]
969+
[fsType, connection, authMode, formatsJson, emitChange, onValidationChange, hasValidWorkspaces, getDuplicateWorkspaceNames]
953970
);
954971

955972
// Update validation when fsType changes (e.g., switching to/from classpath)
956973
useEffect(() => {
957-
const isValid = fsType === 'classpath' || hasValidWorkspaces(workspaces);
974+
const hasDuplicates = getDuplicateWorkspaceNames(workspaces).length > 0;
975+
const isValid = fsType === 'classpath' || (hasValidWorkspaces(workspaces) && !hasDuplicates);
958976
onValidationChange?.(isValid);
959-
}, [fsType, workspaces, hasValidWorkspaces, onValidationChange]);
977+
}, [fsType, workspaces, hasValidWorkspaces, getDuplicateWorkspaceNames, onValidationChange]);
960978

961979
const addWorkspace = useCallback(() => {
962980
const newWorkspace = { key: `ws_${Date.now()}`, name: '', location: '/', writable: false };
@@ -1592,7 +1610,16 @@ export default function FileSystemForm({ config, onChange, onValidationChange, p
15921610
size="small"
15931611
rowKey="key"
15941612
/>
1595-
{!hasValidWorkspaces(workspaces) && (
1613+
{getDuplicateWorkspaceNames(workspaces).length > 0 && (
1614+
<Alert
1615+
type="error"
1616+
showIcon
1617+
message="Duplicate workspace names"
1618+
description={`Workspace names must be unique. Duplicates found: ${getDuplicateWorkspaceNames(workspaces).join(', ')}`}
1619+
style={{ marginTop: 16 }}
1620+
/>
1621+
)}
1622+
{!hasValidWorkspaces(workspaces) && getDuplicateWorkspaceNames(workspaces).length === 0 && (
15961623
<Alert
15971624
type="warning"
15981625
showIcon

0 commit comments

Comments
 (0)