add init method

pull/4791/head
filip mertens 6 months ago
parent a61d3304a1
commit 9459e23d0e
  1. 3
      apps/remix-ide/src/app/tabs/locales/en/git.json
  2. 10
      libs/remix-api/src/lib/plugins/fileSystem-api.ts
  3. 11
      libs/remix-api/src/lib/plugins/filedecorator-api.ts
  4. 4
      libs/remix-api/src/lib/remix-api.ts
  5. 147
      libs/remix-ui/git/src/components/gitui.tsx
  6. 29
      libs/remix-ui/git/src/components/panels/init.tsx
  7. 45
      libs/remix-ui/git/src/lib/gitactions.ts
  8. 14
      libs/remix-ui/git/src/lib/listeners.ts
  9. 11
      libs/remix-ui/git/src/lib/pluginActions.ts
  10. 1
      libs/remix-ui/git/src/state/context.tsx

@ -15,5 +15,6 @@
"git.refresh": "refresh", "git.refresh": "refresh",
"git.unstageall": "unstage all", "git.unstageall": "unstage all",
"git.stageall": "stage all", "git.stageall": "stage all",
"git.noremote": "this repo has no remotes" "git.noremote": "this repo has no remotes",
"git.init": "Initialize repository"
} }

@ -0,0 +1,10 @@
import { commitChange } from "@remix-ui/git";
import { IFileSystem } from "@remixproject/plugin-api"
// Extended interface with 'diff' method
export interface IExtendedFileSystem extends IFileSystem {
methods: IFileSystem['methods'] & {
/** Compare the differences between two files */
diff(change: commitChange): Promise<void>
};
}

@ -0,0 +1,11 @@
import { fileDecoration } from '@remix-ui/file-decorators'
import { StatusEvents } from '@remixproject/plugin-utils'
export interface IFileDecoratorApi {
events: {
} & StatusEvents
methods: {
clearFileDecorators(path?: string): void
setFileDecorators(decorators: fileDecoration[]): void
}
}

@ -2,6 +2,8 @@ import { IGitApi } from "@remix-ui/git"
import { IRemixApi } from "@remixproject/plugin-api" import { IRemixApi } from "@remixproject/plugin-api"
import { StatusEvents } from "@remixproject/plugin-utils" import { StatusEvents } from "@remixproject/plugin-utils"
import { IConfigApi } from "./plugins/config-api" import { IConfigApi } from "./plugins/config-api"
import { IFileDecoratorApi } from "./plugins/filedecorator-api"
import { IExtendedFileSystem } from "./plugins/fileSystem-api"
import { INotificationApi } from "./plugins/notification-api" import { INotificationApi } from "./plugins/notification-api"
import { ISettings } from "./plugins/settings-api" import { ISettings } from "./plugins/settings-api"
@ -10,6 +12,8 @@ export interface ICustomRemixApi extends IRemixApi {
config: IConfigApi config: IConfigApi
notification: INotificationApi notification: INotificationApi
settings: ISettings settings: ISettings
fileDecorator: IFileDecoratorApi
fileManager: IExtendedFileSystem
} }
export declare type CustomRemixApi = Readonly<ICustomRemixApi> export declare type CustomRemixApi = Readonly<ICustomRemixApi>

