@@ -10,8 +10,8 @@ const wellpick = require("../../../../example-data/wellpicks.json");// eslint-di
10
10
import { ToggleButton } from "@mui/material" ;
11
11
12
12
import SyncLogViewer , { argTypesSyncLogViewerProp } from "./SyncLogViewer" ;
13
- import type WellLogView from "./components/WellLogView" ;
14
13
import type {
14
+ WellLogView ,
15
15
WellLogController ,
16
16
TrackMouseEvent ,
17
17
} from "./components/WellLogView" ;
@@ -129,7 +129,7 @@ const stories: Meta = {
129
129
} ;
130
130
export default stories ;
131
131
132
- function fillInfo ( controller ) {
132
+ function fillInfo ( controller : WellLogController | undefined ) {
133
133
if ( ! controller ) return "-" ;
134
134
const baseDomain = controller . getContentBaseDomain ( ) ;
135
135
const domain = controller . getContentDomain ( ) ;
@@ -158,41 +158,41 @@ function fillInfo(controller) {
158
158
159
159
const Template = ( args ) => {
160
160
const infoRef = React . useRef ( ) ;
161
- const setInfo = function ( info ) {
161
+ const setInfo = function ( info : string ) {
162
162
if ( infoRef . current ) infoRef . current . innerHTML = info ;
163
163
} ;
164
164
165
- const [ controller , setController ] =
166
- React . useState < WellLogController | null > ( null ) ; // the first WellLog
167
165
const [ controllers , setControllers ] = React . useState < WellLogController [ ] > (
168
166
[ ]
169
167
) ; // all WellLogs
170
168
171
169
const onCreateController = React . useCallback (
172
- ( iWellLog , controller ) => {
173
- if ( iWellLog === 0 ) setController ( controller ) ;
174
-
170
+ ( iWellLog : number , controller : WellLogController ) => {
175
171
setControllers ( ( prev ) => [ ...prev , controller ] ) ;
176
172
} ,
177
- [ controller ]
173
+ [ ]
174
+ ) ;
175
+ const onDeleteController = React . useCallback (
176
+ ( iWellLog : number , controller : WellLogController ) => {
177
+ setControllers ( ( prev ) => prev . filter ( ( c ) => c !== controller ) ) ;
178
+ } ,
179
+ [ ]
178
180
) ;
179
181
const onContentRescale = React . useCallback (
180
- ( iWellLog ) => {
181
- if ( iWellLog === 0 ) setInfo ( fillInfo ( controller ) ) ;
182
+ ( iWellLog : number ) => {
183
+ if ( iWellLog === 0 ) setInfo ( fillInfo ( controllers [ 0 ] ) ) ;
182
184
} ,
183
- [ controller ]
185
+ [ controllers ]
184
186
) ;
185
187
const onContentSelection = React . useCallback (
186
188
( /*iWellLog*/ ) => {
187
- /*if(iWellLog===0)*/ setInfo ( fillInfo ( controller ) ) ;
189
+ /*if(iWellLog===0)*/ setInfo ( fillInfo ( controllers [ 0 ] ) ) ;
188
190
} ,
189
- [ controller ]
191
+ [ controllers ]
190
192
) ;
191
193
const handleClick = function ( ) {
192
194
for ( const ctrl of controllers ) {
193
- if ( ctrl ) {
194
- ctrl . setControllerDefaultZoom ( ) ;
195
- }
195
+ if ( ctrl ) ctrl . setControllerDefaultZoom ( ) ;
196
196
}
197
197
} ;
198
198
const [ checked , setChecked ] = React . useState ( false ) ;
@@ -217,6 +217,7 @@ const Template = (args) => {
217
217
id = "SyncLogViewer"
218
218
{ ...args }
219
219
onCreateController = { onCreateController }
220
+ onDeleteController = { onDeleteController }
220
221
onContentRescale = { onContentRescale }
221
222
onContentSelection = { onContentSelection }
222
223
onTrackMouseEvent = { checked ? onTrackMouseEventCustom : null }
@@ -427,6 +428,7 @@ import WellLogZoomSlider from "./components/WellLogZoomSlider";
427
428
import WellLogScaleSelector from "./components/WellLogScaleSelector" ;
428
429
import WellInfoIcon from "@mui/icons-material/FormatListBulleted" ; // WaterDrop ShowChart, SearchSharp
429
430
import ArrowDownwardIcon from "@mui/icons-material/ArrowDownward" ;
431
+
430
432
const iconStyle = {
431
433
fontSize : "18px" ,
432
434
verticalAlign : "middle" ,
@@ -514,7 +516,7 @@ CustomLayout.parameters = {
514
516
515
517
Default . tags = [ "no-screenshot-test" ] ;
516
518
517
- const TemplateWithSelection = ( args ) => {
519
+ const TemplateWithSelection = ( args : { welllogs : WellLog [ ] } ) => {
518
520
const [ showWell1 , setShowWell1 ] = React . useState ( true ) ;
519
521
const [ showWell2 , setShowWell2 ] = React . useState ( true ) ;
520
522
const [ showWell3 , setShowWell3 ] = React . useState ( true ) ;
@@ -523,25 +525,27 @@ const TemplateWithSelection = (args) => {
523
525
[ ]
524
526
) ; // all WellLogs
525
527
526
- const onCreateController = React . useCallback ( ( iWellLog , controller ) => {
527
- setControllers ( ( prev ) => [ ...prev , controller ] ) ;
528
- } , [ ] ) ;
528
+ const onCreateController = React . useCallback (
529
+ ( iWellLog : number , controller : WellLogController ) => {
530
+ setControllers ( ( prev ) => [ ...prev , controller ] ) ;
531
+ } ,
532
+ [ ]
533
+ ) ;
534
+ const onDeleteController = React . useCallback (
535
+ ( iWellLog : number , controller : WellLogController ) => {
536
+ setControllers ( ( prev ) => prev . filter ( ( c ) => c !== controller ) ) ;
537
+ } ,
538
+ [ ]
539
+ ) ;
529
540
530
541
const filtered : WellLog [ ] = [ ] ;
531
- if ( showWell1 ) {
532
- filtered . push ( args . welllogs [ 0 ] ) ;
533
- }
534
- if ( showWell2 ) {
535
- filtered . push ( args . welllogs [ 1 ] ) ;
536
- }
537
- if ( showWell3 ) {
538
- filtered . push ( args . welllogs [ 2 ] ) ;
539
- }
542
+ if ( showWell1 && args . welllogs [ 0 ] ) filtered . push ( args . welllogs [ 0 ] ) ;
543
+ if ( showWell2 && args . welllogs [ 1 ] ) filtered . push ( args . welllogs [ 1 ] ) ;
544
+ if ( showWell3 && args . welllogs [ 2 ] ) filtered . push ( args . welllogs [ 2 ] ) ;
545
+
540
546
const handleClick = function ( ) {
541
547
for ( const ctrl of controllers ) {
542
- if ( ctrl ) {
543
- ctrl . setControllerDefaultZoom ( ) ;
544
- }
548
+ if ( ctrl ) ctrl . setControllerDefaultZoom ( ) ;
545
549
}
546
550
} ;
547
551
@@ -557,26 +561,29 @@ const TemplateWithSelection = (args) => {
557
561
< div style = { { flexDirection : "row" } } >
558
562
< ToggleButton
559
563
value = "check"
560
- selected = { showWell1 }
564
+ selected = { showWell1 && ! ! args . welllogs [ 0 ] }
561
565
onChange = { ( ) => {
566
+ if ( ! args . welllogs [ 1 ] ) alert ( "No args.welllogs[0]" ) ;
562
567
setShowWell1 ( ! showWell1 ) ;
563
568
} }
564
569
>
565
570
Well 1
566
571
</ ToggleButton >
567
572
< ToggleButton
568
573
value = "check"
569
- selected = { showWell2 }
574
+ selected = { showWell2 && ! ! args . welllogs [ 1 ] }
570
575
onChange = { ( ) => {
576
+ if ( ! args . welllogs [ 1 ] ) alert ( "No args.welllogs[1]" ) ;
571
577
setShowWell2 ( ! showWell2 ) ;
572
578
} }
573
579
>
574
580
Well 2
575
581
</ ToggleButton >
576
582
< ToggleButton
577
583
value = "check"
578
- selected = { showWell3 }
584
+ selected = { showWell3 && ! ! args . welllogs [ 2 ] }
579
585
onChange = { ( ) => {
586
+ if ( ! args . welllogs [ 2 ] ) alert ( "No args.welllogs[2]" ) ;
580
587
setShowWell3 ( ! showWell3 ) ;
581
588
} }
582
589
>
@@ -591,6 +598,7 @@ const TemplateWithSelection = (args) => {
591
598
id = "SyncLogViewer"
592
599
{ ...argsWithSelection }
593
600
onCreateController = { onCreateController }
601
+ onDeleteController = { onDeleteController }
594
602
/>
595
603
</ div >
596
604
</ div >
0 commit comments