mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-09 06:55:03 +00:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
|
||||
|
||||
@@ -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
|
||||
}));
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user