@ -1,5 +1,5 @@
import React, { useEffect, useReducer, useState } from 'react' 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 } 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 } from '../lib/gitactions'
import { loadFiles, setCallBacks } from '../lib/listeners' import { loadFiles, setCallBacks } from '../lib/listeners'
import { openDiff, openFile, saveToken, setModifiedDecorator, setPlugin, setUntrackedDecorator, statusChanged } from '../lib/pluginActions' import { openDiff, openFile, saveToken, setModifiedDecorator, setPlugin, setUntrackedDecorator, statusChanged } from '../lib/pluginActions'
import { gitActionsContext, pluginActionsContext } from '../state/context' import { gitActionsContext, pluginActionsContext } from '../state/context'
@ -30,12 +30,15 @@ import { BranchHeader } from './branchHeader'
import { SourceControl } from './panels/sourcontrol' import { SourceControl } from './panels/sourcontrol'
import { GitHubCredentials } from './panels/githubcredentials' import { GitHubCredentials } from './panels/githubcredentials'
import { Setup } from './panels/setup' import { Setup } from './panels/setup'
import { Init } from './panels/init'
import { CustomRemixApi } from "@remix-api";
import { Plugin } from "@remixproject/engine";
export const gitPluginContext = React.createContext<gitState>(defaultGitState) export const gitPluginContext = React.createContext<gitState>(defaultGitState)
export const loaderContext = React.createContext<loaderState>(defaultLoaderState) export const loaderContext = React.createContext<loaderState>(defaultLoaderState)
interface IGitUi { interface IGitUi {
plugin: ViewPlugin plugin: Plugin<any, CustomRemixApi>
} }
export const GitUI = (props: IGitUi) => { export const GitUI = (props: IGitUi) => {
@ -44,6 +47,7 @@ export const GitUI = (props: IGitUi) => {
const [loaderState, loaderDispatch] = useReducer(loaderReducer, defaultLoaderState) const [loaderState, loaderDispatch] = useReducer(loaderReducer, defaultLoaderState)
const [activePanel, setActivePanel] = useState<string>("0") const [activePanel, setActivePanel] = useState<string>("0")
const [setup, setSetup] = useState<boolean>(false) const [setup, setSetup] = useState<boolean>(false)
const [needsInit, setNeedsInit] = useState<boolean>(true)
useEffect(() => { useEffect(() => {
setCallBacks(plugin, gitDispatch, loaderDispatch) setCallBacks(plugin, gitDispatch, loaderDispatch)
@ -54,7 +58,7 @@ export const GitUI = (props: IGitUi) => {
useEffect(() => { useEffect(() => {
async function checkconfig() { async function checkconfig() {
const username = await plugin.call('settings', 'get', 'settings/github-user-name') const username = await plugin.call('settings', 'get', 'settings/github-user-name')
const email = await plugin.call('settings', 'get', 'settings/github-email') const email = await plugin.call('settings', 'get', 'settings/github-email')
const token = await plugin.call('settings', 'get', 'settings/gist-access-token') const token = await plugin.call('settings', 'get', 'settings/gist-access-token')
@ -62,7 +66,7 @@ export const GitUI = (props: IGitUi) => {
setSetup(!(username && email)) setSetup(!(username && email))
} }
checkconfig() checkconfig()
},[gitState.gitHubAccessToken, gitState.gitHubUser, gitState.userEmails]) }, [gitState.gitHubAccessToken, gitState.gitHubUser, gitState.userEmails])
useEffect(() => { useEffect(() => {
@ -90,8 +94,10 @@ export const GitUI = (props: IGitUi) => {
updatestate() updatestate()
}) })
setNeedsInit(!(gitState.currentBranch && gitState.currentBranch.name !== ''))
}, [gitState.gitHubUser, gitState.currentBranch, gitState.remotes, gitState.gitHubAccessToken]) }, [gitState.gitHubUser, gitState.currentBranch, gitState.remotes, gitState.gitHubAccessToken])
const gitActionsProviderValue = { const gitActionsProviderValue = {
commit, commit,
@ -121,7 +127,8 @@ export const GitUI = (props: IGitUi) => {
removeRemote, removeRemote,
sendToGitLog, sendToGitLog,
clearGitLog, clearGitLog,
getFileStatusMatrix getFileStatusMatrix,
init
} }
const pluginActionsProviderValue = { const pluginActionsProviderValue = {
@ -139,70 +146,72 @@ export const GitUI = (props: IGitUi) => {
<gitPluginContext.Provider value={gitState}> <gitPluginContext.Provider value={gitState}>
<loaderContext.Provider value={loaderState}> <loaderContext.Provider value={loaderState}>
<gitActionsContext.Provider value={gitActionsProviderValue}> <gitActionsContext.Provider value={gitActionsProviderValue}>
<BranchHeader/> <BranchHeader />
<pluginActionsContext.Provider value={pluginActionsProviderValue}> <pluginActionsContext.Provider value={pluginActionsProviderValue}>
{setup? <Setup></Setup>: null} {setup && !needsInit ? <Setup></Setup> : null}
<Accordion activeKey={activePanel} defaultActiveKey="0"> {needsInit ? <Init></Init> : null}
<SourceControlNavigation eventKey="0" activePanel={activePanel} callback={setActivePanel} /> {!setup && !needsInit ?
<Accordion activeKey={activePanel} defaultActiveKey="0">
<Accordion.Collapse className='bg-light' eventKey="0"> <SourceControlNavigation eventKey="0" activePanel={activePanel} callback={setActivePanel} />
<>
<SourceControlBase><CommitMessage/></SourceControlBase> <Accordion.Collapse className='bg-light' eventKey="0">
<SourceControl/> <>
</> <SourceControlBase><CommitMessage /></SourceControlBase>
</Accordion.Collapse> <SourceControl />
<hr></hr> </>
<CommandsNavigation eventKey="1" activePanel={activePanel} callback={setActivePanel} /> </Accordion.Collapse>
<Accordion.Collapse className='bg-light' eventKey="1"> <hr></hr>
<> <CommandsNavigation eventKey="1" activePanel={activePanel} callback={setActivePanel} />
<Commands></Commands> <Accordion.Collapse className='bg-light' eventKey="1">
</> <>
</Accordion.Collapse> <Commands></Commands>
<hr></hr> </>
<CommitsNavigation title={`COMMITS`} eventKey="3" activePanel={activePanel} callback={setActivePanel} showButtons={true} /> </Accordion.Collapse>
<Accordion.Collapse className='bg-light' eventKey="3"> <hr></hr>
<> <CommitsNavigation title={`COMMITS`} eventKey="3" activePanel={activePanel} callback={setActivePanel} showButtons={true} />
<Commits /> <Accordion.Collapse className='bg-light' eventKey="3">
</> <>
</Accordion.Collapse> <Commits />
<hr></hr> </>
<BranchesNavigation eventKey="2" activePanel={activePanel} callback={setActivePanel} /> </Accordion.Collapse>
<Accordion.Collapse className='bg-light' eventKey="2"> <hr></hr>
<> <BranchesNavigation eventKey="2" activePanel={activePanel} callback={setActivePanel} />
<Branches/></> <Accordion.Collapse className='bg-light' eventKey="2">
</Accordion.Collapse> <>
<hr></hr> <Branches /></>
<RemotesNavigation eventKey="5" activePanel={activePanel} callback={setActivePanel} /> </Accordion.Collapse>
<Accordion.Collapse className='bg-light' eventKey="5"> <hr></hr>
<> <RemotesNavigation eventKey="5" activePanel={activePanel} callback={setActivePanel} />
<Remotes></Remotes> <Accordion.Collapse className='bg-light' eventKey="5">
</> <>
</Accordion.Collapse> <Remotes></Remotes>
<hr></hr> </>
<CloneNavigation eventKey="4" activePanel={activePanel} callback={setActivePanel} /> </Accordion.Collapse>
<Accordion.Collapse className='bg-light' eventKey="4"> <hr></hr>
<> <CloneNavigation eventKey="4" activePanel={activePanel} callback={setActivePanel} />
<Clone /></> <Accordion.Collapse className='bg-light' eventKey="4">
</Accordion.Collapse> <>
<hr></hr> <Clone /></>
<GitHubNavigation eventKey="7" activePanel={activePanel} callback={setActivePanel} /> </Accordion.Collapse>
<Accordion.Collapse className='bg-light' eventKey="7"> <hr></hr>
<> <GitHubNavigation eventKey="7" activePanel={activePanel} callback={setActivePanel} />
<GetDeviceCode></GetDeviceCode> <Accordion.Collapse className='bg-light' eventKey="7">
<hr></hr> <>
<GitHubCredentials></GitHubCredentials> <GetDeviceCode></GetDeviceCode>
</> <hr></hr>
</Accordion.Collapse> <GitHubCredentials></GitHubCredentials>
<hr></hr> </>
<LogNavigation eventKey="6" activePanel={activePanel} callback={setActivePanel} /> </Accordion.Collapse>
<Accordion.Collapse className='bg-light' eventKey="6"> <hr></hr>
<> <LogNavigation eventKey="6" activePanel={activePanel} callback={setActivePanel} />
<LogViewer/> <Accordion.Collapse className='bg-light' eventKey="6">
</> <>
</Accordion.Collapse> <LogViewer />
</>
</Accordion> </Accordion.Collapse>
</Accordion>
: null}
</pluginActionsContext.Provider> </pluginActionsContext.Provider>
</gitActionsContext.Provider> </gitActionsContext.Provider>
</loaderContext.Provider> </loaderContext.Provider>

@ -0,0 +1,29 @@
import { CustomTooltip } from '@remix-ui/helper';
import { pull } from 'lodash';
import React, { useContext } from 'react';
import { FormattedMessage } from 'react-intl';
import { gitActionsContext } from '../../state/context';
import GitUIButton from '../buttons/gituibutton';
export const Init = () => {
const actions = React.useContext(gitActionsContext)
const init = async () => {
actions.init()
}
return (
<>
<div>
<div className='mt-1 mb-2'>
<GitUIButton
onClick={init}
className="btn w-md-25 w-100 btn-primary"
id="initgit-btn"
><FormattedMessage id='git.init'/></GitUIButton>
</div>
</div>
</>
)
}

@ -45,6 +45,13 @@ export const setPlugin = (p: Plugin, dispatcher: React.Dispatch<gitActionDispatc
console.log('setPlugin') console.log('setPlugin')
} }
export const init = async () => {
console.log('gitInit')
await plugin.call('dgitApi', "init");
await gitlog();
await getBranches();
}
export const getBranches = async () => { export const getBranches = async () => {
console.log('getBranches') console.log('getBranches')
const branches = await plugin.call('dgitApi', "branches") const branches = await plugin.call('dgitApi', "branches")
@ -110,25 +117,17 @@ export const gitlog = async () => {
export const showCurrentBranch = async () => { export const showCurrentBranch = async () => {
try { try {
const branch = await currentBranch(); const branch = await currentBranch();
const currentcommitoid = await getCommitFromRef("HEAD"); console.log('branch :>>', branch)
if (typeof branch === "undefined" || branch.name === "") { dispatch(setCanCommit((branch && branch.name !== "")));
dispatch(setCurrentBranch(branch));
branch.name = `HEAD detached at ${currentcommitoid}`;
//canCommit = false;
dispatch(setCanCommit(false));
} else {
//canCommit = true;
dispatch(setCanCommit(true));
dispatch(setCurrentBranch(branch));
}
} catch (e) { } catch (e) {
// show empty branch // show empty branch
} }
} }
export const currentBranch = async () => { export const currentBranch = async () => {
// eslint-disable-next-line no-useless-catch
try { try {
const branch: branch = const branch: branch =
(await plugin.call('dgitApi', "currentbranch")) || { (await plugin.call('dgitApi', "currentbranch")) || {
@ -525,14 +524,14 @@ export const remoteCommits = async (url: string, branch: string, length: number)
export const saveGitHubCredentials = async (credentials: { username: string, email: string, token: string }) => { export const saveGitHubCredentials = async (credentials: { username: string, email: string, token: string }) => {
console.log('saveGitHubCredentials', credentials) console.log('saveGitHubCredentials', credentials)
try { try {
const storedEmail = await plugin.call('config', 'getAppParameter','settings/github-email') const storedEmail = await plugin.call('config', 'getAppParameter', 'settings/github-email')
const storedUsername = await plugin.call('config', 'getAppParameter','settings/github-user-name') const storedUsername = await plugin.call('config', 'getAppParameter', 'settings/github-user-name')
const storedToken = await plugin.call('config', 'getAppParameter','settings/gist-access-token') const storedToken = await plugin.call('config', 'getAppParameter', 'settings/gist-access-token')
if(storedUsername !== credentials.username) await plugin.call('config', 'setAppParameter', 'settings/github-user-name', credentials.username) if (storedUsername !== credentials.username) await plugin.call('config', 'setAppParameter', 'settings/github-user-name', credentials.username)
if(storedEmail !== credentials.email) await plugin.call('config', 'setAppParameter', 'settings/github-email', credentials.email) if (storedEmail !== credentials.email) await plugin.call('config', 'setAppParameter', 'settings/github-email', credentials.email)
if(storedToken !== credentials.token) await plugin.call('config', 'setAppParameter', 'settings/gist-access-token', credentials.token) if (storedToken !== credentials.token) await plugin.call('config', 'setAppParameter', 'settings/gist-access-token', credentials.token)
} catch (e) { } catch (e) {
console.log(e) console.log(e)
} }
@ -570,17 +569,17 @@ export const loadGitHubUserFromToken = async () => {
if (data && data.emails && data.user && data.user.login) { if (data && data.emails && data.user && data.user.login) {
console.log('SET USER"', data) console.log('SET USER"', data)
const primaryEmail = data.emails.find(email => email.primary) const primaryEmail = data.emails.find(email => email.primary)
const storedEmail = await plugin.call('config', 'getAppParameter', 'settings/github-email') const storedEmail = await plugin.call('config', 'getAppParameter', 'settings/github-email')
if (primaryEmail && storedEmail !== primaryEmail.email) await plugin.call('config', 'setAppParameter', 'settings/github-email', primaryEmail.email) if (primaryEmail && storedEmail !== primaryEmail.email) await plugin.call('config', 'setAppParameter', 'settings/github-email', primaryEmail.email)
const storedUsername = await plugin.call('config', 'getAppParameter', 'settings/github-user-name') const storedUsername = await plugin.call('config', 'getAppParameter', 'settings/github-user-name')
if(data.user && data.user.login && (storedUsername !== data.user.login)) await plugin.call('config', 'setAppParameter', 'settings/github-user-name', data.user.login) if (data.user && data.user.login && (storedUsername !== data.user.login)) await plugin.call('config', 'setAppParameter', 'settings/github-user-name', data.user.login)
dispatch(setGitHubUser(data.user)) dispatch(setGitHubUser(data.user))
dispatch(setRateLimit(data.ratelimit)) dispatch(setRateLimit(data.ratelimit))
dispatch(setScopes(data.scopes)) dispatch(setScopes(data.scopes))
dispatch(setUserEmails(data.emails)) dispatch(setUserEmails(data.emails))
} }
} else { } else {
const credentials = await getGitHubCredentialsFromLocalStorage() const credentials = await getGitHubCredentialsFromLocalStorage()

@ -6,6 +6,7 @@ import { Plugin } from "@remixproject/engine";
import { getBranches, getFileStatusMatrix, loadGitHubUserFromToken, getRemotes, gitlog, setPlugin } from "./gitactions"; import { getBranches, getFileStatusMatrix, loadGitHubUserFromToken, getRemotes, gitlog, setPlugin } from "./gitactions";
import { Profile } from "@remixproject/plugin-utils"; import { Profile } from "@remixproject/plugin-utils";
import { CustomRemixApi } from "@remix-api"; import { CustomRemixApi } from "@remix-api";
import { statusChanged } from "./pluginActions";
let plugin: Plugin<any, CustomRemixApi>, gitDispatch: React.Dispatch<gitActionDispatch>, loaderDispatch: React.Dispatch<any>, loadFileQueue: AsyncDebouncedQueue let plugin: Plugin<any, CustomRemixApi>, gitDispatch: React.Dispatch<gitActionDispatch>, loaderDispatch: React.Dispatch<any>, loadFileQueue: AsyncDebouncedQueue
let callBackEnabled: boolean = false let callBackEnabled: boolean = false
@ -103,7 +104,9 @@ export const setCallBacks = (viewPlugin: Plugin, gitDispatcher: React.Dispatch<g
}) })
plugin.on('dgitApi', 'init', async () => { plugin.on('dgitApi', 'init', async () => {
loadFileQueue.enqueue(async () => {
loadFiles()
}, 10)
}) })
plugin.on('dgitApi', 'add', async () => { plugin.on('dgitApi', 'add', async () => {
loadFileQueue.enqueue(async () => { loadFileQueue.enqueue(async () => {
@ -200,7 +203,14 @@ const syncFromWorkspace = async (callback: Function, isLocalhost = false) => {
export const loadFiles = async (filepaths: string[] = null) => { export const loadFiles = async (filepaths: string[] = null) => {
try { try {
await getFileStatusMatrix(filepaths); const branch = await plugin.call('dgitApi', "currentbranch")
console.log('load files', branch)
if(branch) {
await getFileStatusMatrix(filepaths);
}else{
await plugin.call('fileDecorator', 'clearFileDecorators')
statusChanged(0)
}
} catch (e) { } catch (e) {
// TODO: handle error // TODO: handle error
console.error(e); console.error(e);

@ -1,13 +1,14 @@
import { ViewPlugin } from "@remixproject/engine-web"
import { commitChange, fileStatusResult, gitActionDispatch, gitState } from "../types" import { commitChange, fileStatusResult, gitActionDispatch, gitState } from "../types"
import { fileDecoration, fileDecorationType } from "@remix-ui/file-decorators" import { fileDecoration, fileDecorationType } from "@remix-ui/file-decorators"
import { removeSlash } from "../utils" import { removeSlash } from "../utils"
import path from "path" import { getFilesByStatus } from "./fileHelpers"
import { getFilesByStatus, getFilesWithNotModifiedStatus } from "./fileHelpers" import { CustomRemixApi } from "@remix-api";
import { Plugin } from "@remixproject/engine";
let plugin: ViewPlugin, gitDispatch: React.Dispatch<gitActionDispatch>, loaderDispatch: React.Dispatch<any> let plugin: Plugin<any, CustomRemixApi>, gitDispatch: React.Dispatch<gitActionDispatch>, loaderDispatch: React.Dispatch<any>
export const setPlugin = (p: ViewPlugin, gitDispatcher: React.Dispatch<gitActionDispatch>, loaderDispatcher: React.Dispatch<any>) => { export const setPlugin = (p: Plugin<any, CustomRemixApi>, gitDispatcher: React.Dispatch<gitActionDispatch>, loaderDispatcher: React.Dispatch<any>) => {
plugin = p plugin = p
gitDispatch = gitDispatcher gitDispatch = gitDispatcher
loaderDispatch = loaderDispatcher loaderDispatch = loaderDispatcher

@ -31,6 +31,7 @@ export interface gitActions {
sendToGitLog: (message: gitLog) => Promise<void> sendToGitLog: (message: gitLog) => Promise<void>
clearGitLog: () => Promise<void> clearGitLog: () => Promise<void>
getFileStatusMatrix(filespaths:[]): Promise<void> getFileStatusMatrix(filespaths:[]): Promise<void>
init(): Promise<void>
} }
export const gitActionsContext = React.createContext<gitActions>(null) export const gitActionsContext = React.createContext<gitActions>(null)

Loading…
Cancel
Save