Skip to content

Commit 9318321

Browse files
authored
Merge pull request #54 from buggregator/issue/#43-rest-fallback-on-ws-fail
Issue/#43 rest fallback on ws connection fail
2 parents 57fb5c8 + e087931 commit 9318321

File tree

27 files changed

+459
-275
lines changed

27 files changed

+459
-275
lines changed

components/HttpDumpPage/HttpDumpPage.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<h1>Attachments ({{ event.payload.request.files.length }})</h1>
6565

6666
<div class="http-dump-page__attachments">
67-
<Attachment
67+
<SmtpAttachment
6868
v-for="a in event.payload.request.files"
6969
:key="a.id"
7070
:event="event"
@@ -88,13 +88,13 @@ import { defineComponent, PropType } from "vue";
8888
import { NormalizedEvent } from "~/config/types";
8989
import EventTable from "~/components/EventTable/EventTable.vue";
9090
import EventTableRow from "~/components/EventTableRow/EventTableRow.vue";
91-
import Attachment from "~/components/Attachment/Attachment.vue";
91+
import SmtpAttachment from "~/components/SmtpAttachment/SmtpAttachment.vue";
9292
9393
export default defineComponent({
9494
components: {
9595
EventTable,
9696
EventTableRow,
97-
Attachment,
97+
SmtpAttachment,
9898
},
9999
props: {
100100
event: {

components/LayoutSidebar/LayoutSidebar.vue

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939
</nav>
4040

4141
<div class="layout-sidebar__versions">
42+
<IconSvg
43+
class="layout-sidebar__connection-icon"
44+
:name="connectionStatus"
45+
:title="connectionText"
46+
/>
47+
4248
<div
4349
v-if="apiVersion"
4450
class="layout-sidebar__nav-version"
@@ -61,15 +67,12 @@
6167
<script lang="ts">
6268
import IconSvg from "~/components/IconSvg/IconSvg.vue";
6369
import { defineComponent } from "vue";
64-
import { useNuxtApp } from "#app";
70+
import { useConnectionStore } from "~/stores/connections";
71+
import { storeToRefs } from "pinia";
6572
6673
export default defineComponent({
6774
components: { IconSvg },
6875
props: {
69-
isConnected: {
70-
type: Boolean,
71-
required: true,
72-
},
7376
apiVersion: {
7477
type: String,
7578
default: "@dev",
@@ -79,6 +82,17 @@ export default defineComponent({
7982
default: "@dev",
8083
},
8184
},
85+
computed: {
86+
connectionStatus() {
87+
const connectionStore = useConnectionStore();
88+
const { isConnectedWS } = storeToRefs(connectionStore);
89+
90+
return isConnectedWS.value ? "connected" : "disconnected";
91+
},
92+
connectionText() {
93+
return `WS connection is ${this.connectionStatus}`;
94+
},
95+
},
8296
});
8397
</script>
8498

@@ -88,7 +102,7 @@ export default defineComponent({
88102
}
89103
90104
.layout-sidebar__nav {
91-
@apply divide-gray-300 dark:divide-gray-600 flex-col flex overflow-auto divide-y divide-gray-300 dark:divide-gray-600 border-b border-gray-300 dark:border-gray-600;
105+
@apply flex-col flex overflow-auto divide-y divide-gray-300 dark:divide-gray-600 border-b border-gray-300 dark:border-gray-600;
92106
}
93107
94108
.layout-sidebar__link {
@@ -103,6 +117,10 @@ export default defineComponent({
103117
@apply fill-current;
104118
}
105119
120+
.layout-sidebar__connection-icon {
121+
@apply fill-current w-10 h-10 m-auto;
122+
}
123+
106124
.layout-sidebar__versions {
107125
@apply flex justify-center text-xs dark:text-gray-600 text-gray-400 py-2 px-1 left-0 right-0 flex-col mt-auto whitespace-nowrap text-center border-t border-gray-300 dark:border-gray-600;
108126

components/PreviewCard/PreviewCard.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import PreviewCardHeader from "~/components/PreviewCardHeader/PreviewCardHeader.
4848
import { NormalizedEvent } from "~/config/types";
4949
import moment from "moment";
5050
import { useNuxtApp } from "#app";
51-
import { REST_API_URL } from "~/utils/events-transport";
51+
import { REST_API_URL } from "~/utils/io";
5252
5353
export default defineComponent({
5454
components: {

components/RayDumpPreview/RayTypesPreview/LockPayload.vue

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,42 @@
11
<template>
22
<div class="ray-type-lock">
3-
<button :disabled="disabled" @click="continueExecution"
4-
class="btn btn--continue active:bg-grey-300">
5-
<span class="w-3 h-3 block">
6-
<svg xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" viewBox="0 0 20 20">
7-
<path fill="green" fill-rule="evenodd"
8-
d="M16.75 10.83L4.55 19A1 1 0 0 1 3 18.13V1.87A1 1 0 0 1 4.55 1l12.2 8.13a1 1 0 0 1 0 1.7z"/>
9-
</svg>
10-
</span>
3+
<button
4+
:disabled="disabled"
5+
class="btn btn--continue active:bg-grey-300"
6+
@click="continueExecution"
7+
>
8+
<span class="w-3 h-3 block">
9+
<svg
10+
xmlns="http://www.w3.org/2000/svg"
11+
width="100%"
12+
height="100%"
13+
viewBox="0 0 20 20"
14+
>
15+
<path
16+
fill="green"
17+
fill-rule="evenodd"
18+
d="M16.75 10.83L4.55 19A1 1 0 0 1 3 18.13V1.87A1 1 0 0 1 4.55 1l12.2 8.13a1 1 0 0 1 0 1.7z"
19+
/>
20+
</svg>
21+
</span>
1122

1223
<span>Continue</span>
1324
</button>
14-
<button :disabled="disabled" @click="stopExecution"
15-
class="btn btn--stop active:bg-grey-300">
25+
<button
26+
:disabled="disabled"
27+
class="btn btn--stop active:bg-grey-300"
28+
@click="stopExecution"
29+
>
1630
<span class="w-3 h-3 bg-red-700 block"></span>
1731
<span>Stop execution</span>
1832
</button>
1933
</div>
2034
</template>
2135

2236
<script lang="ts">
23-
import {defineComponent, PropType} from "vue";
24-
import {RayPayload} from "~/config/types";
25-
import {apiTransport} from '~/utils/events-transport'
26-
27-
const {
28-
rayStopExecution,
29-
rayContinueExecution
30-
} = apiTransport({onEventReceiveCb: () => {}})
37+
import { defineComponent, PropType } from "vue";
38+
import { RayPayload } from "~/config/types";
39+
import { useNuxtApp } from "#app";
3140
3241
export default defineComponent({
3342
props: {
@@ -36,26 +45,41 @@ export default defineComponent({
3645
required: true,
3746
},
3847
},
48+
setup() {
49+
if (process.client) {
50+
const { $rayExecution } = useNuxtApp();
51+
52+
return {
53+
rayContinueExecution: $rayExecution.continue,
54+
rayStopExecution: $rayExecution.stop,
55+
};
56+
}
57+
58+
return {
59+
rayContinueExecution: () => undefined,
60+
rayStopExecution: () => undefined,
61+
};
62+
},
3963
data() {
4064
return {
4165
disabled: false,
42-
}
66+
};
67+
},
68+
computed: {
69+
hash() {
70+
return this.payload.content.name;
71+
},
4372
},
4473
methods: {
4574
continueExecution() {
46-
this.disabled = true
47-
rayContinueExecution(this.hash)
75+
this.disabled = true;
76+
this.rayContinueExecution(this.hash);
4877
},
4978
stopExecution() {
50-
this.disabled = true
51-
rayStopExecution(this.hash)
52-
}
79+
this.disabled = true;
80+
this.rayStopExecution(this.hash);
81+
},
5382
},
54-
computed: {
55-
hash() {
56-
return this.payload.content.name
57-
}
58-
}
5983
});
6084
</script>
6185

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
import {Meta, Story} from "@storybook/vue3";
2-
import Attachment from '~/components/Attachment/Attachment.vue';
2+
import SmtpAttachment from '~/components/SmtpAttachment/SmtpAttachment.vue';
33

44
export default {
55
title: "Components/Attachment",
6-
component: Attachment
7-
} as Meta<typeof Attachment>;
6+
component: SmtpAttachment
7+
} as Meta<typeof SmtpAttachment>;
88

99
const Template: Story = (args) => ({
10-
components: {Attachment},
10+
components: {SmtpAttachment},
1111
setup() {
1212
return {
1313
args,
1414
};
1515
},
1616
template: `
17-
<Attachment v-bind="args"/>`,
17+
<SmtpAttachment v-bind="args"/>`,
1818
});
1919

2020
export const Default = Template.bind({});
@@ -27,5 +27,5 @@ Default.args = {
2727
size: 234234,
2828
mime: "text/plain",
2929
uri: 'example.com/attachment.txt',
30-
}
30+
},
3131
};

components/Attachment/Attachment.vue renamed to components/SmtpAttachment/SmtpAttachment.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
<script lang="ts">
2424
import { defineComponent, PropType } from "vue";
25-
import { NormalizedEvent, Attachment } from "~/config/types";
26-
import { REST_API_URL } from "~/utils/events-transport";
25+
import { NormalizedEvent, SmtpAttachment } from "~/config/types";
26+
import { REST_API_URL } from "~/utils/io";
2727
import { humanFileSize } from "~/utils/formats";
2828
2929
export default defineComponent({
@@ -33,7 +33,7 @@ export default defineComponent({
3333
required: true,
3434
},
3535
attachment: {
36-
type: Object as PropType<Attachment>,
36+
type: Object as PropType<SmtpAttachment>,
3737
required: true,
3838
},
3939
},
@@ -42,7 +42,7 @@ export default defineComponent({
4242
return `${REST_API_URL}/api/smtp/${this.event.id}/attachment/${this.attachment.id}`;
4343
},
4444
size(): string {
45-
return humanFileSize(this.attachment.size);
45+
return humanFileSize(this.attachment.size || 0);
4646
},
4747
},
4848
});
@@ -60,7 +60,7 @@ export default defineComponent({
6060
}
6161
6262
.attachment--meta {
63-
@apple flex flex-col justify-start;
63+
@apply flex flex-col justify-start;
6464
}
6565
6666
.attachment--name {

components/SmtpPage/SmtpPage.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
</h3>
8484

8585
<div class="flex gap-x-3">
86-
<Attachment
86+
<SmtpAttachment
8787
v-for="a in attachments"
8888
:key="a.id"
8989
:event="event"
@@ -108,7 +108,7 @@ import SmtpPagePreview from "~/components/SmtpPagePreview/SmtpPagePreview.vue";
108108
import SmtpPageAddresses from "~/components/SmtpPageAddresses/SmtpPageAddresses.vue";
109109
import EventTable from "~/components/EventTable/EventTable.vue";
110110
import EventTableRow from "~/components/EventTableRow/EventTableRow.vue";
111-
import Attachment from "~/components/Attachment/Attachment.vue";
111+
import SmtpAttachment from "~/components/SmtpAttachment/SmtpAttachment.vue";
112112
113113
export default defineComponent({
114114
components: {
@@ -119,7 +119,7 @@ export default defineComponent({
119119
CodeSnippet,
120120
Tabs,
121121
Tab,
122-
Attachment,
122+
SmtpAttachment,
123123
},
124124
props: {
125125
event: {

config/types.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,11 @@ export interface RayDump {
251251

252252

253253
export interface SmtpAttachment {
254-
"name": string,
255-
"id": string,
256-
"uri": string
254+
name: string,
255+
id: string,
256+
uri: string,
257+
size?: number,
258+
mime?: string,
257259
}
258260

259261
export interface HttpDumpFile {

layouts/default.vue

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
<div class="main-layout">
33
<LayoutSidebar
44
class="main-layout__sidebar"
5-
:is-connected="isConnected"
65
:api-version="apiVersion"
76
:client-version="clientVersion"
87
/>
@@ -16,7 +15,7 @@
1615
<script lang="ts">
1716
import LayoutSidebar from "~/components/LayoutSidebar/LayoutSidebar.vue";
1817
import { defineComponent } from "vue";
19-
import { THEME_MODES, useSettingsStore } from "~/stores/settings";
18+
import { useSettingsStore } from "~/stores/settings";
2019
import { storeToRefs } from "pinia";
2120
import { useNuxtApp } from "#app";
2221
@@ -59,12 +58,6 @@ export default defineComponent({
5958
apiVersion: "@dev",
6059
};
6160
},
62-
computed: {
63-
isConnected() {
64-
// return this.$store.getters['ws/connected']
65-
return false;
66-
},
67-
},
6861
});
6962
</script>
7063

pages/http-dumps/[id].vue

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,17 @@ export default defineComponent({
4040
4141
if (process.client) {
4242
const { $events } = useNuxtApp();
43-
const { data: event, pending } = await useFetch(
44-
$events.buildItemFetchUrl(eventId),
45-
{
46-
onResponse({ response }) {
47-
return response.data;
48-
},
49-
onResponseError() {
50-
router.push("/404");
51-
},
52-
onRequestError() {
53-
router.push("/404");
54-
},
55-
}
56-
);
43+
const { data: event, pending } = await useFetch($events.getUrl(eventId), {
44+
onResponse({ response }) {
45+
return response.data;
46+
},
47+
onResponseError() {
48+
router.push("/404");
49+
},
50+
onRequestError() {
51+
router.push("/404");
52+
},
53+
});
5754
5855
return {
5956
serverEvent: event,

0 commit comments

Comments
 (0)