Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default meter select #1348

Merged
merged 3 commits into from
Oct 6, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 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, dispatch]);
huss marked this conversation as resolved.
Show resolved Hide resolved

// When a Pill Badge is clicked update threeD state to indicate new meter or group to render.
const handlePillClick = (pillData: MeterOrGroupPill) => dispatch(
updateThreeDMeterOrGroupInfo({
Expand All @@ -48,6 +62,7 @@ export default function ThreeDPillComponent() {
})
);

huss marked this conversation as resolved.
Show resolved Hide resolved

// Method Generates Reactstrap Pill Badges for selected meters or groups
const populatePills = (meterOrGroupPillData: MeterOrGroupPill[]) => {
return meterOrGroupPillData.map(pillData => {
Expand Down
Loading