|
|
@ -1,9 +1,10 @@ |
|
|
|
/* eslint-disable no-debugger */ |
|
|
|
/* eslint-disable no-debugger */ |
|
|
|
import React, { useState } from 'react' |
|
|
|
import React, { Dispatch, useReducer } from 'react' |
|
|
|
import { ModalDialog } from '@remix-ui/modal-dialog' |
|
|
|
import { ModalDialog } from '@remix-ui/modal-dialog' |
|
|
|
import { Toaster } from '@remix-ui/toaster' |
|
|
|
import { Toaster } from '@remix-ui/toaster' |
|
|
|
import { IframePlugin, WebsocketPlugin } from '@remixproject/engine-web' |
|
|
|
import { IframePlugin, WebsocketPlugin } from '@remixproject/engine-web' |
|
|
|
import { FormStateProps, PluginManagerComponent } from '../../types' |
|
|
|
import { FormStateProps, PluginManagerComponent } from '../../types' |
|
|
|
|
|
|
|
import { localPluginReducerActionType, localPluginToastReducer } from '../../pluginManagerReducer' |
|
|
|
|
|
|
|
|
|
|
|
interface LocalPluginFormProps { |
|
|
|
interface LocalPluginFormProps { |
|
|
|
changeHandler: (propertyName: string, value: any) => void |
|
|
|
changeHandler: (propertyName: string, value: any) => void |
|
|
@ -13,7 +14,8 @@ interface LocalPluginFormProps { |
|
|
|
pluginManager: PluginManagerComponent |
|
|
|
pluginManager: PluginManagerComponent |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const handleModalOkClick = async (pluginManager: PluginManagerComponent, plugin: FormStateProps, setErrorMsg: React.Dispatch<React.SetStateAction<string>>) => { |
|
|
|
const handleModalOkClick = async (pluginManager: PluginManagerComponent, plugin: FormStateProps, |
|
|
|
|
|
|
|
toastDispatcher: Dispatch<localPluginReducerActionType>) => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const profile = JSON.parse(localStorage.getItem('plugins/local')) |
|
|
|
const profile = JSON.parse(localStorage.getItem('plugins/local')) |
|
|
|
if (profile && profile.profile && Object.keys(profile).length > 0) { |
|
|
|
if (profile && profile.profile && Object.keys(profile).length > 0) { |
|
|
@ -28,7 +30,6 @@ const handleModalOkClick = async (pluginManager: PluginManagerComponent, plugin: |
|
|
|
const localPlugin = plugin.type === 'iframe' ? new IframePlugin(plugin) : new WebsocketPlugin(plugin) |
|
|
|
const localPlugin = plugin.type === 'iframe' ? new IframePlugin(plugin) : new WebsocketPlugin(plugin) |
|
|
|
|
|
|
|
|
|
|
|
localPlugin.profile.hash = `local-${plugin.name}` |
|
|
|
localPlugin.profile.hash = `local-${plugin.name}` |
|
|
|
// <-------------------------------- Plumbing starts here --------------------------------------->
|
|
|
|
|
|
|
|
const targetPlugin = { |
|
|
|
const targetPlugin = { |
|
|
|
name: localPlugin.profile.name, |
|
|
|
name: localPlugin.profile.name, |
|
|
|
displayName: localPlugin.profile.displayName, |
|
|
|
displayName: localPlugin.profile.displayName, |
|
|
@ -45,13 +46,14 @@ const handleModalOkClick = async (pluginManager: PluginManagerComponent, plugin: |
|
|
|
localPlugin.profile = { ...localPlugin.profile, ...targetPlugin } |
|
|
|
localPlugin.profile = { ...localPlugin.profile, ...targetPlugin } |
|
|
|
pluginManager.activateAndRegisterLocalPlugin(localPlugin) |
|
|
|
pluginManager.activateAndRegisterLocalPlugin(localPlugin) |
|
|
|
} catch (error) { |
|
|
|
} catch (error) { |
|
|
|
console.error(error) |
|
|
|
console.log(error) |
|
|
|
// setErrorMsg(error.message)
|
|
|
|
// setErrorMsg(error.message)
|
|
|
|
setErrorMsg(error.message) |
|
|
|
const action: localPluginReducerActionType = { type: 'show', payload: `${error.message}` } |
|
|
|
|
|
|
|
toastDispatcher(action) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
function LocalPluginForm ({ changeHandler, plugin, closeModal, visible, pluginManager }: LocalPluginFormProps) { |
|
|
|
function LocalPluginForm ({ changeHandler, plugin, closeModal, visible, pluginManager }: LocalPluginFormProps) { |
|
|
|
const [errorMsg, setErrorMsg] = useState('') |
|
|
|
const [errorMsg, dispatchToastMsg] = useReducer(localPluginToastReducer, '') |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<><ModalDialog |
|
|
|
<><ModalDialog |
|
|
@ -60,7 +62,7 @@ function LocalPluginForm ({ changeHandler, plugin, closeModal, visible, pluginMa |
|
|
|
hide={visible} |
|
|
|
hide={visible} |
|
|
|
title="Local Plugin" |
|
|
|
title="Local Plugin" |
|
|
|
okLabel="OK" |
|
|
|
okLabel="OK" |
|
|
|
okFn={() => handleModalOkClick(pluginManager, plugin, setErrorMsg) } |
|
|
|
okFn={() => handleModalOkClick(pluginManager, plugin, dispatchToastMsg) } |
|
|
|
cancelLabel="Cancel" |
|
|
|
cancelLabel="Cancel" |
|
|
|
cancelFn={closeModal} |
|
|
|
cancelFn={closeModal} |
|
|
|
> |
|
|
|
> |
|
|
@ -173,7 +175,9 @@ function LocalPluginForm ({ changeHandler, plugin, closeModal, visible, pluginMa |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</form> |
|
|
|
</form> |
|
|
|
</ModalDialog><Toaster message={`Cannot create Plugin : ${errorMsg}`} timeOut={10000} /></> |
|
|
|
</ModalDialog> |
|
|
|
|
|
|
|
{errorMsg ? <Toaster message={errorMsg} timeOut={3000} /> : null} |
|
|
|
|
|
|
|
</> |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|