Merge pull request #2895 from ethereum/wscat

workspace template categories
pull/5370/head
bunsenstraat 2 years ago committed by GitHub
commit 55977f42e1
  1. 9
      apps/remix-ide/webpack.config.js
  2. 2
      libs/remix-ui/workspace/src/lib/actions/events.ts
  3. 13
      libs/remix-ui/workspace/src/lib/actions/workspace.ts
  4. 2
      libs/remix-ui/workspace/src/lib/contexts/index.ts
  5. 4
      libs/remix-ui/workspace/src/lib/providers/FileSystemProvider.tsx
  6. 68
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx
  7. 4
      libs/remix-ws-templates/src/templates/ozerc20/index.ts
  8. 4
      libs/remix-ws-templates/src/templates/ozerc721/index.ts
  9. 1
      package.json
  10. 5
      yarn.lock

@ -16,6 +16,13 @@ module.exports = config => {
const nxWebpackConfig = nxWebpack(config)
const webpackConfig = {
...nxWebpackConfig,
resolve: {
...nxWebpackConfig.resolve,
alias: {
path: require.resolve("path-browserify"),
}
},
node: {
fs: 'empty',
tls: 'empty',
@ -38,7 +45,7 @@ module.exports = config => {
})
]
}
webpackConfig.output.chunkLoadTimeout = 600000
if (process.env.NODE_ENV === 'production') {

@ -13,7 +13,7 @@ export const listenOnPluginEvents = (filePanelPlugin) => {
plugin = filePanelPlugin
plugin.on('filePanel', 'createWorkspaceReducerEvent', (name: string, workspaceTemplateName: WorkspaceTemplate, isEmpty = false, cb: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => {
createWorkspace(name, workspaceTemplateName, isEmpty, cb)
createWorkspace(name, workspaceTemplateName, null, isEmpty, cb)
})
plugin.on('filePanel', 'renameWorkspaceReducerEvent', (oldName: string, workspaceName: string, cb: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => {

@ -43,18 +43,19 @@ export const addInputField = async (type: 'file' | 'folder', path: string, cb?:
return promise
}
export const createWorkspace = async (workspaceName: string, workspaceTemplateName: WorkspaceTemplate, isEmpty = false, cb?: (err: Error, result?: string | number | boolean | Record<string, any>) => void, isGitRepo: boolean = false) => {
export const createWorkspace = async (workspaceName: string, workspaceTemplateName: WorkspaceTemplate, opts = null, isEmpty = false, cb?: (err: Error, result?: string | number | boolean | Record<string, any>) => void, isGitRepo: boolean = false) => {
await plugin.fileManager.closeAllFiles()
const promise = createWorkspaceTemplate(workspaceName, workspaceTemplateName)
dispatch(createWorkspaceRequest(promise))
promise.then(async () => {
dispatch(createWorkspaceSuccess({ name: workspaceName, isGitRepo }))
await plugin.setWorkspace({ name: workspaceName, isLocalhost: false })
await plugin.setWorkspaces(await getWorkspaces())
await plugin.workspaceCreated(workspaceName)
if (isGitRepo) await plugin.call('dGitProvider', 'init')
if (!isEmpty) await loadWorkspacePreset(workspaceTemplateName)
if (!isEmpty) await loadWorkspacePreset(workspaceTemplateName, opts)
cb && cb(null, workspaceName)
}).catch((error) => {
dispatch(createWorkspaceError({ error }))
@ -81,7 +82,7 @@ export type UrlParametersType = {
language: string
}
export const loadWorkspacePreset = async (template: WorkspaceTemplate = 'remixDefault') => {
export const loadWorkspacePreset = async (template: WorkspaceTemplate = 'remixDefault', opts?) => {
const workspaceProvider = plugin.fileProviders.workspace
const params = queryParams.get() as UrlParametersType
@ -160,7 +161,7 @@ export const loadWorkspacePreset = async (template: WorkspaceTemplate = 'remixDe
if (!templateList.includes(template)) break
_paq.push(['trackEvent', 'workspace', 'template', template])
// @ts-ignore
const files = await templateWithContent[template]()
const files = await templateWithContent[template](opts)
for (const file in files) {
try {
await workspaceProvider.set(file, files[file])
@ -340,7 +341,7 @@ export const cloneRepository = async (url: string) => {
try {
const repoName = await getRepositoryTitle(url)
await createWorkspace(repoName, 'blank', true, null, true)
await createWorkspace(repoName, 'blank', null, true, null, true)
const promise = plugin.call('dGitProvider', 'clone', repoConfig, repoName, true)
dispatch(cloneRepositoryRequest())

@ -9,7 +9,7 @@ export const FileSystemContext = createContext<{
dispatchFetchDirectory:(path: string) => Promise<void>,
dispatchAddInputField:(path: string, type: 'file' | 'folder') => Promise<void>,
dispatchRemoveInputField:(path: string) => Promise<void>,
dispatchCreateWorkspace: (workspaceName: string, workspaceTemplateName: string, initGitRepo?: boolean) => Promise<void>,
dispatchCreateWorkspace: (workspaceName: string, workspaceTemplateName: string, opts?, initGitRepo?: boolean) => Promise<void>,
toast: (toasterMsg: string) => void,
dispatchFetchWorkspaceDirectory: (path: string) => Promise<void>,
dispatchSwitchToWorkspace: (name: string) => Promise<void>,

@ -45,8 +45,8 @@ export const FileSystemProvider = (props: WorkspaceProps) => {
await removeInputField(path)
}
const dispatchCreateWorkspace = async (workspaceName: string, workspaceTemplateName: WorkspaceTemplate, initGitRepo?: boolean) => {
await createWorkspace(workspaceName, workspaceTemplateName, null, null, initGitRepo)
const dispatchCreateWorkspace = async (workspaceName: string, workspaceTemplateName: WorkspaceTemplate, opts?, initGitRepo?: boolean) => {
await createWorkspace(workspaceName, workspaceTemplateName, opts, null, null, initGitRepo)
}
const dispatchFetchWorkspaceDirectory = async (path: string) => {

@ -15,6 +15,8 @@ export function Workspace () {
const [currentWorkspace, setCurrentWorkspace] = useState<string>(NO_WORKSPACE)
const [selectedWorkspace, setSelectedWorkspace] = useState<{ name: string, isGitRepo: boolean}>(null)
const [showDropdown, setShowDropdown] = useState<boolean>(false)
const displayOzCustomRef = useRef<HTMLDivElement>()
const upgradeable = useRef()
const global = useContext(FileSystemContext)
const workspaceRenameInput = useRef()
const workspaceCreateInput = useRef()
@ -107,8 +109,12 @@ export function Workspace () {
const workspaceTemplateName = workspaceCreateTemplateInput.current.value || 'remixDefault'
const initGitRepo = initGitRepoRef.current.checked
const opts = {
upgradeable: upgradeable.current
}
try {
await global.dispatchCreateWorkspace(workspaceName, workspaceTemplateName, initGitRepo)
await global.dispatchCreateWorkspace(workspaceName, workspaceTemplateName, opts, initGitRepo)
} catch (e) {
global.modal('Create Workspace', e.message, 'OK', () => {}, '')
console.error(e)
@ -140,6 +146,11 @@ export function Workspace () {
}
const updateWsName = () => {
// @ts-ignore
if (workspaceCreateTemplateInput.current.value.startsWith('oz') && displayOzCustomRef && displayOzCustomRef.current)
displayOzCustomRef.current.style.display = 'block'
else displayOzCustomRef.current.style.display = 'none'
// @ts-ignore
workspaceCreateInput.current.value = `${workspaceCreateTemplateInput.current.value || 'remixDefault'}_${Date.now()}`
}
@ -158,19 +169,49 @@ export function Workspace () {
setShowDropdown(isOpen)
}
const handleUpgradeability = (e) => {
// @ts-ignore
upgradeable.current = e.target.value
// @ts-ignore
workspaceCreateInput.current.value = `${workspaceCreateTemplateInput.current.value + '_upgradeable'}_${Date.now()}`
}
const createModalMessage = () => {
return (
<>
<label id="wsName" className="form-check-label">Workspace name</label>
<input type="text" data-id="modalDialogCustomPromptTextCreate" defaultValue={`remixDefault_${Date.now()}`} ref={workspaceCreateInput} className="form-control" /><br/>
<label id="selectWsTemplate" className="form-check-label">Choose a template</label>
<select name="wstemplate" className="form-control custom-select" id="wstemplate" defaultValue='remixDefault' ref={workspaceCreateTemplateInput} onChange={updateWsName}>
<option value='remixDefault'>Default</option>
<option value='blank'>Blank</option>
<option value='ozerc20'>OpenZeppelin ERC20</option>
<option value='zeroxErc20'>0xProject ERC20</option>
<option value='ozerc721'>OpenZeppelin ERC721</option>
<label id="selectWsTemplate" className="form-check-label" style={{fontWeight: "bolder"}}>Choose a template</label>
<select name="wstemplate" className="mb-3 form-control custom-select" id="wstemplate" defaultValue='remixDefault' ref={workspaceCreateTemplateInput} onChange={updateWsName}>
<optgroup style={{fontSize: "medium"}} label="General">
<option style={{fontSize: "small"}} value='remixDefault'>Default</option>
<option style={{fontSize: "small"}} value='blank'>Blank</option>
</optgroup>
<optgroup style={{fontSize: "medium"}} label="OpenZepplin">
<option style={{fontSize: "small"}} value='ozerc20'>ERC20</option>
<option style={{fontSize: "small"}} value='ozerc721'>ERC721</option>
</optgroup>
<optgroup style={{fontSize: "medium"}} label="0xProject">
<option style={{fontSize: "small"}} value='zeroxErc20'>ERC20</option>
</optgroup>
</select>
<div id="ozcustomization" ref={displayOzCustomRef} style={{display: 'none'}} className="mb-2">
<label className="form-check-label d-block mb-2" style={{fontWeight: "bolder"}}>Customize template</label>
<label id="wsName" className="form-check-label d-block mb-1">Upgradeability</label>
<div onChange={(e) => handleUpgradeability(e)}>
<div className="d-flex ml-2 custom-control custom-radio">
<input className="custom-control-input" type="radio" name="upgradeability" value="transparent" id="transparent" />
<label className="form-check-label custom-control-label" htmlFor="transparent" data-id="upgradeTypeTransparent" >Transparent</label>
</div>
<div className="d-flex ml-2 custom-control custom-radio">
<input className="custom-control-input" type="radio" name="upgradeability" value="uups" id="uups" />
<label className="form-check-label custom-control-label" htmlFor="uups" data-id="upgradeTypeUups" >UUPS</label>
</div>
</div>
</div>
<label id="wsName" className="form-check-label" style={{fontWeight: "bolder"}} >Workspace name</label>
<input type="text" data-id="modalDialogCustomPromptTextCreate" defaultValue={`remixDefault_${Date.now()}`} ref={workspaceCreateInput} className="form-control" />
<div className="d-flex py-2 align-items-center custom-control custom-checkbox">
<input
ref={initGitRepoRef}
@ -189,6 +230,7 @@ export function Workspace () {
Initialize workspace as a new git repository
</label>
</div>
</>
)
}
@ -299,9 +341,9 @@ export function Workspace () {
<Dropdown.Menu as={CustomMenu} className='w-100 custom-dropdown-items' data-id="custom-dropdown-items">
<Dropdown.Item
onClick={() => {
createWorkspace()
}}
onClick={() => {
createWorkspace()
}}
>
{
<span className="pl-3"> - create a new workspace - </span>

@ -1,8 +1,8 @@
import { erc20 } from '@openzeppelin/wizard';
export default async () => {
export default async (opts) => {
return {
'contracts/MyToken.sol': erc20.print(),
'contracts/MyToken.sol': erc20.print({ ...erc20.defaults, upgradeable: opts.upgradeable}),
// @ts-ignore
'scripts/deploy_with_ethers.ts': (await import('!!raw-loader!./scripts/deploy_with_ethers.ts')).default,
// @ts-ignore

@ -1,8 +1,8 @@
import { erc721 } from '@openzeppelin/wizard';
export default async () => {
export default async (opts) => {
return {
'contracts/MyToken.sol': erc721.print(),
'contracts/MyToken.sol': erc721.print({ ...erc721.defaults, upgradeable: opts.upgradeable}),
// @ts-ignore
'scripts/deploy_with_ethers.ts': (await import('!!raw-loader!./scripts/deploy_with_ethers.ts')).default,
// @ts-ignore

@ -198,6 +198,7 @@
"merge": "^2.1.1",
"monaco-editor": "^0.30.1",
"npm-install-version": "^6.0.2",
"path-browserify": "^1.0.1",
"prettier": "^2.7.1",
"prettier-plugin-solidity": "^1.0.0-beta.24",
"raw-loader": "^4.0.2",

@ -18523,6 +18523,11 @@ path-browserify@0.0.1, path-browserify@~0.0.0:
resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-0.0.1.tgz#e6c4ddd7ed3aa27c68a20cc4e50e1a4ee83bbc4a"
integrity sha512-BapA40NHICOS+USX9SN4tyhq+A2RrN/Ws5F0Z5aMHDp98Fl86lX8Oti8B7uN93L4Ifv4fHOEA+pQw87gmMO/lQ==
path-browserify@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-1.0.1.tgz#d98454a9c3753d5790860f16f68867b9e46be1fd"
integrity sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==
path-case@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/path-case/-/path-case-3.0.4.tgz#9168645334eb942658375c56f80b4c0cb5f82c6f"

Loading…
Cancel
Save