Skip to content

Commit

Permalink
Merge pull request #1348 from oss-slu/defaultMeterSelect
Browse files Browse the repository at this point in the history
Default meter select
  • Loading branch information
huss authored Oct 6, 2024
2 parents 9128b6d + ac7c528 commit c17b2fe
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/client/app/components/ThreeDPillComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import * as React from 'react';
import { useEffect } from 'react';
import { Badge } from 'reactstrap';
import { selectGraphState, selectThreeDState, updateThreeDMeterOrGroupInfo } from '../redux/slices/graphSlice';
import { selectGroupDataById } from '../redux/api/groupsApi';
Expand Down Expand Up @@ -40,6 +41,19 @@ export default function ThreeDPillComponent() {
return { meterOrGroupID: groupID, isDisabled: isDisabled, meterOrGroup: MeterOrGroup.groups } as MeterOrGroupPill;
});

// when there is only one choice, it must be selected as a default (there is no other option)
useEffect(() => {
const combinedPillData = [...meterPillData, ...groupPillData];

if (combinedPillData.length === 1) {
const singlePill = combinedPillData[0];
dispatch(updateThreeDMeterOrGroupInfo({
meterOrGroupID: singlePill.meterOrGroupID,
meterOrGroup: singlePill.meterOrGroup
}));
}
}, [meterPillData, groupPillData]);

// When a Pill Badge is clicked update threeD state to indicate new meter or group to render.
const handlePillClick = (pillData: MeterOrGroupPill) => dispatch(
updateThreeDMeterOrGroupInfo({
Expand Down

0 comments on commit c17b2fe

Please sign in to comment.