From 7a1b6de99f485313ae736ef03c6032d5119713ec Mon Sep 17 00:00:00 2001 From: Ruben Thoms Date: Fri, 6 Dec 2024 10:28:35 +0100 Subject: [PATCH] Adjustments to review comments --- .../settings/components/wellboreSelector.tsx | 34 ++--- .../colorLegendsContainer.tsx | 117 +++++++++--------- 2 files changed, 81 insertions(+), 70 deletions(-) diff --git a/frontend/src/modules/3DViewer/settings/components/wellboreSelector.tsx b/frontend/src/modules/3DViewer/settings/components/wellboreSelector.tsx index 454415aae..27d47536d 100644 --- a/frontend/src/modules/3DViewer/settings/components/wellboreSelector.tsx +++ b/frontend/src/modules/3DViewer/settings/components/wellboreSelector.tsx @@ -30,33 +30,29 @@ export function WellboreSelector(props: WellboreSelectorProps): React.ReactNode }); React.useEffect(() => { onSelectedWellboreUuidsChange( - props.wellboreHeaders - .filter((header) => selectedWellborePurposes.includes(header.wellborePurpose)) - .filter((header) => selectedWellboreStatuses.includes(header.wellboreStatus)) - // .filter((header) => props.selectedWellboreUuids.includes(header.wellboreUuid)) - .map((header) => header.wellboreUuid) + filterWellboreHeaders(props.wellboreHeaders, selectedWellboreStatuses, selectedWellborePurposes).map( + (header) => header.wellboreUuid + ) ); }, [selectedWellborePurposes, selectedWellboreStatuses, onSelectedWellboreUuidsChange, props.wellboreHeaders]); function handleSelectAll() { props.onSelectedWellboreUuidsChange( - props.wellboreHeaders - .filter((header) => selectedWellborePurposes.includes(header.wellborePurpose)) - .filter((header) => selectedWellboreStatuses.includes(header.wellboreStatus)) - .map((header) => header.wellboreUuid) + filterWellboreHeaders(props.wellboreHeaders, selectedWellboreStatuses, selectedWellborePurposes).map( + (header) => header.wellboreUuid + ) ); } function handleUnselectAll() { props.onSelectedWellboreUuidsChange([]); } function makeWellHeadersOptions(): SelectOption[] { - return props.wellboreHeaders - .filter((header) => selectedWellboreStatuses.includes(header.wellboreStatus)) - .filter((header) => selectedWellborePurposes.includes(header.wellborePurpose)) - .map((wellHeader) => ({ + return filterWellboreHeaders(props.wellboreHeaders, selectedWellboreStatuses, selectedWellborePurposes).map( + (wellHeader) => ({ label: wellHeader.uniqueWellboreIdentifier, value: wellHeader.wellboreUuid, - })); + }) + ); } return ( @@ -134,3 +130,13 @@ function makeWellboreStatusOptions(wellHeaders: WellboreHeader_api[]): SelectOpt value: status, })); } + +function filterWellboreHeaders( + wellHeaders: WellboreHeader_api[], + selectedWellboreStatuses: string[], + selectedWellborePurposes: string[] +): WellboreHeader_api[] { + return wellHeaders + .filter((header) => selectedWellboreStatuses.includes(header.wellboreStatus)) + .filter((header) => selectedWellborePurposes.includes(header.wellborePurpose)); +} diff --git a/frontend/src/modules/_shared/components/ColorLegendsContainer/colorLegendsContainer.tsx b/frontend/src/modules/_shared/components/ColorLegendsContainer/colorLegendsContainer.tsx index b3273e056..a42525741 100644 --- a/frontend/src/modules/_shared/components/ColorLegendsContainer/colorLegendsContainer.tsx +++ b/frontend/src/modules/_shared/components/ColorLegendsContainer/colorLegendsContainer.tsx @@ -4,7 +4,7 @@ import { ColorScale, ColorScaleGradientType, ColorScaleType } from "@lib/utils/C import { resolveClassNames } from "@lib/utils/resolveClassNames"; import { ColorScaleWithName } from "@modules_shared/utils/ColorScaleWithName"; -const PREFERENCES = { +const STYLE_CONSTANTS = { lineWidth: 6, lineColor: "#555", textGap: 6, @@ -36,7 +36,7 @@ function makeMarkers( ): React.ReactNode[] { const sectionHeight = Math.abs(sectionBottom - sectionTop); - const minMarkerHeight = PREFERENCES.fontSize + 4 * PREFERENCES.textGap; + const minMarkerHeight = STYLE_CONSTANTS.fontSize + 4 * STYLE_CONSTANTS.textGap; const maxNumMarkers = Math.floor(sectionHeight / minMarkerHeight); // Odd number of markers makes sure the midpoint in each section is shown which is preferable @@ -57,16 +57,16 @@ function makeMarkers( key={`${sectionTop}-${i}-marker`} x1={left} y1={globalY + 1} - x2={left + PREFERENCES.lineWidth} + x2={left + STYLE_CONSTANTS.lineWidth} y2={globalY + 1} - stroke={PREFERENCES.lineColor} + stroke={STYLE_CONSTANTS.lineColor} strokeWidth="1" /> ); markers.push( ); markers.push( ); @@ -165,7 +165,7 @@ function ColorLegend(props: ColorLegendProps): React.ReactNode { @@ -175,7 +175,12 @@ function ColorLegend(props: ColorLegendProps): React.ReactNode { if (props.colorScale.getType() === ColorScaleType.Discrete) { markers.push( - makeDiscreteMarkers(props.colorScale, lineMarkerStartPosition, props.top + PREFERENCES.offset, barHeight) + makeDiscreteMarkers( + props.colorScale, + lineMarkerStartPosition, + props.top + STYLE_CONSTANTS.offset, + barHeight + ) ); } else { if (props.colorScale.getGradientType() === ColorScaleGradientType.Diverging) { @@ -187,9 +192,9 @@ function ColorLegend(props: ColorLegendProps): React.ReactNode { markers.push( makeMarkers( props.colorScale, - props.top + PREFERENCES.offset, - props.top + PREFERENCES.offset, - props.top + PREFERENCES.offset + barHeight * relY, + props.top + STYLE_CONSTANTS.offset, + props.top + STYLE_CONSTANTS.offset, + props.top + STYLE_CONSTANTS.offset + barHeight * relY, lineMarkerStartPosition, barHeight ) @@ -199,10 +204,10 @@ function ColorLegend(props: ColorLegendProps): React.ReactNode { ); @@ -212,12 +217,12 @@ function ColorLegend(props: ColorLegendProps): React.ReactNode { x={ props.left + props.barWidth + - PREFERENCES.lineWidth + - PREFERENCES.textGap + - PREFERENCES.nameLabelWidth + - PREFERENCES.textGap + STYLE_CONSTANTS.lineWidth + + STYLE_CONSTANTS.textGap + + STYLE_CONSTANTS.nameLabelWidth + + STYLE_CONSTANTS.textGap } - y={props.top + relY * barHeight + PREFERENCES.offset + 3} + y={props.top + relY * barHeight + STYLE_CONSTANTS.offset + 3} fontSize="10" style={TEXT_STYLE} > @@ -228,9 +233,9 @@ function ColorLegend(props: ColorLegendProps): React.ReactNode { markers.push( makeMarkers( props.colorScale, - props.top + PREFERENCES.offset, - props.top + relY * barHeight + PREFERENCES.offset, - props.top + PREFERENCES.offset + barHeight, + props.top + STYLE_CONSTANTS.offset, + props.top + relY * barHeight + STYLE_CONSTANTS.offset, + props.top + STYLE_CONSTANTS.offset + barHeight, lineMarkerStartPosition, barHeight ) @@ -239,9 +244,9 @@ function ColorLegend(props: ColorLegendProps): React.ReactNode { markers.push( makeMarkers( props.colorScale, - props.top + PREFERENCES.offset, - props.top + PREFERENCES.offset, - props.top + PREFERENCES.offset + barHeight, + props.top + STYLE_CONSTANTS.offset, + props.top + STYLE_CONSTANTS.offset, + props.top + STYLE_CONSTANTS.offset + barHeight, lineMarkerStartPosition, barHeight ) @@ -253,10 +258,10 @@ function ColorLegend(props: ColorLegendProps): React.ReactNode { ); @@ -264,7 +269,7 @@ function ColorLegend(props: ColorLegendProps): React.ReactNode { @@ -277,7 +282,7 @@ function ColorLegend(props: ColorLegendProps): React.ReactNode { @@ -285,7 +290,7 @@ function ColorLegend(props: ColorLegendProps): React.ReactNode { @@ -329,11 +334,11 @@ export function ColorLegendsContainer(props: ColorLegendsContainerProps): React. } const width = Math.max(5, Math.min(10, 120 / props.colorScales.length)); - const minHeight = Math.min(60 + 2 * PREFERENCES.offset, props.height); + const minHeight = Math.min(60 + 2 * STYLE_CONSTANTS.offset, props.height); const numRows = Math.min(Math.floor(props.height / minHeight), props.colorScales.length); const numCols = Math.ceil(props.colorScales.length / numRows); - const height = Math.max(minHeight, props.height / numRows - (numRows - 1) * PREFERENCES.legendGap); + const height = Math.max(minHeight, props.height / numRows - (numRows - 1) * STYLE_CONSTANTS.legendGap); function makeLegends(): React.ReactNode[] { const legends: React.ReactNode[] = []; @@ -344,15 +349,15 @@ export function ColorLegendsContainer(props: ColorLegendsContainerProps): React. break; } const { id, colorScale } = props.colorScales[index++]; - const top = row * (height + 2 * PREFERENCES.offset) + row * PREFERENCES.legendGap; + const top = row * (height + 2 * STYLE_CONSTANTS.offset) + row * STYLE_CONSTANTS.legendGap; const left = col * (width + - PREFERENCES.legendGap + - PREFERENCES.lineWidth + - PREFERENCES.textGap + - PREFERENCES.textWidth + - PREFERENCES.nameLabelWidth); + STYLE_CONSTANTS.legendGap + + STYLE_CONSTANTS.lineWidth + + STYLE_CONSTANTS.textGap + + STYLE_CONSTANTS.textWidth + + STYLE_CONSTANTS.nameLabelWidth); legends.push(