@@ -57,8 +57,6 @@ import * as commonStorage from './storage/common_storage';
57
57
import * as ChangeFramework from './blocks/utils/change_framework'
58
58
import { mutatorOpenListener } from './blocks/mrc_class_method_def'
59
59
60
- import { create as createOpMode } from './modules/mrc_module_opmode'
61
-
62
60
63
61
type NewWorkspaceNameModalProps = {
64
62
isOpen : boolean ;
@@ -253,9 +251,11 @@ const App: React.FC = () => {
253
251
const [ newOpModeNameModalInitialValue , setNewOpModeNameModalInitialValue ] = useState ( '' ) ;
254
252
const [ newOpModeNameModalIsOpen , setNewOpModeNameModalIsOpen ] = useState ( false ) ;
255
253
const [ toolboxSettingsModalIsOpen , setToolboxSettingsModalIsOpen ] = useState ( false ) ;
256
- const [ openAskToSave , setOpenAskToSave ] = useState ( false ) ;
257
- const afterAskToSaveOk = useRef < ( ) => void > ( ( ) => { } ) ;
258
- const [ askToSaveSaving , setAskToSaveSaving ] = useState ( false ) ;
254
+ const [ popconfirmTitle , setPopconfirmTitle ] = useState ( '' ) ;
255
+ const [ popconfirmDescription , setPopconfirmDescription ] = useState ( '' ) ;
256
+ const [ openPopconfirm , setOpenPopconfirm ] = useState ( false ) ;
257
+ const afterPopconfirmOk = useRef < ( ) => void > ( ( ) => { } ) ;
258
+ const [ popconfirmLoading , setPopconfirmLoading ] = useState ( false ) ;
259
259
260
260
const ignoreEffect = ( ) => {
261
261
if ( ! process . env . NODE_ENV || process . env . NODE_ENV === 'development' ) {
@@ -470,7 +470,7 @@ const App: React.FC = () => {
470
470
blocklyWorkspace . addChangeListener ( mutatorOpenListener ) ;
471
471
472
472
// Show generated python code.
473
- blocklyWorkspace . addChangeListener ( handleBlocksChanged ) ;
473
+ blocklyWorkspace . addChangeListener ( handleBlocksChanged ) ;
474
474
}
475
475
476
476
blocksEditor . current = new editor . Editor ( blocklyWorkspace ) ;
@@ -498,9 +498,9 @@ const App: React.FC = () => {
498
498
setGeneratedCode ( code ) ;
499
499
} ;
500
500
501
- const handleAskToSaveOk = ( ) => {
502
- const callback = afterAskToSaveOk . current ;
503
- afterAskToSaveOk . current = ( ) => { } ;
501
+ const handlePopconfirmOk = ( ) => {
502
+ const callback = afterPopconfirmOk . current ;
503
+ afterPopconfirmOk . current = ( ) => { } ;
504
504
callback ( ) ;
505
505
} ;
506
506
@@ -516,18 +516,20 @@ const App: React.FC = () => {
516
516
}
517
517
518
518
// Show a bubble confirmation box to ask the user if they want to save the blocks.
519
- // Set the function to be executed if the user clicks "ok".
520
- afterAskToSaveOk . current = ( ) => {
521
- setAskToSaveSaving ( true ) ;
519
+ setPopconfirmTitle ( 'Blocks have been modified!' ) ;
520
+ setPopconfirmDescription ( 'Press ok to save and continue' ) ;
521
+ // Set the function to be executed if the user clicks 'ok'.
522
+ afterPopconfirmOk . current = ( ) => {
523
+ setPopconfirmLoading ( true ) ;
522
524
saveModule ( ( success ) => {
523
- setOpenAskToSave ( false ) ;
524
- setAskToSaveSaving ( false ) ;
525
+ setOpenPopconfirm ( false ) ;
526
+ setPopconfirmLoading ( false ) ;
525
527
if ( success ) {
526
528
callback ( ) ;
527
529
}
528
530
} ) ;
529
531
} ;
530
- setOpenAskToSave ( true ) ;
532
+ setOpenPopconfirm ( true ) ;
531
533
}
532
534
} ;
533
535
@@ -548,9 +550,9 @@ const App: React.FC = () => {
548
550
} ;
549
551
550
552
const handleNewWorkspaceNameOk = ( newWorkspaceName : string ) => {
551
- const newWorkspacePath = commonStorage . makeModulePath ( newWorkspaceName , newWorkspaceName ) ;
553
+ const newWorkspacePath = commonStorage . makeWorkspacePath ( newWorkspaceName ) ;
552
554
if ( newWorkspaceNameModalPurpose === 'NewWorkspace' ) {
553
- const workspaceContent = commonStorage . newModuleContent ( commonStorage . MODULE_TYPE_WORKSPACE ) ;
555
+ const workspaceContent = commonStorage . newWorkspaceContent ( newWorkspaceName ) ;
554
556
storage . createModule (
555
557
commonStorage . MODULE_TYPE_WORKSPACE , newWorkspacePath , workspaceContent ,
556
558
( success : boolean , errorMessage : string ) => {
@@ -606,7 +608,7 @@ const App: React.FC = () => {
606
608
// Provide a callback so the NewOpModeNameModal will know what the current
607
609
// workspace name is.
608
610
const getCurrentWorkspaceName = ( ) : string => {
609
- return ( currentModule ) ? currentModule . workspaceName : '' ;
611
+ return currentModule ? currentModule . workspaceName : '' ;
610
612
} ;
611
613
612
614
// Provide a callback so the NewOpModeNameModal will know what the existing
@@ -627,7 +629,7 @@ const App: React.FC = () => {
627
629
const handleNewOpModeNameOk = ( workspaceName : string , newOpModeName : string ) => {
628
630
const newOpModePath = commonStorage . makeModulePath ( workspaceName , newOpModeName ) ;
629
631
if ( newOpModeNameModalPurpose === 'NewOpMode' ) {
630
- const opModeContent = commonStorage . newModuleContent ( commonStorage . MODULE_TYPE_OPMODE ) ;
632
+ const opModeContent = commonStorage . newOpModeContent ( workspaceName , newOpModeName ) ;
631
633
storage . createModule (
632
634
commonStorage . MODULE_TYPE_OPMODE , newOpModePath , opModeContent ,
633
635
( success : boolean , errorMessage : string ) => {
@@ -640,14 +642,7 @@ const App: React.FC = () => {
640
642
setAlertErrorMessage ( 'Failed to create a new OpMode: ' + errorMessage ) ;
641
643
setAlertErrorVisible ( true ) ;
642
644
}
643
- } ) ;
644
- // TODO: This needs to be changed based off the type
645
- if ( blocklyComponent . current ) {
646
- const blocklyWorkspace = blocklyComponent . current . getBlocklyWorkspace ( ) ;
647
- if ( blocklyComponent ) {
648
- createOpMode ( blocklyWorkspace ) ;
649
- }
650
- }
645
+ } ) ;
651
646
} else if ( newOpModeNameModalPurpose === 'RenameOpMode' ) {
652
647
const workspaceName = commonStorage . getWorkspaceName ( currentModulePath ) ;
653
648
const oldOpModeName = commonStorage . getModuleName ( currentModulePath ) ;
@@ -729,62 +724,80 @@ const App: React.FC = () => {
729
724
if ( currentModule . moduleType == commonStorage . MODULE_TYPE_WORKSPACE ) {
730
725
// This is a workspace.
731
726
setNewWorkspaceNameModalPurpose ( 'CopyWorkspace' ) ;
732
- setNewWorkspaceNameModalInitialValue ( currentModule . workspaceName + " _copy" ) ;
727
+ setNewWorkspaceNameModalInitialValue ( currentModule . workspaceName + ' _copy' ) ;
733
728
setNewWorkspaceNameModalIsOpen ( true ) ;
734
729
} else if ( currentModule . moduleType == commonStorage . MODULE_TYPE_OPMODE ) {
735
730
// This is an OpMode.
736
731
setNewOpModeNameModalPurpose ( 'CopyOpMode' ) ;
737
- setNewOpModeNameModalInitialValue ( currentModule . moduleName + " _copy" ) ;
732
+ setNewOpModeNameModalInitialValue ( currentModule . moduleName + ' _copy' ) ;
738
733
setNewOpModeNameModalIsOpen ( true ) ;
739
734
}
740
735
} ) ;
741
736
} ;
742
737
743
738
const handleDeleteClicked = ( ) => {
744
- checkIfBlocksWereModified ( ( ) => {
745
- if ( ! currentModule ) {
746
- return ;
747
- }
748
- if ( currentModule . moduleType == commonStorage . MODULE_TYPE_WORKSPACE ) {
749
- // This is a workspace.
750
- // Before deleting it, select another workspace, if there is one.
751
- const workspaceNameToDelete = currentModule . workspaceName ;
752
- let foundAnotherWorkspace = false ;
753
- for ( const workspace of modules ) {
754
- if ( workspace . workspaceName !== workspaceNameToDelete ) {
755
- setCurrentModulePath ( workspace . modulePath ) ;
756
- foundAnotherWorkspace = true ;
757
- break ;
758
- }
759
- }
760
- if ( ! foundAnotherWorkspace ) {
761
- setCurrentModulePath ( '' ) ;
739
+ if ( ! currentModule ) {
740
+ return ;
741
+ }
742
+ // Show a bubble confirmation box to ask the user if they are sure.
743
+ setPopconfirmTitle ( 'Are you sure?' ) ;
744
+ if ( currentModule . moduleType == commonStorage . MODULE_TYPE_WORKSPACE ) {
745
+ setPopconfirmDescription ( 'Press ok to delete this Workspace' ) ;
746
+ } else if ( currentModule . moduleType == commonStorage . MODULE_TYPE_OPMODE ) {
747
+ setPopconfirmDescription ( 'Press ok to delete this OpMode' ) ;
748
+ } else if ( currentModule . moduleType == commonStorage . MODULE_TYPE_MECHANISM ) {
749
+ // TODO: delete the mechanism.
750
+ return ;
751
+ }
752
+ // Set the function to be executed if the user clicks 'ok'.
753
+ afterPopconfirmOk . current = ( ) => {
754
+ setOpenPopconfirm ( false ) ;
755
+ checkIfBlocksWereModified ( ( ) => {
756
+ if ( ! currentModule ) {
757
+ return ;
762
758
}
763
- storage . deleteWorkspace ( workspaceNameToDelete ,
764
- ( success : boolean , errorMessage : string ) => {
765
- if ( success ) {
766
- setTriggerListModules ( ! triggerListModules ) ;
767
- } else if ( errorMessage ) {
768
- setAlertErrorMessage ( 'Failed to rename the Workspace: ' + errorMessage ) ;
769
- setAlertErrorVisible ( true ) ;
759
+ if ( currentModule . moduleType == commonStorage . MODULE_TYPE_WORKSPACE ) {
760
+ // This is a workspace.
761
+ // Before deleting it, select another workspace, if there is one.
762
+ const workspaceNameToDelete = currentModule . workspaceName ;
763
+ let foundAnotherWorkspace = false ;
764
+ for ( const workspace of modules ) {
765
+ if ( workspace . workspaceName !== workspaceNameToDelete ) {
766
+ setCurrentModulePath ( workspace . modulePath ) ;
767
+ foundAnotherWorkspace = true ;
768
+ break ;
770
769
}
771
- } ) ;
772
- } else if ( currentModule . moduleType == commonStorage . MODULE_TYPE_OPMODE ) {
773
- // This is an OpMode.
774
- const modulePathToDelete = currentModulePath ;
775
- const workspacePath = commonStorage . makeWorkspacePath ( currentModule . workspaceName ) ;
776
- setCurrentModulePath ( workspacePath ) ;
777
- storage . deleteOpMode ( modulePathToDelete ,
778
- ( success : boolean , errorMessage : string ) => {
779
- if ( success ) {
780
- setTriggerListModules ( ! triggerListModules ) ;
781
- } else if ( errorMessage ) {
782
- setAlertErrorMessage ( 'Failed to rename the Workspace: ' + errorMessage ) ;
783
- setAlertErrorVisible ( true ) ;
784
- }
785
- } ) ;
786
- }
787
- } ) ;
770
+ }
771
+ if ( ! foundAnotherWorkspace ) {
772
+ setCurrentModulePath ( '' ) ;
773
+ }
774
+ storage . deleteWorkspace ( workspaceNameToDelete ,
775
+ ( success : boolean , errorMessage : string ) => {
776
+ if ( success ) {
777
+ setTriggerListModules ( ! triggerListModules ) ;
778
+ } else if ( errorMessage ) {
779
+ setAlertErrorMessage ( 'Failed to delete the Workspace: ' + errorMessage ) ;
780
+ setAlertErrorVisible ( true ) ;
781
+ }
782
+ } ) ;
783
+ } else if ( currentModule . moduleType == commonStorage . MODULE_TYPE_OPMODE ) {
784
+ // This is an OpMode.
785
+ const modulePathToDelete = currentModulePath ;
786
+ const workspacePath = commonStorage . makeWorkspacePath ( currentModule . workspaceName ) ;
787
+ setCurrentModulePath ( workspacePath ) ;
788
+ storage . deleteOpMode ( modulePathToDelete ,
789
+ ( success : boolean , errorMessage : string ) => {
790
+ if ( success ) {
791
+ setTriggerListModules ( ! triggerListModules ) ;
792
+ } else if ( errorMessage ) {
793
+ setAlertErrorMessage ( 'Failed to delete the OpMode: ' + errorMessage ) ;
794
+ setAlertErrorVisible ( true ) ;
795
+ }
796
+ } ) ;
797
+ }
798
+ } ) ;
799
+ } ;
800
+ setOpenPopconfirm ( true ) ;
788
801
} ;
789
802
790
803
const handleUploadClicked = ( ) => {
@@ -901,9 +914,11 @@ const App: React.FC = () => {
901
914
>
902
915
< Flex vertical gap = "small" >
903
916
< Space >
904
- < Tooltip title = "New Workspace" >
917
+ < Tooltip title = "New Workspace"
918
+ placement = "bottomRight"
919
+ >
905
920
< Button
906
- icon = { < FolderAddOutlined /> }
921
+ icon = { < FolderAddOutlined /> }
907
922
size = "small"
908
923
onClick = { handleNewWorkspaceClicked }
909
924
style = { { color : 'white' } }
@@ -912,7 +927,7 @@ const App: React.FC = () => {
912
927
</ Tooltip >
913
928
< Tooltip title = "New OpMode" >
914
929
< Button
915
- icon = { < FileAddOutlined /> }
930
+ icon = { < FileAddOutlined /> }
916
931
size = "small"
917
932
disabled = { ! currentModulePath }
918
933
onClick = { handleNewOpModeClicked }
@@ -922,7 +937,7 @@ const App: React.FC = () => {
922
937
</ Tooltip >
923
938
< Tooltip title = "Save" >
924
939
< Button
925
- icon = { < SaveOutlined /> }
940
+ icon = { < SaveOutlined /> }
926
941
size = "small"
927
942
disabled = { ! currentModulePath }
928
943
onClick = { handleSaveClicked }
@@ -932,9 +947,11 @@ const App: React.FC = () => {
932
947
</ Tooltip >
933
948
</ Space >
934
949
< Space >
935
- < Tooltip title = { renameTooltip } >
950
+ < Tooltip title = { renameTooltip }
951
+ placement = "topRight"
952
+ >
936
953
< Button
937
- icon = { < EditOutlined /> }
954
+ icon = { < EditOutlined /> }
938
955
size = "small"
939
956
disabled = { ! currentModulePath }
940
957
onClick = { handleRenameClicked }
@@ -944,7 +961,7 @@ const App: React.FC = () => {
944
961
</ Tooltip >
945
962
< Tooltip title = { copyTooltip } >
946
963
< Button
947
- icon = { < CopyOutlined /> }
964
+ icon = { < CopyOutlined /> }
948
965
size = "small"
949
966
disabled = { ! currentModulePath }
950
967
onClick = { handleCopyClicked }
@@ -954,7 +971,7 @@ const App: React.FC = () => {
954
971
</ Tooltip >
955
972
< Tooltip title = { deleteTooltip } >
956
973
< Button
957
- icon = { < DeleteOutlined /> }
974
+ icon = { < DeleteOutlined /> }
958
975
size = "small"
959
976
disabled = { ! currentModulePath }
960
977
onClick = { handleDeleteClicked }
@@ -1011,12 +1028,12 @@ const App: React.FC = () => {
1011
1028
</ Tooltip >
1012
1029
</ Space >
1013
1030
< Popconfirm
1014
- title = "Blocks have been modified!"
1015
- description = "Press ok to save and continue"
1016
- open = { openAskToSave }
1017
- onConfirm = { handleAskToSaveOk }
1018
- okButtonProps = { { loading : askToSaveSaving } }
1019
- onCancel = { ( ) => setOpenAskToSave ( false ) }
1031
+ title = { popconfirmTitle }
1032
+ description = { popconfirmDescription }
1033
+ open = { openPopconfirm }
1034
+ onConfirm = { handlePopconfirmOk }
1035
+ okButtonProps = { { loading : popconfirmLoading } }
1036
+ onCancel = { ( ) => setOpenPopconfirm ( false ) }
1020
1037
>
1021
1038
< Flex
1022
1039
style = { {
0 commit comments