From 3c37d7c1977d7a644ea235133c5a16f56e1f1579 Mon Sep 17 00:00:00 2001 From: Fine0830 Date: Tue, 7 Jun 2022 21:54:29 +0800 Subject: [PATCH] fix: set the duration and scroll position for on-demand logs (#104) --- src/graphql/fragments/demand-log.ts | 2 - src/store/modules/demand-log.ts | 3 + .../dashboard/related/demand-log/Content.vue | 21 ++++++- .../dashboard/related/demand-log/Header.vue | 62 +++++++++++-------- 4 files changed, 59 insertions(+), 29 deletions(-) diff --git a/src/graphql/fragments/demand-log.ts b/src/graphql/fragments/demand-log.ts index 40df4977..3579f8c5 100644 --- a/src/graphql/fragments/demand-log.ts +++ b/src/graphql/fragments/demand-log.ts @@ -30,8 +30,6 @@ export const queryStreamingLogs = { logs: ondemandPodLogs(condition: $condition) { errorReason logs { - timestamp - contentType content } }`, diff --git a/src/store/modules/demand-log.ts b/src/store/modules/demand-log.ts index 87565091..3aa37ac7 100644 --- a/src/store/modules/demand-log.ts +++ b/src/store/modules/demand-log.ts @@ -31,6 +31,7 @@ interface DemandLogState { logs: Log[]; loadLogs: boolean; message: string; + total: number; } export const demandLogStore = defineStore({ @@ -47,6 +48,7 @@ export const demandLogStore = defineStore({ logs: [], loadLogs: false, message: "", + total: 0, }), actions: { setLogCondition(data: Conditions) { @@ -109,6 +111,7 @@ export const demandLogStore = defineStore({ this.setLogs("", res.data.data.logs.errorReason); return res.data; } + this.total = res.data.data.logs.logs.length; const logs = res.data.data.logs.logs .map((d: Log) => d.content) .join("\n"); diff --git a/src/views/dashboard/related/demand-log/Content.vue b/src/views/dashboard/related/demand-log/Content.vue index a3577f97..b06d49d3 100644 --- a/src/views/dashboard/related/demand-log/Content.vue +++ b/src/views/dashboard/related/demand-log/Content.vue @@ -31,20 +31,25 @@ const demandLogStore = useDemandLogStore(); const monacoInstance = ref(); const logContent = ref>(null); -onMounted(async () => { +onMounted(() => { + init(); +}); +async function init() { const monaco = await import("monaco-editor"); monacoInstanceGen(monaco); window.addEventListener("resize", () => { editorLayout(); }); -}); +} function monacoInstanceGen(monaco: any) { monacoInstance.value = monaco.editor.create(logContent.value, { value: "", language: "text", wordWrap: true, minimap: { enabled: false }, + readonly: true, }); + toRaw(monacoInstance.value).updateOptions({ readOnly: true }); } function editorLayout() { if (!logContent.value) { @@ -66,7 +71,19 @@ onUnmounted(() => { watch( () => demandLogStore.logs, () => { + if (!toRaw(monacoInstance.value)) { + return; + } toRaw(monacoInstance.value).setValue(demandLogStore.logs); + if (!demandLogStore.logs) { + return; + } + setTimeout(() => { + toRaw(monacoInstance.value).revealPosition({ + column: 1, + lineNumber: demandLogStore.total, + }); + }, 1000); } ); diff --git a/src/views/dashboard/related/demand-log/Header.vue b/src/views/dashboard/related/demand-log/Header.vue index 3164bc9c..b7f26cec 100644 --- a/src/views/dashboard/related/demand-log/Header.vue +++ b/src/views/dashboard/related/demand-log/Header.vue @@ -110,11 +110,6 @@ limitations under the License. --> v-model="excludingContentStr" @change="addLabels('excludingKeywordsOfContent')" /> - - - - -
@@ -135,7 +130,7 @@ limitations under the License. -->