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

fix: StrictMode behaviour #2139

Merged
merged 12 commits into from
Jul 11, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const RTCTabsLayout: StoryObj<typeof RTCWellLogViewer> = {
decorators: [tabDecorator],
render: () => (
<React.StrictMode>
<RTCWellLogViewer />,
<RTCWellLogViewer />
</React.StrictMode>
),
};
80 changes: 44 additions & 36 deletions typescript/packages/well-log-viewer/src/SyncLogViewer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const wellpick = require("../../../../example-data/wellpicks.json");// eslint-di
import { ToggleButton } from "@mui/material";

import SyncLogViewer, { argTypesSyncLogViewerProp } from "./SyncLogViewer";
import type WellLogView from "./components/WellLogView";
import type {
WellLogView,
WellLogController,
TrackMouseEvent,
} from "./components/WellLogView";
Expand Down Expand Up @@ -129,7 +129,7 @@ const stories: Meta = {
};
export default stories;

function fillInfo(controller) {
function fillInfo(controller: WellLogController | undefined) {
if (!controller) return "-";
const baseDomain = controller.getContentBaseDomain();
const domain = controller.getContentDomain();
Expand Down Expand Up @@ -158,41 +158,41 @@ function fillInfo(controller) {

const Template = (args) => {
const infoRef = React.useRef();
const setInfo = function (info) {
const setInfo = function (info: string) {
if (infoRef.current) infoRef.current.innerHTML = info;
};

const [controller, setController] =
React.useState<WellLogController | null>(null); // the first WellLog
const [controllers, setControllers] = React.useState<WellLogController[]>(
[]
); // all WellLogs

const onCreateController = React.useCallback(
(iWellLog, controller) => {
if (iWellLog === 0) setController(controller);

(iWellLog: number, controller: WellLogController) => {
setControllers((prev) => [...prev, controller]);
},
[controller]
[]
);
const onDeleteController = React.useCallback(
Vladimir-Kokin marked this conversation as resolved.
Show resolved Hide resolved
(iWellLog: number, controller: WellLogController) => {
setControllers((prev) => prev.filter((c) => c !== controller));
},
[]
);
const onContentRescale = React.useCallback(
(iWellLog) => {
if (iWellLog === 0) setInfo(fillInfo(controller));
(iWellLog: number) => {
if (iWellLog === 0) setInfo(fillInfo(controllers[0]));
},
[controller]
[controllers]
);
const onContentSelection = React.useCallback(
(/*iWellLog*/) => {
/*if(iWellLog===0)*/ setInfo(fillInfo(controller));
/*if(iWellLog===0)*/ setInfo(fillInfo(controllers[0]));
},
[controller]
[controllers]
);
const handleClick = function () {
for (const ctrl of controllers) {
if (ctrl) {
ctrl.setControllerDefaultZoom();
}
if (ctrl) ctrl.setControllerDefaultZoom();
}
};
const [checked, setChecked] = React.useState(false);
Expand All @@ -217,6 +217,7 @@ const Template = (args) => {
id="SyncLogViewer"
{...args}
onCreateController={onCreateController}
onDeleteController={onDeleteController}
onContentRescale={onContentRescale}
onContentSelection={onContentSelection}
onTrackMouseEvent={checked ? onTrackMouseEventCustom : null}
Expand Down Expand Up @@ -427,6 +428,7 @@ import WellLogZoomSlider from "./components/WellLogZoomSlider";
import WellLogScaleSelector from "./components/WellLogScaleSelector";
import WellInfoIcon from "@mui/icons-material/FormatListBulleted"; // WaterDrop ShowChart, SearchSharp
import ArrowDownwardIcon from "@mui/icons-material/ArrowDownward";

const iconStyle = {
fontSize: "18px",
verticalAlign: "middle",
Expand Down Expand Up @@ -514,7 +516,7 @@ CustomLayout.parameters = {

Default.tags = ["no-screenshot-test"];

const TemplateWithSelection = (args) => {
const TemplateWithSelection = (args: { welllogs: WellLog[] }) => {
const [showWell1, setShowWell1] = React.useState(true);
const [showWell2, setShowWell2] = React.useState(true);
const [showWell3, setShowWell3] = React.useState(true);
Expand All @@ -523,25 +525,27 @@ const TemplateWithSelection = (args) => {
[]
); // all WellLogs

const onCreateController = React.useCallback((iWellLog, controller) => {
setControllers((prev) => [...prev, controller]);
}, []);
const onCreateController = React.useCallback(
(iWellLog: number, controller: WellLogController) => {
setControllers((prev) => [...prev, controller]);
},
[]
);
const onDeleteController = React.useCallback(
(iWellLog: number, controller: WellLogController) => {
setControllers((prev) => prev.filter((c) => c !== controller));
},
[]
);

const filtered: WellLog[] = [];
if (showWell1) {
filtered.push(args.welllogs[0]);
}
if (showWell2) {
filtered.push(args.welllogs[1]);
}
if (showWell3) {
filtered.push(args.welllogs[2]);
}
if (showWell1 && args.welllogs[0]) filtered.push(args.welllogs[0]);
if (showWell2 && args.welllogs[1]) filtered.push(args.welllogs[1]);
if (showWell3 && args.welllogs[2]) filtered.push(args.welllogs[2]);

const handleClick = function () {
for (const ctrl of controllers) {
if (ctrl) {
ctrl.setControllerDefaultZoom();
}
if (ctrl) ctrl.setControllerDefaultZoom();
}
};

Expand All @@ -557,26 +561,29 @@ const TemplateWithSelection = (args) => {
<div style={{ flexDirection: "row" }}>
<ToggleButton
value="check"
selected={showWell1}
selected={showWell1 && !!args.welllogs[0]}
onChange={() => {
if (!args.welllogs[1]) alert("No args.welllogs[0]");
setShowWell1(!showWell1);
}}
>
Well 1
</ToggleButton>
<ToggleButton
value="check"
selected={showWell2}
selected={showWell2 && !!args.welllogs[1]}
onChange={() => {
if (!args.welllogs[1]) alert("No args.welllogs[1]");
setShowWell2(!showWell2);
}}
>
Well 2
</ToggleButton>
<ToggleButton
value="check"
selected={showWell3}
selected={showWell3 && !!args.welllogs[2]}
onChange={() => {
if (!args.welllogs[2]) alert("No args.welllogs[2]");
setShowWell3(!showWell3);
}}
>
Expand All @@ -591,6 +598,7 @@ const TemplateWithSelection = (args) => {
id="SyncLogViewer"
{...argsWithSelection}
onCreateController={onCreateController}
onDeleteController={onDeleteController}
/>
</div>
</div>
Expand Down
Loading
Loading