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

Commit

Permalink
Fix embed preview bug with inconsistent options (#289)
Browse files Browse the repository at this point in the history
* Extend embed params with default params for conditionally shown embed preview options to work properly

* add changeset
  • Loading branch information
farskid committed Oct 6, 2021
1 parent cd128a1 commit 48af2ef
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/eighty-birds-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'xstate-viz-app': patch
---

Fix a bug with inconsistent embed previews
7 changes: 5 additions & 2 deletions src/EmbedPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { useMachine } from '@xstate/react';
import React, { useEffect, useRef, useState } from 'react';
import { createModel } from 'xstate/lib/model';
import { EmbedMode, EmbedPanel, ParsedEmbed } from './types';
import { makeEmbedUrl, paramsToRecord } from './utils';
import { DEFAULT_EMBED_PARAMS, makeEmbedUrl, paramsToRecord } from './utils';
import { send, assign, ContextFrom } from 'xstate';
import { Overlay } from './Overlay';
import { useRouter } from 'next/router';
Expand Down Expand Up @@ -268,7 +268,10 @@ const EmbedPreviewContent: React.FC = () => {
onChange={() => {
sendPreviewEvent({
type: 'PARAMS_CHANGED',
params: extractFormData(form.current),
params: {
...DEFAULT_EMBED_PARAMS,
...extractFormData(form.current),
},
});
}}
ref={form}
Expand Down
19 changes: 10 additions & 9 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,16 +206,17 @@ export function isDelayedTransitionAction(
* /?mode=viz|full|panels default:viz
* /?mode=panels&panel=code|state|events|actors default:code
*/
export const DEFAULT_EMBED_PARAMS: ParsedEmbed = {
mode: EmbedMode.Viz,
panel: EmbedPanel.Code,
showOriginalLink: true,
readOnly: true,
pan: false,
zoom: false,
controls: false,
};
export const parseEmbedQuery = (query?: NextRouter['query']): ParsedEmbed => {
const parsedEmbed = {
mode: EmbedMode.Viz,
panel: EmbedPanel.Code,
showOriginalLink: true,
readOnly: true,
pan: false,
zoom: false,
controls: false,
};
const parsedEmbed = DEFAULT_EMBED_PARAMS;

const getQueryParamValue = (qParamValue: string | string[]) => {
return Array.isArray(qParamValue) ? qParamValue[0] : qParamValue;
Expand Down

0 comments on commit 48af2ef

Please sign in to comment.