fix: history entries becoming undefined over reloads

This commit is contained in:
Andrew Bastin
2021-08-23 12:34:30 +05:30
parent 97b92ba35b
commit f20fed444a
2 changed files with 26 additions and 9 deletions

View File

@@ -144,7 +144,7 @@ export default defineComponent({
})
},
useHistory(entry: any) {
if (this.page === "rest") setRESTRequest(entry)
if (this.page === "rest") setRESTRequest(entry.request)
},
deleteHistory(entry: any) {
if (this.page === "rest") deleteRESTHistoryEntry(entry)

View File

@@ -8,6 +8,8 @@ import {
} from "~/helpers/types/HoppRESTRequest"
export type RESTHistoryEntry = {
v: number
request: HoppRESTRequest
responseMeta: {
@@ -20,13 +22,26 @@ export type RESTHistoryEntry = {
id?: string // For when Firebase Firestore is set
}
export function makeHistoryEntry(
x: Omit<RESTHistoryEntry, "v">
): RESTHistoryEntry {
return {
v: 1,
...x,
}
}
export function translateToNewRESTHistory(x: any): RESTHistoryEntry {
if (x.v === 1) return x
// Legacy
const request = translateToNewRequest(x)
const star = x.star ?? false
const duration = x.duration ?? null
const statusCode = x.status ?? null
const obj: RESTHistoryEntry = {
v: 1,
request,
star,
responseMeta: {
@@ -222,13 +237,15 @@ completedRESTResponse$.subscribe((res) => {
if (res !== null) {
if (res.type === "loading" || res.type === "network_fail") return
addRESTHistoryEntry({
request: res.req,
responseMeta: {
duration: res.meta.responseDuration,
statusCode: res.statusCode,
},
star: false,
})
addRESTHistoryEntry(
makeHistoryEntry({
request: res.req,
responseMeta: {
duration: res.meta.responseDuration,
statusCode: res.statusCode,
},
star: false,
})
)
}
})