history.ts (hoppscotch-2.2.1) | : | history.ts (hoppscotch-3.0.0) | ||
---|---|---|---|---|
import eq from "lodash/eq" | import { isEqual } from "lodash-es" | |||
import { pluck } from "rxjs/operators" | import { pluck } from "rxjs/operators" | |||
import { | import { | |||
HoppRESTRequest, | HoppRESTRequest, | |||
translateToNewRequest, | translateToNewRequest, | |||
HoppGQLRequest, | HoppGQLRequest, | |||
translateToGQLRequest, | translateToGQLRequest, | |||
GQL_REQ_SCHEMA_VERSION, | ||||
} from "@hoppscotch/data" | } from "@hoppscotch/data" | |||
import DispatchingStore, { defineDispatchers } from "./DispatchingStore" | import DispatchingStore, { defineDispatchers } from "./DispatchingStore" | |||
import { completedRESTResponse$ } from "./RESTSession" | import { completedRESTResponse$ } from "./RESTSession" | |||
export type RESTHistoryEntry = { | export type RESTHistoryEntry = { | |||
v: number | v: number | |||
request: HoppRESTRequest | request: HoppRESTRequest | |||
responseMeta: { | responseMeta: { | |||
skipping to change at line 86 | skipping to change at line 87 | |||
}, | }, | |||
updatedOn, | updatedOn, | |||
}) | }) | |||
if (x.id) obj.id = x.id | if (x.id) obj.id = x.id | |||
return obj | return obj | |||
} | } | |||
export function translateToNewGQLHistory(x: any): GQLHistoryEntry { | export function translateToNewGQLHistory(x: any): GQLHistoryEntry { | |||
if (x.v === 1) return x | if (x.v === 1 && x.request.v === GQL_REQ_SCHEMA_VERSION) return x | |||
// Legacy | // Legacy | |||
const request = translateToGQLRequest(x) | const request = x.request | |||
? translateToGQLRequest(x.request) | ||||
: translateToGQLRequest(x) | ||||
const star = x.star ?? false | const star = x.star ?? false | |||
const response = x.response ?? "" | const response = x.response ?? "" | |||
const updatedOn = x.updatedOn ?? "" | const updatedOn = x.updatedOn ?? "" | |||
const obj: GQLHistoryEntry = makeGQLHistoryEntry({ | const obj: GQLHistoryEntry = makeGQLHistoryEntry({ | |||
request, | request, | |||
star, | star, | |||
response, | response, | |||
updatedOn, | updatedOn, | |||
}) | }) | |||
skipping to change at line 138 | skipping to change at line 141 | |||
) { | ) { | |||
return { | return { | |||
state: [entry, ...currentVal.state].slice(0, HISTORY_LIMIT), | state: [entry, ...currentVal.state].slice(0, HISTORY_LIMIT), | |||
} | } | |||
}, | }, | |||
deleteEntry( | deleteEntry( | |||
currentVal: RESTHistoryType, | currentVal: RESTHistoryType, | |||
{ entry }: { entry: RESTHistoryEntry } | { entry }: { entry: RESTHistoryEntry } | |||
) { | ) { | |||
return { | return { | |||
state: currentVal.state.filter((e) => !eq(e, entry)), | state: currentVal.state.filter((e) => !isEqual(e, entry)), | |||
} | } | |||
}, | }, | |||
clearHistory() { | clearHistory() { | |||
return { | return { | |||
state: [], | state: [], | |||
} | } | |||
}, | }, | |||
toggleStar( | toggleStar( | |||
currentVal: RESTHistoryType, | currentVal: RESTHistoryType, | |||
{ entry }: { entry: RESTHistoryEntry } | { entry }: { entry: RESTHistoryEntry } | |||
) { | ) { | |||
return { | return { | |||
state: currentVal.state.map((e) => { | state: currentVal.state.map((e) => { | |||
if (eq(e, entry) && e.star !== undefined) { | if (isEqual(e, entry) && e.star !== undefined) { | |||
return { | return { | |||
...e, | ...e, | |||
star: !e.star, | star: !e.star, | |||
} | } | |||
} | } | |||
return e | return e | |||
}), | }), | |||
} | } | |||
}, | }, | |||
}) | }) | |||
skipping to change at line 186 | skipping to change at line 189 | |||
) { | ) { | |||
return { | return { | |||
state: [entry, ...currentVal.state].slice(0, HISTORY_LIMIT), | state: [entry, ...currentVal.state].slice(0, HISTORY_LIMIT), | |||
} | } | |||
}, | }, | |||
deleteEntry( | deleteEntry( | |||
currentVal: GraphqlHistoryType, | currentVal: GraphqlHistoryType, | |||
{ entry }: { entry: GQLHistoryEntry } | { entry }: { entry: GQLHistoryEntry } | |||
) { | ) { | |||
return { | return { | |||
state: currentVal.state.filter((e) => !eq(e, entry)), | state: currentVal.state.filter((e) => !isEqual(e, entry)), | |||
} | } | |||
}, | }, | |||
clearHistory() { | clearHistory() { | |||
return { | return { | |||
state: [], | state: [], | |||
} | } | |||
}, | }, | |||
toggleStar( | toggleStar( | |||
currentVal: GraphqlHistoryType, | currentVal: GraphqlHistoryType, | |||
{ entry }: { entry: GQLHistoryEntry } | { entry }: { entry: GQLHistoryEntry } | |||
) { | ) { | |||
return { | return { | |||
state: currentVal.state.map((e) => { | state: currentVal.state.map((e) => { | |||
if (eq(e, entry) && e.star !== undefined) { | if (isEqual(e, entry) && e.star !== undefined) { | |||
return { | return { | |||
...e, | ...e, | |||
star: !e.star, | star: !e.star, | |||
} | } | |||
} | } | |||
return e | return e | |||
}), | }), | |||
} | } | |||
}, | }, | |||
}) | }) | |||
End of changes. 8 change blocks. | ||||
7 lines changed or deleted | 10 lines changed or added |