From 4a83223c0deb2342f827505cf1ceb5e78c7a0efb Mon Sep 17 00:00:00 2001 From: Joseph Izang Date: Thu, 10 Apr 2025 00:38:35 +0100 Subject: [PATCH 1/4] fix template selection to have oZ options --- .../templates-selection-plugin.tsx | 235 ++++++++++++------ 1 file changed, 153 insertions(+), 82 deletions(-) diff --git a/apps/remix-ide/src/app/plugins/templates-selection/templates-selection-plugin.tsx b/apps/remix-ide/src/app/plugins/templates-selection/templates-selection-plugin.tsx index ef12c7461f9..8583718e980 100644 --- a/apps/remix-ide/src/app/plugins/templates-selection/templates-selection-plugin.tsx +++ b/apps/remix-ide/src/app/plugins/templates-selection/templates-selection-plugin.tsx @@ -1,6 +1,6 @@ import React from 'react' -import { FormattedMessage, useIntl } from 'react-intl' +import { FormattedMessage } from 'react-intl' import { CustomTooltip } from "@remix-ui/helper" import { AppModal } from '@remix-ui/app' import { ViewPlugin } from '@remixproject/engine-web' @@ -29,6 +29,8 @@ const profile = { export class TemplatesSelectionPlugin extends ViewPlugin { templates: Array dispatch: React.Dispatch = () => { } + opts: any = {} + constructor() { super(profile) } @@ -69,22 +71,24 @@ export class TemplatesSelectionPlugin extends ViewPlugin { } updateComponent() { - /* - This represents the different options available from the openzeppelin library. - const opts = { - // @ts-ignore: Object is possibly 'null'. - mintable: mintableCheckboxRef.current.checked, - // @ts-ignore: Object is possibly 'null'. - burnable: burnableCheckboxRef.current.checked, - // @ts-ignore: Object is possibly 'null'. - pausable: pausableCheckboxRef.current.checked, - // @ts-ignore: Object is possibly 'null'. - upgradeable: transparentRadioRef.current.checked ? transparentRadioRef.current.value : uupsRadioRef.current.checked ? uupsRadioRef.current.value : false + + const errorCallback = async (error, data) => { + if (error) { + const modal: AppModal = { + id: 'TemplatesSelection', + title: window._intl.formatMessage({ id: !isElectron() ? 'filePanel.workspace.create': 'filePanel.workspace.create.desktop' }), + message: error.message, + okLabel: window._intl.formatMessage({ id: 'filePanel.ok' }), + cancelLabel: window._intl.formatMessage({ id: 'filePanel.cancel' }) + } + await this.call('notification', 'modal', modal) + console.error(error) + } + } - */ - const createWorkspace = async (item) => { - const defaultName = await this.call('filePanel', 'getAvailableWorkspaceName', item.displayName) + const createWorkspace = async (item, templateName: string) => { + const defaultName = await this.call('filePanel', 'getAvailableWorkspaceName', item.displayName) const username = await this.call('settings', 'get', 'settings/github-user-name') const email = await this.call('settings', 'get', 'settings/github-email') const gitNotSet = !username || !email @@ -93,31 +97,18 @@ export class TemplatesSelectionPlugin extends ViewPlugin { const modal: AppModal = { id: 'TemplatesSelection', title: window._intl.formatMessage({ id: !isElectron() ? 'filePanel.workspace.create': 'filePanel.workspace.create.desktop' }), - message: await createModalMessage(defaultName, gitNotSet, (value) => workspaceName = value, (value) => initGit = !!value), + message: await createModalMessage(defaultName, gitNotSet, (value) => workspaceName = value, (value) => initGit = !!value, (event) => setCheckBoxRefs(event), (event) => setRadioRefs(event), templateName), okLabel: window._intl.formatMessage({ id: !isElectron() ? 'filePanel.ok':'filePanel.selectFolder' }), } const modalResult = await this.call('notification', 'modal', modal) if (!modalResult) return _paq.push(['trackEvent', 'template-selection', 'createWorkspace', item.value]) - this.emit('createWorkspaceReducerEvent', workspaceName, item.value, item.opts, false, async (e, data) => { - if (e) { - const modal: AppModal = { - id: 'TemplatesSelection', - title: window._intl.formatMessage({ id: !isElectron() ? 'filePanel.workspace.create': 'filePanel.workspace.create.desktop' }), - message: e.message, - okLabel: window._intl.formatMessage({ id: 'filePanel.ok' }), - cancelLabel: window._intl.formatMessage({ id: 'filePanel.cancel' }) - } - await this.call('notification', 'modal', modal) - console.error(e) - } - - }, initGit) + this.emit('createWorkspaceReducerEvent', workspaceName, item.value, this.opts, false, errorCallback, initGit) } const addToCurrentWorkspace = async (item) => { _paq.push(['trackEvent', 'template-selection', 'addToCurrentWorkspace', item.value]) - this.emit('addTemplateToWorkspaceReducerEvent', item.value, item.opts, false, async (e, data) => { + this.emit('addTemplateToWorkspaceReducerEvent', item.value, this.opts, false, async (e, data) => { if (e) { const modal: AppModal = { id: 'TemplatesSelection', @@ -134,6 +125,26 @@ export class TemplatesSelectionPlugin extends ViewPlugin { }) } + const setCheckBoxRefs = (event) => { + const { value, checked } = event.target + if (value === 'mintable') { + this.opts.mintable = checked + } else if (value === 'burnable') { + this.opts.burnable = checked + } else if (value === 'pausable') { + this.opts.pausable = checked + } + } + + const setRadioRefs = (event) => { + const { value } = event.target + if (value === 'transparent') { + this.opts.upgradeable = value + } else if (value === 'uups') { + this.opts.upgradeable = value + } + } + return ( {template.items.map((item, index) => { - return -
-
-
- {item.description && {item.description}} -
-
- {(item.opts && item.opts.upgradeable && item.opts.upgradeable === 'uupds') && Upgradeable-UUPS} - {(item.opts && item.opts.mintable) && mintable} - {(item.opts && item.opts.burnable) && burnable} - {(item.opts && item.opts.pausable) && pausable} -
-
-
- {(!template.IsArtefact || !item.isArtefact) && - createWorkspace(item)} - className="btn btn-sm mr-2 border border-primary" - > + if (!item.opts) { + return ( + +
+
+
+ {item.description && {item.description}} +
+
+ {(item.opts && item.opts.upgradeable && item.opts.upgradeable === 'uupds') && Upgradeable-UUPS} + {(item.opts && item.opts.mintable) && mintable} + {(item.opts && item.opts.burnable) && burnable} + {(item.opts && item.opts.pausable) && pausable} +
+
+
+ {(!template.IsArtefact || !item.isArtefact) && + { + createWorkspace(item, template.name) + }} + className="btn btn-sm mr-2 border border-primary" + > Create - - } - - addToCurrentWorkspace(item)} - className="btn btn-sm border" - > + + } + + addToCurrentWorkspace(item)} + className="btn btn-sm border" + > Add to current - - -
-
-
+
+
+
+
+
+ ) + } })} { template.name === 'Cookbook' && void, - onChangeInitGit: (name: string) => void) => { - + onChangeInitGit: (name: string) => void, + onChangeCheckBoxRefs: (event: any) => void, + onChangeRadioRefs: (event: any) => void, + templateName?: string +) => { return ( <>