add warning

pull/3097/head
filip mertens 2 years ago committed by Aniket
parent 7d11e11702
commit 96c36acc4b
  1. 2
      libs/remix-ui/settings/src/lib/constants.ts
  2. 2
      libs/remix-ui/settings/src/lib/github-settings.tsx
  3. 7
      libs/remix-ui/workspace/src/lib/actions/payload.ts
  4. 29
      libs/remix-ui/workspace/src/lib/actions/workspace.ts
  5. 15
      libs/remix-ui/workspace/src/lib/reducers/workspace.ts
  6. 7
      libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx

@ -5,7 +5,7 @@ export const warnText = 'Be sure the endpoint is opened before enabling it. \nTh
export const gitAccessTokenTitle = 'GitHub Access Token'
export const gitAccessTokenText = 'Manage the access token used to publish to Gist and retrieve GitHub contents.'
export const gitAccessTokenText2 = 'Go to github token page (link below) to create a new token and save it in Remix. Make sure this token has only \'create gist\' permission.'
export const gitAccessTokenText2 = 'Go to github token page (link below) to create a new token and save it in Remix. To create gists set the scope to "gist". To retrieve GitHub contents set the scope to "repo".'
export const gitAccessTokenLink = 'https://github.com/settings/tokens/new?scopes=gist,repo&description=Remix%20IDE%20Token'
export const etherscanTokenTitle = 'EtherScan Access Token'
export const etherscanTokenLink = 'https://etherscan.io/myapikey'

@ -73,7 +73,7 @@ export function GithubSettings (props: GithubSettingsProps) {
<div className="text-secondary mb-0 h6">
<input id="githubemail" data-id="settingsTabGithubEmail" type="text" className="form-control" onChange={(e) => handleChangeEmailState(e)} value={ githubEmail } />
<div className="d-flex justify-content-end pt-2">
<input className="btn btn-sm btn-primary ml-2" id="savegisttoken" data-id="settingsTabSaveGistToken" onClick={saveGithubToken} value="Save" type="button" disabled={githubToken === ''}></input>
<input className="btn btn-sm btn-primary ml-2" id="savegisttoken" data-id="settingsTabSaveGistToken" onClick={saveGithubToken} value="Save" type="button"></input>
<CustomTooltip
tooltipText="Delete Github Credentials"
tooltipClasses="text-nowrap"

@ -285,3 +285,10 @@ export const setCurrentWorkspaceIsGitRepo = (isRepo: boolean) => {
payload: isRepo
}
}
export const setGitConfig = (config: {username: string, token: string, email: string}) => {
return {
type: 'SET_GIT_CONFIG',
payload: config
}
}

