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 [showFolderForm, setShowFolderForm] = useState(false);
|
||||||
const [selectedFolder, setSelectedFolder] = useState<ConfigFolder | null>(null);
|
const [selectedFolder, setSelectedFolder] = useState<ConfigFolder | null>(null);
|
||||||
|
|
||||||
const selectedToolType = toolTypes.find((t) => t.id === selectedToolTypeId) || null;
|
const selectedToolType = (toolTypes || []).find((t) => t.id === selectedToolTypeId) || null;
|
||||||
const toolConfigs = configs.filter((c) => c.tool_type_id === selectedToolTypeId);
|
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 toolFolders = folders || []; // Config folders are global, not per-tool-type in current API
|
||||||
|
|
||||||
const loadData = useCallback(async () => {
|
const loadData = useCallback(async () => {
|
||||||
setStatus("loading");
|
setStatus("loading");
|
||||||
@@ -101,9 +101,9 @@ export const ToolWorkshopPage = () => {
|
|||||||
listToolConfigs(),
|
listToolConfigs(),
|
||||||
listConfigFolders(),
|
listConfigFolders(),
|
||||||
]);
|
]);
|
||||||
setToolTypes(types);
|
setToolTypes(types || []);
|
||||||
setConfigs(cfgs);
|
setConfigs(cfgs || []);
|
||||||
setFolders(fldrs);
|
setFolders(fldrs || []);
|
||||||
setStatus("ready");
|
setStatus("ready");
|
||||||
} catch {
|
} catch {
|
||||||
setStatus("error");
|
setStatus("error");
|
||||||
|
|||||||
Reference in New Issue
Block a user