pull/4791/head
filip mertens 5 months ago
parent 5964cfd619
commit 91aaf32ab8
  1. 15
      libs/remix-ui/git/src/components/buttons/commitmessage.tsx
  2. 2
      libs/remix-ui/git/src/components/buttons/sourcecontrolbuttons.tsx
  3. 12
      libs/remix-ui/git/src/components/gitui.tsx
  4. 2
      libs/remix-ui/git/src/components/navigation/branchedetails.tsx
  5. 2
      libs/remix-ui/git/src/components/panels/branches.tsx
  6. 6
      libs/remix-ui/git/src/components/panels/branches/branchdifferences.tsx
  7. 1
      libs/remix-ui/git/src/components/panels/commits.tsx
  8. 4
      libs/remix-ui/git/src/components/panels/commits/commitsummary.tsx
  9. 1
      libs/remix-ui/git/src/components/panels/githubcredentials.tsx
  10. 3
      libs/remix-ui/git/src/components/panels/setup.tsx
  11. 8
      libs/remix-ui/git/src/components/panels/sourcecontrol/sourcontrolitembuttons.tsx
  12. 24
      libs/remix-ui/git/src/lib/gitactions.ts
  13. 81
      libs/remix-ui/git/src/lib/listeners.ts
  14. 5
      libs/remix-ui/git/src/state/gitreducer.tsx
  15. 93
      libs/remix-ui/git/src/types/index.ts
  16. 15
      libs/remix-ui/workspace/src/lib/actions/workspace.ts

