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:
@@ -189,7 +189,7 @@ export default class ExamplesSelectValueRetainer extends React.PureComponent {
|
|||||||
nextProps
|
nextProps
|
||||||
)
|
)
|
||||||
|
|
||||||
const exampleMatchingNewValue = examples.find(
|
const examplesMatchingNewValue = examples.filter(
|
||||||
(example) =>
|
(example) =>
|
||||||
example.get("value") === newValue ||
|
example.get("value") === newValue ||
|
||||||
// sometimes data is stored as a string (e.g. in Request Bodies), so
|
// 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
|
stringify(example.get("value")) === newValue
|
||||||
)
|
)
|
||||||
|
|
||||||
if (exampleMatchingNewValue) {
|
if (examplesMatchingNewValue.size) {
|
||||||
onSelect(examples.keyOf(exampleMatchingNewValue), {
|
let key
|
||||||
|
if(examplesMatchingNewValue.has(nextProps.currentKey))
|
||||||
|
{
|
||||||
|
key = nextProps.currentKey
|
||||||
|
} else {
|
||||||
|
key = examplesMatchingNewValue.keySeq().first()
|
||||||
|
}
|
||||||
|
onSelect(key, {
|
||||||
isSyntheticChange: true,
|
isSyntheticChange: true,
|
||||||
})
|
})
|
||||||
} else if (
|
} else if (
|
||||||
|
|||||||
@@ -83,7 +83,18 @@ const RequestBody = ({
|
|||||||
|
|
||||||
const mediaTypeValue = requestBodyContent.get(contentType, OrderedMap())
|
const mediaTypeValue = requestBodyContent.get(contentType, OrderedMap())
|
||||||
const schemaForMediaType = mediaTypeValue.get("schema", OrderedMap())
|
const schemaForMediaType = mediaTypeValue.get("schema", OrderedMap())
|
||||||
const examplesForMediaType = mediaTypeValue.get("examples", null)
|
const rawExamplesOfMediaType = mediaTypeValue.get("examples", null)
|
||||||
|
const sampleForMediaType = rawExamplesOfMediaType?.map((container, key) => {
|
||||||
|
const val = container?.get("value", null)
|
||||||
|
if(val) {
|
||||||
|
container = container.set("value", getDefaultRequestBodyValue(
|
||||||
|
requestBody,
|
||||||
|
contentType,
|
||||||
|
key,
|
||||||
|
), val)
|
||||||
|
}
|
||||||
|
return container
|
||||||
|
})
|
||||||
|
|
||||||
const handleExamplesSelect = (key /*, { isSyntheticChange } */) => {
|
const handleExamplesSelect = (key /*, { isSyntheticChange } */) => {
|
||||||
updateActiveExamplesKey(key)
|
updateActiveExamplesKey(key)
|
||||||
@@ -223,10 +234,10 @@ const RequestBody = ({
|
|||||||
<Markdown source={requestBodyDescription} />
|
<Markdown source={requestBodyDescription} />
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
examplesForMediaType ? (
|
sampleForMediaType ? (
|
||||||
<ExamplesSelectValueRetainer
|
<ExamplesSelectValueRetainer
|
||||||
userHasEditedBody={userHasEditedBody}
|
userHasEditedBody={userHasEditedBody}
|
||||||
examples={examplesForMediaType}
|
examples={sampleForMediaType}
|
||||||
currentKey={activeExamplesKey}
|
currentKey={activeExamplesKey}
|
||||||
currentUserInputValue={requestBodyValue}
|
currentUserInputValue={requestBodyValue}
|
||||||
onSelect={handleExamplesSelect}
|
onSelect={handleExamplesSelect}
|
||||||
@@ -269,9 +280,9 @@ const RequestBody = ({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
examplesForMediaType ? (
|
sampleForMediaType ? (
|
||||||
<Example
|
<Example
|
||||||
example={examplesForMediaType.get(activeExamplesKey)}
|
example={sampleForMediaType.get(activeExamplesKey)}
|
||||||
getComponent={getComponent}
|
getComponent={getComponent}
|
||||||
getConfigs={getConfigs}
|
getConfigs={getConfigs}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user