Skip to content

Commit

Permalink
fix(elements-core): display end of url server vars correctly (stoplig…
Browse files Browse the repository at this point in the history
  • Loading branch information
dotslashderek committed Oct 19, 2023
1 parent 9ee311b commit ac55f02
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 62 deletions.
2 changes: 1 addition & 1 deletion packages/elements-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stoplight/elements-core",
"version": "7.13.7",
"version": "7.13.8",
"sideEffects": [
"web-components.min.js",
"src/web-components/**",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export const httpOperation: IHttpOperation = {
{
id: '?http-server-todos-pr.stoplight.io?',
description: 'PR',
url: '{proto}://x-{pr}.todos-pr.stoplight.io',
url: '{proto}://x-{pr}.todos-pr.stoplight.io:{port}',
variables: {
proto: {
default: 'http',
Expand All @@ -291,6 +291,10 @@ export const httpOperation: IHttpOperation = {
pr: {
default: '1000',
},
port: {
default: '80',
enum: ['443', '80'],
},
},
},
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HttpParamStyles, IHttpOperation } from '@stoplight/types';
import { screen } from '@testing-library/dom';
import { act, render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import * as React from 'react';
import { MemoryRouter } from 'react-router-dom';

Expand Down Expand Up @@ -57,6 +58,21 @@ describe('HttpOperation', () => {

unmount();
});

it('should correctly display with server variables at beginning, middle, and end', () => {
const { unmount } = render(<HttpOperation data={{ ...httpOperation, deprecated: false }} />);

const serversButton = screen.getByRole('button', { name: /server/i });
userEvent.click(serversButton);

const enableItem = screen.getByRole('menuitemradio', { name: /pr/i });
userEvent.click(enableItem);

expect(serversButton).toHaveTextContent('PR');

expect(screen.queryByText(/{proto}:\/\/x-{pr}.todos-pr.stoplight.io:{port}/)).toBeInTheDocument();
unmount();
});
});

describe('Security', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { HttpMethodColors } from '../../../constants';
import { MockingContext } from '../../../containers/MockingProvider';
import { useResolvedObject } from '../../../context/InlineRefResolver';
import { useOptionsCtx } from '../../../context/Options';
import { useChosenServerUrl } from '../../../hooks/useChosenServerUrl';
import { useIsCompact } from '../../../hooks/useIsCompact';
import { MarkdownViewer } from '../../MarkdownViewer';
import { chosenServerAtom, TryItWithRequestSamples } from '../../TryIt';
Expand Down Expand Up @@ -126,20 +125,14 @@ function MethodPath({ method, path }: MethodPathProps) {
function MethodPathInner({ method, path, chosenServerUrl }: MethodPathProps & { chosenServerUrl: string }) {
const isDark = useThemeIsDark();
const fullUrl = `${chosenServerUrl}${path}`;
const { leading, trailing } = useChosenServerUrl(chosenServerUrl);

const pathElem = (
<Flex overflowX="hidden" fontSize="lg" userSelect="all">
<Box dir="rtl" color="muted" textOverflow="truncate" overflowX="hidden">
{leading}

{trailing !== null && (
<Box as="span" dir="ltr" style={{ unicodeBidi: 'bidi-override' }}>
{trailing}
</Box>
)}
<Box as="span" dir="ltr" style={{ unicodeBidi: 'bidi-override' }}>
{chosenServerUrl}
</Box>
</Box>

<Box fontWeight="semibold" flex={1}>
{path}
</Box>
Expand Down

This file was deleted.

22 changes: 0 additions & 22 deletions packages/elements-core/src/hooks/useChosenServerUrl.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/elements-dev-portal/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stoplight/elements-dev-portal",
"version": "1.16.8",
"version": "1.16.9",
"description": "UI components for composing beautiful developer documentation.",
"keywords": [],
"sideEffects": [
Expand Down Expand Up @@ -64,7 +64,7 @@
]
},
"dependencies": {
"@stoplight/elements-core": "~7.13.7",
"@stoplight/elements-core": "~7.13.8",
"@stoplight/markdown-viewer": "^5.5.0",
"@stoplight/mosaic": "^1.44.3",
"@stoplight/path": "^1.3.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/elements-dev-portal/src/version.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// auto-updated during build
export const appVersion = '1.16.4';
export const appVersion = '1.16.9';
4 changes: 2 additions & 2 deletions packages/elements/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@stoplight/elements",
"version": "7.13.7",
"version": "7.13.8",
"description": "UI components for composing beautiful developer documentation.",
"keywords": [],
"sideEffects": [
Expand Down Expand Up @@ -62,7 +62,7 @@
]
},
"dependencies": {
"@stoplight/elements-core": "~7.13.7",
"@stoplight/elements-core": "~7.13.8",
"@stoplight/http-spec": "^6.0.0",
"@stoplight/json": "^3.18.1",
"@stoplight/mosaic": "^1.44.3",
Expand Down

0 comments on commit ac55f02

Please sign in to comment.