pull/4791/head
filip mertens 6 months ago
parent fea8d9c5f6
commit 8695d259bf
  1. 8
      apps/remix-ide-e2e/src/tests/vyper_api.test.ts
  2. 8
      apps/remix-ide/src/app/files/dgitProvider.ts
  3. 12
      apps/vyper/src/app/utils/remix-client.tsx
  4. 4
      apps/vyper/src/main.tsx
  5. 1
      libs/remix-ui/editor/src/lib/remix-ui-editor.tsx
  6. 46
      libs/remix-ui/git/src/components/branchHeader.tsx
  7. 21
      libs/remix-ui/git/src/components/gitui.tsx
  8. 16
      libs/remix-ui/git/src/components/panels/branches.tsx
  9. 9
      libs/remix-ui/git/src/components/panels/branches/localbranchdetails.tsx
  10. 11
      libs/remix-ui/git/src/components/panels/branches/remotebranchedetails.tsx
  11. 27
      libs/remix-ui/git/src/lib/gitactions.ts
  12. 3
      libs/remix-ui/git/src/lib/listeners.ts
  13. 1
      libs/remix-ui/git/src/state/actions.ts
  14. 1
      libs/remix-ui/git/src/state/context.tsx
  15. 7
      libs/remix-ui/git/src/state/gitpayload.ts
  16. 6
      libs/remix-ui/git/src/state/gitreducer.tsx
  17. 11
      libs/remix-ui/git/src/types/index.ts
  18. 1
      libs/remix-ui/workspace/src/lib/actions/index.ts

