Skip to content

Commit

Permalink
feat: WLV callback to reset component to given props (#1993) (#2047)
Browse files Browse the repository at this point in the history
Co-authored-by: DShamakin <[email protected]>
Co-authored-by: t0oF <[email protected]>
Co-authored-by: Vladimir-Kokin <[email protected]>
  • Loading branch information
4 people authored May 28, 2024
1 parent 603d3a1 commit 18ea7cb
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 7 deletions.
46 changes: 44 additions & 2 deletions typescript/packages/well-log-viewer/src/SyncLogViewer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const wellpick = require("../../../../example-data/wellpicks.json");// eslint-di
import { ToggleButton } from "@mui/material";

import SyncLogViewer, { argTypesSyncLogViewerProp } from "./SyncLogViewer";
import type { WellLogController } from "./components/WellLogView";

const ComponentCode =
'<SyncLogViewer id="SyncLogViewer" \r\n' +
Expand Down Expand Up @@ -156,10 +157,17 @@ const Template = (args) => {
const setInfo = function (info) {
if (infoRef.current) infoRef.current.innerHTML = info;
};

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

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

setControllers((prev) => [...prev, controller]);
},
[controller]
);
Expand All @@ -175,6 +183,13 @@ const Template = (args) => {
},
[controller]
);
const handleClick = function () {
for (const ctrl of controllers) {
if (ctrl) {
ctrl.setControllerDefaultZoom();
}
}
};

return (
<div
Expand All @@ -190,7 +205,12 @@ const Template = (args) => {
/>
</div>
{/* Print info for the first WellLog */}
<div ref={infoRef} style={{ width: "100%", flex: 0 }}></div>
<div style={{ display: "flex", flexDirection: "row" }}>
<div ref={infoRef}></div>
<button onClick={handleClick} style={{ marginLeft: 10 }}>
Reset
</button>
</div>
</div>
);
};
Expand Down Expand Up @@ -472,6 +492,14 @@ const TemplateWithSelection = (args) => {
const [showWell2, setShowWell2] = React.useState(true);
const [showWell3, setShowWell3] = React.useState(true);

const [controllers, setControllers] = React.useState<WellLogController[]>(
[]
); // all WellLogs

const onCreateController = React.useCallback((iWellLog, controller) => {
setControllers((prev) => [...prev, controller]);
}, []);

const filtered: WellLog[] = [];
if (showWell1) {
filtered.push(args.welllogs[0]);
Expand All @@ -482,6 +510,13 @@ const TemplateWithSelection = (args) => {
if (showWell3) {
filtered.push(args.welllogs[2]);
}
const handleClick = function () {
for (const ctrl of controllers) {
if (ctrl) {
ctrl.setControllerDefaultZoom();
}
}
};

const argsWithSelection = {
...args,
Expand Down Expand Up @@ -520,9 +555,16 @@ const TemplateWithSelection = (args) => {
>
Well 3
</ToggleButton>
<button onClick={handleClick} style={{ float: "right" }}>
Reset
</button>
</div>
<div style={{ width: "100%", height: "100%", flex: 1 }}>
<SyncLogViewer id="SyncLogViewer" {...argsWithSelection} />
<SyncLogViewer
id="SyncLogViewer"
{...argsWithSelection}
onCreateController={onCreateController}
/>
</div>
</div>
);
Expand Down
18 changes: 13 additions & 5 deletions typescript/packages/well-log-viewer/src/WellLogViewer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,15 @@ const StoryTemplate = (args) => {
const onContentSelection = React.useCallback(() => {
setInfo(fillInfo(controller));
}, [controller]);
const handleClick = () => {
if (controller) {
controller.setControllerDefaultZoom();
}
};

return (
<div
style={{ height: "92vh", display: "flex", flexDirection: "column" }}
>
<div style={{ width: "100%", height: "100%", flex: 1 }}>
<div>
<div style={{ height: "92vh", width: "100%" }}>
<WellLogViewer
id="WellLogViewer"
{...args}
Expand All @@ -141,7 +144,12 @@ const StoryTemplate = (args) => {
onContentSelection={onContentSelection}
/>
</div>
<div ref={infoRef} style={{ width: "100%", flex: 0 }}></div>
<div style={{ display: "inline-flex" }}>
<div ref={infoRef}></div>
<button onClick={handleClick} style={{ marginLeft: 10 }}>
Reset
</button>
</div>
</div>
);
};
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,10 @@ class WellLogView
setControllerSelection(): void {
if (this.props.selection) this.selectContent(this.props.selection);
}
setControllerDefaultZoom(): void {
if (this.props.domain) this.zoomContentTo(this.props.domain);
else this.zoomContentTo(this.getContentBaseDomain());
}

/**
Display current state of track scrolling
Expand Down

0 comments on commit 18ea7cb

Please sign in to comment.