Skip to content

Commit 3c8965f

Browse files
Suppress debug info when not enabled
1 parent 51b8464 commit 3c8965f

3 files changed

Lines changed: 59 additions & 36 deletions

File tree

manage_breast_screening/assets/js/breast-diagram.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,16 @@ export class BreastDiagram extends ConfigurableComponent {
7373
}
7474

7575
this.$imageMap = $imageMaps[0]
76-
this.$imageMap.addEventListener('click', (event) => this.onClick(event))
77-
this.$imageMap.addEventListener('hover', (event) => this.debug(event))
76+
77+
if (!this.$imageMap.config.readOnly) {
78+
this.$imageMap.addEventListener('click', (event) => this.onClick(event))
79+
this.$imageMap.addEventListener('hover', (event) => this.log(event))
80+
}
7881

7982
// Render diagram features
8083
this.read()
8184
this.render()
82-
this.debug()
85+
this.log()
8386
}
8487

8588
/**
@@ -134,9 +137,14 @@ export class BreastDiagram extends ConfigurableComponent {
134137
*
135138
* @param {CustomEvent<ImageMapPayload>} [event] - Image map event
136139
*/
137-
debug(event) {
140+
log(event) {
141+
const { debug } = this.config
138142
const { point, $path } = event?.detail ?? {}
139143

144+
if (!debug) {
145+
return
146+
}
147+
140148
/** @type {Element | null} */
141149
this.$debugX = this.$debugX ?? this.$root.querySelector('.app-js-image-x')
142150

@@ -152,7 +160,14 @@ export class BreastDiagram extends ConfigurableComponent {
152160
this.$debugInput ?? this.$root.querySelector('.app-js-image-input')
153161

154162
const { $debugX, $debugY, $debugRegion, $debugInput } = this
155-
if (!$debugX || !$debugY || !$debugRegion || !$debugInput) {
163+
if (!$debugInput) {
164+
return
165+
}
166+
167+
$debugInput.textContent =
168+
this.values.map(({ id }) => id).join(', ') || 'N/A'
169+
170+
if (!$debugX || !$debugY || !$debugRegion) {
156171
return
157172
}
158173

@@ -161,9 +176,6 @@ export class BreastDiagram extends ConfigurableComponent {
161176

162177
$debugRegion.textContent =
163178
$path?.querySelector('title')?.textContent ?? 'N/A'
164-
165-
$debugInput.textContent =
166-
this.values.map(({ id }) => id).join(', ') || 'N/A'
167179
}
168180

169181
/**
@@ -184,7 +196,7 @@ export class BreastDiagram extends ConfigurableComponent {
184196
y: point.y
185197
})
186198

187-
this.debug(event)
199+
this.log(event)
188200
}
189201

190202
/**
@@ -222,7 +234,7 @@ export class BreastDiagram extends ConfigurableComponent {
222234

223235
this.render()
224236
this.write()
225-
this.debug()
237+
this.log()
226238
}
227239

228240
/**

manage_breast_screening/assets/js/breast-diagram.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ jest.mock('./image-map', () => {
77
return {
88
ImageMap: class MockImageMap extends Component {
99
addEventListener() {}
10+
config = { readOnly: false }
1011
static moduleName = 'app-image-map'
1112
}
1213
}

manage_breast_screening/assets/sass/components/_breast-diagram.scss

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,50 @@ $state-active: nhsuk-tint(nhsuk-colour("blue"), 50%);
2525

2626
.app-breast-diagram__svg {
2727
display: block;
28-
pointer-events: all;
29-
cursor: crosshair;
3028
}
3129

32-
input[readonly] ~ .app-breast-diagram__image-map .app-breast-diagram__svg {
33-
pointer-events: auto;
34-
cursor: default;
30+
.app-breast-diagram__regions [data-active] {
31+
[data-debug] & {
32+
fill: $state-active;
33+
}
3534
}
3635

37-
.app-breast-diagram__regions path,
38-
.app-breast-diagram__regions polygon {
39-
// Slow fade out (default)
40-
transition: fill 0.3s ease-in;
41-
}
36+
.app-breast-diagram__image-map:not([data-read-only]) {
37+
.app-breast-diagram__svg {
38+
pointer-events: all;
39+
cursor: crosshair;
40+
}
4241

43-
.app-breast-diagram__regions path:hover,
44-
.app-breast-diagram__regions polygon:hover,
45-
.app-breast-diagram__regions [data-active] {
46-
// Fast fade in (on hover)
47-
transition-duration: 0.05s;
48-
transition-timing-function: ease-out;
49-
}
42+
.app-breast-diagram__regions path,
43+
.app-breast-diagram__regions polygon {
44+
[data-debug] & {
45+
// Slow fade out (default)
46+
transition: fill 0.3s ease-in;
47+
}
48+
}
5049

51-
.app-breast-diagram__regions path:hover,
52-
.app-breast-diagram__regions polygon:hover {
53-
fill: $state-highlight;
54-
}
50+
.app-breast-diagram__regions path:hover,
51+
.app-breast-diagram__regions polygon:hover,
52+
.app-breast-diagram__regions [data-active] {
53+
[data-debug] & {
54+
// Fast fade in (on hover)
55+
transition-duration: 0.05s;
56+
transition-timing-function: ease-out;
57+
}
58+
}
5559

56-
.app-breast-diagram__regions [data-active] {
57-
fill: $state-active;
58-
}
60+
.app-breast-diagram__regions path:hover,
61+
.app-breast-diagram__regions polygon:hover {
62+
[data-debug] & {
63+
fill: $state-highlight;
64+
}
65+
}
5966

60-
.app-breast-diagram__regions [data-active]:hover {
61-
fill: color.adjust(color.mix($state-active, $state-highlight, 75%), $lightness: 10%, $saturation: 25%);
67+
.app-breast-diagram__regions [data-active]:hover {
68+
[data-debug] & {
69+
fill: color.adjust(color.mix($state-active, $state-highlight, 75%), $lightness: 10%, $saturation: 25%);
70+
}
71+
}
6272
}
6373

6474
.app-breast-diagram__diagram {

0 commit comments

Comments
 (0)