From 3ca820b2167cfdb3a25dddc433c4110df6061759 Mon Sep 17 00:00:00 2001 From: Melloware Date: Thu, 18 Aug 2022 12:50:31 -0400 Subject: [PATCH] Fix #3124: Warn if a code sandbox demo is not available (#3165) * Fix #3124: Warn if a code sandbox demo is not available * Fix #3124: Ability to hide certain code sandbox props --- components/doc/common/docactions.js | 17 +++++++++++++---- components/doc/common/liveeditor.js | 12 ++++++++++-- pages/formik/index.js | 2 +- pages/reactfinalform/index.js | 2 +- pages/reacthookform/index.js | 2 +- 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/components/doc/common/docactions.js b/components/doc/common/docactions.js index 90b70a8773..8131adb32f 100644 --- a/components/doc/common/docactions.js +++ b/components/doc/common/docactions.js @@ -2,12 +2,14 @@ import React, { useEffect, useContext } from 'react'; import { useRef } from 'react'; import { Button } from '../../lib/button/Button'; import { Menu } from '../../lib/menu/Menu'; +import { Toast } from '../../lib/toast/Toast'; import DomHandler from '../../lib/utils/DomHandler'; import { useLiveEditor } from './liveeditor'; import AppContentContext from '../../../components/layout/appcontentcontext'; export const DocActions = (props) => { const menu = useRef(null); + const toast = useRef(null); const liveEditor = useRef(null); const context = useContext(AppContentContext); @@ -20,19 +22,23 @@ export const DocActions = (props) => { const items = [ { label: 'Hooks Source Demo', - command: () => liveEditor.current.postSandboxParameters('hooks') + className: props.showHooksSource === false ? 'hidden' : '', + command: () => liveEditor.current.postSandboxParameters('hooks', toast) }, { label: 'Class Source Demo', - command: () => liveEditor.current.postSandboxParameters('class') + className: props.showClassSource === false ? 'hidden' : '', + command: () => liveEditor.current.postSandboxParameters('class', toast) }, { label: 'TS Source Demo', - command: () => liveEditor.current.postSandboxParameters('ts') + className: props.showTsSource === false ? 'hidden' : '', + command: () => liveEditor.current.postSandboxParameters('ts', toast) }, { label: 'Browser Source Demo', - command: () => liveEditor.current.postSandboxParameters('browser') + className: props.showBrowserSource === false ? 'hidden' : '', + command: () => liveEditor.current.postSandboxParameters('browser', toast) } ]; @@ -61,6 +67,8 @@ export const DocActions = (props) => { } return ( + <> +
+ ) } diff --git a/components/doc/common/liveeditor.js b/components/doc/common/liveeditor.js index fd39abf658..4ba42b8859 100644 --- a/components/doc/common/liveeditor.js +++ b/components/doc/common/liveeditor.js @@ -382,6 +382,9 @@ ${extIndexCSS} const getSandboxParameters = (sourceType) => { let { name, sources, dependencies } = props; + if (!sources[sourceType]) { + return null; + } let extension = '.js'; let serviceExtension = extension; let extDependencies = dependencies || {}; @@ -485,14 +488,19 @@ ${extIndexCSS} } return { - postSandboxParameters(sourceType) { + postSandboxParameters(sourceType, toast) { + const sandboxParameters = getSandboxParameters(sourceType); + if (!sandboxParameters) { + toast.current.show({severity: 'warn', summary: 'Not Available', detail: 'That code sandbox demonstration is not available!'}); + return; + } fetch('https://codesandbox.io/api/v1/sandboxes/define?json=1', { method: "POST", headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' }, - body: JSON.stringify(getSandboxParameters(sourceType)) + body: JSON.stringify(sandboxParameters) }) .then(response => response.json()) .then(data => window.open(`https://codesandbox.io/s/${data.sandbox_id}`, '_blank')); diff --git a/pages/formik/index.js b/pages/formik/index.js index a8ce17f72c..b342427544 100644 --- a/pages/formik/index.js +++ b/pages/formik/index.js @@ -98,7 +98,7 @@ const FormikFormDemo = () => {

PrimeReact components can be easily used/integrated with Formik. In this example, a register panel is simulated using Formik.

- +
setShowMessage(false)} position="top" footer={dialogFooter} showHeader={false} breakpoints={{ '960px': '80vw' }} style={{ width: '30vw' }}> diff --git a/pages/reactfinalform/index.js b/pages/reactfinalform/index.js index e437ebbc8d..5ed82bda45 100644 --- a/pages/reactfinalform/index.js +++ b/pages/reactfinalform/index.js @@ -90,7 +90,7 @@ const ReactFinalFormDemo = () => {
- +
diff --git a/pages/reacthookform/index.js b/pages/reacthookform/index.js index 94f1b3d2b7..6ffb1cc8a3 100644 --- a/pages/reacthookform/index.js +++ b/pages/reacthookform/index.js @@ -73,7 +73,7 @@ const ReactHookFormDemo = () => {

PrimeReact components can be easily used/integrated with React Hook Form. In this example, a register panel is simulated using React Hook Form.

- +