From fb1da491d8b22f6a1e07f99dea56c6454beeab8c Mon Sep 17 00:00:00 2001 From: Joel Jacob Stephen <70131076+JoelJacobStephen@users.noreply.github.com> Date: Tue, 10 May 2022 02:05:24 +0530 Subject: [PATCH] refactor: realtime log entry revamp (#2240) Co-authored-by: liyasthomas Co-authored-by: Andrew Bastin --- .../assets/icons/arrow-down-left.svg | 4 + .../assets/icons/arrow-down.svg | 4 + .../assets/icons/arrow-up-right.svg | 4 + .../hoppscotch-app/assets/icons/arrow-up.svg | 4 + .../assets/icons/chevrons-down.svg | 4 + .../assets/icons/chevrons-up.svg | 4 + .../assets/icons/info-disconnect.svg | 5 + .../assets/icons/info-realtime.svg | 5 + .../components/realtime/Log.vue | 145 ++++--- .../components/realtime/LogEntry.vue | 388 ++++++++++++++++++ .../components/realtime/Mqtt.vue | 51 ++- .../components/realtime/Socketio.vue | 36 +- .../components/realtime/Sse.vue | 42 +- .../components/realtime/Websocket.vue | 41 +- .../hoppscotch-app/helpers/functional/json.ts | 8 + .../hoppscotch-app/helpers/utils/string.ts | 12 - packages/hoppscotch-app/locales/en.json | 3 + pnpm-lock.yaml | 39 +- 18 files changed, 654 insertions(+), 145 deletions(-) create mode 100644 packages/hoppscotch-app/assets/icons/arrow-down-left.svg create mode 100644 packages/hoppscotch-app/assets/icons/arrow-down.svg create mode 100644 packages/hoppscotch-app/assets/icons/arrow-up-right.svg create mode 100644 packages/hoppscotch-app/assets/icons/arrow-up.svg create mode 100644 packages/hoppscotch-app/assets/icons/chevrons-down.svg create mode 100644 packages/hoppscotch-app/assets/icons/chevrons-up.svg create mode 100644 packages/hoppscotch-app/assets/icons/info-disconnect.svg create mode 100644 packages/hoppscotch-app/assets/icons/info-realtime.svg create mode 100644 packages/hoppscotch-app/components/realtime/LogEntry.vue delete mode 100644 packages/hoppscotch-app/helpers/utils/string.ts diff --git a/packages/hoppscotch-app/assets/icons/arrow-down-left.svg b/packages/hoppscotch-app/assets/icons/arrow-down-left.svg new file mode 100644 index 000000000..583988208 --- /dev/null +++ b/packages/hoppscotch-app/assets/icons/arrow-down-left.svg @@ -0,0 +1,4 @@ + + + + diff --git a/packages/hoppscotch-app/assets/icons/arrow-down.svg b/packages/hoppscotch-app/assets/icons/arrow-down.svg new file mode 100644 index 000000000..ad365d5fc --- /dev/null +++ b/packages/hoppscotch-app/assets/icons/arrow-down.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/packages/hoppscotch-app/assets/icons/arrow-up-right.svg b/packages/hoppscotch-app/assets/icons/arrow-up-right.svg new file mode 100644 index 000000000..6ac911836 --- /dev/null +++ b/packages/hoppscotch-app/assets/icons/arrow-up-right.svg @@ -0,0 +1,4 @@ + + + + diff --git a/packages/hoppscotch-app/assets/icons/arrow-up.svg b/packages/hoppscotch-app/assets/icons/arrow-up.svg new file mode 100644 index 000000000..9966fa544 --- /dev/null +++ b/packages/hoppscotch-app/assets/icons/arrow-up.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/packages/hoppscotch-app/assets/icons/chevrons-down.svg b/packages/hoppscotch-app/assets/icons/chevrons-down.svg new file mode 100644 index 000000000..b46abe3a6 --- /dev/null +++ b/packages/hoppscotch-app/assets/icons/chevrons-down.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/packages/hoppscotch-app/assets/icons/chevrons-up.svg b/packages/hoppscotch-app/assets/icons/chevrons-up.svg new file mode 100644 index 000000000..d79fc4952 --- /dev/null +++ b/packages/hoppscotch-app/assets/icons/chevrons-up.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/packages/hoppscotch-app/assets/icons/info-disconnect.svg b/packages/hoppscotch-app/assets/icons/info-disconnect.svg new file mode 100644 index 000000000..ab55c86fd --- /dev/null +++ b/packages/hoppscotch-app/assets/icons/info-disconnect.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/packages/hoppscotch-app/assets/icons/info-realtime.svg b/packages/hoppscotch-app/assets/icons/info-realtime.svg new file mode 100644 index 000000000..ab55c86fd --- /dev/null +++ b/packages/hoppscotch-app/assets/icons/info-realtime.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/packages/hoppscotch-app/components/realtime/Log.vue b/packages/hoppscotch-app/components/realtime/Log.vue index 348a2fab7..e46dc21d0 100644 --- a/packages/hoppscotch-app/components/realtime/Log.vue +++ b/packages/hoppscotch-app/components/realtime/Log.vue @@ -1,77 +1,128 @@ - + diff --git a/packages/hoppscotch-app/components/realtime/LogEntry.vue b/packages/hoppscotch-app/components/realtime/LogEntry.vue new file mode 100644 index 000000000..941455294 --- /dev/null +++ b/packages/hoppscotch-app/components/realtime/LogEntry.vue @@ -0,0 +1,388 @@ + + + + + diff --git a/packages/hoppscotch-app/components/realtime/Mqtt.vue b/packages/hoppscotch-app/components/realtime/Mqtt.vue index 6cd482c20..b04000091 100644 --- a/packages/hoppscotch-app/components/realtime/Mqtt.vue +++ b/packages/hoppscotch-app/components/realtime/Mqtt.vue @@ -48,7 +48,11 @@ @@ -136,7 +140,8 @@ export default defineComponent({ { payload: this.$t("state.connecting_to", { name: this.server }), source: "info", - color: "var(--accent-color)", + event: "connecting", + ts: Date.now(), }, ] if (typeof EventSource !== "undefined") { @@ -149,8 +154,8 @@ export default defineComponent({ { payload: this.$t("state.connected_to", { name: this.server }), source: "info", - color: "var(--accent-color)", - ts: new Date().toLocaleTimeString(), + event: "connected", + ts: Date.now(), }, ] this.$toast.success(this.$t("state.connected")) @@ -164,9 +169,9 @@ export default defineComponent({ payload: this.$t("state.disconnected_from", { name: this.server, }), - source: "info", - color: "#ff5555", - ts: new Date().toLocaleTimeString(), + source: "disconnected", + event: "disconnected", + ts: Date.now(), }) this.$toast.error(this.$t("state.disconnected")) } @@ -174,7 +179,7 @@ export default defineComponent({ addSSELogLine({ payload: data, source: "server", - ts: new Date().toLocaleTimeString(), + ts: Date.now(), }) }) } catch (e) { @@ -185,9 +190,9 @@ export default defineComponent({ this.log = [ { payload: this.$t("error.browser_support_sse"), - source: "info", - color: "#ff5555", - ts: new Date().toLocaleTimeString(), + source: "disconnected", + event: "error", + ts: Date.now(), }, ] } @@ -201,22 +206,25 @@ export default defineComponent({ this.connectionSSEState = false addSSELogLine({ payload: this.$t("error.something_went_wrong"), - source: "info", - color: "#ff5555", - ts: new Date().toLocaleTimeString(), + source: "disconnected", + event: "error", + ts: Date.now(), }) if (error !== null) addSSELogLine({ payload: error, - source: "info", - color: "#ff5555", - ts: new Date().toLocaleTimeString(), + source: "disconnected", + event: "error", + ts: Date.now(), }) }, stop() { this.sse.close() this.sse.onclose() }, + clearLogEntries() { + this.log = [] + }, }, }) diff --git a/packages/hoppscotch-app/components/realtime/Websocket.vue b/packages/hoppscotch-app/components/realtime/Websocket.vue index cd1ce8ee5..9ac8705a8 100644 --- a/packages/hoppscotch-app/components/realtime/Websocket.vue +++ b/packages/hoppscotch-app/components/realtime/Websocket.vue @@ -137,22 +137,23 @@ class="inline-flex flex-col object-contain object-center w-16 h-16 my-4" :alt="$t('empty.protocols')" /> - - {{ $t("empty.protocols") }} - + {{ $t("empty.protocols") }}