blob: 8cbe647e7cbcae263bf835c59cb26b46913465f5 [file] [log] [blame]
Adrià Vilanova Martínez035b5432021-09-03 14:16:59 +02001<script>
2import {browsers} from '../consts.js';
3
4import * as ksObjectsPb from '../api_proto/kill_switch_objects_pb.js';
5import * as ksPb from '../api_proto/kill_switch_pb.js';
6import * as commonPb from '../api_proto/common_pb.js';
7
8import KillSwitch from './KillSwitch.vue';
9
10let browserOptions = {...browsers};
11delete browserOptions['0'];
12let defaultBrowsers = Object.keys(browserOptions);
13
14export default {
15 components: {
16 KillSwitch,
17 },
18 props: {
19 modelValue: Boolean,
20 },
21 emits: [
22 'killSwitchAdded',
23 ],
24 data() {
25 return {
26 secondOpen: false,
27 featuresList: [],
28 browserOptions,
29 feature: "",
30 minVersion: "",
31 maxVersion: "",
32 browsers: [...defaultBrowsers],
33 };
34 },
35 mounted() {
36 this.loadData();
37 },
38 computed: {
39 killSwitch() {
40 let ks = new ksObjectsPb.KillSwitch();
41 for (let f of this.featuresList) {
42 if (f.getId() == this.feature) {
43 ks.setFeature(f);
44 break;
45 }
46 }
47 ks.setMinVersion(this.minVersion);
48 ks.setMaxVersion(this.maxVersion);
49 ks.setBrowsersList(this.browsers);
50 ks.setActive(true);
51 return ks;
52 },
53 },
54 methods: {
55 loadData() {
56 let request = new ksPb.ListFeaturesRequest();
57 request.setWithDeprecatedFeatures(true);
58
59 this.$store.state.client.listFeatures(
60 request, {authorization: this.$store.state.jwtToken})
61 .then(res => {
62 this.$data.featuresList = res.getFeaturesList();
63 })
64 .catch(err => console.error(err));
65 },
66 onCancel() {
67 this.secondOpen = false;
68 this.feature = "";
69 this.minVersion = "";
70 this.maxVersion = "";
71 this.browsers = [...defaultBrowsers];
72 },
73 onNext() {
74 this.secondOpen = true;
75 },
76 onPrevious() {
77 this.secondOpen = false;
78 this.$emit('update:modelValue', true);
79 },
80 onConfirm() {
81 let request = new ksPb.EnableKillSwitchRequest();
82 request.setKillSwitch(this.killSwitch.cloneMessage());
83
84 this.$store.state.client.enableKillSwitch(
85 request, {authorization: this.$store.state.jwtToken})
86 .then(res => {
87 this.$emit('killSwitchAdded');
88 this.onCancel();
89 })
90 .catch(err => console.error(err));
91 },
92 },
93};
94</script>
95
96<template>
97 <mcw-dialog
98 v-model="modelValue"
99 @update:modelValue="$emit('update:modelValue', $event)"
100 escape-key-action="close"
101 scrim-click-action="close"
102 :auto-stack-buttons="true">
103 <mcw-dialog-title>Enable Kill Switch</mcw-dialog-title>
104 <mcw-dialog-content>
105 <div>
106 <p>
107 <mcw-select ref="featureSelect" v-model="feature" label="Feature to disable" required>
108 <mcw-list-item data-value="" role="option"></mcw-list-item>
109 <mcw-list-item v-for="feature in featuresList" :data-value="feature.getId()" role="option">
110 {{ feature.getCodename() }}
111 </mcw-list-item>
112 </mcw-select>
113 </p>
114 <p>
115 <span class="helper-text">Disable the feature on extension versions greater or equal to:</span><br>
116 <mcw-textfield v-model="minVersion" label="Minimum version" helptext="(optional)" helptext-persistent fullwidth />
117 </p>
118 <p>
119 <span class="helper-text">Disable the feature on extension versions less or equal to:</span><br>
120 <mcw-textfield v-model="maxVersion" label="Maximum version" helptext="(optional)" helptext-persistent fullwidth />
121 </p>
122 <p>
123 <span class="helper-text">Disable in the following browsers:</span>
124 <template v-for="(b, i) in browserOptions"><br><mcw-checkbox :value="i" v-model="browsers" :label="b" /></template>
125 </p>
126 </div>
127 </mcw-dialog-content>
128 <mcw-dialog-footer>
129 <mcw-dialog-button @click="onCancel" action="dismiss">Cancel</mcw-dialog-button>
130 <mcw-dialog-button @click="onNext" action="accept">Next</mcw-dialog-button>
131 </mcw-dialog-footer>
132 </mcw-dialog>
133 <mcw-dialog
134 v-model="secondOpen"
135 escape-key-action="close"
136 scrim-click-action="close"
137 :auto-stack-buttons="true">
138 <mcw-dialog-title>Enable Kill Switch?</mcw-dialog-title>
139 <mcw-dialog-content>
140 <div>
141 <p>This will disable the feature globally for all the extension users, if they use one of the versions and browsers specified.</p>
142 <p>Please take a look at this preview and confirm that this is indeed what you want to do:</p>
143 <kill-switch :kill-switch="killSwitch" />
144 </div>
145 </mcw-dialog-content>
146 <mcw-dialog-footer>
147 <mcw-dialog-button @click="onPrevious">Previous</mcw-dialog-button>
148 <mcw-dialog-button class="confirm-bad" @click="onConfirm" action="accept">Confirm</mcw-dialog-button>
149 </mcw-dialog-footer>
150 </mcw-dialog>
151</template>
152
153<style scoped lang="scss">
154@use "@material/theme/color-palette" as palette;
155@use "@material/button";
156
157.helper-text {
158 font-size: 14px;
159 color: palette.$grey-700;
160}
161
162.confirm-bad {
163 @include button.ink-color(palette.$red-500);
164}
165</style>