-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ajiang/trigger
- Loading branch information
Showing
41 changed files
with
1,190 additions
and
617 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/ui/app/src/playground/endpoint/PlaygroundEndpointAliasForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as ApiDefinition from "@fern-api/fdr-sdk/api-definition"; | ||
import { unwrapReference } from "@fern-api/fdr-sdk/api-definition"; | ||
import { ReactElement, useMemo } from "react"; | ||
import { PlaygroundObjectForm } from "../form/PlaygroundObjectForm"; | ||
import { PlaygroundTypeReferenceForm } from "../form/PlaygroundTypeReferenceForm"; | ||
import { PlaygroundEndpointFormSection } from "./PlaygroundEndpointFormSection"; | ||
|
||
interface PlaygroundEndpointAliasFormProps { | ||
alias: ApiDefinition.HttpRequestBodyShape.Alias; | ||
types: Record<ApiDefinition.TypeId, ApiDefinition.TypeDefinition>; | ||
ignoreHeaders: boolean; | ||
setBodyJson: (value: unknown) => void; | ||
value: unknown; | ||
} | ||
|
||
export function PlaygroundEndpointAliasForm({ | ||
alias, | ||
types, | ||
ignoreHeaders, | ||
setBodyJson, | ||
value, | ||
}: PlaygroundEndpointAliasFormProps): ReactElement { | ||
const { shape, isOptional } = useMemo(() => unwrapReference(alias.value, types), [alias.value, types]); | ||
|
||
if (shape.type === "object" && !isOptional) { | ||
return ( | ||
<PlaygroundEndpointFormSection ignoreHeaders={ignoreHeaders} title="Body Parameters"> | ||
<PlaygroundObjectForm id="body" shape={shape} onChange={setBodyJson} value={value} types={types} /> | ||
</PlaygroundEndpointFormSection> | ||
); | ||
} | ||
return ( | ||
<PlaygroundEndpointFormSection ignoreHeaders={ignoreHeaders} title={isOptional ? "Optional Body" : "Body"}> | ||
<PlaygroundTypeReferenceForm id="body" shape={shape} onChange={setBodyJson} value={value} types={types} /> | ||
</PlaygroundEndpointFormSection> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
packages/ui/app/src/playground/form/PlaygroundAdditionalProperties.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
// import { Property, TypeIdKey, TypeId } from "@fern-api/fdr-sdk/navigation"; | ||
import * as ApiDefinition from "@fern-api/fdr-sdk/api-definition"; | ||
import clsx from "clsx"; | ||
import { ReactElement, useCallback, useMemo } from "react"; | ||
import { noop } from "ts-essentials"; | ||
import { WithLabel } from "../WithLabel"; | ||
import { castToRecord } from "../utils"; | ||
import { PlaygroundMapForm } from "./PlaygroundMapForm"; | ||
|
||
const ADDITIONAL_PROPERTIES_KEY_SHAPE = { | ||
type: "primitive", | ||
value: { | ||
type: "string", | ||
regex: undefined, | ||
minLength: undefined, | ||
maxLength: undefined, | ||
default: undefined, | ||
}, | ||
} as const; | ||
|
||
const ADDITIONAL_PROPERTIES_VALUE_SHAPE = { | ||
type: "primitive", | ||
value: { | ||
type: "string", | ||
regex: undefined, | ||
minLength: undefined, | ||
maxLength: undefined, | ||
default: undefined, | ||
}, | ||
} as const; | ||
|
||
// TODO: This is hardcoded for now, but change to dynamic type references, by setting value | ||
const ADDITIONAL_PROPERTIES_DEFAULT_SHAPE = { | ||
type: "alias", | ||
value: { | ||
type: "optional", | ||
shape: { | ||
type: "alias", | ||
value: { | ||
type: "map", | ||
keyShape: { | ||
type: "alias", | ||
value: ADDITIONAL_PROPERTIES_KEY_SHAPE, | ||
}, | ||
valueShape: { | ||
type: "alias", | ||
value: ADDITIONAL_PROPERTIES_VALUE_SHAPE, | ||
}, | ||
}, | ||
}, | ||
default: undefined, | ||
}, | ||
} as const; | ||
|
||
interface PlaygroundAdditionalPropertiesProps { | ||
onChange: (dispatch: unknown) => void; | ||
properties: readonly ApiDefinition.ObjectProperty[]; | ||
extraProperties: ApiDefinition.TypeReference; | ||
value: unknown; | ||
types: Record<ApiDefinition.TypeId, ApiDefinition.TypeDefinition>; | ||
} | ||
|
||
export function PlaygroundAdditionalProperties({ | ||
onChange, | ||
properties, | ||
// TODO: this should be used: | ||
// extraProperties, | ||
value, | ||
types, | ||
}: PlaygroundAdditionalPropertiesProps): ReactElement { | ||
const additionalProperties = useMemo(() => { | ||
// remove property keys from value | ||
const valueAsRecord = castToRecord(value); | ||
|
||
const additionalPropertiesOnly: Record<string, unknown> = {}; | ||
|
||
Object.keys(valueAsRecord).forEach((key) => { | ||
if (!properties.some((p) => p.key === key)) { | ||
additionalPropertiesOnly[key] = valueAsRecord[key]; | ||
} | ||
}); | ||
|
||
return additionalPropertiesOnly; | ||
}, [properties, value]); | ||
|
||
const handleChange = useCallback( | ||
(dispatch: unknown) => { | ||
onChange((prev: unknown) => { | ||
const castedPrev = castToRecord(prev); | ||
const newValue = typeof dispatch === "function" ? dispatch(prev) : dispatch; | ||
|
||
// spread in the properties that are not in the extraProperties | ||
const obj = { ...newValue }; | ||
Object.keys(castedPrev).forEach((key) => { | ||
if (properties.find((p) => p.key === key)) { | ||
obj[key] = castedPrev[key]; | ||
} | ||
}); | ||
return obj; | ||
}); | ||
}, | ||
[onChange, properties], | ||
); | ||
|
||
return ( | ||
<div className={clsx("flex-1 shrink min-w-0 mt-8")}> | ||
<WithLabel | ||
property={{ | ||
key: ApiDefinition.PropertyKey("Optional Extra Properties"), | ||
valueShape: ADDITIONAL_PROPERTIES_DEFAULT_SHAPE, | ||
description: undefined, | ||
availability: undefined, | ||
}} | ||
value={"Optional Extra Properties"} | ||
onRemove={noop} | ||
types={types} | ||
> | ||
<PlaygroundMapForm | ||
id="extraProperties" | ||
keyShape={ADDITIONAL_PROPERTIES_KEY_SHAPE} | ||
valueShape={ADDITIONAL_PROPERTIES_VALUE_SHAPE} | ||
onChange={handleChange} | ||
value={additionalProperties} | ||
types={types} | ||
/> | ||
</WithLabel> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.