fix: add missing field and translateToNewRequest for history (#6068)

This commit is contained in:
Nivedin 2026-03-30 15:27:54 +05:30 committed by GitHub
parent ad4041e51a
commit 40d65dba49
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 36 additions and 70 deletions

View file

@ -341,22 +341,14 @@ export function removeDuplicateGraphqlHistoryEntry(id: string) {
// Listen to completed responses to add to history // Listen to completed responses to add to history
executedResponses$.subscribe((res) => { executedResponses$.subscribe((res) => {
// Spread to auto-capture any future fields, but omit _ref_id and id
// since history entries are snapshots and shouldn't carry collection/firestore references
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { _ref_id, id, ...request } = res.req
addRESTHistoryEntry( addRESTHistoryEntry(
makeRESTHistoryEntry({ makeRESTHistoryEntry({
request: { request,
auth: res.req.auth,
body: res.req.body,
endpoint: res.req.endpoint,
headers: res.req.headers,
method: res.req.method,
name: res.req.name,
params: res.req.params,
preRequestScript: res.req.preRequestScript,
testScript: res.req.testScript,
requestVariables: res.req.requestVariables,
v: res.req.v,
responses: res.req.responses,
},
responseMeta: { responseMeta: {
duration: res.meta.responseDuration, duration: res.meta.responseDuration,
statusCode: res.statusCode, statusCode: res.statusCode,

View file

@ -15,6 +15,7 @@ import {
deleteGraphqlHistoryEntry, deleteGraphqlHistoryEntry,
clearGraphqlHistory, clearGraphqlHistory,
} from "@hoppscotch/common/newstore/history" } from "@hoppscotch/common/newstore/history"
import { translateToNewRequest, translateToGQLRequest } from "@hoppscotch/data"
import { HistoryPlatformDef } from "@hoppscotch/common/platform/history" import { HistoryPlatformDef } from "@hoppscotch/common/platform/history"
import { import {
getUserHistoryEntries, getUserHistoryEntries,
@ -98,7 +99,7 @@ async function loadHistoryEntries() {
const restHistoryEntries: RESTHistoryEntry[] = restEntries.map((entry) => ({ const restHistoryEntries: RESTHistoryEntry[] = restEntries.map((entry) => ({
v: 1, v: 1,
request: JSON.parse(entry.request), request: translateToNewRequest(JSON.parse(entry.request)),
responseMeta: JSON.parse(entry.responseMetadata), responseMeta: JSON.parse(entry.responseMetadata),
star: entry.isStarred, star: entry.isStarred,
updatedOn: new Date(entry.executedOn), updatedOn: new Date(entry.executedOn),
@ -107,7 +108,7 @@ async function loadHistoryEntries() {
const gqlHistoryEntries: GQLHistoryEntry[] = gqlEntries.map((entry) => ({ const gqlHistoryEntries: GQLHistoryEntry[] = gqlEntries.map((entry) => ({
v: 1, v: 1,
request: JSON.parse(entry.request), request: translateToGQLRequest(JSON.parse(entry.request)),
response: JSON.parse(entry.responseMetadata), response: JSON.parse(entry.responseMetadata),
star: entry.isStarred, star: entry.isStarred,
updatedOn: new Date(entry.executedOn), updatedOn: new Date(entry.executedOn),
@ -165,7 +166,7 @@ function setupUserHistoryCreatedSubscription() {
? addRESTHistoryEntry({ ? addRESTHistoryEntry({
v: 1, v: 1,
id, id,
request: JSON.parse(request), request: translateToNewRequest(JSON.parse(request)),
responseMeta: JSON.parse(responseMetadata), responseMeta: JSON.parse(responseMetadata),
star: isStarred, star: isStarred,
updatedOn: new Date(executedOn), updatedOn: new Date(executedOn),
@ -173,7 +174,7 @@ function setupUserHistoryCreatedSubscription() {
: addGraphqlHistoryEntry({ : addGraphqlHistoryEntry({
v: 1, v: 1,
id, id,
request: JSON.parse(request), request: translateToGQLRequest(JSON.parse(request)),
response: JSON.parse(responseMetadata), response: JSON.parse(responseMetadata),
star: isStarred, star: isStarred,
updatedOn: new Date(executedOn), updatedOn: new Date(executedOn),
@ -192,45 +193,31 @@ function setupUserHistoryUpdatedSubscription() {
userHistoryUpdated$.subscribe((res) => { userHistoryUpdated$.subscribe((res) => {
if (E.isRight(res)) { if (E.isRight(res)) {
const { id, executedOn, isStarred, request, responseMetadata, reqType } = const { id, reqType, isStarred } = res.right.userHistoryUpdated
res.right.userHistoryUpdated
if (reqType == ReqType.Rest) { if (reqType == ReqType.Rest) {
const updatedRestEntryIndex = restHistoryStore.value.state.findIndex( const existingEntry = restHistoryStore.value.state.find(
(entry) => entry.id == id (entry) => entry.id == id
) )
if (updatedRestEntryIndex != -1) { // Only toggle if the store entry's star doesn't match the server state.
// Without this guard, the subscription echo from the same client's own
// toggle would cause a second toggle and revert the star.
if (existingEntry && existingEntry.star !== isStarred) {
runDispatchWithOutSyncing(() => { runDispatchWithOutSyncing(() => {
toggleRESTHistoryEntryStar({ toggleRESTHistoryEntryStar(existingEntry)
v: 1,
id,
request: JSON.parse(request),
responseMeta: JSON.parse(responseMetadata),
// because the star will be toggled in the store, we need to pass the opposite value
star: !isStarred,
updatedOn: new Date(executedOn),
})
}) })
} }
} }
if (reqType == ReqType.Gql) { if (reqType == ReqType.Gql) {
const updatedGQLEntryIndex = graphqlHistoryStore.value.state.findIndex( const existingEntry = graphqlHistoryStore.value.state.find(
(entry) => entry.id == id (entry) => entry.id == id
) )
if (updatedGQLEntryIndex != -1) { if (existingEntry && existingEntry.star !== isStarred) {
runDispatchWithOutSyncing(() => { runDispatchWithOutSyncing(() => {
toggleGraphqlHistoryEntryStar({ toggleGraphqlHistoryEntryStar(existingEntry)
v: 1,
id,
request: JSON.parse(request),
response: JSON.parse(responseMetadata),
// because the star will be toggled in the store, we need to pass the opposite value
star: !isStarred,
updatedOn: new Date(executedOn),
})
}) })
} }
} }

View file

@ -15,6 +15,7 @@ import {
deleteGraphqlHistoryEntry, deleteGraphqlHistoryEntry,
clearGraphqlHistory, clearGraphqlHistory,
} from "@hoppscotch/common/newstore/history" } from "@hoppscotch/common/newstore/history"
import { translateToNewRequest, translateToGQLRequest } from "@hoppscotch/data"
import { HistoryPlatformDef } from "@hoppscotch/common/platform/history" import { HistoryPlatformDef } from "@hoppscotch/common/platform/history"
import { import {
getUserHistoryEntries, getUserHistoryEntries,
@ -101,7 +102,7 @@ async function loadHistoryEntries() {
const restHistoryEntries: RESTHistoryEntry[] = restEntries.map((entry) => ({ const restHistoryEntries: RESTHistoryEntry[] = restEntries.map((entry) => ({
v: 1, v: 1,
request: JSON.parse(entry.request), request: translateToNewRequest(JSON.parse(entry.request)),
responseMeta: JSON.parse(entry.responseMetadata), responseMeta: JSON.parse(entry.responseMetadata),
star: entry.isStarred, star: entry.isStarred,
updatedOn: new Date(entry.executedOn), updatedOn: new Date(entry.executedOn),
@ -110,7 +111,7 @@ async function loadHistoryEntries() {
const gqlHistoryEntries: GQLHistoryEntry[] = gqlEntries.map((entry) => ({ const gqlHistoryEntries: GQLHistoryEntry[] = gqlEntries.map((entry) => ({
v: 1, v: 1,
request: JSON.parse(entry.request), request: translateToGQLRequest(JSON.parse(entry.request)),
response: JSON.parse(entry.responseMetadata), response: JSON.parse(entry.responseMetadata),
star: entry.isStarred, star: entry.isStarred,
updatedOn: new Date(entry.executedOn), updatedOn: new Date(entry.executedOn),
@ -168,7 +169,7 @@ function setupUserHistoryCreatedSubscription() {
? addRESTHistoryEntry({ ? addRESTHistoryEntry({
v: 1, v: 1,
id, id,
request: JSON.parse(request), request: translateToNewRequest(JSON.parse(request)),
responseMeta: JSON.parse(responseMetadata), responseMeta: JSON.parse(responseMetadata),
star: isStarred, star: isStarred,
updatedOn: new Date(executedOn), updatedOn: new Date(executedOn),
@ -176,7 +177,7 @@ function setupUserHistoryCreatedSubscription() {
: addGraphqlHistoryEntry({ : addGraphqlHistoryEntry({
v: 1, v: 1,
id, id,
request: JSON.parse(request), request: translateToGQLRequest(JSON.parse(request)),
response: JSON.parse(responseMetadata), response: JSON.parse(responseMetadata),
star: isStarred, star: isStarred,
updatedOn: new Date(executedOn), updatedOn: new Date(executedOn),
@ -195,45 +196,31 @@ function setupUserHistoryUpdatedSubscription() {
userHistoryUpdated$.subscribe((res) => { userHistoryUpdated$.subscribe((res) => {
if (E.isRight(res)) { if (E.isRight(res)) {
const { id, executedOn, isStarred, request, responseMetadata, reqType } = const { id, reqType, isStarred } = res.right.userHistoryUpdated
res.right.userHistoryUpdated
if (reqType == ReqType.Rest) { if (reqType == ReqType.Rest) {
const updatedRestEntryIndex = restHistoryStore.value.state.findIndex( const existingEntry = restHistoryStore.value.state.find(
(entry) => entry.id == id (entry) => entry.id == id
) )
if (updatedRestEntryIndex != -1) { // Only toggle if the store entry's star doesn't match the server state.
// Without this guard, the subscription echo from the same client's own
// toggle would cause a second toggle and revert the star.
if (existingEntry && existingEntry.star !== isStarred) {
runDispatchWithOutSyncing(() => { runDispatchWithOutSyncing(() => {
toggleRESTHistoryEntryStar({ toggleRESTHistoryEntryStar(existingEntry)
v: 1,
id,
request: JSON.parse(request),
responseMeta: JSON.parse(responseMetadata),
// because the star will be toggled in the store, we need to pass the opposite value
star: !isStarred,
updatedOn: new Date(executedOn),
})
}) })
} }
} }
if (reqType == ReqType.Gql) { if (reqType == ReqType.Gql) {
const updatedGQLEntryIndex = graphqlHistoryStore.value.state.findIndex( const existingEntry = graphqlHistoryStore.value.state.find(
(entry) => entry.id == id (entry) => entry.id == id
) )
if (updatedGQLEntryIndex != -1) { if (existingEntry && existingEntry.star !== isStarred) {
runDispatchWithOutSyncing(() => { runDispatchWithOutSyncing(() => {
toggleGraphqlHistoryEntryStar({ toggleGraphqlHistoryEntryStar(existingEntry)
v: 1,
id,
request: JSON.parse(request),
response: JSON.parse(responseMetadata),
// because the star will be toggled in the store, we need to pass the opposite value
star: !isStarred,
updatedOn: new Date(executedOn),
})
}) })
} }
} }