Software indicator: reduce number of API calls
The useSoftwareIndicator hook requests its data in several API calls. For example, it loads the dimensions, attributes and levels in three different requests.
We could try to reduce the number of requests by combining the different endpoints into one. Here are some ideas:
- The dimensions, attributes and levels could be loaded from a single endpoint
/get_software_indicator_data(possibly a better name) that would take the evaluation year as a parameter. The data could be returned nested or flat:- Nested:
type Level = { id: number level: number description: string } type Attribute = { id: number name: string weight: number levels: Level[] // or Record<number, Level> } type Dimension = { id: number name: string year: string description: string attributes: Attribute[] // or Record<number, Attribute> } type SoftwareIndicatorData = Dimension[] // or Record<number, Dimension> - Flat:
type Level = { id: number level: number description: string attribute: number } type Attribute = { id: number name: string weight: number dimension: number } type Dimension = { id: number name: string year: string description: string } type SoftwareIndicatorData = { dimensions: Dimension[] // or Record<...> attributes: Attribute[] // or Record<...> levels: Level[] // or Record<...> }
- Nested:
- The dimension and attributes scores could be loaded in the same request. The calculation of the dimension score already includes the calculation of the attribute scores, so this would also avoid doing the same calculation twice.