Skip to content

Commit

Permalink
Add a group by function as a prop to the ScenarioListOLD - Allowing o…
Browse files Browse the repository at this point in the history
…utside users to specify a special group by function for dates
  • Loading branch information
JacobJsuh committed Jun 7, 2024
1 parent 67b00aa commit a60637a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const ScenarioListOLD = (props: ScenarioListOLDProps) => {
nameField,
timeZone,
statusOverrideFunction,
groupByItemFunction,
} = props;
const [groupedScenarios, setGroupedScenarios] = useState<Dictionary<ScenarioOLD[]>>();
const [selectedId, setSelectedId] = useState(selectedScenarioId);
Expand All @@ -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),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const ScenariosOLD = (props: ScenariosOLDProps) => {
translations,
timeZone,
statusOverrideFunction,
groupByItemFunction,
} = props;

const [dialog, setDialog] = useState<GeneralDialogProps>();
Expand Down Expand Up @@ -419,6 +420,7 @@ const ScenariosOLD = (props: ScenariosOLDProps) => {
status={status}
timeZone={timeZone}
statusOverrideFunction={statusOverrideFunction}
groupByItemFunction={groupByItemFunction}
/>
);
}
Expand Down
5 changes: 5 additions & 0 deletions packages/react-components/src/Scenarios/ScenariosOLD/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a60637a

Please sign in to comment.