mirror of
https://github.com/usebruno/bruno.git
synced 2026-06-27 06:34:06 +00:00
fix: correct the request type tabs in the snapshot (#7994)
This commit is contained in:
@@ -93,7 +93,7 @@ const useOpenAPISync = (collection) => {
|
||||
uid: itemUid,
|
||||
collectionUid: collection.uid,
|
||||
requestPaneTab: item ? getDefaultRequestPaneTab(item) : undefined,
|
||||
type: 'request'
|
||||
type: item?.type ?? 'request'
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -34,6 +34,8 @@ taskMiddleware.startListening({
|
||||
addTab({
|
||||
uid: item.uid,
|
||||
collectionUid: collection.uid,
|
||||
type: item.type,
|
||||
pathname: item.pathname,
|
||||
requestPaneTab: getDefaultRequestPaneTab(item),
|
||||
preview: task?.preview ?? true,
|
||||
...(item.isTransient ? { isTransient: true } : {})
|
||||
|
||||
@@ -349,6 +349,18 @@ const getAccessor = (tab) => {
|
||||
return 'pathname';
|
||||
};
|
||||
|
||||
const getDefaultRequestPaneTabForType = (type) => {
|
||||
if (type === 'grpc-request' || type === 'ws-request') {
|
||||
return 'body';
|
||||
}
|
||||
|
||||
if (type === 'graphql-request') {
|
||||
return 'query';
|
||||
}
|
||||
|
||||
return 'params';
|
||||
};
|
||||
|
||||
export const serializeTab = (tab, collection) => {
|
||||
const accessor = getAccessor(tab);
|
||||
const serialized = {
|
||||
@@ -436,6 +448,7 @@ export const isActiveTab = (tab, activeTab, collection) => {
|
||||
|
||||
export const deserializeTab = (snapshotTab, collection) => {
|
||||
const { accessor, pathname, exampleName, type } = snapshotTab;
|
||||
const restoredRequestPaneTab = typeof snapshotTab.request?.tab === 'string' ? snapshotTab.request.tab : null;
|
||||
|
||||
const tab = {
|
||||
collectionUid: collection.uid,
|
||||
@@ -443,7 +456,7 @@ export const deserializeTab = (snapshotTab, collection) => {
|
||||
preview: !snapshotTab.permanent,
|
||||
name: snapshotTab.name || null,
|
||||
pathname: pathname || null,
|
||||
requestPaneTab: snapshotTab.request?.tab || 'params',
|
||||
requestPaneTab: restoredRequestPaneTab || getDefaultRequestPaneTabForType(type),
|
||||
requestPaneWidth: snapshotTab.request?.width || null,
|
||||
requestPaneHeight: snapshotTab.request?.height || null,
|
||||
responsePaneTab: snapshotTab.response?.tab || 'response',
|
||||
@@ -461,6 +474,11 @@ export const deserializeTab = (snapshotTab, collection) => {
|
||||
|
||||
if (accessor === 'pathname' && pathname) {
|
||||
const item = findItemInCollectionByPathname(collection, pathname);
|
||||
const resolvedType = item?.type || type;
|
||||
tab.type = resolvedType;
|
||||
if (!restoredRequestPaneTab) {
|
||||
tab.requestPaneTab = getDefaultRequestPaneTabForType(resolvedType);
|
||||
}
|
||||
tab.uid = item?.uid || pathname;
|
||||
if (type === 'folder-settings') {
|
||||
tab.folderUid = item?.uid || pathname;
|
||||
|
||||
@@ -279,6 +279,114 @@ describe('deserializeTab', () => {
|
||||
const tab = deserializeTab(snapshotTab, collection);
|
||||
expect(tab.uid).toBe('collection-uid-preferences');
|
||||
});
|
||||
|
||||
it('defaults grpc request pane to body when snapshot request tab is missing', () => {
|
||||
const snapshotTab = {
|
||||
type: 'grpc-request',
|
||||
accessor: 'pathname',
|
||||
pathname: '/collections/a/grpc-request.bru',
|
||||
permanent: true
|
||||
};
|
||||
|
||||
const tab = deserializeTab(snapshotTab, collection);
|
||||
expect(tab.requestPaneTab).toBe('body');
|
||||
});
|
||||
|
||||
it('defaults websocket request pane to body when snapshot request tab is missing', () => {
|
||||
const snapshotTab = {
|
||||
type: 'ws-request',
|
||||
accessor: 'pathname',
|
||||
pathname: '/collections/a/ws-request.bru',
|
||||
permanent: true
|
||||
};
|
||||
|
||||
const tab = deserializeTab(snapshotTab, collection);
|
||||
expect(tab.requestPaneTab).toBe('body');
|
||||
});
|
||||
|
||||
it('resolves generic request snapshot type to item type using pathname', () => {
|
||||
const collectionWithGrpcItem = {
|
||||
...collection,
|
||||
items: [
|
||||
{
|
||||
uid: 'grpc-item-1',
|
||||
pathname: '/collections/a/grpc-item.bru',
|
||||
type: 'grpc-request'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const snapshotTab = {
|
||||
type: 'request',
|
||||
accessor: 'pathname',
|
||||
pathname: '/collections/a/grpc-item.bru',
|
||||
permanent: true
|
||||
};
|
||||
|
||||
const tab = deserializeTab(snapshotTab, collectionWithGrpcItem);
|
||||
expect(tab.type).toBe('grpc-request');
|
||||
expect(tab.requestPaneTab).toBe('body');
|
||||
});
|
||||
|
||||
it('defaults to body for resolved websocket item type when generic snapshot request tab is missing', () => {
|
||||
const collectionWithWsItem = {
|
||||
...collection,
|
||||
items: [
|
||||
{
|
||||
uid: 'ws-item-1',
|
||||
pathname: '/collections/a/ws-item.bru',
|
||||
type: 'ws-request'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const snapshotTab = {
|
||||
type: 'request',
|
||||
accessor: 'pathname',
|
||||
pathname: '/collections/a/ws-item.bru',
|
||||
permanent: true
|
||||
};
|
||||
|
||||
const tab = deserializeTab(snapshotTab, collectionWithWsItem);
|
||||
expect(tab.type).toBe('ws-request');
|
||||
expect(tab.requestPaneTab).toBe('body');
|
||||
});
|
||||
|
||||
it('defaults graphql request pane to query when snapshot request tab is missing', () => {
|
||||
const snapshotTab = {
|
||||
type: 'graphql-request',
|
||||
accessor: 'pathname',
|
||||
pathname: '/collections/a/graphql-request.bru',
|
||||
permanent: true
|
||||
};
|
||||
|
||||
const tab = deserializeTab(snapshotTab, collection);
|
||||
expect(tab.requestPaneTab).toBe('query');
|
||||
});
|
||||
|
||||
it('resolves generic request snapshot type to graphql-request item type using pathname', () => {
|
||||
const collectionWithGraphqlItem = {
|
||||
...collection,
|
||||
items: [
|
||||
{
|
||||
uid: 'graphql-item-1',
|
||||
pathname: '/collections/a/graphql-item.bru',
|
||||
type: 'graphql-request'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
const snapshotTab = {
|
||||
type: 'request',
|
||||
accessor: 'pathname',
|
||||
pathname: '/collections/a/graphql-item.bru',
|
||||
permanent: true
|
||||
};
|
||||
|
||||
const tab = deserializeTab(snapshotTab, collectionWithGraphqlItem);
|
||||
expect(tab.type).toBe('graphql-request');
|
||||
expect(tab.requestPaneTab).toBe('query');
|
||||
});
|
||||
});
|
||||
|
||||
describe('hydrateCollectionTabs', () => {
|
||||
|
||||
Reference in New Issue
Block a user