Skip to content

Commit 52427b8

Browse files
luizhf42otavio
authored andcommitted
fix(ui): make session recording switch reactive
1 parent 6631599 commit 52427b8

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

ui/src/components/Setting/SettingSessionRecording.vue

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</template>
1111

1212
<script setup lang="ts">
13-
import { computed, onMounted, ref, watch } from "vue";
13+
import { computed, onMounted } from "vue";
1414
import hasPermission from "@/utils/permission";
1515
import { actions, authorizer } from "@/authorizer";
1616
import { useStore } from "@/store";
@@ -23,11 +23,10 @@ const props = defineProps({
2323
default: false,
2424
},
2525
});
26-
const store = useStore();
2726
28-
const sessionRecordingStatus = ref(store.getters["sessionRecording/getStatus"]);
27+
const store = useStore();
2928
30-
watch(sessionRecordingStatus, async (value: boolean) => {
29+
const updateSessionRecordingStatus = async (value: boolean) => {
3130
const data = {
3231
id: localStorage.getItem("tenant"),
3332
status: value,
@@ -42,6 +41,13 @@ watch(sessionRecordingStatus, async (value: boolean) => {
4241
store.dispatch("snackbar/showSnackbarErrorDefault");
4342
handleError(error);
4443
}
44+
};
45+
46+
const sessionRecordingStatus = computed({
47+
get: () => store.getters["sessionRecording/isEnabled"],
48+
set: async (value: boolean) => {
49+
updateSessionRecordingStatus(value);
50+
},
4551
});
4652
4753
const hasAuthorization = computed(() => {
@@ -65,5 +71,6 @@ onMounted(async () => {
6571
handleError(error);
6672
}
6773
});
74+
6875
defineExpose({ sessionRecordingStatus });
6976
</script>

ui/tests/components/Setting/SettingSessionRecording.spec.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createVuetify } from "vuetify";
2-
import { flushPromises, mount, VueWrapper } from "@vue/test-utils";
2+
import { mount, VueWrapper } from "@vue/test-utils";
33
import { beforeEach, describe, expect, it, vi } from "vitest";
44
import MockAdapter from "axios-mock-adapter";
55
import SettingSessionRecording from "@/components/Setting/SettingSessionRecording.vue";
@@ -54,10 +54,8 @@ describe("Setting Session Recording", () => {
5454
it("Changes status in store when ref is mutated", async () => {
5555
mockUser.onPut("http://localhost:3000/api/users/security/fake-tenant-data").reply(200);
5656

57-
wrapper.vm.sessionRecordingStatus = false;
58-
5957
const dispatchSpy = vi.spyOn(store, "dispatch");
60-
await flushPromises();
58+
wrapper.vm.sessionRecordingStatus = false;
6159

6260
expect(dispatchSpy).toHaveBeenCalledWith("sessionRecording/setStatus", { id: "fake-tenant-data", status: false });
6361
});

ui/tests/components/Setting/__snapshots__/SettingNamespace.spec.ts.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,16 +170,16 @@ exports[`Setting Namespace > Renders the component 1`] = `
170170
<!----><span class="v-card__underlay"></span>
171171
</div>
172172
<div data-v-80a16399="" class="v-col d-flex align-center justify-end bg-background">
173-
<div data-v-80a16399="" class="v-input v-input--horizontal v-input--center-affix v-input--density-default v-theme--light v-locale--is-ltr v-switch v-switch--inset" data-test="session-recording-setting-component">
173+
<div data-v-80a16399="" class="v-input v-input--horizontal v-input--center-affix v-input--density-default v-theme--light v-locale--is-ltr v-input--dirty v-switch v-switch--inset" data-test="session-recording-setting-component">
174174
<!---->
175175
<div class="v-input__control">
176-
<div class="v-selection-control v-selection-control--density-default">
177-
<div class="v-selection-control__wrapper">
178-
<div class="v-switch__track">
176+
<div class="v-selection-control v-selection-control--dirty v-selection-control--density-default">
177+
<div class="v-selection-control__wrapper text-primary">
178+
<div class="v-switch__track bg-primary">
179179
<!---->
180180
<!---->
181181
</div>
182-
<div class="v-selection-control__input"><input id="switch-v-6" aria-disabled="false" type="checkbox" aria-describedby="switch-v-6-messages" value="true">
182+
<div class="v-selection-control__input"><input checked="" id="switch-v-6" aria-disabled="false" type="checkbox" aria-describedby="switch-v-6-messages" value="true">
183183
<div class="v-switch__thumb">
184184
<transition-stub name="scale-transition" appear="false" persisted="false" css="true">
185185
<!---->

ui/tests/components/Setting/__snapshots__/SettingSessionRecording.spec.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

33
exports[`Setting Session Recording > Renders the component 1`] = `
4-
"<div class="v-input v-input--horizontal v-input--center-affix v-input--density-default v-theme--light v-locale--is-ltr v-input--disabled v-switch v-switch--inset" data-test="session-recording-switch">
4+
"<div class="v-input v-input--horizontal v-input--center-affix v-input--density-default v-theme--light v-locale--is-ltr v-input--dirty v-input--disabled v-switch v-switch--inset" data-test="session-recording-switch">
55
<!---->
66
<div class="v-input__control">
7-
<div class="v-selection-control v-selection-control--disabled v-selection-control--density-default">
7+
<div class="v-selection-control v-selection-control--dirty v-selection-control--disabled v-selection-control--density-default">
88
<div class="v-selection-control__wrapper">
99
<div class="v-switch__track">
1010
<!---->
1111
<!---->
1212
</div>
13-
<div class="v-selection-control__input"><input disabled="" id="switch-v-0" aria-disabled="true" type="checkbox" aria-describedby="switch-v-0-messages" value="true">
13+
<div class="v-selection-control__input"><input checked="" disabled="" id="switch-v-0" aria-disabled="true" type="checkbox" aria-describedby="switch-v-0-messages" value="true">
1414
<div class="v-switch__thumb">
1515
<transition-stub name="scale-transition" appear="false" persisted="false" css="true">
1616
<!---->

0 commit comments

Comments
 (0)