Skip to content

Commit 9e127d3

Browse files
luizhf42otavio
authored andcommitted
refactor(ui): refactor session recording store
1 parent 35910f7 commit 9e127d3

File tree

11 files changed

+132
-209
lines changed

11 files changed

+132
-209
lines changed

ui/src/components/Setting/SettingNamespace.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,10 @@
145145
</template>
146146
</v-card>
147147
<v-col class="d-flex align-center justify-end bg-background">
148-
<SettingSecurity :hasTenant="hasTenant()" data-test="security-setting-component" />
148+
<SettingSessionRecording
149+
:hasTenant="hasTenant()"
150+
data-test="session-recording-setting-component"
151+
/>
149152
</v-col>
150153
</v-row>
151154
<v-divider />
@@ -187,7 +190,7 @@ import { useField } from "vee-validate";
187190
import hasPermission from "@/utils/permission";
188191
import { actions, authorizer } from "@/authorizer";
189192
import { useStore } from "@/store";
190-
import SettingSecurity from "./SettingSecurity.vue";
193+
import SettingSessionRecording from "./SettingSessionRecording.vue";
191194
import NamespaceDelete from "../Namespace/NamespaceDelete.vue";
192195
import NamespaceEdit from "../Namespace/NamespaceEdit.vue";
193196
import {

ui/src/components/Setting/SettingSecurity.vue renamed to ui/src/components/Setting/SettingSessionRecording.vue

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<v-switch
33
hide-details
44
inset
5-
v-model="sessionRecord"
5+
v-model="sessionRecordingStatus"
66
:disabled="!hasAuthorization"
77
color="primary"
8-
data-test="security-switch"
8+
data-test="session-recording-switch"
99
/>
1010
</template>
1111

@@ -25,15 +25,15 @@ const props = defineProps({
2525
});
2626
const store = useStore();
2727
28-
const sessionRecord = ref(store.getters["security/get"]);
28+
const sessionRecordingStatus = ref(store.getters["sessionRecording/getStatus"]);
2929
30-
watch(sessionRecord, async (value: boolean) => {
30+
watch(sessionRecordingStatus, async (value: boolean) => {
3131
const data = {
3232
id: localStorage.getItem("tenant"),
3333
status: value,
3434
};
3535
try {
36-
await store.dispatch("security/set", data);
36+
await store.dispatch("sessionRecording/setStatus", data);
3737
store.dispatch(
3838
"snackbar/showSnackbarSuccessAction",
3939
INotificationsSuccess.namespaceEdit,
@@ -58,12 +58,12 @@ const hasAuthorization = computed(() => {
5858
onMounted(async () => {
5959
try {
6060
if (props.hasTenant) {
61-
await store.dispatch("security/get");
61+
await store.dispatch("sessionRecording/getStatus");
6262
}
6363
} catch (error: unknown) {
6464
store.dispatch("snackbar/showSnackbarErrorDefault");
6565
handleError(error);
6666
}
6767
});
68-
defineExpose({ sessionRecord });
68+
defineExpose({ sessionRecordingStatus });
6969
</script>

ui/src/store/api/users.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ export const postRecoverPassword = async (username: string) => usersApi.recoverP
1616

1717
export const postValidationAccount = async (data: IUser) => usersApi.getValidateAccount(data.email, data.token);
1818

19-
export const setSessionRecordStatus = async (data: IUserPutSecurity) => usersApi.setSessionRecord(data.id, { session_record: data.status });
19+
export const setSessionRecordStatus = async (data: IUserPutSessionRecording) => usersApi.setSessionRecord(
20+
data.id,
21+
{ session_record: data.status },
22+
);
2023

2124
export const getSessionRecordStatus = async () => usersApi.checkSessionRecord();
2225

ui/src/store/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { support, SupportState } from "./modules/support";
1111
import { spinner, SpinnerState } from "./modules/spinner";
1212
import { snackbar, SnackbarState } from "./modules/snackbar";
1313
import { sessions, SessionsState } from "./modules/sessions";
14-
import { security, SecurityState } from "./modules/security";
14+
import { sessionRecording, SessionRecordingState } from "./modules/session_recording";
1515
import { publicKeys, PublicKeysState } from "./modules/public_keys";
1616
import { privateKey, PrivateKeyState } from "./modules/private_key";
1717
import { notifications, NotificationsState } from "./modules/notifications";
@@ -43,7 +43,7 @@ export interface State {
4343
notifications: NotificationsState;
4444
privateKey: PrivateKeyState;
4545
publicKeys: PublicKeysState;
46-
security: SecurityState;
46+
sessionRecording: SessionRecordingState;
4747
sessions: SessionsState;
4848
snackbar: SnackbarState;
4949
spinner: SpinnerState;
@@ -73,7 +73,7 @@ export const store = createStore<State>({
7373
notifications,
7474
privateKey,
7575
publicKeys,
76-
security,
76+
sessionRecording,
7777
sessions,
7878
snackbar,
7979
spinner,

ui/src/store/modules/security.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Module } from "vuex";
2+
import * as usersApi from "../api/users";
3+
import { State } from "..";
4+
5+
export interface SessionRecordingState {
6+
enabled: boolean,
7+
}
8+
9+
export const sessionRecording: Module<SessionRecordingState, State> = {
10+
namespaced: true,
11+
state: {
12+
enabled: true,
13+
},
14+
15+
getters: {
16+
isEnabled: (state) => state.enabled,
17+
},
18+
19+
mutations: {
20+
setEnabled: (state, status) => {
21+
state.enabled = status;
22+
},
23+
},
24+
25+
actions: {
26+
async setStatus(context, data) {
27+
await usersApi.setSessionRecordStatus(data);
28+
context.commit("setEnabled", data.status);
29+
},
30+
31+
async getStatus(context) {
32+
const res = await usersApi.getSessionRecordStatus();
33+
context.commit("setEnabled", res.data);
34+
},
35+
},
36+
};

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

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ 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 SettingNamespace from "@/components/Setting/SettingNamespace.vue";
6-
import { namespacesApi, usersApi, apiKeysApi } from "@/api/http";
6+
import { namespacesApi, usersApi } from "@/api/http";
77
import { store, key } from "@/store";
88
import { router } from "@/router";
99
import { envVariables } from "@/envVariables";
@@ -17,11 +17,8 @@ describe("Setting Namespace", () => {
1717
const vuetify = createVuetify();
1818

1919
let mockNamespace: MockAdapter;
20-
2120
let mockUser: MockAdapter;
2221

23-
let mockApiKeys: MockAdapter;
24-
2522
const members = [
2623
{
2724
id: "507f1f77bcf86cd799439011",
@@ -61,25 +58,6 @@ describe("Setting Namespace", () => {
6158
},
6259
};
6360

64-
const session = true;
65-
66-
const getKeyResponse = [
67-
{
68-
id: "3e5a5194-9dec-4a32-98db-7434c6d49df1",
69-
tenant_id: "fake-tenant",
70-
user_id: "507f1f77bcf86cd799439011",
71-
name: "my api key",
72-
expires_in: 1707958989,
73-
},
74-
{
75-
id: "3e5a5194-9dec-4a32-98db-7434c6d49df2",
76-
tenant_id: "fake-tenant",
77-
user_id: "507f1f77bcf86cd799439011",
78-
name: "my api key",
79-
expires_in: 1707958989,
80-
},
81-
];
82-
8361
beforeEach(async () => {
8462
window.matchMedia = vi.fn().mockImplementation((query) => ({
8563
matches: false,
@@ -98,19 +76,13 @@ describe("Setting Namespace", () => {
9876

9977
mockNamespace = new MockAdapter(namespacesApi.getAxios());
10078
mockUser = new MockAdapter(usersApi.getAxios());
101-
mockApiKeys = new MockAdapter(apiKeysApi.getAxios());
10279

10380
mockNamespace.onGet("http://localhost:3000/api/namespaces/fake-tenant").reply(200, namespaceData);
10481
mockUser.onGet("http://localhost:3000/api/users/security").reply(200, session);
10582
mockUser.onGet("http://localhost:3000/api/auth/user").reply(200, authData);
106-
mockUser.onGet("http://localhost:3000/api/auth/user").reply(200, authData);
107-
mockApiKeys.onGet("http://localhost:3000/api/namespaces/fake-tenant/api-key").reply(200, getKeyResponse, { "x-total-count": 2 });
10883

10984
store.commit("auth/authSuccess", authData);
110-
store.commit("auth/changeData", authData);
11185
store.commit("namespaces/setNamespace", namespaceData);
112-
store.commit("security/setSecurity", session);
113-
store.commit("apiKeys/setKeyList", { data: getKeyResponse, headers: { "x-total-count": 2 } });
11486

11587
wrapper = mount(SettingNamespace, {
11688
global: {
@@ -154,7 +126,7 @@ describe("Setting Namespace", () => {
154126
"record-icon",
155127
"record-title",
156128
"record-description",
157-
"security-setting-component",
129+
"session-recording-setting-component",
158130
"delete-leave-item",
159131
"delete-leave-icon",
160132
"delete-leave-title",

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

Lines changed: 0 additions & 118 deletions
This file was deleted.

0 commit comments

Comments
 (0)