@@ -10,11 +10,13 @@ import {
1010 MenuList ,
1111 Portal ,
1212 VStack ,
13+ useDisclosure ,
1314} from "@chakra-ui/react" ;
1415import { MakeCodeRenderBlocksProvider } from "@microbit/makecode-embed/react" ;
15- import React from "react" ;
16+ import React , { useCallback } from "react" ;
1617import { RiArrowRightLine , RiDeleteBin2Line } from "react-icons/ri" ;
1718import { FormattedMessage , useIntl } from "react-intl" ;
19+ import { useConnectActions } from "../connect-actions-hooks" ;
1820import { usePrediction } from "../hooks/ml-hooks" ;
1921import { useProject } from "../hooks/project-hooks" ;
2022import { mlSettings } from "../ml" ;
@@ -26,6 +28,7 @@ import CodeViewCard from "./CodeViewCard";
2628import CodeViewGridItem from "./CodeViewGridItem" ;
2729import GestureNameGridItem from "./GestureNameGridItem" ;
2830import HeadingGrid from "./HeadingGrid" ;
31+ import UnsupportedEditorDevice from "./IncompatibleEditorDevice" ;
2932import LiveGraphPanel from "./LiveGraphPanel" ;
3033import MoreMenuButton from "./MoreMenuButton" ;
3134
@@ -59,12 +62,34 @@ const TestingModelGridView = () => {
5962 const gestures = useStore ( ( s ) => s . gestures ) ;
6063 const setRequiredConfidence = useStore ( ( s ) => s . setRequiredConfidence ) ;
6164 const { openEditor, project, resetProject, projectEdited } = useProject ( ) ;
65+ const { getDataCollectionBoardVersion } = useConnectActions ( ) ;
6266
6367 const [ { languageId } ] = useSettings ( ) ;
6468 const makeCodeLang = getMakeCodeLang ( languageId ) ;
6569
70+ const { isOpen, onOpen, onClose } = useDisclosure ( ) ;
71+
72+ const continueToEditor = useCallback ( async ( ) => {
73+ await openEditor ( ) ;
74+ onClose ( ) ;
75+ } , [ onClose , openEditor ] ) ;
76+
77+ const maybeOpenEditor = useCallback ( ( ) => {
78+ // Open editor if device is not a V1, otherwise show warning dialog.
79+ if ( getDataCollectionBoardVersion ( ) === "V1" ) {
80+ return onOpen ( ) ;
81+ }
82+ void openEditor ( ) ;
83+ } , [ getDataCollectionBoardVersion , onOpen , openEditor ] ) ;
84+
6685 return (
6786 < >
87+ < UnsupportedEditorDevice
88+ isOpen = { isOpen }
89+ onClose = { onClose }
90+ onNext = { continueToEditor }
91+ stage = "openEditor"
92+ />
6893 < MakeCodeRenderBlocksProvider
6994 key = { makeCodeLang }
7095 options = { {
@@ -154,7 +179,7 @@ const TestingModelGridView = () => {
154179 < ButtonGroup isAttached >
155180 < Button
156181 variant = "primary"
157- onClick = { openEditor }
182+ onClick = { maybeOpenEditor }
158183 className = { tourElClassname . editInMakeCodeButton }
159184 >
160185 < FormattedMessage id = "edit-in-makecode-action" />
0 commit comments