Tech Radar Data Utility
The Tech Radar Data utility provides functions for fetching Tech Radar information from the AWS S3 Bucket. It serves as a data provider for the DataContext, enabling the application to access and display technology categorisation and status information throughout the app.
Core Functionality
The utility exports a primary function:
fetchTechRadarJSONFromS3
This function:
- Fetches Tech Radar data from the API endpoint
- Handles environment-specific URLs (development vs production)
- Implements error handling with user feedback
- Returns structured Tech Radar data for consumption by the DataContext
Implementation Details
The function follows a straightforward request pattern:
-
Environment-Specific URL: Determines the correct API endpoint
- Uses
localhost:5001/api/tech-radar/json
in development - Uses
/api/tech-radar/json
in production
- Uses
-
Request Execution: Fetches data from the determined endpoint
- Validates response status
- Returns
null
for unsuccessful responses
-
Response Parsing: Converts the JSON response to a JavaScript object
-
Error Handling: Manages request failures
- Catches and logs network errors
- Displays error toast notification
- Returns
null
to indicate failure
Integration with DataContext
The DataContext uses this utility to:
- Fetch Tech Radar data on initial application load
- Refresh Tech Radar data when requested by the user
- Cache the returned data to minimize redundant API calls
Example usage within DataContext:
const getTechRadarData = useCallback(async (forceRefresh = false) => {
// Check cache first unless forceRefresh is true
if (techRadarData && !forceRefresh) {
return techRadarData;
}
// Check for pending request
if (pendingRequests.techRadar) {
return pendingRequests.techRadar;
}
// Create new request
const request = fetchTechRadarJSONFromS3();
pendingRequests.techRadar = request;
try {
const data = await request;
setTechRadarData(data);
return data;
} finally {
pendingRequests.techRadar = null;
}
}, [techRadarData, pendingRequests]);
Error Handling
The utility implements error handling:
- Catches and logs network errors
- Provides user feedback via toast notifications
- Returns
null
when data is unavailable
Usage in Components
The Tech Radar data is used throughout the application to:
- Build the radar visualisation
- Display technology status in the Statistics view
- Highlight technologies in project listings
- Provide filtering options based on technology status
- Show historical movement of technologies between rings