Skip to content
This repository has been archived by the owner on Feb 25, 2024. It is now read-only.

Commit

Permalink
Fixed an issue with right-side panels getting cut off after stretchin…
Browse files Browse the repository at this point in the history
…g them and shrinking back with the resize handle (#263)
  • Loading branch information
Andarist authored Sep 13, 2021
1 parent c36ce23 commit 4a0f041
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/famous-cats-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'xstate-viz-app': patch
---

Fixed an issue with right-side panels getting cut off after stretching them and shrinking back with the resize handle.
18 changes: 18 additions & 0 deletions cypress/integration/visual.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ describe('Visual', () => {
});
});

it('should have login button in the viewport after the right panel gets stretched and shrinked again', () => {
cy.visit('/viz');

cy.getMonacoEditor();

cy.getResizeHandle().realSwipe('toLeft', {
length: 100,
});

cy.getResizeHandle().realSwipe('toRight', {
length: 100,
});

cy.findByRole('button', { name: 'Login' }).then(($button) => {
expect(isInViewport($button)).to.be.true;
});
});

it('should have editor buttons aligned vertically with canvas buttons', () => {
cy.visit('/viz');

Expand Down
7 changes: 7 additions & 0 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ const getControlButtons = () => {
return cy.findByTestId('controls');
};

const getResizeHandle = () => {
return cy.findByTestId('resize-handle');
};

type DeepPartial<T> = T extends Function
? T
: T extends Array<infer U>
Expand Down Expand Up @@ -220,6 +224,8 @@ declare global {
getCanvasGraph: typeof getCanvasGraph;

getControlButtons: typeof getControlButtons;

getResizeHandle: typeof getResizeHandle;
}
}
}
Expand All @@ -236,3 +242,4 @@ Cypress.Commands.add('getCanvasHeader', getCanvasHeader);
Cypress.Commands.add('getStatePanel', getStatePanel);
Cypress.Commands.add('getCanvasGraph', getCanvasGraph);
Cypress.Commands.add('getControlButtons', getControlButtons);
Cypress.Commands.add('getResizeHandle', getResizeHandle);
11 changes: 6 additions & 5 deletions src/EditorPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,13 @@ const editorPanelMachine = editorPanelModel.createMachine(
src: async (ctx) => {
const monaco = ctx.monacoRef!;
const uri = monaco.Uri.parse(ctx.mainFile);
const getWorker = await monaco.languages.typescript.getTypeScriptWorker();
const getWorker =
await monaco.languages.typescript.getTypeScriptWorker();
const tsWorker = await getWorker(uri);

const usedXStateGistIdentifiers: string[] = await (tsWorker as any).queryXStateGistIdentifiers(
uri.toString(),
);
const usedXStateGistIdentifiers: string[] = await (
tsWorker as any
).queryXStateGistIdentifiers(uri.toString());

if (usedXStateGistIdentifiers.length > 0) {
const fixupImportsText = buildGistFixupImportsText(
Expand Down Expand Up @@ -436,7 +437,7 @@ export const EditorPanel: React.FC<{
{simulationMode === 'visualizing' && (
<>
{/* This extra div acts as a placeholder that is supposed to stretch while EditorWithXStateImports lazy-loads (thanks to `1fr` on the grid) */}
<div style={{ minHeight: 0 }}>
<div style={{ minHeight: 0, minWidth: 0 }}>
<EditorWithXStateImports
value={value}
onMount={(standaloneEditor, monaco) => {
Expand Down
12 changes: 9 additions & 3 deletions src/ResizableBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const ResizeHandle: React.FC<{

return (
<Box
data-testid="resize-handle"
width="1"
css={{
position: 'absolute',
Expand Down Expand Up @@ -100,6 +101,9 @@ const ResizeHandle: React.FC<{
onPointerUp={() => {
send(dragDropModel.events['DRAG.END']());
}}
onPointerCancel={() => {
send(dragDropModel.events['DRAG.END']());
}}
></Box>
);
};
Expand All @@ -120,9 +124,11 @@ export const ResizableBox: React.FC<ResizableBoxProps> = ({
// into multiple lines
<Box
{...props}
{...(!disabled && {
width: `clamp(35rem, calc(35rem + ${widthDelta}px), 70vw)`,
})}
style={
!disabled
? { width: `clamp(35rem, calc(35rem + ${widthDelta}px), 70vw)` }
: undefined
}
>
{children}
{!disabled && <ResizeHandle onChange={(value) => setWidthDelta(value)} />}
Expand Down

0 comments on commit 4a0f041

Please sign in to comment.