@ -40,7 +40,7 @@ module.exports = {
.openFile('src')
.openFile('src/snekmate')
.openFile('src/snekmate/tokens')
.openFile('src/snekmate/tokens/erc721.vy')
.openFile('src/snekmate/tokens/ERC721.vy')
},
// 'Add vyper file to run tests #group1': function (browser: NightwatchBrowser) {
// browser.addFile('TestBallot.sol', sources[0]['TestBallot.sol'])
@ -149,7 +149,7 @@ module.exports = {
})
},
'Compile Ownable contract from snekmate #group1': !function (browser: NightwatchBrowser) {
'Compile Ownable contract from snekmate #group1': function (browser: NightwatchBrowser) {
let contractAddress
browser
.frameParent()
@ -158,8 +158,8 @@ module.exports = {
.openFile('src')
.openFile('src/snekmate')
.openFile('src/snekmate/auth')
.openFile('src/snekmate/auth/ownable.vy')
.rightClick('*[data-id="treeViewLitreeViewItemsrc/snekmate/auth/ownable.vy"]')
.openFile('src/snekmate/auth/Ownable.vy')
.rightClick('*[data-id="treeViewLitreeViewItemsrc/snekmate/auth/Ownable.vy"]')
.waitForElementVisible('*[data-id="contextMenuItemvyper"]')
.click('*[data-id="contextMenuItemvyper"]')
.clickLaunchIcon('vyper')

@ -446,6 +446,7 @@ class DGitProvider extends Plugin {
}
return branches
} catch (e) {
console.log(e)
return []
}
}
@ -803,7 +804,7 @@ class DGitProvider extends Plugin {
relative: input.relative,
input
}
console.log('fetch input', cmd)
let result
if ((Registry.getInstance().get('platform').api.isDesktop())) {
result = await this.call('isogit', 'fetch', cmd)
@ -816,7 +817,7 @@ class DGitProvider extends Plugin {
...await this.addIsomorphicGitConfigFS(),
...cmd2
})
console.log('fetch result', cmd2, result)
}
setTimeout(async () => {
@ -1066,7 +1067,6 @@ class DGitProvider extends Plugin {
readCommitResults.push(readCommitResult)
}
console.log(readCommitResults)
// Check for the Link header to determine pagination
const linkHeader = response.headers.link;
@ -1077,7 +1077,7 @@ class DGitProvider extends Plugin {
hasNextPage = linkHeader.includes('rel="next"');
}
console.log("Has next page:", hasNextPage);
pages.push({
page: input.page,
perPage: input.length,

@ -86,7 +86,17 @@ export class RemixClient extends PluginClient<any, CustomRemixApi> {
await this.call(
'dgitApi',
'clone',
{url: 'https://github.com/pcaversaccio/snekmate', token: null, branch: 'main', singleBranch: true, workspaceName: 'snekmate'},
{url: 'https://github.com/pcaversaccio/snekmate', token: null, branch: 'main', singleBranch: false, workspaceName: 'snekmate'},
)
await this.call(
'dgitApi',
'checkout',
{
ref:'v0.0.5',
force: true,
refresh: true,
}
)
this.call(

@ -6,8 +6,8 @@ import App from './app/app'
const container = document.getElementById('root');
if (container) {
createRoot(container).render(<React.StrictMode>
createRoot(container).render(
<App />
</React.StrictMode>);
);
}

@ -332,7 +332,6 @@ export const EditorUI = (props: EditorUIProps) => {
})
useEffect(() => {
console.log(props.isDiff, props.currentFile)
if (!(editorRef.current || diffEditorRef.current ) || !props.currentFile) return
currentFileRef.current = props.currentFile
props.plugin.call('fileManager', 'getUrlFromPath', currentFileRef.current).then((url) => (currentUrlRef.current = url.file))

@ -1,17 +1,39 @@
import React, { useEffect, useReducer, useState } from 'react'
import { gitActionsContext } from '../state/context'
import React, { useEffect, useState } from 'react'
import { gitActionsContext, pluginActionsContext } from '../state/context'
import { ReadCommitResult } from "isomorphic-git"
import { gitPluginContext } from './gitui'
export const BranchHeader = () => {
const context = React.useContext(gitPluginContext)
const actions = React.useContext(gitActionsContext)
const pluginActions = React.useContext(pluginActionsContext)
const [changed, setChanged] = useState(false)
const [isDetached, setIsDetached] = useState(false)
const [latestCommit, setLatestCommit] = useState<ReadCommitResult>(null)
useEffect(() => {
if (context.currentBranch) {
actions.getBranchDifferences(context.currentBranch, null, context)
}
}, [context.currentBranch, context.commits, context.branches, context.remotes])
if (!context.currentBranch || (context.currentBranch && context.currentBranch.name === '')) {
if (context.currentHead === '') {
setIsDetached(false)
} else {
setIsDetached(true)
}
} else {
setIsDetached(false)
}
setLatestCommit(null)
if (context.currentHead !== '') {
if (context.commits && context.commits.length > 0) {
const commit = context.commits.find(commit => commit.oid === context.currentHead)
if (commit) {
setLatestCommit(commit)
}
}
}
}, [context.currentBranch, context.commits, context.branches, context.remotes, context.currentHead])
useEffect(() => {
if (context.fileStatusResult) {
@ -21,11 +43,27 @@ export const BranchHeader = () => {
}
}, [context.fileStatusResult, context.modified, context.allchangesnotstaged, context.untracked, context.deleted])
const showDetachedWarningText = async () => {
await pluginActions.showAlert({
message: `You are in 'detached HEAD' state. This means you are not on a branch because you checkout a tag or a specific commit. If you want to commit changes, you will need to create a new branch.`,
title: 'Warning'
})
}
return (<>
<div className='text-sm w-100'>
<div className='text-secondary long-and-truncated'>
<i className="fa fa-code-branch mr-1 pl-2"></i>
{changed?'*':''}{context.currentBranch && context.currentBranch.name}</div>
{changed ? '*' : ''}{context.currentBranch && context.currentBranch.name}
</div>
{latestCommit ?
<div className='text-secondary long-and-truncated'>
{latestCommit.commit && latestCommit.commit.message ? latestCommit.commit.message : ''}
</div> : null}
{isDetached ?
<div className='text-warning long-and-truncated'>
You are in a detached state<i onClick={showDetachedWarningText} className="btn fa fa-info-circle mr-1 pl-2"></i>
</div> : null}
</div>
<hr></hr>
</>)

@ -1,5 +1,5 @@
import React, { useEffect, useReducer, useState } from 'react'
import { add, addall, checkout, checkoutfile, clone, commit, createBranch, remoteBranches, repositories, rm, getCommitChanges, diff, resolveRef, getBranchCommits, setUpstreamRemote, loadGitHubUserFromToken, getBranches, getRemotes, remoteCommits, saveGitHubCredentials, getGitHubCredentialsFromLocalStorage, fetch, pull, push, setDefaultRemote, addRemote, removeRemote, sendToGitLog, clearGitLog, getBranchDifferences, getFileStatusMatrix, init } from '../lib/gitactions'
import { add, addall, checkout, checkoutfile, clone, commit, createBranch, remoteBranches, repositories, rm, getCommitChanges, diff, resolveRef, getBranchCommits, setUpstreamRemote, loadGitHubUserFromToken, getBranches, getRemotes, remoteCommits, saveGitHubCredentials, getGitHubCredentialsFromLocalStorage, fetch, pull, push, setDefaultRemote, addRemote, removeRemote, sendToGitLog, clearGitLog, getBranchDifferences, getFileStatusMatrix, init, showAlert } from '../lib/gitactions'
import { loadFiles, setCallBacks } from '../lib/listeners'
import { openDiff, openFile, saveToken, setModifiedDecorator, setPlugin, setUntrackedDecorator, statusChanged } from '../lib/pluginActions'
import { gitActionsContext, pluginActionsContext } from '../state/context'
@ -52,14 +52,14 @@ export const GitUI = (props: IGitUi) => {
useEffect(() => {
plugin.emit('statusChanged', {
key:'loading',
key: 'loading',
type: 'info',
title: 'Loading Git Plugin'
})
setTimeout(() => {
setAppLoaded(true)
}, 2000)
},[])
}, [])
useEffect(() => {
if (!appLoaded) return
@ -108,9 +108,14 @@ export const GitUI = (props: IGitUi) => {
updatestate()
})
setNeedsInit(!(gitState.currentBranch && gitState.currentBranch.name !== ''))
let needsInit = false
if (!(gitState.currentBranch && gitState.currentBranch.name !== '') && gitState.currentHead === '') {
needsInit = true
}
setNeedsInit(needsInit)
}, [gitState.gitHubUser, gitState.currentBranch, gitState.remotes, gitState.gitHubAccessToken])
}, [gitState.gitHubUser, gitState.currentBranch, gitState.remotes, gitState.gitHubAccessToken, gitState.currentHead])
const gitActionsProviderValue = {
commit,
@ -151,7 +156,8 @@ export const GitUI = (props: IGitUi) => {
openDiff,
saveToken,
saveGitHubCredentials,
getGitHubCredentialsFromLocalStorage
getGitHubCredentialsFromLocalStorage,
showAlert
}
return (
@ -159,8 +165,9 @@ export const GitUI = (props: IGitUi) => {
<gitPluginContext.Provider value={gitState}>
<loaderContext.Provider value={loaderState}>
<gitActionsContext.Provider value={gitActionsProviderValue}>
<BranchHeader />
<pluginActionsContext.Provider value={pluginActionsProviderValue}>
<BranchHeader />
{setup && !needsInit ? <Setup></Setup> : null}
{needsInit ? <Init></Init> : null}
{!setup && !needsInit ?

@ -16,14 +16,6 @@ export const Branches = () => {
setNewBranch({ value: e.currentTarget.value });
};
const checkout = async (oid: string, remote: remote) => {
try {
actions.checkout({ ref: oid, remote: remote.name });
} catch (e) {
// do nothing
}
};
return (
<>
<div className="pt-1">
@ -35,6 +27,13 @@ export const Branches = () => {
);
})}
<hr />
</div> : null}
{context.currentBranch
&& context.currentBranch.name !== ''
&& (!context.branches || context.branches.length === 0) ?
<div className="text-muted">Current branch is `{context.currentBranch.name}` but you have no commits.<hr /></div>
: null}
<label>create branch</label>
<div className="form-group">
@ -53,7 +52,6 @@ export const Branches = () => {
>
create new branch
</GitUIButton>
</div> : <div className="text-muted">No branches</div>}
</div>
</>
);

@ -35,7 +35,8 @@ export const LocalBranchDetails = (props: BrancheDetailsProps) => {
const checkout = (branch: branch) => {
actions.checkout({
ref: branch.name,
remote: branch.remote && branch.remote.name || null
remote: branch.remote && branch.remote.name || null,
refresh: true
});
}
@ -45,11 +46,11 @@ export const LocalBranchDetails = (props: BrancheDetailsProps) => {
const checkoutCommit = async (oid: string) => {
try {
//await ModalRef.current?.show();
actions.checkout({ ref: oid })
//Utils.log("yes");
;
} catch (e) {
//Utils.log("no");
//
}
};

@ -46,9 +46,18 @@ export const RemoteBranchDetails = (props: BrancheDetailsProps) => {
}, [context.remoteBranchCommits])
const checkout = async (branch: branch) => {
await actions.fetch({
remote: branch.remote,
ref: branch,
depth: 20,
singleBranch: true,
relative: false,
quiet: true
})
await actions.checkout({
ref: branch.name,
remote: branch.remote && branch.remote.name || null
remote: branch.remote && branch.remote.name || null,
refresh: true
});
await actions.getBranches()
}

@ -1,6 +1,6 @@
import { ReadBlobResult, ReadCommitResult } from "isomorphic-git";
import React from "react";
import { fileStatus, fileStatusMerge, setRemoteBranchCommits, resetRemoteBranchCommits, setBranches, setCanCommit, setCommitChanges, setCommits, setCurrentBranch, setGitHubUser, setLoading, setRemoteBranches, setRemotes, setRepos, setUpstream, setLocalBranchCommits, setBranchDifferences, setRemoteAsDefault, setScopes, setLog, clearLog, setUserEmails } from "../state/gitpayload";
import { fileStatus, fileStatusMerge, setRemoteBranchCommits, resetRemoteBranchCommits, setBranches, setCanCommit, setCommitChanges, setCommits, setCurrentBranch, setGitHubUser, setLoading, setRemoteBranches, setRemotes, setRepos, setUpstream, setLocalBranchCommits, setBranchDifferences, setRemoteAsDefault, setScopes, setLog, clearLog, setUserEmails, setCurrenHead } from "../state/gitpayload";
import { GitHubUser, branch, commitChange, gitActionDispatch, statusMatrixType, gitState, branchDifference, remote, gitLog, fileStatusResult, customGitApi, IGitApi, cloneInputType, fetchInputType, pullInputType, pushInputType, checkoutInput, rmInput, addInput, repository, userEmails } from '../types';
import { removeSlash } from "../utils";
import { disableCallBacks, enableCallBacks } from "./listeners";
@ -107,13 +107,22 @@ export const gitlog = async () => {
export const showCurrentBranch = async () => {
try {
const branch = await currentBranch();
dispatch(setCanCommit((branch && branch.name !== "")));
dispatch(setCurrentBranch(branch));
} catch (e) {
console.log(e)
dispatch(setCanCommit(false));
dispatch(setCurrentBranch({ name: "", remote: { name: "", url: "" } }));
}
try {
const currentHead = await getCommitFromRef('HEAD');
dispatch(setCurrenHead(currentHead));
} catch (e) {
// show empty branch
console.log(e)
dispatch(setCurrenHead(''));
}
}
export const currentBranch = async () => {
@ -133,8 +142,7 @@ export const currentBranch = async () => {
export const createBranch = async (name: string = "") => {
dispatch(setLoading(true))
if (name) {
await plugin.call('dgitApi', 'branch', { ref: name });
await plugin.call('dgitApi', 'checkout', { ref: name });
await plugin.call('dgitApi', 'branch', { ref: name, force: true, checkout: true });
}
dispatch(setLoading(false))
}
@ -272,8 +280,8 @@ export const checkout = async (cmd: checkoutInput) => {
await plugin.call('fileManager', 'closeAllFiles')
try {
await plugin.call('dgitApi', 'checkout', cmd)
gitlog();
} catch (e) {
console.log(e)
plugin.call('notification', 'toast', `${e}`)
}
await enableCallBacks();
@ -536,6 +544,13 @@ export const getGitHubCredentialsFromLocalStorage = async () => {
}
}
export const showAlert = async ({ title, message }: { title: string, message: string }) => {
await plugin.call('notification', 'alert', {
title: title,
message: message
})
}
export const loadGitHubUserFromToken = async () => {
if (!plugin) return
try {

@ -120,6 +120,9 @@ export const setCallBacks = (viewPlugin: Plugin, gitDispatcher: React.Dispatch<g
loadFileQueue.enqueue(async () => {
gitlog()
}, 10)
loadFileQueue.enqueue(async () => {
getBranches()
}, 20)
gitDispatch(setLog({
message: 'Committed changes...',
type: 'success'

@ -7,6 +7,7 @@ export interface ActionPayloadTypes {
SET_COMMITS: ReadCommitResult[]
SET_BRANCHES: branch[]
SET_CURRENT_BRANCH: branch
SET_CURRENT_HEAD: string
SET_CAN_USE_APP: boolean
SET_REPO_NAME: string
SET_LOADING: boolean

@ -52,6 +52,7 @@ export interface pluginActions {
email: string
token: string
}>
showAlert({ title, message }:{title: string, message: string}): Promise<void>
}
export const pluginActionsContext = React.createContext<pluginActions>(null)

@ -101,6 +101,13 @@ export const setCurrentBranch = (currentBranch: branch) => {
}
}
export const setCurrenHead = (currentHead: string) => {
return {
type: 'SET_CURRENT_HEAD',
payload: currentHead
}
}
export const setCanCommit = (canCommit: boolean) => {
return {
type: 'SET_CAN_COMMIT',

@ -56,6 +56,12 @@ export const gitReducer = (state: gitState = defaultGitState, action: Actions):
currentBranch: action.payload
}
case 'SET_CURRENT_HEAD':
return {
...state,
currentHead: action.payload
}
case 'SET_CAN_USE_APP':
return {
...state,

@ -82,6 +82,7 @@ export type branchInputType = {
ref: string,
checkout?: boolean
refresh?: boolean
force?: boolean
}
export type currentBranchInput = {
@ -94,6 +95,7 @@ export type checkoutInput = {
force?: boolean,
remote?: string
refresh?: boolean
fetch?: boolean
}
export type addInput = {
@ -151,6 +153,7 @@ export interface customGitApi extends IRemixApi {
export type gitState = {
currentBranch: branch
currentHead: string
commits: ReadCommitResult[]
branch: string
canCommit: boolean
@ -264,6 +267,7 @@ export type remoteBranch = {
export const defaultGitState: gitState = {
currentBranch: { name: "", remote: { name: "", url: "" } },
currentHead: "",
commits: [],
branch: "",
canCommit: true,
@ -370,6 +374,11 @@ export interface setCurrentBranchAction {
payload: branch
}
export interface setCurrentHeadAction {
type: string,
payload: string
}
export interface setRemotesAction {
type: string,
payload: remote[]
@ -424,4 +433,4 @@ export interface clearLogAction {
type: string
}
export type gitActionDispatch = clearLogAction | setLogAction | setDefaultRemoteAction | setTokenAction | setUpstreamAction | setRemoteBranchCommitsAction | setLocalBranchCommitsAction | setBranchDifferencesAction | setRemotesAction | setCurrentBranchAction | fileStatusAction | setLoadingAction | setCanUseAppAction | setRepoNameAction | setCommitsAction | setBranchesAction | setReposAction | setRemoteBranchesAction
export type gitActionDispatch = setCurrentHeadAction | clearLogAction | setLogAction | setDefaultRemoteAction | setTokenAction | setUpstreamAction | setRemoteBranchCommitsAction | setLocalBranchCommitsAction | setBranchDifferencesAction | setRemotesAction | setCurrentBranchAction | fileStatusAction | setLoadingAction | setCanUseAppAction | setRepoNameAction | setCommitsAction | setBranchesAction | setReposAction | setRemoteBranchesAction

@ -60,7 +60,6 @@ export const initWorkspace = (filePanelPlugin) => async (reducerDispatch: React.
let filePathToOpen = null
let workspaces = []
plugin.on('editor', 'editorMounted', async () => {
console.log('editor mounted')
editorMounted = true
if (filePathToOpen){
setTimeout(async () => {

Loading…
Cancel
Save