Skip to content

Commit

Permalink
[Overlay] add suppression option to overlay dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
johnriedel committed Jan 16, 2025
1 parent 5be103e commit baae9c2
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 19 deletions.
10 changes: 10 additions & 0 deletions src/api/overlays/Overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class Overlay extends EventEmitter {
element,
onDestroy,
onDismiss,
showSuppressOption = false,
suppressionKey = null,
suppressionText = "Don't ask again",
size
} = {}) {
super();
Expand All @@ -29,6 +32,10 @@ class Overlay extends EventEmitter {
this.autoHide = autoHide;
this.dismissible = dismissible !== false;

if (showSuppressOption && !suppressionKey) {
throw "A 'suppressionKey' parameter is required when showSuppressOption is set to TRUE in an overlay dialog.";

Check warning on line 36 in src/api/overlays/Overlay.js

View check run for this annotation

Codecov / codecov/patch

src/api/overlays/Overlay.js#L36

Added line #L36 was not covered by tests
}

const { destroy } = mount(
{
components: {
Expand All @@ -38,6 +45,9 @@ class Overlay extends EventEmitter {
dismiss: this.notifyAndDismiss.bind(this),
element,
buttons,
showSuppressOption,
suppressionKey,
suppressionText,
dismissible: this.dismissible
},
template: '<overlay-component></overlay-component>'
Expand Down
50 changes: 35 additions & 15 deletions src/api/overlays/components/OverlayComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,27 @@
class="c-overlay__contents js-notebook-snapshot-item-wrapper"
tabindex="0"
></div>
<div v-if="buttons" class="c-overlay__button-bar">
<button
v-for="(button, index) in buttons"
ref="buttons"
:key="index"
class="c-button js-overlay__button"
tabindex="0"
:class="{ 'c-button--major': focusIndex === index }"
@focus="focusIndex = index"
@click="buttonClickHandler(button.callback)"
>
{{ button.label }}
</button>
<div v-if="buttons || showSuppressOption" class="c-overlay__footer">
<div class="c-overlay__suppress-option">
<div v-if="showSuppressOption">
<input v-model="suppress" type="checkbox" class="l-composite-control l-checkbox" />
<label>{{ suppressionText }}</label>
</div>
</div>
<div v-if="buttons" class="c-overlay__button-bar">
<button
v-for="(button, index) in buttons"
ref="buttons"
:key="index"
class="c-button js-overlay__button"
tabindex="0"
:class="{ 'c-button--major': focusIndex === index }"
@focus="focusIndex = index"
@click="buttonClickHandler(button.callback)"
>
{{ button.label }}
</button>
</div>
</div>
</div>
</div>
Expand All @@ -56,11 +64,20 @@

<script>
export default {
inject: ['dismiss', 'element', 'buttons', 'dismissible'],
inject: [
'dismiss',
'element',
'buttons',
'dismissible',
'showSuppressOption',
'suppressionKey',
'suppressionText'
],
emits: ['destroy'],
data() {
return {
focusIndex: -1
focusIndex: -1,
suppress: false
};
},
mounted() {
Expand All @@ -78,6 +95,9 @@ export default {
}
},
buttonClickHandler(method) {
if (this.showSuppressOption && this.suppress && this.suppressionKey) {
localStorage.setItem(this.suppressionKey, true);

Check warning on line 99 in src/api/overlays/components/OverlayComponent.vue

View check run for this annotation

Codecov / codecov/patch

src/api/overlays/components/OverlayComponent.vue#L99

Added line #L99 was not covered by tests
}
method();
this.$emit('destroy');
},
Expand Down
19 changes: 16 additions & 3 deletions src/api/overlays/components/overlay-component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,24 @@
padding-right: $interiorMargin; // fend off scroll bar
}

&__footer {
margin-top: $interiorMargin;
display: flex;
justify-content: space-between;
width: 100%;
}

&__suppress-option {
width: 25%;
justify-items: start;
align-self: center;
padding-left: $interiorMargin;
}

&__button-bar {
flex: 0 0 auto;
width: 75%;
display: flex;
justify-content: flex-end;
margin-top: $interiorMargin;
justify-content: end;
body.mobile & {
justify-content: flex-end;
padding-right: $interiorMargin;
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/plot/MctPlot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1795,7 +1795,9 @@ export default {

showSynchronizeDialog() {
const isFixedTimespanMode = this.timeContext.isFixed();
if (!isFixedTimespanMode) {
const SYNC_TIME_CONDUCTOR_SUPPRESSION_KEY = 'sync-time-conductor-modal-suppression';
let isSuppressed = localStorage.getItem(SYNC_TIME_CONDUCTOR_SUPPRESSION_KEY);

Check warning on line 1799 in src/plugins/plot/MctPlot.vue

View check run for this annotation

Codecov / codecov/patch

src/plugins/plot/MctPlot.vue#L1798-L1799

Added lines #L1798 - L1799 were not covered by tests
if (!isFixedTimespanMode && !isSuppressed) {
const message = `
This action will change the Time Conductor to Fixed Timespan mode with this plot view's current time bounds.
Do you want to continue?
Expand All @@ -1806,6 +1808,8 @@ export default {
iconClass: 'alert',
size: 'fit',
message: message,
showSuppressOption: true,
suppressionKey: SYNC_TIME_CONDUCTOR_SUPPRESSION_KEY,
buttons: [
{
label: 'Ok',
Expand Down

0 comments on commit baae9c2

Please sign in to comment.