From 664f2c11e56f18a7c3e4a9fb83ba5b7e19fbb9a9 Mon Sep 17 00:00:00 2001 From: Julien Bourdeau Date: Sun, 31 Mar 2024 10:20:07 +0200 Subject: [PATCH] limit request list to 25 items (frontend config maxRequests) --- client/src/models/Config.ts | 2 ++ client/src/stores/RequestsStore.ts | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/client/src/models/Config.ts b/client/src/models/Config.ts index cb01e7a..b96d2a5 100644 --- a/client/src/models/Config.ts +++ b/client/src/models/Config.ts @@ -12,6 +12,7 @@ export type DebugbarConfigOptions = { interval: number } height: number + maxRequests: number } export type DebugbarConfig = DebugbarConfigOptions & { @@ -32,6 +33,7 @@ export function newDebugbarConfig(options: DebugbarConfigOptions) { interval: 500, }, height: 360, + maxRequests: 25, } as DebugbarConfigOptions) obj.actionCableUrl = `${obj.cable.url}${obj.prefix}/cable` diff --git a/client/src/stores/RequestsStore.ts b/client/src/stores/RequestsStore.ts index ad0b17d..0b00c9f 100644 --- a/client/src/stores/RequestsStore.ts +++ b/client/src/stores/RequestsStore.ts @@ -1,5 +1,6 @@ import { defineStore } from "pinia" import { BackendRequest, BackendRequestData } from "@/models/Request.ts" +import { useConfigStore } from "@/stores/configStore.ts" export let useRequestsStore = defineStore("requests", { state: () => { @@ -20,6 +21,11 @@ export let useRequestsStore = defineStore("requests", { } ids.push(r.id) }) + + while (this.requests.length > useConfigStore().config.maxRequests) { + this.requests.shift() + } + return ids }, setCurrentRequestById(id: string) { @@ -29,8 +35,5 @@ export let useRequestsStore = defineStore("requests", { this.requests = [] this.currentRequest = null }, - // removeRequest(request) { - // this.requests.splice(this.requests.indexOf(request), 1) - // }, }, })