From 4e2beab35b69938098ca874756f057c7d489bbe3 Mon Sep 17 00:00:00 2001 From: Ludy87 Date: Fri, 26 Sep 2025 08:47:31 +0200 Subject: [PATCH] Refactor array type annotations to use shorthand syntax Replaces verbose Array type annotations with the shorthand T[] across multiple frontend files for consistency and readability. Also includes minor improvements such as using optional chaining, simplifying type casts, and updating dependency versions in package.json. --- frontend/package-lock.json | 38 +++++++++---------- frontend/package.json | 6 +-- frontend/src/components/toast/index.ts | 2 +- .../src/components/tools/SearchResults.tsx | 2 +- frontend/src/components/tools/ToolPicker.tsx | 2 +- .../tools/shared/renderToolButtons.tsx | 6 +-- frontend/src/contexts/ToolWorkflowContext.tsx | 4 +- .../hooks/tools/merge/useMergeOperation.ts | 2 +- .../hooks/tools/shared/useToolOperation.ts | 4 +- frontend/src/hooks/useToolSections.ts | 6 +-- frontend/src/services/http.ts | 4 +- frontend/src/types/automation.ts | 2 +- frontend/src/utils/fuzzySearch.ts | 4 +- frontend/src/utils/toolSearch.ts | 8 ++-- 14 files changed, 45 insertions(+), 45 deletions(-) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index ba290dcd5..9b83a6b11 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -49,17 +49,17 @@ "license-report": "^6.8.0", "pdf-lib": "^1.17.1", "pdfjs-dist": "^5.4.149", - "posthog-js": "^1.268.4", + "posthog-js": "^1.268.5", "react": "^19.1.1", "react-dom": "^19.1.1", - "react-i18next": "^15.7.3", + "react-i18next": "^16.0.0", "react-router-dom": "^7.9.2", "tailwindcss": "^4.1.13", "web-vitals": "^5.1.0" }, "devDependencies": { "@eslint/js": "^9.36.0", - "@iconify-json/material-symbols": "^1.2.38", + "@iconify-json/material-symbols": "^1.2.39", "@iconify/utils": "^3.0.2", "@playwright/test": "^1.55.1", "@testing-library/dom": "^10.4.1", @@ -1653,9 +1653,9 @@ } }, "node_modules/@iconify-json/material-symbols": { - "version": "1.2.38", - "resolved": "https://registry.npmjs.org/@iconify-json/material-symbols/-/material-symbols-1.2.38.tgz", - "integrity": "sha512-I13hrSxRJG3ZwIhBTMXMXxxGAlooqZzivF/TQasvRMBeBFDjGK5+IcCzhEApKZlqiWOK3Sqx2Rf7ihiFS/zNvw==", + "version": "1.2.39", + "resolved": "https://registry.npmjs.org/@iconify-json/material-symbols/-/material-symbols-1.2.39.tgz", + "integrity": "sha512-spjiB1I5jPi6hV5b/QyC4zO8GRYGCbb6/DaHm754NJFqNli6bsYDpN4HYVl67XhU49rYljvJyNc/6lYEf+jokA==", "dev": true, "license": "Apache-2.0", "dependencies": { @@ -4581,9 +4581,9 @@ "license": "MIT" }, "node_modules/baseline-browser-mapping": { - "version": "2.8.6", - "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.8.6.tgz", - "integrity": "sha512-wrH5NNqren/QMtKUEEJf7z86YjfqW/2uw3IL3/xpqZUC95SSVIFXYQeeGjL6FT/X68IROu6RMehZQS5foy2BXw==", + "version": "2.8.7", + "resolved": "https://registry.npmjs.org/baseline-browser-mapping/-/baseline-browser-mapping-2.8.7.tgz", + "integrity": "sha512-bxxN2M3a4d1CRoQC//IqsR5XrLh0IJ8TCv2x6Y9N0nckNz/rTjZB3//GGscZziZOxmjP55rzxg/ze7usFI9FqQ==", "license": "Apache-2.0", "bin": { "baseline-browser-mapping": "dist/cli.js" @@ -5699,9 +5699,9 @@ "license": "MIT" }, "node_modules/electron-to-chromium": { - "version": "1.5.223", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.223.tgz", - "integrity": "sha512-qKm55ic6nbEmagFlTFczML33rF90aU+WtrJ9MdTCThrcvDNdUHN4p6QfVN78U06ZmguqXIyMPyYhw2TrbDUwPQ==", + "version": "1.5.224", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.224.tgz", + "integrity": "sha512-kWAoUu/bwzvnhpdZSIc6KUyvkI1rbRXMT0Eq8pKReyOyaPZcctMli+EgvcN1PAvwVc7Tdo4Fxi2PsLNDU05mdg==", "license": "ISC" }, "node_modules/emoji-regex": { @@ -10042,9 +10042,9 @@ } }, "node_modules/posthog-js": { - "version": "1.268.4", - "resolved": "https://registry.npmjs.org/posthog-js/-/posthog-js-1.268.4.tgz", - "integrity": "sha512-kbE8SeH4Hi6uETEzO4EVANULz1ncw+PXC/SMfDdByf4Qt0a/AKoxjlGCZwHuZuflQmBfTwwQcjHeQxnmIxti1A==", + "version": "1.268.5", + "resolved": "https://registry.npmjs.org/posthog-js/-/posthog-js-1.268.5.tgz", + "integrity": "sha512-IRhFBeCKkl4bapbxmLvWedKUOG7Fh9jJab718qm7ce8j66LWaPiX7mEi/iuoYLYRU3wD6mWFFiWmeXh6prczRg==", "license": "SEE LICENSE IN LICENSE", "dependencies": { "@posthog/core": "1.2.1", @@ -10364,16 +10364,16 @@ } }, "node_modules/react-i18next": { - "version": "15.7.3", - "resolved": "https://registry.npmjs.org/react-i18next/-/react-i18next-15.7.3.tgz", - "integrity": "sha512-AANws4tOE+QSq/IeMF/ncoHlMNZaVLxpa5uUGW1wjike68elVYr0018L9xYoqBr1OFO7G7boDPrbn0HpMCJxTw==", + "version": "16.0.0", + "resolved": "https://registry.npmjs.org/react-i18next/-/react-i18next-16.0.0.tgz", + "integrity": "sha512-JQ+dFfLnFSKJQt7W01lJHWRC0SX7eDPobI+MSTJ3/gP39xH2g33AuTE7iddAfXYHamJdAeMGM0VFboPaD3G68Q==", "license": "MIT", "dependencies": { "@babel/runtime": "^7.27.6", "html-parse-stringify": "^3.0.1" }, "peerDependencies": { - "i18next": ">= 25.4.1", + "i18next": ">= 25.5.2", "react": ">= 16.8.0", "typescript": "^5" }, diff --git a/frontend/package.json b/frontend/package.json index f0822d047..20eb07b0d 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -45,10 +45,10 @@ "license-report": "^6.8.0", "pdf-lib": "^1.17.1", "pdfjs-dist": "^5.4.149", - "posthog-js": "^1.268.4", + "posthog-js": "^1.268.5", "react": "^19.1.1", "react-dom": "^19.1.1", - "react-i18next": "^15.7.3", + "react-i18next": "^16.0.0", "react-router-dom": "^7.9.2", "tailwindcss": "^4.1.13", "web-vitals": "^5.1.0" @@ -99,7 +99,7 @@ }, "devDependencies": { "@eslint/js": "^9.36.0", - "@iconify-json/material-symbols": "^1.2.38", + "@iconify-json/material-symbols": "^1.2.39", "@iconify/utils": "^3.0.2", "@playwright/test": "^1.55.1", "@testing-library/dom": "^10.4.1", diff --git a/frontend/src/components/toast/index.ts b/frontend/src/components/toast/index.ts index d0b1045f2..1279ae46a 100644 --- a/frontend/src/components/toast/index.ts +++ b/frontend/src/components/toast/index.ts @@ -8,7 +8,7 @@ export { useToast, ToastProvider, ToastRenderer }; let _api: ReturnType | null = null; function createImperativeApi() { - const subscribers: Array<(fn: any) => void> = []; + const subscribers: ((fn: any) => void)[] = []; let api: any = null; return { provide(instance: any) { diff --git a/frontend/src/components/tools/SearchResults.tsx b/frontend/src/components/tools/SearchResults.tsx index 5bd6036cc..6a274b1a8 100644 --- a/frontend/src/components/tools/SearchResults.tsx +++ b/frontend/src/components/tools/SearchResults.tsx @@ -9,7 +9,7 @@ import NoToolsFound from './shared/NoToolsFound'; import "./toolPicker/ToolPicker.css"; interface SearchResultsProps { - filteredTools: Array<{ item: [string, ToolRegistryEntry]; matchedText?: string }>; + filteredTools: { item: [string, ToolRegistryEntry]; matchedText?: string }[]; onSelect: (id: string) => void; searchQuery?: string; } diff --git a/frontend/src/components/tools/ToolPicker.tsx b/frontend/src/components/tools/ToolPicker.tsx index 4b0c54536..16f18265c 100644 --- a/frontend/src/components/tools/ToolPicker.tsx +++ b/frontend/src/components/tools/ToolPicker.tsx @@ -10,7 +10,7 @@ import { renderToolButtons } from "./shared/renderToolButtons"; interface ToolPickerProps { selectedToolKey: string | null; onSelect: (id: string) => void; - filteredTools: Array<{ item: [string, ToolRegistryEntry]; matchedText?: string }>; + filteredTools: { item: [string, ToolRegistryEntry]; matchedText?: string }[]; isSearching?: boolean; } diff --git a/frontend/src/components/tools/shared/renderToolButtons.tsx b/frontend/src/components/tools/shared/renderToolButtons.tsx index 0716bf3e8..6ffb58373 100644 --- a/frontend/src/components/tools/shared/renderToolButtons.tsx +++ b/frontend/src/components/tools/shared/renderToolButtons.tsx @@ -13,9 +13,9 @@ export const renderToolButtons = ( subcategory: SubcategoryGroup, selectedToolKey: string | null, onSelect: (id: string) => void, - showSubcategoryHeader: boolean = true, - disableNavigation: boolean = false, - searchResults?: Array<{ item: [string, any]; matchedText?: string }> + showSubcategoryHeader = true, + disableNavigation = false, + searchResults?: { item: [string, any]; matchedText?: string }[] ) => { // Create a map of matched text for quick lookup const matchedTextMap = new Map(); diff --git a/frontend/src/contexts/ToolWorkflowContext.tsx b/frontend/src/contexts/ToolWorkflowContext.tsx index ddca58912..35c98a793 100644 --- a/frontend/src/contexts/ToolWorkflowContext.tsx +++ b/frontend/src/contexts/ToolWorkflowContext.tsx @@ -101,7 +101,7 @@ interface ToolWorkflowContextValue extends ToolWorkflowState { handleReaderToggle: () => void; // Computed values - filteredTools: Array<{ item: [string, ToolRegistryEntry]; matchedText?: string }>; // Filtered by search + filteredTools: { item: [string, ToolRegistryEntry]; matchedText?: string }[]; // Filtered by search isPanelVisible: boolean; } @@ -223,7 +223,7 @@ export function ToolWorkflowProvider({ children }: ToolWorkflowProviderProps) { // Filter tools based on search query with fuzzy matching (name, description, id, synonyms) const filteredTools = useMemo(() => { if (!toolRegistry) return []; - return filterToolRegistryByQuery(toolRegistry as Record, state.searchQuery); + return filterToolRegistryByQuery(toolRegistry, state.searchQuery); }, [toolRegistry, state.searchQuery]); const isPanelVisible = useMemo(() => diff --git a/frontend/src/hooks/tools/merge/useMergeOperation.ts b/frontend/src/hooks/tools/merge/useMergeOperation.ts index a334babb6..687163d8a 100644 --- a/frontend/src/hooks/tools/merge/useMergeOperation.ts +++ b/frontend/src/hooks/tools/merge/useMergeOperation.ts @@ -10,7 +10,7 @@ const buildFormData = (parameters: MergeParameters, files: File[]): FormData => formData.append("fileInput", file); }); // Provide stable client file IDs (align with files order) - const clientIds: string[] = files.map((f: any) => String((f as any).fileId || f.name)); + const clientIds: string[] = files.map((f: any) => String((f).fileId || f.name)); formData.append('clientFileIds', JSON.stringify(clientIds)); formData.append("sortType", "orderProvided"); // Always use orderProvided since UI handles sorting formData.append("removeCertSign", parameters.removeDigitalSignature.toString()); diff --git a/frontend/src/hooks/tools/shared/useToolOperation.ts b/frontend/src/hooks/tools/shared/useToolOperation.ts index 2e9c67bd3..a06adee96 100644 --- a/frontend/src/hooks/tools/shared/useToolOperation.ts +++ b/frontend/src/hooks/tools/shared/useToolOperation.ts @@ -199,7 +199,7 @@ export const useToolOperation = ( // Listen for global error file id events from HTTP interceptor during this run let externalErrorFileIds: string[] = []; const errorListener = (e: Event) => { - const detail = (e as CustomEvent)?.detail as any; + const detail = (e as CustomEvent)?.detail; if (detail?.fileIds) { externalErrorFileIds = Array.isArray(detail.fileIds) ? detail.fileIds : []; } @@ -416,7 +416,7 @@ export const useToolOperation = ( let parsed: any = payload; if (typeof payload === 'string') { try { parsed = JSON.parse(payload); } catch { parsed = payload; } - } else if (payload && typeof (payload as any).text === 'function') { + } else if (payload && typeof (payload).text === 'function') { // Blob or Response-like object from axios when responseType='blob' const text = await (payload as Blob).text(); try { parsed = JSON.parse(text); } catch { parsed = text; } diff --git a/frontend/src/hooks/useToolSections.ts b/frontend/src/hooks/useToolSections.ts index 4a285f32e..cfd0c0538 100644 --- a/frontend/src/hooks/useToolSections.ts +++ b/frontend/src/hooks/useToolSections.ts @@ -24,7 +24,7 @@ export interface ToolSection { }; export function useToolSections( - filteredTools: Array<{ item: [string /* FIX ME: Should be ToolId */, ToolRegistryEntry]; matchedText?: string }>, + filteredTools: { item: [string /* FIX ME: Should be ToolId */, ToolRegistryEntry]; matchedText?: string }[], searchQuery?: string ) { const { t } = useTranslation(); @@ -102,7 +102,7 @@ export function useToolSections( const subMap = {} as SubcategoryIdMap; const seen = new Set(); filteredTools.forEach(({ item: [id, tool] }) => { - const toolId = id as string /* FIX ME: Should be ToolId */; + const toolId = id /* FIX ME: Should be ToolId */; if (seen.has(toolId)) return; seen.add(toolId); const sub = tool.subcategoryId; @@ -113,7 +113,7 @@ export function useToolSections( // If a search query is present, always order subcategories by first occurrence in // the ranked filteredTools list so the top-ranked tools' subcategory appears first. - if (searchQuery && searchQuery.trim()) { + if (searchQuery?.trim()) { const order: SubcategoryId[] = []; filteredTools.forEach(({ item: [_, tool] }) => { const sc = tool.subcategoryId; diff --git a/frontend/src/services/http.ts b/frontend/src/services/http.ts index 20a983525..77aa97c31 100644 --- a/frontend/src/services/http.ts +++ b/frontend/src/services/http.ts @@ -149,7 +149,7 @@ const __INTERCEPTOR_ID__ = apiClient?.interceptors?.response?.use const { title, body } = extractAxiosErrorMessage(error); // Normalize response data ONCE, reuse for both ID extraction and special-toast matching - const raw = (error?.response?.data) as any; + const raw = (error?.response?.data); let normalized: unknown = raw; try { normalized = await normalizeAxiosErrorData(raw); } catch (e) { console.debug('normalizeAxiosErrorData', e); } @@ -170,7 +170,7 @@ const __INTERCEPTOR_ID__ = apiClient?.interceptors?.response?.use const isSpecial = status === 422 || status === 409 || // often actionable conflicts - /Failed files:/.test(body) || + body.includes('Failed files:') || /invalid\/corrupted file\(s\)/i.test(body); if (isSpecial && url) { diff --git a/frontend/src/types/automation.ts b/frontend/src/types/automation.ts index 08a5b0a56..808b158f0 100644 --- a/frontend/src/types/automation.ts +++ b/frontend/src/types/automation.ts @@ -82,4 +82,4 @@ export type JsonValue = | JsonValue[] | { [key: string]: JsonValue }; -export type JsonObject = { [key: string]: JsonValue }; +export type JsonObject = Record; diff --git a/frontend/src/utils/fuzzySearch.ts b/frontend/src/utils/fuzzySearch.ts index e8e8bdf01..c0d2f0742 100644 --- a/frontend/src/utils/fuzzySearch.ts +++ b/frontend/src/utils/fuzzySearch.ts @@ -82,8 +82,8 @@ export function isFuzzyMatch(query: string, target: string, minScore?: number): } // Convenience: rank a list of items by best score across provided getters -export function rankByFuzzy(items: T[], query: string, getters: Array<(item: T) => string>, minScore?: number): Array<{ item: T; score: number; matchedText?: string }>{ - const results: Array<{ item: T; score: number; matchedText?: string }> = []; +export function rankByFuzzy(items: T[], query: string, getters: ((item: T) => string)[], minScore?: number): { item: T; score: number; matchedText?: string }[]{ + const results: { item: T; score: number; matchedText?: string }[] = []; const threshold = typeof minScore === 'number' ? minScore : minScoreForQuery(query); for (const item of items) { let best = 0; diff --git a/frontend/src/utils/toolSearch.ts b/frontend/src/utils/toolSearch.ts index dda5749a8..670dba491 100644 --- a/frontend/src/utils/toolSearch.ts +++ b/frontend/src/utils/toolSearch.ts @@ -18,10 +18,10 @@ export function filterToolRegistryByQuery( const nq = normalizeForSearch(query); const threshold = minScoreForQuery(query); - const exactName: Array<{ id: string; tool: ToolRegistryEntry; pos: number }> = []; - const exactSyn: Array<{ id: string; tool: ToolRegistryEntry; text: string; pos: number }> = []; - const fuzzyName: Array<{ id: string; tool: ToolRegistryEntry; score: number; text: string }> = []; - const fuzzySyn: Array<{ id: string; tool: ToolRegistryEntry; score: number; text: string }> = []; + const exactName: { id: string; tool: ToolRegistryEntry; pos: number }[] = []; + const exactSyn: { id: string; tool: ToolRegistryEntry; text: string; pos: number }[] = []; + const fuzzyName: { id: string; tool: ToolRegistryEntry; score: number; text: string }[] = []; + const fuzzySyn: { id: string; tool: ToolRegistryEntry; score: number; text: string }[] = []; for (const [id, tool] of entries) { const nameNorm = normalizeForSearch(tool.name || '');