From a60637a3e45837cd11f465ee0b6dba8318df16bd Mon Sep 17 00:00:00 2001 From: Jacob Suhr Date: Sat, 8 Jun 2024 08:12:43 +1000 Subject: [PATCH 1/2] Add a group by function as a prop to the ScenarioListOLD - Allowing outside users to specify a special group by function for dates --- .../src/Scenarios/ScenarioListOLD/ScenarioList.tsx | 9 ++++++--- .../src/Scenarios/ScenarioListOLD/types.ts | 4 ++++ .../src/Scenarios/ScenariosOLD/Scenarios.tsx | 2 ++ .../react-components/src/Scenarios/ScenariosOLD/types.ts | 5 +++++ 4 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/react-components/src/Scenarios/ScenarioListOLD/ScenarioList.tsx b/packages/react-components/src/Scenarios/ScenarioListOLD/ScenarioList.tsx index e7513623..9ba7375d 100644 --- a/packages/react-components/src/Scenarios/ScenarioListOLD/ScenarioList.tsx +++ b/packages/react-components/src/Scenarios/ScenarioListOLD/ScenarioList.tsx @@ -25,6 +25,7 @@ const ScenarioListOLD = (props: ScenarioListOLDProps) => { nameField, timeZone, statusOverrideFunction, + groupByItemFunction, } = props; const [groupedScenarios, setGroupedScenarios] = useState>(); const [selectedId, setSelectedId] = useState(selectedScenarioId); @@ -42,9 +43,11 @@ const ScenarioListOLD = (props: ScenarioListOLDProps) => { setGroupedScenarios( showHour || showDate ? groupBy(scenarios, (scenario) => { - return scenario.dateTime && timeZone - ? format(utcToTz(scenario.dateTime, timeZone), 'yyyy-MM-dd') - : format(parseISO(scenario.dateTime), 'yyyy-MM-dd') || ''; + return groupByItemFunction ? + groupByItemFunction(scenario, timeZone) : + scenario.dateTime && timeZone + ? format(utcToTz(scenario.dateTime, timeZone), 'yyyy-MM-dd') + : format(parseISO(scenario.dateTime), 'yyyy-MM-dd') || ''; }) : groupBy(scenarios, (scenario) => scenario.dateTime), ); diff --git a/packages/react-components/src/Scenarios/ScenarioListOLD/types.ts b/packages/react-components/src/Scenarios/ScenarioListOLD/types.ts index d5187ad3..33895bea 100644 --- a/packages/react-components/src/Scenarios/ScenarioListOLD/types.ts +++ b/packages/react-components/src/Scenarios/ScenarioListOLD/types.ts @@ -65,6 +65,10 @@ interface ScenarioListOLDProps { * The function that returns the new status to override */ statusOverrideFunction?: (scenario: Scenario) => StatusOverride; + /** + * The function that returns the item to be used for grouping by: + */ + groupByItemFunction?: (scenario: Scenario, timeZone?: string) => string; } export default ScenarioListOLDProps; diff --git a/packages/react-components/src/Scenarios/ScenariosOLD/Scenarios.tsx b/packages/react-components/src/Scenarios/ScenariosOLD/Scenarios.tsx index c656e72d..6ecffa41 100644 --- a/packages/react-components/src/Scenarios/ScenariosOLD/Scenarios.tsx +++ b/packages/react-components/src/Scenarios/ScenariosOLD/Scenarios.tsx @@ -50,6 +50,7 @@ const ScenariosOLD = (props: ScenariosOLDProps) => { translations, timeZone, statusOverrideFunction, + groupByItemFunction, } = props; const [dialog, setDialog] = useState(); @@ -419,6 +420,7 @@ const ScenariosOLD = (props: ScenariosOLDProps) => { status={status} timeZone={timeZone} statusOverrideFunction={statusOverrideFunction} + groupByItemFunction={groupByItemFunction} /> ); } diff --git a/packages/react-components/src/Scenarios/ScenariosOLD/types.ts b/packages/react-components/src/Scenarios/ScenariosOLD/types.ts index fb40c6e8..9da635af 100644 --- a/packages/react-components/src/Scenarios/ScenariosOLD/types.ts +++ b/packages/react-components/src/Scenarios/ScenariosOLD/types.ts @@ -153,6 +153,11 @@ interface ScenariosOLDProps { * The function that returns the new status to override */ statusOverrideFunction?: (scenario: Scenario) => StatusOverride | {}; + + /** + * The function that returns the item to be used for grouping by: + */ + groupByItemFunction?: (scenario: Scenario, timeZone?: string) => string; } interface dataFilterbyPropertyObj { From 42a76eff437f747c3ff7e8eea49be0b9f6ee30ba Mon Sep 17 00:00:00 2001 From: Jacob Suhr Date: Sat, 8 Jun 2024 08:13:10 +1000 Subject: [PATCH 2/2] Increment minor package version --- packages/react-components/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-components/package.json b/packages/react-components/package.json index 876ef500..f0a62796 100644 --- a/packages/react-components/package.json +++ b/packages/react-components/package.json @@ -1,5 +1,5 @@ { - "version": "0.8.48", + "version": "0.8.49", "license": "MIT", "main": "dist/index.js", "typings": "dist/index.d.ts",