Skip to content

Commit

Permalink
user can select whether to show duplicate sessions from Sessions page
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaLRussell committed Oct 26, 2023
1 parent c6c70a7 commit 6579771
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 20 deletions.
3 changes: 2 additions & 1 deletion app/server/src/controllers/sessionsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ export class SessionsController {
const sessionIdsString = req.query.sessionIds as string;
let metadata: SessionMetadata[] = [];
if (sessionIdsString) {
const removeDups = req.query.removeDuplicates === "true";
const sessionIds = sessionIdsString.split(",");
const store = getSessionStore(req);
metadata = await store.getSessionsMetadata(sessionIds);
metadata = await store.getSessionsMetadata(sessionIds, removeDups);
}
jsonResponseSuccess(metadata, res);
});
Expand Down
3 changes: 2 additions & 1 deletion app/server/src/db/sessionStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as md5 from "md5";
import { generateId } from "zoo-ids";
import { Request } from "express";
import { AppLocals, SessionMetadata } from "../types";
import {Session} from "inspector";

export const cleanFriendlyId = (id: string): string => {
let ret = id.toLowerCase();
Expand Down Expand Up @@ -104,7 +105,7 @@ export class SessionStore {
allResults = ids.map((id: string, idx: number) => buildSessionMetadata(id, idx))
.filter((session) => session.time !== null);
}
return allResults.sort((a, b) => a.time!! < b.time!! ? 1 : -1);
return allResults.sort((a, b) => a.time!! < b.time!! ? 1 : -1) as SessionMetadata[];
});
}

Expand Down
20 changes: 19 additions & 1 deletion app/server/tests/controllers/sessionsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,37 @@ describe("SessionsController", () => {
const metadataReq = {
...req,
query: {
sessionIds: "1234,5678"
sessionIds: "1234,5678",
removeDuplicates: "true"
}
};
await SessionsController.getSessionsMetadata(metadataReq, res, jest.fn());
expect(mockGetSessionStore).toHaveBeenCalledTimes(1);
expect(mockGetSessionStore.mock.calls[0][0]).toBe(metadataReq);
expect(mockSessionStore.getSessionsMetadata).toHaveBeenCalledTimes(1);
expect(mockSessionStore.getSessionsMetadata.mock.calls[0][0]).toStrictEqual(["1234", "5678"]);
expect(mockSessionStore.getSessionsMetadata.mock.calls[0][1]).toStrictEqual(true);

expect(res.header).toHaveBeenCalledWith("Content-Type", "application/json");
expect(res.end).toHaveBeenCalledTimes(1);
});

it("getSessionMetadata can pass false remove duplicates parameter to session store", async () => {
const metadataReq = {
...req,
query: {
sessionIds: "1234",
removeDuplicates: "false"
}
};
await SessionsController.getSessionsMetadata(metadataReq, res, jest.fn());
expect(mockGetSessionStore).toHaveBeenCalledTimes(1);
expect(mockGetSessionStore.mock.calls[0][0]).toBe(metadataReq);
expect(mockSessionStore.getSessionsMetadata).toHaveBeenCalledTimes(1);
expect(mockSessionStore.getSessionsMetadata.mock.calls[0][0]).toStrictEqual(["1234"]);
expect(mockSessionStore.getSessionsMetadata.mock.calls[0][1]).toStrictEqual(false);
});

it("getSessionMetadata handles error", async () => {
mockSessionStore.getSessionsMetadata.mockImplementation(() => { throw testError; });
const next = jest.fn();
Expand Down
13 changes: 0 additions & 13 deletions app/static/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions app/static/src/app/components/sessions/SessionsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
<p>
<input id="show-unlabelled-check" type="checkbox" class="form-check-input" v-model="showUnlabelledSessions" />
<label for="show-unlabelled-check" class="form-check-label ms-2">Show unlabelled sessions</label>
<input id="show-duplicates-check" type="checkbox" class="form-check-input ms-4" v-model="showDuplicateSessions" />
<label for="show-duplicates-check" class="form-check-label ms-2">Show duplicate sessions</label>
</p>
<template v-if="previousSessions && previousSessions.length">
<div class="row fw-bold py-2" id="previous-sessions-headers">
Expand Down Expand Up @@ -195,6 +197,15 @@ export default defineComponent({
}
});
const showDuplicateSessions = computed({
get() {
return store.state.userPreferences?.showDuplicateSessions;
},
set(newValue: boolean) {
store.dispatch(AppStateAction.SaveUserPreferences, { showDuplicateSessions: newValue });
}
});
const isCurrentSession = (sessionId: string) => sessionId === currentSessionId.value;
const previousSessions = computed(() => {
Expand Down Expand Up @@ -312,6 +323,7 @@ export default defineComponent({
toggleConfirmDeleteSessionOpen,
deleteSession,
showUnlabelledSessions,
showDuplicateSessions,
sessionCode,
loadSessionFromCode,
messages
Expand Down
3 changes: 2 additions & 1 deletion app/static/src/app/localStorageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class LocalStorageManager {
static _preferencesKey = "preferences";

static _initialUserPreferences = (): UserPreferences => ({
showUnlabelledSessions: true
showUnlabelledSessions: true,
showDuplicateSessions: false
});

getSessionIds = (appName: string, basePath: string): string[] => {
Expand Down
6 changes: 5 additions & 1 deletion app/static/src/app/store/appState/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,13 @@ export const appStateActions: ActionTree<AppState, AppState> = {
},

async [AppStateAction.SaveUserPreferences](context, payload: Partial<UserPreferences>) {
const { commit, state } = context;
const { commit, state, dispatch } = context;
const newPrefs = { ...state.userPreferences, ...payload };
const duplicatesPrefChanged = newPrefs.showDuplicateSessions !== state.userPreferences.showDuplicateSessions;
localStorageManager.setUserPreferences(newPrefs);
commit(AppStateMutation.SetUserPreferences, newPrefs);
if (duplicatesPrefChanged) {
await dispatch(`sessions/${SessionsAction.GetSessions}`);
}
}
};
3 changes: 2 additions & 1 deletion app/static/src/app/store/appState/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export enum VisualisationTab {
}

export interface UserPreferences {
showUnlabelledSessions: boolean
showUnlabelledSessions: boolean,
showDuplicateSessions: boolean
}

export interface AppState {
Expand Down
3 changes: 2 additions & 1 deletion app/static/src/app/store/sessions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export const actions: ActionTree<SessionsState, AppState> = {

const sessionIds = localStorageManager.getSessionIds(appName!, rootGetters[AppStateGetter.baseUrlPath]);
const sessionIdsQs = sessionIds.join(",");
const url = `/${appsPath}/${appName}/sessions/metadata?sessionIds=${sessionIdsQs}`;
const removeDuplicates = !rootState.userPreferences.showDuplicateSessions;
const url = `/${appsPath}/${appName}/sessions/metadata?sessionIds=${sessionIdsQs}&removeDuplicates=${removeDuplicates}`;
await api(context)
.withSuccess(SessionsMutation.SetSessionsMetadata)
.withError(`errors/${ErrorsMutation.AddError}`, true)
Expand Down

0 comments on commit 6579771

Please sign in to comment.