Skip to content

Commit

Permalink
add trailing path to parsed url in playground (#1481)
Browse files Browse the repository at this point in the history
  • Loading branch information
RohinBhargava authored Sep 16, 2024
1 parent 2f8d334 commit 36274b1
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 36 deletions.
81 changes: 45 additions & 36 deletions packages/ui/app/src/components/MaybeEnvironmentDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ interface MaybeEnvironmentDropdownProps {
protocolTextStyle?: string;
small?: boolean;
environmentFilters?: APIV1Read.EnvironmentId[];
trailingPath?: boolean;
}
export function MaybeEnvironmentDropdown(props: MaybeEnvironmentDropdownProps): ReactElement | null {
export function MaybeEnvironmentDropdown({
selectedEnvironment,
urlTextStyle,
protocolTextStyle,
small,
environmentFilters,
trailingPath,
}: MaybeEnvironmentDropdownProps): ReactElement | null {
const [allEnvironmentIds] = useAtom(ALL_ENVIRONMENTS_ATOM);
const [selectedEnvironmentId, setSelectedEnvironmentId] = useAtom(SELECTED_ENVIRONMENT_ATOM);

const { selectedEnvironment, urlTextStyle, protocolTextStyle, small, environmentFilters } = props;

const environmentIds = environmentFilters
? environmentFilters.filter((environmentFilter) => allEnvironmentIds.includes(environmentFilter))
: allEnvironmentIds;
Expand All @@ -28,38 +34,41 @@ export function MaybeEnvironmentDropdown(props: MaybeEnvironmentDropdownProps):
const url = selectedEnvironment?.baseUrl && parse(selectedEnvironment?.baseUrl);

return (
<span>
{environmentIds && environmentIds.length > 1 ? (
<FernDropdown
key="selectedEnvironment-selector"
options={environmentIds.map((env) => ({
value: env,
label: env,
type: "value",
}))}
onValueChange={(value) => {
setSelectedEnvironmentId(value);
}}
value={selectedEnvironmentId ?? selectedEnvironment?.id}
>
<FernButton
text={
<span key="protocol" className="whitespace-nowrap max-sm:hidden">
<span className={protocolTextStyle}>{`${url && url.protocol}//`}</span>
<span className={urlTextStyle}>{(url && url.host) ?? selectedEnvironmentId}</span>
</span>
}
size={small ? "small" : "normal"}
variant="outlined"
mono={true}
/>
</FernDropdown>
) : (
<span key="protocol" className="whitespace-nowrap max-sm:hidden">
<span className={protocolTextStyle}>{`${url && url.protocol}//`}</span>
<span className={urlTextStyle}>{(url && url.host) ?? selectedEnvironmentId}</span>
</span>
)}
</span>
<>
<span>
{environmentIds && environmentIds.length > 1 ? (
<FernDropdown
key="selectedEnvironment-selector"
options={environmentIds.map((env) => ({
value: env,
label: env,
type: "value",
}))}
onValueChange={(value) => {
setSelectedEnvironmentId(value);
}}
value={selectedEnvironmentId ?? selectedEnvironment?.id}
>
<FernButton
text={
<span key="protocol" className="whitespace-nowrap max-sm:hidden">
<span className={protocolTextStyle}>{`${url && url.protocol}//`}</span>
<span className={urlTextStyle}>{(url && url.host) ?? selectedEnvironmentId}</span>
</span>
}
size={small ? "small" : "normal"}
variant="outlined"
mono={true}
/>
</FernDropdown>
) : (
<span key="protocol" className="whitespace-nowrap max-sm:hidden">
<span className={protocolTextStyle}>{`${url && url.protocol}//`}</span>
<span className={urlTextStyle}>{(url && url.host) ?? selectedEnvironmentId}</span>
</span>
)}
</span>
{trailingPath && url && url.pathname !== "/" && <span>{url.pathname}</span>}
</>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const PlaygroundEndpointPath: FC<PlaygroundEndpointPathProps> = ({
small
urlTextStyle="playground-endpoint-baseurl max-sm:hidden"
protocolTextStyle="playground-endpoint-baseurl max-sm:hidden"
trailingPath={true}
/>
)}
</span>
Expand Down

0 comments on commit 36274b1

Please sign in to comment.