From dfdbbbaa06fff55b94ec79f2f5f79b610a377523 Mon Sep 17 00:00:00 2001 From: Tero Tikkanen Date: Tue, 29 Oct 2024 22:56:44 +0200 Subject: [PATCH] Layout paths values and params on cards --- components/paths/ActionParameters.tsx | 9 +++- components/paths/CategoryCard.tsx | 76 +++++++++++++++++++-------- components/paths/ParameterWidget.tsx | 34 ++++++++++-- package.json | 1 + yarn.lock | 16 +++++- 5 files changed, 105 insertions(+), 31 deletions(-) diff --git a/components/paths/ActionParameters.tsx b/components/paths/ActionParameters.tsx index b8f59ff0..f0f1af8d 100644 --- a/components/paths/ActionParameters.tsx +++ b/components/paths/ActionParameters.tsx @@ -17,13 +17,18 @@ const Parameters = styled.div` const ActionParameters = (props: { parameters: ParameterInterface[] }) => { const { parameters } = props; + console.log('parameters', parameters); if (!parameters) { return null; } // Separate mandatory on/off parameter with standard id - const actionParameterSwitch = parameters.find( + const actionParameterSwitchParameter = parameters.find( (param) => param.node && param.id === `${param.node.id}.enabled` - ) as (ParameterInterface & { __typename: 'BoolParameterType' }) | null; + ); + const actionParameterSwitch = { + ...actionParameterSwitchParameter, + __typename: 'EnableParameterType', + } as ParameterInterface; const actionOtherParameters = parameters.filter( (param) => param.id !== actionParameterSwitch?.id ); diff --git a/components/paths/CategoryCard.tsx b/components/paths/CategoryCard.tsx index 893b69ed..1b0c6100 100644 --- a/components/paths/CategoryCard.tsx +++ b/components/paths/CategoryCard.tsx @@ -67,6 +67,27 @@ const Identifier = styled.span` color: ${(props) => props.theme.textColor.tertiary}; `; +const Values = styled.div` + display: flex; + flex-wrap: wrap; + gap: 10px 10px; +`; + +const TotalValue = styled.div` + flex: 100% 0 0; +`; + +const SubValue = styled.div` + flex: 45% 1 0; +`; + +const ParametersWrapper = styled.div` + display: flex; + flex-direction: column; + flex: 45% 1 0; + align-items: flex-end; +`; + const PathsContentLoader = (props) => { const theme = useTheme(); return ( @@ -130,6 +151,7 @@ type Emissions = { total: { value: number | null; label: string | null }; indirect: { value: number | null; label: string | null }; direct: { value: number | null; label: string | null }; + goal: { value: number | null; label: string | null }; }; const PathsBasicNodeContent = (props: PathsBasicNodeContentProps) => { @@ -140,6 +162,7 @@ const PathsBasicNodeContent = (props: PathsBasicNodeContentProps) => { total: { value: null, label: null }, indirect: { value: null, label: null }, direct: { value: null, label: null }, + goal: { value: null, label: null }, }); const [unit, setUnit] = useState(null); @@ -155,6 +178,8 @@ const PathsBasicNodeContent = (props: PathsBasicNodeContentProps) => { label: getScopeLabel(nodeMetric, 'indirect'), }, direct: { value: direct, label: getScopeLabel(nodeMetric, 'direct') }, + // TODO: handle having goals + goal: { value: null, label: null }, }); setUnit(nodeMetric.getUnit()); onLoaded(categoryId, indirect + direct); @@ -164,42 +189,38 @@ const PathsBasicNodeContent = (props: PathsBasicNodeContentProps) => { return ( -
+ {emissions.total.value ? ( -
+ -
+ ) : null} {emissions.direct.value ? ( -
+ -
- ) : ( -
- )} + + ) : null} {emissions.indirect.value ? ( -
+ -
- ) : ( -
- )} -
+ + ) : null} + ); }; @@ -227,15 +248,23 @@ const PathsActionNodeContent = (props: PathsActionNodeContentProps) => { return ( - - + + + + + + + + ); }; @@ -270,6 +299,7 @@ const PathsNodeContent = React.memo((props: PathsNodeContentProps) => { return
Error: {error.message}
; // Handle error appropriately } if (data) { + console.log(data); if (data.node.__typename === 'ActionNode') { return ( void; loading: boolean; WidgetWrapper: typeof WidgetWrapper; + hideLabel?: boolean; }; export const BoolWidget = (props: BoolWidgetProps) => { - const { parameter, handleChange, loading, WidgetWrapper } = props; + const { + parameter, + handleChange, + loading, + WidgetWrapper, + hideLabel = false, + } = props; const { id, boolValue, isCustomized, isCustomizable } = parameter; const t = useTranslations(); @@ -219,11 +227,16 @@ export const BoolWidget = (props: BoolWidgetProps) => { } disabled={!isCustomizable || loading} style={{ transform: 'scale(1.5)' }} + data-tooltip-id="my-tooltip" + data-tooltip-content={parameter.description || label} /> - + {!hideLabel && ( + + )} + {hideLabel && } ); }; @@ -285,6 +298,17 @@ const ParameterWidget = (props: ParameterWidgetProps) => { /> ); + case 'EnableParameterType': + return ( + + ); + default: return null; } diff --git a/package.json b/package.json index 4676687c..6e3c6a4c 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,7 @@ "react-select": "^5.4.0", "react-sizeme": "^3.0.2", "react-sparklines": "^1.7.0", + "react-tooltip": "^5.28.0", "reactstrap": "9.2.1", "sass": "^1.51.0", "styled-components": "^6.0.0", diff --git a/yarn.lock b/yarn.lock index 82ceddaf..f30b0181 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10039,7 +10039,7 @@ __metadata: languageName: node linkType: hard -"classnames@npm:^2.2.0, classnames@npm:^2.2.3, classnames@npm:^2.2.6": +"classnames@npm:^2.2.0, classnames@npm:^2.2.3, classnames@npm:^2.2.6, classnames@npm:^2.3.0": version: 2.5.1 resolution: "classnames@npm:2.5.1" checksum: da424a8a6f3a96a2e87d01a432ba19315503294ac7e025f9fece656db6b6a0f7b5003bb1fbb51cbb0d9624d964f1b9bb35a51c73af9b2434c7b292c42231c1e5 @@ -16944,6 +16944,7 @@ __metadata: react-select: ^5.4.0 react-sizeme: ^3.0.2 react-sparklines: ^1.7.0 + react-tooltip: ^5.28.0 reactstrap: 9.2.1 regenerator-runtime: ^0.13.9 sass: ^1.51.0 @@ -20609,6 +20610,19 @@ __metadata: languageName: node linkType: hard +"react-tooltip@npm:^5.28.0": + version: 5.28.0 + resolution: "react-tooltip@npm:5.28.0" + dependencies: + "@floating-ui/dom": ^1.6.1 + classnames: ^2.3.0 + peerDependencies: + react: ">=16.14.0" + react-dom: ">=16.14.0" + checksum: 4d1efae0fbd39ec7f1414bb325582cca2f7541a8d464b61bf3a7c5e119821868aa2d47c28509e7ea3cca844a9655feb56fc466def0edaa8db07ce427146ef3b0 + languageName: node + linkType: hard + "react-transition-group@npm:^4.3.0, react-transition-group@npm:^4.4.2": version: 4.4.5 resolution: "react-transition-group@npm:4.4.5"