Skip to content

Commit e535b3d

Browse files
committed
Fix workspace initialization on first mount
The workspace list wasn't being loaded on first component mount because lastConfigRef was initialized with config, so on the first useEffect run, lastConnection === currentConnection and initialization was skipped. Added initializedRef flag to ensure workspaces are loaded on first mount, then only re-initialize when the connection string changes. This ensures saved workspaces appear in the UI after page reload while still preserving local edits during the same session.
1 parent fe9dbc8 commit e535b3d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ export default function FileSystemForm({ config, onChange, onValidationChange, p
251251
const [workspaces, setWorkspaces] = useState<WorkspaceRow[]>([]);
252252
const [formatsJson, setFormatsJson] = useState<string>('{}');
253253
const lastConfigRef = useRef<Record<string, unknown>>(config);
254+
const initializedRef = useRef(false);
254255

255256
// Test connection state
256257
const [testing, setTesting] = useState(false);
@@ -353,12 +354,12 @@ export default function FileSystemForm({ config, onChange, onValidationChange, p
353354
setBoxClientId(detectedType === 'box' ? (cpCreds?.clientID || '') : '');
354355
setBoxClientSecret(detectedType === 'box' ? (cpCreds?.clientSecret || '') : '');
355356

356-
// Update workspaces from config only if the connection or fs type changed
357+
// Update workspaces from config on first initialization or when connection changes
357358
// Don't reinitialize if we're just reflecting our own emitChange back
358359
const lastConnection = lastConfigRef.current.connection as string;
359360
const currentConnection = config.connection as string;
360361

361-
if (lastConnection !== currentConnection) {
362+
if (!initializedRef.current || lastConnection !== currentConnection) {
362363
const ws = (config.workspaces as Record<string, WorkspaceConfig>) || {};
363364
setWorkspaces(
364365
Object.entries(ws).map(([name, w]) => ({
@@ -369,6 +370,7 @@ export default function FileSystemForm({ config, onChange, onValidationChange, p
369370
defaultInputFormat: w.defaultInputFormat,
370371
}))
371372
);
373+
initializedRef.current = true;
372374
}
373375

374376
const formats = config.formats || {};

0 commit comments

Comments
 (0)