@ -8,7 +8,7 @@ import { syncStateContext } from "./sourceControlBase";
enum buttonStateValues {
Commit ,
Sync = 1,
Sync = 1,
PublishBranch = 2
}
@ -52,7 +52,7 @@ export const CommitMessage = () => {
ref: context.currentBranch
})
}
const commitNotAllowed = () => {
return context.canCommit === false || message.value === "" || ( context.staged.length === 0 && context.allchangesnotstaged.length == 0 )
}
@ -92,20 +92,20 @@ export const CommitMessage = () => {
}
const setButtonStateValues = () => {
console.log('setButtonStateValues', context)
if(!commitNotAllowed() || context.allchangesnotstaged.length > 0 || context.staged.length > 0){
if(context.allchangesnotstaged.length == 0 && context.staged.length == 0 && message.value === "" && publishEnabled()){
console.log('setButtonStateValues', context)
if (!commitNotAllowed() || context.allchangesnotstaged.length > 0 || context.staged.length > 0){
if (context.allchangesnotstaged.length == 0 && context.staged.length == 0 && message.value === "" && publishEnabled()){
setButtonState(buttonStateValues.PublishBranch)
return
}
setButtonState(buttonStateValues.Commit)
return
}
if(syncEnabled()){
if (syncEnabled()){
setButtonState(buttonStateValues.Sync)
return
}
if(publishEnabled()){
if (publishEnabled()){
setButtonState(buttonStateValues.PublishBranch)
return
}
@ -116,7 +116,6 @@ export const CommitMessage = () => {
setButtonStateValues()
},[context.canCommit, context.staged, context.allchangesnotstaged, context.currentBranch, syncState.commitsAhead, syncState.commitsBehind, message.value])
return (
<>
<div className="form-group">

@ -71,7 +71,7 @@ export const SourceControlButtons = () => {
<span className='d-flex justify-content-end align-items-center'>
<CustomTooltip tooltipText={getTooltipText('git.pull')}>
<GitUIButton disabledCondition={buttonsDisabled()} onClick={pull} className='btn btn-sm pl-0 pr-2'>
<div className="d-flex align-items-baseline">
<div className="d-flex align-items-baseline">
{syncState.commitsBehind.length ? <div className="badge badge-pill pl-0">
{syncState.commitsBehind.length}
</div> : null}

@ -50,7 +50,6 @@ export const GitUI = (props: IGitUi) => {
const [needsInit, setNeedsInit] = useState<boolean>(true)
const [appLoaded, setAppLoaded] = useState<boolean>(false)
useEffect(() => {
plugin.emit('statusChanged', {
key:'loading',
@ -63,7 +62,7 @@ export const GitUI = (props: IGitUi) => {
},[])
useEffect(() => {
if(!appLoaded) return
if (!appLoaded) return
setCallBacks(plugin, gitDispatch, loaderDispatch)
setPlugin(plugin, gitDispatch, loaderDispatch)
loaderDispatch({ type: 'plugin', payload: true })
@ -71,9 +70,9 @@ export const GitUI = (props: IGitUi) => {
}, [appLoaded])
useEffect(() => {
if(!appLoaded) return
if (!appLoaded) return
async function checkconfig() {
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')
@ -84,7 +83,7 @@ export const GitUI = (props: IGitUi) => {
}, [gitState.gitHubAccessToken, gitState.gitHubUser, gitState.userEmails])
useEffect(() => {
if(!appLoaded) return
if (!appLoaded) return
async function setDecorators(gitState: gitState) {
await plugin.call('fileDecorator', 'clearFileDecorators')
await setModifiedDecorator(gitState.modified)
@ -98,7 +97,7 @@ export const GitUI = (props: IGitUi) => {
}, [gitState.fileStatusResult])
useEffect(() => {
if(!appLoaded) return
if (!appLoaded) return
async function updatestate() {
console.log('updatestate', gitState)
if (gitState.currentBranch && gitState.currentBranch.remote && gitState.currentBranch.remote.url) {
@ -113,7 +112,6 @@ export const GitUI = (props: IGitUi) => {
}, [gitState.gitHubUser, gitState.currentBranch, gitState.remotes, gitState.gitHubAccessToken])
const gitActionsProviderValue = {
commit,
addall,

@ -89,7 +89,7 @@ export const BrancheDetailsNavigation = (props: BrancheDetailsNavigationProps) =
<GitUIButton className="btn btn-sm p-0 mr-1 text-muted" onClick={() => openRemote()}>
<FontAwesomeIcon icon={faGlobe} ></FontAwesomeIcon>
</GitUIButton>
</>}
</>}
</div>
</>

@ -24,12 +24,10 @@ export const Branches = () => {
}
};
useEffect(() => {
console.log("branches", context.branches)
}, [context.branches])
return (
<>
<div className="pt-1">

@ -26,16 +26,16 @@ export const BranchDifferences = (props: BrancheDetailsProps) => {
}, [context.branchDifferences])
const commitsAhead = (remote: remote) => {
if(!remote) return [];
if (!remote) return [];
return context.branchDifferences[`${remote.name}/${branch.name}`]?.uniqueHeadCommits || [];
}
const commitsBehind = (remote: remote) => {
if(!remote) return [];
if (!remote) return [];
return context.branchDifferences[`${remote.name}/${branch.name}`]?.uniqueRemoteCommits || [];
}
if(!getRemote()) return null;
if (!getRemote()) return null;
return (

@ -40,7 +40,6 @@ export const Commits = () => {
return context.upstream ? context.upstream : context.defaultRemote ? context.defaultRemote : null
}
const getCommitChanges = async (commit: ReadCommitResult) => {
await actions.getCommitChanges(commit.oid, commit.commit.parent[0],null, getRemote())
}

@ -50,8 +50,8 @@ export const CommitSummary = (props: CommitSummaryProps) => {
}
const openRemote = () => {
if(getRemote())
window.open(`${getRemote().url}/commit/${commit.oid}`, '_blank');
if (getRemote())
window.open(`${getRemote().url}/commit/${commit.oid}`, '_blank');
}
return (

@ -6,7 +6,6 @@ import { CustomTooltip } from "@remix-ui/helper";
import { useIntl, FormattedMessage } from "react-intl";
import { CopyToClipboard } from "@remix-ui/clipboard";
export const GitHubCredentials = () => {
const context = React.useContext(gitPluginContext)
const pluginactions = React.useContext(pluginActionsContext)

@ -6,7 +6,6 @@ export const Setup = () => {
const [screen, setScreen] = useState(0)
if (screen === 0) {
return (
<>
@ -22,7 +21,7 @@ export const Setup = () => {
</div>
</>
)
}else if (screen === 1) {
} else if (screen === 1) {
return (
<>
<h5>SETUP</h5>

@ -23,17 +23,17 @@ export const SourceControlItemButtons = (props: SourceControlItemButtonsProps) =
{status && status.indexOf("modified") === -1 ? <></> : <button onClick={async () => await actions.checkoutfile(file.filename)} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faUndo} className="" /></button>}
{status && status.indexOf("deleted") === -1 ? <></> : <button onClick={async () => await actions.checkoutfile(file.filename)} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faUndo} className="" /></button>}
{status && status.indexOf("deleted") !== -1 ? <></> : <button data-id={`unStage${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.rm({filepath:file.filename})} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faMinus} className="" /></button>}
{status && status.indexOf("deleted") !== -1 ? <></> : <button data-id={`unStage${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.rm({ filepath:file.filename })} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faMinus} className="" /></button>}
</>
}
if (group.name === 'Changes') {
return <>
{status && status.indexOf("deleted") === -1 ? <></> : <><button onClick={async () => await actions.checkoutfile(file.filename)} data-id={`undo${group.name}${path.basename(file.filename)}`} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faUndo} className="" /></button><button data-id={`addToGit${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.rm({filepath:file.filename})} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faPlus} className="" /></button></>}
{status && status.indexOf("deleted") === -1 ? <></> : <><button onClick={async () => await actions.checkoutfile(file.filename)} data-id={`undo${group.name}${path.basename(file.filename)}`} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faUndo} className="" /></button><button data-id={`addToGit${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.rm({ filepath:file.filename })} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faPlus} className="" /></button></>}
{status && status.indexOf("modified") === -1 ? <></> : <button onClick={async () => await actions.checkoutfile(file.filename)} data-id={`undo${group.name}${path.basename(file.filename)}`} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faUndo} className="" /></button>}
{(status && status.indexOf("unstaged") !== -1 || status && status.indexOf("deleted") !== -1) ? <></> : <button data-id={`addToGit${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.add({filepath:file.filename})} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faPlus} className="" /></button>}
{(status && status.indexOf("unstaged") !== -1 && status && status.indexOf("modified") !== -1) ? <button data-id={`addToGit${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.add({filepath:file.filename})} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faPlus} className="" /></button> : <></>}
{(status && status.indexOf("unstaged") !== -1 || status && status.indexOf("deleted") !== -1) ? <></> : <button data-id={`addToGit${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.add({ filepath:file.filename })} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faPlus} className="" /></button>}
{(status && status.indexOf("unstaged") !== -1 && status && status.indexOf("modified") !== -1) ? <button data-id={`addToGit${group.name}${path.basename(file.filename)}`} onClick={async () => await actions.add({ filepath:file.filename })} className='btn btn-sm btn-secondary mr-1 '><FontAwesomeIcon icon={faPlus} className="" /></button> : <></>}
</>
}
return <></>

@ -128,19 +128,17 @@ export const showCurrentBranch = async () => {
}
export const currentBranch = async () => {
try {
const branch: branch =
(await plugin.call('dgitApi', "currentbranch")) || {
const branch: branch =
(await plugin.call('dgitApi', "currentbranch")) || {
name: "",
remote: {
name: "",
remote: {
name: "",
url: "",
},
};
return branch;
} catch (e) {
throw e;
}
url: "",
},
};
return branch;
}
export const createBranch = async (name: string = "") => {
@ -595,7 +593,7 @@ export const loadGitHubUserFromToken = async () => {
}
export const statusMatrix = async (filepaths: string[]) => {
const matrix = await plugin.call('dgitApi', 'status', { ref: "HEAD", filepaths: filepaths || ['.'] });
const matrix = await plugin.call('dgitApi', 'status', { ref: "HEAD", filepaths: filepaths || ['.']});
const result = (matrix || []).map((x) => {
return {
filename: `/${x.shift()}`,

@ -14,27 +14,25 @@ let callBackEnabled: boolean = false
type AsyncCallback = () => Promise<void>;
class AsyncDebouncedQueue {
private queues: Map<AsyncCallback, { timer: any, lastCall: number }>;
private queues: Map<AsyncCallback, { timer: any, lastCall: number }>;
constructor(private delay: number = 300) {
this.queues = new Map();
}
enqueue(callback: AsyncCallback, customDelay?:number): void {
if (this.queues.has(callback)) {
clearTimeout(this.queues.get(callback)!.timer);
}
let timer = setTimeout(async () => {
await callback();
this.queues.delete(callback);
}, customDelay || this.delay);
constructor(private delay: number = 300) {
this.queues = new Map();
}
this.queues.set(callback, { timer, lastCall: Date.now() });
enqueue(callback: AsyncCallback, customDelay?:number): void {
if (this.queues.has(callback)) {
clearTimeout(this.queues.get(callback)!.timer);
}
}
const timer = setTimeout(async () => {
await callback();
this.queues.delete(callback);
}, customDelay || this.delay);
this.queues.set(callback, { timer, lastCall: Date.now() });
}
}
export const setCallBacks = (viewPlugin: Plugin, gitDispatcher: React.Dispatch<gitActionDispatch>, loaderDispatcher: React.Dispatch<any>) => {
plugin = viewPlugin
@ -101,7 +99,7 @@ export const setCallBacks = (viewPlugin: Plugin, gitDispatcher: React.Dispatch<g
});
plugin.on('dgitApi', 'checkout', async () => {
})
plugin.on('dgitApi', 'init', async () => {
loadFileQueue.enqueue(async () => {
@ -156,7 +154,7 @@ export const setCallBacks = (viewPlugin: Plugin, gitDispatcher: React.Dispatch<g
plugin.on('settings', 'configChanged', async () => {
console.log('settings changed')
await getGitConfig()
})
})
callBackEnabled = true;
}
@ -168,46 +166,17 @@ export const getGitConfig = async () => {
const config = { username, email, token }
loadGitHubUserFromToken()
return
}
return
const syncFromWorkspace = async (callback: Function, isLocalhost = false) => {
//gitDispatch(setLoading(true));
await disableCallBacks();
if (isLocalhost) {
gitDispatch(setCanUseApp(false));
gitDispatch(setLoading(false));
await enableCallBacks();
return;
}
try {
const workspace = await plugin.call(
"filePanel",
"getCurrentWorkspace"
);
if (workspace.isLocalhost) {
gitDispatch(setCanUseApp(false));
await enableCallBacks();
return
}
gitDispatch(setRepoName(workspace.name));
gitDispatch(setCanUseApp(true));
} catch (e) {
gitDispatch(setCanUseApp(false));
}
await callback();
await enableCallBacks();
}
export const loadFiles = async (filepaths: string[] = null) => {
try {
const branch = await plugin.call('dgitApi', "currentbranch")
console.log('load files', branch)
if(branch) {
if (branch) {
await getFileStatusMatrix(filepaths);
}else{
} else {
await plugin.call('fileDecorator', 'clearFileDecorators')
statusChanged(0)
}
@ -217,18 +186,6 @@ export const loadFiles = async (filepaths: string[] = null) => {
}
}
const getStorageUsed = async () => {
try {
const storageUsed = await plugin.call("storage" as any, "getStorage" as any);
} catch (e) {
const storage: string = await plugin.call('dgitApi', "localStorageUsed" as any);
const storageUsed = {
usage: parseFloat(storage) * 1000,
quota: 10000000,
};
}
}
export const disableCallBacks = async () => {
callBackEnabled = false;
}

@ -178,11 +178,10 @@ export const gitReducer = (state: gitState = defaultGitState, action: Actions):
case 'SET_USER_EMAILS':
return {
...state,
userEmails: action.payload
...state,
userEmails: action.payload
}
case 'SET_DEFAULT_REMOTE':
return {
...state,

@ -62,12 +62,12 @@ export type compareBranchesInput = {
}
export type fetchInputType = {
remote: remote,
ref?: branch,
remoteRef?: branch,
depth?: number,
singleBranch?: boolean,
relative?: boolean,
remote: remote,
ref?: branch,
remoteRef?: branch,
depth?: number,
singleBranch?: boolean,
relative?: boolean,
quiet?: boolean
}
@ -142,11 +142,10 @@ export interface repositoriesInput { token: string, page?: number, per_page?: nu
export interface statusInput { ref: string, filepaths?: string[] }
export const dGitProfile: LibraryProfile<IGitApi> = {
name: 'dgitApi',
methods: ['clone', 'branches', 'remotes', 'getCommitChanges', 'log', 'remotecommits'],
name: 'dgitApi',
methods: ['clone', 'branches', 'remotes', 'getCommitChanges', 'log', 'remotecommits'],
}
export interface customGitApi extends IRemixApi {
dgit: IGitApi
}
@ -266,47 +265,47 @@ export type remoteBranch = {
}
export const defaultGitState: gitState = {
currentBranch: { name: "", remote: { name: "", url: "" } },
commits: [],
branch: "",
canCommit: true,
branches: [],
remotes: [],
defaultRemote: null,
fileStatusResult: [],
staged: [],
untracked: [],
deleted: [],
modified: [],
allchangesnotstaged: [],
canUseApp: false,
loading: false,
storageUsed: {},
reponame: "",
repositories: [],
remoteBranches: [],
commitChanges: [],
remoteBranchCommits: {},
localBranchCommits: {},
branchDifferences: {},
syncStatus: syncStatus.none,
localCommitCount: 0,
remoteCommitCount: 0,
upstream: null,
gitHubUser: {} as GitHubUser,
rateLimit: {} as RateLimit,
userEmails: [] as userEmails,
gitHubScopes: [],
gitHubAccessToken: "",
log: []
currentBranch: { name: "", remote: { name: "", url: "" } },
commits: [],
branch: "",
canCommit: true,
branches: [],
remotes: [],
defaultRemote: null,
fileStatusResult: [],
staged: [],
untracked: [],
deleted: [],
modified: [],
allchangesnotstaged: [],
canUseApp: false,
loading: false,
storageUsed: {},
reponame: "",
repositories: [],
remoteBranches: [],
commitChanges: [],
remoteBranchCommits: {},
localBranchCommits: {},
branchDifferences: {},
syncStatus: syncStatus.none,
localCommitCount: 0,
remoteCommitCount: 0,
upstream: null,
gitHubUser: {} as GitHubUser,
rateLimit: {} as RateLimit,
userEmails: [] as userEmails,
gitHubScopes: [],
gitHubAccessToken: "",
log: []
}
export const defaultLoaderState: loaderState = {
branches: false,
commits: false,
sourcecontrol: false,
remotes: false,
plugin: false
branches: false,
commits: false,
sourcecontrol: false,
remotes: false,
plugin: false
}
export type fileStatusResult = {

@ -204,11 +204,7 @@ export const createWorkspace = async (
}, 5000)
} else if (!isEmpty && !(isGitRepo && createCommit)) await loadWorkspacePreset(workspaceTemplateName, opts)
cb && cb(null, workspaceName)
if (isGitRepo && false) {
await checkGit()
const isActive = await plugin.call('manager', 'isActive', 'dgit')
if (!isActive) await plugin.call('manager', 'activatePlugin', 'dgit')
}
if (workspaceTemplateName === 'semaphore' || workspaceTemplateName === 'hashchecker' || workspaceTemplateName === 'rln') {
const isCircomActive = await plugin.call('manager', 'isActive', 'circuit-compiler')
if (!isCircomActive) await plugin.call('manager', 'activatePlugin', 'circuit-compiler')
@ -513,10 +509,7 @@ export const switchToWorkspace = async (name: string) => {
await plugin.fileProviders.workspace.setWorkspace(name)
await plugin.setWorkspace({ name, isLocalhost: false })
const isGitRepo = await plugin.fileManager.isGitRepo()
if (isGitRepo && false) {
const isActive = await plugin.call('manager', 'isActive', 'dgit')
if (!isActive) await plugin.call('manager', 'activatePlugin', 'dgit')
}
dispatch(setMode('browser'))
dispatch(setCurrentWorkspace({ name, isGitRepo }))
dispatch(setReadOnlyMode(false))
@ -669,7 +662,7 @@ export const cloneRepository = async (url: string) => {
const repoName = await getRepositoryTitle(url)
await createWorkspace(repoName, 'blank', null, true, null, true, false)
const promise = dgitPlugin.call('dgitApi', 'clone', {...repoConfig, workspaceExists: true, workspaceName: repoName})
const promise = dgitPlugin.call('dgitApi', 'clone', { ...repoConfig, workspaceExists: true, workspaceName: repoName })
dispatch(cloneRepositoryRequest())
promise
@ -800,7 +793,7 @@ export const switchBranch = async (branch: branch) => {
okLabel: 'Force Checkout',
okFn: async () => {
dispatch(cloneRepositoryRequest())
plugin
plugin
.call('dgitApi', 'checkout', { ref: branch, force: true }, false)
.then(async () => {
await fetchWorkspaceDirectory(ROOT_PATH)

Loading…
Cancel
Save