Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
braddf committed Aug 5, 2024
2 parents 964d8b2 + c2e5933 commit 36dab90
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
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");
expect(formatDNORegionName("NPG (Northern Electric)")).toBe("Northern Electric (NPG)");
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,27 @@ 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;

// remove last ')'
const regionNameParts = regionName.replace(")", "");

// split by first ' ('
const regionAbbAndName = regionNameParts.split(" (");

if (regionAbbAndName.length > 1) {
// join names back together
regionName = `${regionAbbAndName[1]} (${regionAbbAndName[0]})`;
}

return regionName;
};

export const useAggregateSitesDataForTimestamp = (
combinedSitesData: CombinedSitesData,
selectedISOTime: string
Expand Down Expand Up @@ -108,9 +129,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,
Expand Down

0 comments on commit 36dab90

Please sign in to comment.