Skip to content

Commit

Permalink
Merge pull request #369 from DHI/feat/Scenarios-Old-Add-GroupBy-Function
Browse files Browse the repository at this point in the history
feat: Scenarios old add group by function as prop
  • Loading branch information
FranzThomsen1089 authored Jun 12, 2024
2 parents 67b00aa + 42a76ef commit 37aa1c2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/react-components/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.8.48",
"version": "0.8.49",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
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 37aa1c2

Please sign in to comment.