Skip to content

Commit c796207

Browse files
committed
Tools.json build file was to be removed
1 parent 3523c89 commit c796207

File tree

4 files changed

+252
-6
lines changed

4 files changed

+252
-6
lines changed

components/tools/ToolsDashboard.tsx

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ import SearchIcon from '../icons/Search';
1212
import CategoryDropdown from './CategoryDropdown';
1313
import Filters from './Filters';
1414
import ToolsList from './ToolsList';
15-
16-
const ToolsData = ToolsDataList as ToolsListData;
17-
15+
import { processToolsData } from '@/utils/processToolsData';
16+
const ToolsData = processToolsData() as ToolsListData;
1817
/**
1918
* @description This component displays Tools Dashboard.
2019
*/
@@ -60,7 +59,7 @@ export default function ToolsDashboard() {
6059
});
6160

6261
// useMemo function to filter the tools according to the filters applied by the user
63-
const toolsList = useMemo(() => {
62+
const toolsList = useMemo<ToolsListData>(() => {
6463
let tempToolsList: ToolsListData = {};
6564

6665
// Tools data list is first filtered according to the category filter if applied by the user.

config/tools.json

+1-1
Large diffs are not rendered by default.

pages/casestudies/[id].tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const renderContent = (
4242
allComponents: Record<string, React.ComponentType<any>>,
4343
level: number
4444
): JSX.Element[] => {
45-
let typeStyle;
45+
let typeStyle:HeadingTypeStyle;
4646

4747
if (level === 0) {
4848
typeStyle = HeadingTypeStyle.lg;

utils/processToolsData.ts

+247
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,247 @@
1+
import allTags from '../config/all-tags.json';
2+
3+
import automatedTools from '../config/tools-automated.json';
4+
5+
import manualTools from '../config/tools-manual.json';
6+
7+
import type { ToolData, ToolsListData } from '../types/components/tools/ToolDataType';
8+
9+
10+
11+
12+
// Caching the processed results to avoid unnecessary reprocessing of the data
13+
14+
let cachedToolsData: ToolsListData | null = null;
15+
16+
17+
18+
19+
//Interface for tool object data
20+
21+
interface RawToolData {
22+
23+
title: string;
24+
25+
description: string | null;
26+
27+
links: any;
28+
29+
filters: {
30+
31+
categories?: string[];
32+
33+
hasCommercial: boolean;
34+
35+
isAsyncAPIOwner: boolean;
36+
37+
language?: string;
38+
39+
technology?: string[];
40+
41+
};
42+
43+
}
44+
45+
46+
47+
48+
export const processToolsData = (): ToolsListData => {
49+
50+
// Returning the cached data if available in the memory
51+
52+
if (cachedToolsData) return cachedToolsData;
53+
54+
55+
56+
57+
// Creating a tag color lookup mapping from the allTags data
58+
59+
const tagColorMap: Record<string, { color: string; borderColor: string }> = {};
60+
61+
62+
63+
64+
// Processing allTags to build the color map from the allTags data
65+
66+
if (Array.isArray(allTags)) {
67+
68+
allTags.forEach((tag: any) => {
69+
70+
tagColorMap[tag.name] = {
71+
72+
color: tag.color,
73+
74+
borderColor: tag.borderColor
75+
76+
};
77+
78+
});
79+
80+
} else if (allTags.languages && allTags.technologies) {
81+
82+
// Handling the structure with separate languages and technologies arrays for each language and technology array separately in allTags
83+
84+
allTags.languages.forEach((tag: any) => {
85+
86+
tagColorMap[tag.name] = {
87+
88+
color: tag.color,
89+
90+
borderColor: tag.borderColor
91+
92+
};
93+
94+
});
95+
96+
97+
98+
99+
allTags.technologies.forEach((tag: any) => {
100+
101+
tagColorMap[tag.name] = {
102+
103+
color: tag.color,
104+
105+
borderColor: tag.borderColor
106+
107+
};
108+
109+
});
110+
111+
}
112+
113+
114+
115+
116+
// Initializing the result object to store the processed tools data in the required format
117+
118+
const result: ToolsListData = {};
119+
120+
121+
122+
123+
// Helper function to process a tool object and return the processed tool object
124+
125+
const processTool = (tool: RawToolData): ToolData => {
126+
127+
// Processing technology tags with color information if available in the tool data and convert null descriptions to undefined
128+
129+
const processedTechnology = Array.isArray(tool.filters?.technology)
130+
131+
? tool.filters.technology.map((tech: string) => ({
132+
133+
name: tech,
134+
135+
color: tagColorMap[tech]?.color || '#cccccc',
136+
137+
borderColor: tagColorMap[tech]?.borderColor || '#999999'
138+
139+
}))
140+
141+
: [];
142+
143+
144+
145+
146+
// Processing language tags with color information if available in the tool data and convert null descriptions to undefined
147+
148+
const processedLanguage = tool.filters?.language
149+
150+
? [
151+
152+
{
153+
154+
name: tool.filters.language,
155+
156+
color: tagColorMap[tool.filters.language]?.color || '#cccccc',
157+
158+
borderColor: tagColorMap[tool.filters.language]?.borderColor || '#999999'
159+
160+
}
161+
162+
]
163+
164+
: undefined;
165+
166+
167+
168+
169+
// Returning the processed tool object with null descriptions converted to undefined values
170+
171+
return {
172+
173+
title: tool.title,
174+
175+
description: tool.description === null ? undefined : tool.description,
176+
177+
links: tool.links,
178+
179+
filters: {
180+
181+
categories: tool.filters.categories || [],
182+
183+
hasCommercial: tool.filters.hasCommercial,
184+
185+
isAsyncAPIOwner: tool.filters.isAsyncAPIOwner,
186+
187+
language: processedLanguage,
188+
189+
technology: processedTechnology
190+
191+
}
192+
193+
};
194+
195+
};
196+
197+
198+
199+
200+
// Processing tools from both sources and adding them to the result object
201+
202+
[automatedTools, manualTools].forEach((source: any) => {
203+
204+
Object.entries(source).forEach(([category, data]: [string, any]) => {
205+
206+
if (!result[category]) {
207+
208+
result[category] = {
209+
210+
description: data.description,
211+
212+
toolsList: []
213+
214+
};
215+
216+
}
217+
218+
219+
220+
221+
if (Array.isArray(data.toolsList)) {
222+
223+
data.toolsList.forEach((tool: any) => {
224+
225+
result[category].toolsList.push(processTool(tool));
226+
227+
});
228+
229+
}
230+
231+
});
232+
233+
});
234+
235+
236+
237+
238+
// Caching and return the result data from the result object
239+
240+
cachedToolsData = result;
241+
242+
243+
244+
245+
return result;
246+
247+
};

0 commit comments

Comments
 (0)