feat: use example gen for multiple example value retainer examples (#6920)

* fix: multiple examples with same value jumps to first example
This commit is contained in:
Mahtis Michel
2021-02-11 18:33:04 +01:00
committed by GitHub
parent 649be5d78b
commit fad81f8cb9
2 changed files with 26 additions and 8 deletions

View File

@@ -189,7 +189,7 @@ export default class ExamplesSelectValueRetainer extends React.PureComponent {
nextProps
)
const exampleMatchingNewValue = examples.find(
const examplesMatchingNewValue = examples.filter(
(example) =>
example.get("value") === newValue ||
// sometimes data is stored as a string (e.g. in Request Bodies), so
@@ -197,8 +197,15 @@ export default class ExamplesSelectValueRetainer extends React.PureComponent {
stringify(example.get("value")) === newValue
)
if (exampleMatchingNewValue) {
onSelect(examples.keyOf(exampleMatchingNewValue), {
if (examplesMatchingNewValue.size) {
let key
if(examplesMatchingNewValue.has(nextProps.currentKey))
{
key = nextProps.currentKey
} else {
key = examplesMatchingNewValue.keySeq().first()
}
onSelect(key, {
isSyntheticChange: true,
})
} else if (