fix: example-request tab collision (#7989)

* fix: prevent response-example tabs from hijacking request sidebar selection

* fix: add selectors for examples with index

* test: better locator

* fix: duplicate name collision

* fix: refactor sidebar example handling functions for better clarity and reusability

* chore: cr comments
This commit is contained in:
Sid
2026-05-13 21:47:39 +05:30
committed by GitHub
parent 4fa882c67c
commit 57d2fc7899
12 changed files with 574 additions and 24 deletions

View File

@@ -335,6 +335,9 @@ const RequestTabPanel = () => {
let example = null;
if (item?.examples) {
example = item.examples.find((ex) => ex.uid === focusedTab.uid);
if (!example && typeof focusedTab.exampleIndex === 'number' && focusedTab.exampleIndex >= 0) {
example = item.examples[focusedTab.exampleIndex] || null;
}
if (!example && focusedTab.exampleName) {
example = item.examples.find((ex) => ex.name === focusedTab.exampleName);
}

View File

@@ -26,11 +26,15 @@ const ExampleTab = ({ tab, collection }) => {
if (!item?.examples) return null;
const byUid = item.examples.find((ex) => ex.uid === tab.uid);
if (byUid) return byUid;
if (typeof tab.exampleIndex === 'number' && tab.exampleIndex >= 0) {
const byIndex = item.examples[tab.exampleIndex];
if (byIndex) return byIndex;
}
if (tab.exampleName) {
return item.examples.find((ex) => ex.name === tab.exampleName);
}
return null;
}, [item?.examples, tab.uid, tab.exampleName]);
}, [item?.examples, tab.uid, tab.exampleIndex, tab.exampleName]);
const hasChanges = useMemo(() => hasExampleChanges(item, example?.uid), [item, example?.uid]);

View File

@@ -37,13 +37,16 @@ const ExampleItem = ({ example, item, collection }) => {
const indents = range((item.depth || 0) + 1);
const handleExampleClick = () => {
const exampleIndex = item?.examples?.findIndex((ex) => ex.uid === example.uid);
dispatch(addTab({
uid: example.uid,
collectionUid: collection.uid,
type: 'response-example',
itemUid: item.uid,
pathname: item.pathname,
exampleName: example.name
exampleName: example.name,
exampleIndex: typeof exampleIndex === 'number' && exampleIndex >= 0 ? exampleIndex : undefined
}));
};