diff --git a/apps/nowcasting-app/components/hooks/useAggregateSitesDataForTimestamp.test.tsx b/apps/nowcasting-app/components/hooks/useAggregateSitesDataForTimestamp.test.tsx new file mode 100644 index 00000000..15da02a2 --- /dev/null +++ b/apps/nowcasting-app/components/hooks/useAggregateSitesDataForTimestamp.test.tsx @@ -0,0 +1,11 @@ +import { describe, expect, test } from "@jest/globals"; +import { + formatDNORegionName, +} from "./useAggregateSitesDataForTimestamp"; + +describe("check formatDNORegionName ", () => { + test("Check we are getting the correct respsonse", () => { + expect(formatDNORegionName("UKPN (East)")).toBe("East (UKPN)"); + expect(formatDNORegionName("SSE")).toBe("SSE"); + }); +}); \ No newline at end of file diff --git a/apps/nowcasting-app/components/hooks/useAggregateSitesDataForTimestamp.tsx b/apps/nowcasting-app/components/hooks/useAggregateSitesDataForTimestamp.tsx index 08beacf2..359c03a9 100644 --- a/apps/nowcasting-app/components/hooks/useAggregateSitesDataForTimestamp.tsx +++ b/apps/nowcasting-app/components/hooks/useAggregateSitesDataForTimestamp.tsx @@ -42,6 +42,25 @@ const getPvActualGenerationForSite = ( ); }; +export const formatDNORegionName = (regionName: string) => { + /* The long name is like this "UKPN (East)" or just "SSE". + We want to change this to "East (UKPN)" or just "SSE" */ + + // if regionName is empty then return now + if (!regionName) return regionName; + + const regionNameParts = regionName.split(" "); + if (regionNameParts.length > 1) { + // Strip out the brackets + regionName = `${regionNameParts[1].replace('(','').replace(')','')}`; + + // join names back together + regionName = `${regionName} (${regionNameParts[0]})`; + } + + return regionName; +}; + export const useAggregateSitesDataForTimestamp = ( combinedSitesData: CombinedSitesData, selectedISOTime: string @@ -108,9 +127,12 @@ export const useAggregateSitesDataForTimestamp = ( const regionLatLong = dnoLatLongMap.get(region.dno_id); const regionLat = regionLatLong?.lat || 0; const regionLong = regionLatLong?.long || 0; + + const regionNameFormatted = formatDNORegionName(regionName); + let updatedRegionData = sitesTableData.regions.get(regionId) || { id: regionId, - label: regionName, + label: regionNameFormatted, capacity: 0, actualPV: 0, expectedPV: 0, @@ -205,3 +227,4 @@ export const useAggregateSitesDataForTimestamp = ( return sitesTableData; }, [firstForecastData, selectedISOTime]); }; +