@ -1,7 +1,7 @@
import React from 'react'
import { bufferToHex, keccakFromString } from 'ethereumjs-util'
import axios, { AxiosResponse } from 'axios'
import { addInputFieldSuccess, cloneRepositoryFailed, cloneRepositoryRequest, cloneRepositorySuccess, createWorkspaceError, createWorkspaceRequest, createWorkspaceSuccess, displayNotification, displayPopUp, fetchWorkspaceDirectoryError, fetchWorkspaceDirectoryRequest, fetchWorkspaceDirectorySuccess, hideNotification, setCurrentWorkspace, setCurrentWorkspaceBranches, setCurrentWorkspaceCurrentBranch, setDeleteWorkspace, setMode, setReadOnlyMode, setRenameWorkspace, setCurrentWorkspaceIsGitRepo } from './payload'
import { addInputFieldSuccess, cloneRepositoryFailed, cloneRepositoryRequest, cloneRepositorySuccess, createWorkspaceError, createWorkspaceRequest, createWorkspaceSuccess, displayNotification, displayPopUp, fetchWorkspaceDirectoryError, fetchWorkspaceDirectoryRequest, fetchWorkspaceDirectorySuccess, hideNotification, setCurrentWorkspace, setCurrentWorkspaceBranches, setCurrentWorkspaceCurrentBranch, setDeleteWorkspace, setMode, setReadOnlyMode, setRenameWorkspace, setCurrentWorkspaceIsGitRepo, setGitConfig } from './payload'
import { addSlash, checkSlash, checkSpecialChars } from '@remix-ui/helper'
import { JSONStandardInput, WorkspaceTemplate } from '../types'
@ -41,6 +41,13 @@ export const setPlugin = (filePanelPlugin, reducerDispatch) => {
plugin.on('dGitProvider', 'branch', async () => {
await checkGit()
})
plugin.on('config', 'configChanged', async () => {
await getGitConfig()
})
plugin.on('settings', 'configChanged', async () => {
await getGitConfig()
})
getGitConfig()
}
export const addInputField = async (type: 'file' | 'folder', path: string, cb?: (err: Error, result?: string | number | boolean | Record<string, any>) => void) => {
@ -80,12 +87,7 @@ export const createWorkspace = async (workspaceName: string, workspaceTemplateNa
await plugin.workspaceCreated(workspaceName)
if (isGitRepo) {
const workspacesPath = plugin.fileProviders.workspace.workspacesPath
const allBranches = await getGitRepoBranches(workspacesPath + '/' + workspaceName)
// selected branch will be 'master' or 'main'
const selectedBranch = allBranches?.length ? allBranches[0].name : 'main'
await plugin.call('dGitProvider', 'init', { branch: selectedBranch })
dispatch(setCurrentWorkspaceCurrentBranch(selectedBranch))
await checkGit()
const isActive = await plugin.call('manager', 'isActive', 'dgit')
if (!isActive) await plugin.call('manager', 'activatePlugin', 'dgit')
@ -95,9 +97,8 @@ export const createWorkspace = async (workspaceName: string, workspaceTemplateNa
if (isGitRepo) {
const name = await plugin.call('settings', 'get', 'settings/github-user-name')
const email = await plugin.call('settings', 'get', 'settings/github-email')
const token = await plugin.call('settings', 'get', 'settings/gist-access-token')
if (!name || !email || !token) {
if (!name || !email ) {
await plugin.call('notification', 'toast', 'Please provide GitHub details in the settings section to start committing and branching.')
} else {
// commit the template as first commit
@ -518,12 +519,20 @@ export const getGitRepoCurrentBranch = async (workspaceName: string) => {
export const showAllBranches = async () => {
const isActive = await plugin.call('manager', 'isActive', 'dgit')
if (!isActive) await plugin.call('manager', 'activatePlugin', 'dgit')
plugin.call('menuicons', 'select', 'dgit')
plugin.call('dgit', 'open', 'branches')
}
export const getGitConfig = async () => {
const username = await plugin.call('settings', 'get', 'settings/github-user-name')
const email = await plugin.call('settings', 'get', 'settings/github-email')
const token = await plugin.call('settings', 'get', 'settings/gist-access-token')
const config = { username, email, token }
dispatch(setGitConfig(config))
return config
}
const refreshBranches = async () => {
const workspacesPath = plugin.fileProviders.workspace.workspacesPath
const workspaceName = plugin.fileProviders.workspace.workspace

@ -64,7 +64,8 @@ export interface BrowserState {
popup: string,
focusEdit: string,
focusElement: { key: string, type: 'file' | 'folder' | 'gist' }[],
initializingFS: boolean
initializingFS: boolean,
gitConfig: { username: string, email: string, token: string },
}
export const browserInitialState: BrowserState = {
@ -116,7 +117,8 @@ export const browserInitialState: BrowserState = {
popup: '',
focusEdit: '',
focusElement: [],
initializingFS: true
initializingFS: true,
gitConfig: { username: '', email: '', token: '' }
}
export const browserReducer = (state = browserInitialState, action: Action) => {
@ -718,6 +720,15 @@ export const browserReducer = (state = browserInitialState, action: Action) => {
}
}
case 'SET_GIT_CONFIG' : {
const payload: { username: string, token: string, email: string } = action.payload
return {
...state,
gitConfig: payload
}
}
default:
throw new Error()
}

@ -303,6 +303,7 @@ export function Workspace () {
data-id="initGitRepository"
className="form-check-input custom-control-input"
type="checkbox"
disabled={!global.fs.gitConfig.username || !global.fs.gitConfig.email}
onChange={() => {}}
/>
<label
@ -314,6 +315,12 @@ export function Workspace () {
Initialize workspace as a new git repository
</label>
</div>
{!global.fs.gitConfig.username || !global.fs.gitConfig.email ?
(
<div className='text-warning'>You need to set a username and email to be able to use git features.<br>
</br>Please update these fields in the settings of Remix</div>)
:<></>
}
</>
)

Loading…
Cancel
Save