fix: add defensive null checks to prevent filter crash
- Add fallback to empty arrays for toolTypes, configs, and folders - Handle undefined API responses gracefully - Prevent Cannot read properties of undefined (reading 'filter') error Quality gates: npm run build passed
This commit is contained in:
@@ -89,9 +89,9 @@ export const ToolWorkshopPage = () => {
|
||||
const [showFolderForm, setShowFolderForm] = useState(false);
|
||||
const [selectedFolder, setSelectedFolder] = useState<ConfigFolder | null>(null);
|
||||
|
||||
const selectedToolType = toolTypes.find((t) => t.id === selectedToolTypeId) || null;
|
||||
const toolConfigs = configs.filter((c) => c.tool_type_id === selectedToolTypeId);
|
||||
const toolFolders = folders; // Config folders are global, not per-tool-type in current API
|
||||
const selectedToolType = (toolTypes || []).find((t) => t.id === selectedToolTypeId) || null;
|
||||
const toolConfigs = (configs || []).filter((c) => c.tool_type_id === selectedToolTypeId);
|
||||
const toolFolders = folders || []; // Config folders are global, not per-tool-type in current API
|
||||
|
||||
const loadData = useCallback(async () => {
|
||||
setStatus("loading");
|
||||
@@ -101,9 +101,9 @@ export const ToolWorkshopPage = () => {
|
||||
listToolConfigs(),
|
||||
listConfigFolders(),
|
||||
]);
|
||||
setToolTypes(types);
|
||||
setConfigs(cfgs);
|
||||
setFolders(fldrs);
|
||||
setToolTypes(types || []);
|
||||
setConfigs(cfgs || []);
|
||||
setFolders(fldrs || []);
|
||||
setStatus("ready");
|
||||
} catch {
|
||||
setStatus("error");
|
||||
|
||||
Reference in New Issue
Block a user