pull/4791/head
filip mertens 7 months ago
parent aec183366f
commit 40b0b93558
  1. 11
      libs/remix-api/src/lib/plugins/config-api.ts
  2. 29
      libs/remix-api/src/lib/plugins/notification-api.ts
  3. 11
      libs/remix-api/src/lib/plugins/settings-api.ts
  4. 10
      libs/remix-api/src/lib/remix-api.ts
  5. 5
      libs/remix-ui/git/src/components/gitui.tsx
  6. 39
      libs/remix-ui/git/src/lib/gitactions.ts
  7. 18
      libs/remix-ui/git/src/lib/listeners.ts
  8. 6
      libs/remix-ui/git/src/types/index.ts
  9. 2
      libs/remix-ui/workspace/src/lib/actions/workspace.ts

@ -0,0 +1,11 @@
import { StatusEvents } from "@remixproject/plugin-utils"
export interface IConfigApi {
events: {
configChanged: () => void
} & StatusEvents,
methods: {
getAppParameter(key: string): Promise<any>,
setAppParameter(key: string, value: any): Promise<void>
}
}

@ -0,0 +1,29 @@
import { ModalTypes } from "@remix-ui/app"
import { StatusEvents } from "@remixproject/plugin-utils"
export interface INotificationApi {
events: {
} & StatusEvents,
methods: {
toast(key: string): Promise<void>,
alert({
title,
message
}:{
title: string,
message: string,
}): Promise<void>,
modal({
title,
message,
okLabel,
type
}:{
title: string,
message: string,
okLabel: string,
type: ModalTypes
}): Promise<void>,
}
}

@ -0,0 +1,11 @@
import { StatusEvents } from '@remixproject/plugin-utils'
export interface ISettings {
events: {
configChanged: () => void,
} & StatusEvents
methods: {
getGithubAccessToken(): string
get(key: string): Promise<any>
}
}

@ -1,9 +1,15 @@
import { customDGitSystem } from "@remix-ui/git" 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 { INotificationApi } from "./plugins/notification-api"
import { ISettings } from "./plugins/settings-api"
export interface ICustomRemixApi extends IRemixApi { export interface ICustomRemixApi extends IRemixApi {
dgitApi: customDGitSystem dgitApi: IGitApi
config: IConfigApi
notification: INotificationApi
settings: ISettings
} }
export declare type CustomRemixApi = Readonly<ICustomRemixApi> export declare type CustomRemixApi = Readonly<ICustomRemixApi>

@ -5,7 +5,6 @@ import { openDiff, openFile, saveToken, setModifiedDecorator, setPlugin, setUntr
import { gitActionsContext, pluginActionsContext } from '../state/context' import { gitActionsContext, pluginActionsContext } from '../state/context'
import { gitReducer } from '../state/gitreducer' import { gitReducer } from '../state/gitreducer'
import { defaultGitState, defaultLoaderState, gitState, loaderState } from '../types' import { defaultGitState, defaultLoaderState, gitState, loaderState } from '../types'
import { Accordion } from "react-bootstrap"; import { Accordion } from "react-bootstrap";
import { CommitMessage } from './buttons/commitmessage' import { CommitMessage } from './buttons/commitmessage'
import { Commits } from './panels/commits' import { Commits } from './panels/commits'
@ -29,7 +28,6 @@ import LogViewer from './panels/log'
import { SourceControlBase } from './buttons/sourceControlBase' import { SourceControlBase } from './buttons/sourceControlBase'
import { BranchHeader } from './branchHeader' import { BranchHeader } from './branchHeader'
import { SourceControl } from './panels/sourcontrol' import { SourceControl } from './panels/sourcontrol'
import { Settings } from './panels/settings'
import { GitHubCredentials } from './panels/githubcredentials' import { GitHubCredentials } from './panels/githubcredentials'
export const gitPluginContext = React.createContext<gitState>(defaultGitState) export const gitPluginContext = React.createContext<gitState>(defaultGitState)
@ -44,7 +42,6 @@ export const GitUI = (props: IGitUi) => {
const [gitState, gitDispatch] = useReducer(gitReducer, defaultGitState) const [gitState, gitDispatch] = useReducer(gitReducer, defaultGitState)
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 [timeOut, setTimeOut] = useState<number>(null)
useEffect(() => { useEffect(() => {
setCallBacks(plugin, gitDispatch, loaderDispatch) setCallBacks(plugin, gitDispatch, loaderDispatch)
@ -61,8 +58,6 @@ export const GitUI = (props: IGitUi) => {
await setUntrackedDecorator(gitState.untracked) await setUntrackedDecorator(gitState.untracked)
} }
console.log('gitState.fileStatusResult', gitState.fileStatusResult)
setTimeout(() => { setTimeout(() => {
setDecorators(gitState) setDecorators(gitState)
}) })

@ -2,7 +2,7 @@ import { ViewPlugin } from "@remixproject/engine-web";
import { ReadBlobResult, ReadCommitResult } from "isomorphic-git"; import { ReadBlobResult, ReadCommitResult } from "isomorphic-git";
import React from "react"; import React from "react";
import { fileStatus, fileStatusMerge, setRemoteBranchCommits, resetRemoteBranchCommits, setBranches, setCanCommit, setCommitChanges, setCommits, setCurrentBranch, setGitHubUser, setLoading, setRateLimit, setRemoteBranches, setRemotes, setRepos, setUpstream, setLocalBranchCommits, setBranchDifferences, setRemoteAsDefault, setScopes, setLog, clearLog } from "../state/gitpayload"; import { fileStatus, fileStatusMerge, setRemoteBranchCommits, resetRemoteBranchCommits, setBranches, setCanCommit, setCommitChanges, setCommits, setCurrentBranch, setGitHubUser, setLoading, setRateLimit, setRemoteBranches, setRemotes, setRepos, setUpstream, setLocalBranchCommits, setBranchDifferences, setRemoteAsDefault, setScopes, setLog, clearLog } from "../state/gitpayload";
import { GitHubUser, RateLimit, branch, commitChange, gitActionDispatch, statusMatrixType, gitState, branchDifference, remote, gitLog, fileStatusResult, customGitApi, customDGitSystem, cloneInputType, fetchInputType, pullInputType, pushInputType, checkoutInput, rmInput, addInput, repository } from '../types'; import { GitHubUser, RateLimit, branch, commitChange, gitActionDispatch, statusMatrixType, gitState, branchDifference, remote, gitLog, fileStatusResult, customGitApi, IGitApi, cloneInputType, fetchInputType, pullInputType, pushInputType, checkoutInput, rmInput, addInput, repository } from '../types';
import { removeSlash } from "../utils"; import { removeSlash } from "../utils";
import { disableCallBacks, enableCallBacks } from "./listeners"; import { disableCallBacks, enableCallBacks } from "./listeners";
import { AlertModal, ModalTypes } from "@remix-ui/app"; import { AlertModal, ModalTypes } from "@remix-ui/app";
@ -25,7 +25,6 @@ export const fileStatuses = [
["modified,staged,with unstaged changes", 1, 2, 3], // modified, staged, with unstaged changes ["modified,staged,with unstaged changes", 1, 2, 3], // modified, staged, with unstaged changes
["deleted,unstaged", 1, 0, 1], // deleted, unstaged ["deleted,unstaged", 1, 0, 1], // deleted, unstaged
["deleted,staged", 1, 0, 0], ["deleted,staged", 1, 0, 0],
//["deleted", 1, 1, 0], // deleted, staged
["unmodified", 1, 1, 3], ["unmodified", 1, 1, 3],
["deleted,not in git", 0, 0, 3], ["deleted,not in git", 0, 0, 3],
["unstaged,modified", 1, 2, 0] ["unstaged,modified", 1, 2, 0]
@ -162,10 +161,10 @@ export const getCommitFromRef = async (ref: string) => {
} }
const settingsWarning = async () => { const settingsWarning = async () => {
const username = await plugin.call('config' as any, 'getAppParameter', 'settings/github-user-name') const username = await plugin.call('config', 'getAppParameter', 'settings/github-user-name')
const email = await plugin.call('config' as any, 'getAppParameter', 'settings/github-email') const email = await plugin.call('config', 'getAppParameter', 'settings/github-email')
if (!username || !email) { if (!username || !email) {
plugin.call('notification' as any, 'toast', 'Please set your github username and email in the settings') plugin.call('notification', 'toast', 'Please set your github username and email in the settings')
return false; return false;
} else { } else {
return { return {
@ -198,7 +197,7 @@ export const commit = async (message: string = "") => {
}) })
} catch (err) { } catch (err) {
plugin.call('notification' as any, 'toast', `${err}`) plugin.call('notification', 'toast', `${err}`)
} }
} }
@ -216,7 +215,7 @@ export const addall = async (files: fileStatusResult[]) => {
}) })
} catch (e) { } catch (e) {
plugin.call('notification' as any, 'toast', `${e}`) plugin.call('notification', 'toast', `${e}`)
} }
} }
@ -228,7 +227,7 @@ export const add = async (filepath: addInput) => {
message: `Added to git` message: `Added to git`
}) })
} catch (e) { } catch (e) {
plugin.call('notification' as any, 'toast', `${e}`) plugin.call('notification', 'toast', `${e}`)
} }
} }
@ -275,7 +274,7 @@ export const checkoutfile = async (filename: string) => {
); );
await enableCallBacks(); await enableCallBacks();
} catch (e) { } catch (e) {
plugin.call('notification' as any, 'toast', `No such file`) plugin.call('notification', 'toast', `No such file`)
} }
} }
@ -287,7 +286,7 @@ export const checkout = async (cmd: checkoutInput) => {
await plugin.call('dgitApi', 'checkout', cmd) await plugin.call('dgitApi', 'checkout', cmd)
gitlog(); gitlog();
} catch (e) { } catch (e) {
plugin.call('notification' as any, 'toast', `${e}`) plugin.call('notification', 'toast', `${e}`)
} }
await enableCallBacks(); await enableCallBacks();
} }
@ -376,7 +375,7 @@ const parseError = async (e: any) => {
console.trace(e) console.trace(e)
// if message conttains 401 Unauthorized, show token warning // if message conttains 401 Unauthorized, show token warning
if (e.message.includes('401')) { if (e.message.includes('401')) {
const result = await plugin.call('notification' as any, 'modal' as any, { const result = await plugin.call('notification', 'modal' as any, {
title: 'The GitHub token may be missing or invalid', title: 'The GitHub token may be missing or invalid',
message: 'Please check the GitHub token and try again. Error: 401 Unauthorized', message: 'Please check the GitHub token and try again. Error: 401 Unauthorized',
okLabel: 'Go to settings', okLabel: 'Go to settings',
@ -387,7 +386,7 @@ const parseError = async (e: any) => {
} }
// if message contains 404 Not Found, show repo not found // if message contains 404 Not Found, show repo not found
else if (e.message.includes('404')) { else if (e.message.includes('404')) {
await plugin.call('notification' as any, 'modal' as any, { await plugin.call('notification', 'modal' as any, {
title: 'Repository not found', title: 'Repository not found',
message: 'Please check the URL and try again.', message: 'Please check the URL and try again.',
okLabel: 'Go to settings', okLabel: 'Go to settings',
@ -397,7 +396,7 @@ const parseError = async (e: any) => {
} }
// if message contains 403 Forbidden // if message contains 403 Forbidden
else if (e.message.includes('403')) { else if (e.message.includes('403')) {
await plugin.call('notification' as any, 'modal' as any, { await plugin.call('notification', 'modal' as any, {
title: 'The GitHub token may be missing or invalid', title: 'The GitHub token may be missing or invalid',
message: 'Please check the GitHub token and try again. Error: 403 Forbidden', message: 'Please check the GitHub token and try again. Error: 403 Forbidden',
okLabel: 'Go to settings', okLabel: 'Go to settings',
@ -405,14 +404,14 @@ const parseError = async (e: any) => {
type: ModalTypes.confirm type: ModalTypes.confirm
}) })
} else if (e.toString().includes('NotFoundError') && !e.toString().includes('fetch')) { } else if (e.toString().includes('NotFoundError') && !e.toString().includes('fetch')) {
await plugin.call('notification' as any, 'modal', { await plugin.call('notification', 'modal', {
title: 'Remote branch not found', title: 'Remote branch not found',
message: 'The branch you are trying to fetch does not exist on the remote. If you have forked this branch from another branch, you may need to fetch the original branch first or publish this branch on the remote.', message: 'The branch you are trying to fetch does not exist on the remote. If you have forked this branch from another branch, you may need to fetch the original branch first or publish this branch on the remote.',
okLabel: 'OK', okLabel: 'OK',
type: ModalTypes.alert type: ModalTypes.alert
}) })
} else { } else {
await plugin.call('notification' as any, 'alert' as any, { await plugin.call('notification', 'alert' as any, {
title: 'Error', title: 'Error',
message: e.message message: e.message
}) })
@ -439,7 +438,7 @@ export const repositories = async () => {
} }
} else { } else {
plugin.call('notification' as any, 'alert', { plugin.call('notification', 'alert', {
title: 'Error getting repositories', title: 'Error getting repositories',
message: `Please check your GitHub token in the GitHub settings... cannot connect to GitHub` message: `Please check your GitHub token in the GitHub settings... cannot connect to GitHub`
}) })
@ -447,7 +446,7 @@ export const repositories = async () => {
} }
} catch (e) { } catch (e) {
console.log(e) console.log(e)
plugin.call('notification' as any, 'alert', { plugin.call('notification', 'alert', {
title: 'Error getting repositories', title: 'Error getting repositories',
message: `${e.message}: Please check your GitHub token in the GitHub settings.` message: `${e.message}: Please check your GitHub token in the GitHub settings.`
}) })
@ -474,7 +473,7 @@ export const remoteBranches = async (owner: string, repo: string) => {
page++ page++
} }
} else { } else {
plugin.call('notification' as any, 'alert', { plugin.call('notification', 'alert', {
title: 'Error getting branches', title: 'Error getting branches',
message: `Please check your GitHub token in the GitHub settings. It needs to have access to the branches.` message: `Please check your GitHub token in the GitHub settings. It needs to have access to the branches.`
}) })
@ -482,7 +481,7 @@ export const remoteBranches = async (owner: string, repo: string) => {
} }
} catch (e) { } catch (e) {
console.log(e) console.log(e)
plugin.call('notification' as any, 'alert', { plugin.call('notification', 'alert', {
title: 'Error', title: 'Error',
message: e.message message: e.message
}) })
@ -516,7 +515,7 @@ export const remoteCommits = async (url: string, branch: string, length: number)
} }
} catch (e) { } catch (e) {
console.log(e) console.log(e)
plugin.call('notification' as any, 'alert', { plugin.call('notification', 'alert', {
title: 'Error', title: 'Error',
message: e.message message: e.message
}) })

@ -1,16 +1,14 @@
import { ViewPlugin } from "@remixproject/engine-web";
import React from "react"; import React from "react";
import { setCanUseApp, setLoading, setRepoName, setGItHubToken, setLog } from "../state/gitpayload"; import { setCanUseApp, setLoading, setRepoName, setGItHubToken, setLog } from "../state/gitpayload";
import { customDGitSystem, gitActionDispatch } from "../types"; import { gitActionDispatch } from "../types";
import { Plugin } from "@remixproject/engine"; import { Plugin } from "@remixproject/engine";
import { diffFiles, getBranches, getFileStatusMatrix, getGitHubUser, getRemotes, gitlog, setPlugin } from "./gitactions"; import { getBranches, getFileStatusMatrix, getGitHubUser, 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";
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
let syncTimer: NodeJS.Timer = null
type AsyncCallback = () => Promise<void>; type AsyncCallback = () => Promise<void>;
@ -27,7 +25,7 @@ class AsyncDebouncedQueue {
} }
let timer = setTimeout(async () => { let timer = setTimeout(async () => {
await callback(); // Await the asynchronous operation await callback();
this.queues.delete(callback); this.queues.delete(callback);
}, customDelay || this.delay); }, customDelay || this.delay);
@ -148,10 +146,10 @@ export const setCallBacks = (viewPlugin: Plugin, gitDispatcher: React.Dispatch<g
} }
}) })
plugin.on('config' as any, 'configChanged', async () => { plugin.on('config', 'configChanged', async () => {
await getGitConfig() await getGitConfig()
}) })
plugin.on('settings' as any, 'configChanged', async () => { plugin.on('settings', 'configChanged', async () => {
await getGitConfig() await getGitConfig()
}) })
@ -159,9 +157,9 @@ export const setCallBacks = (viewPlugin: Plugin, gitDispatcher: React.Dispatch<g
} }
export const getGitConfig = async () => { export const getGitConfig = async () => {
const username = await plugin.call('settings' as any, 'get', 'settings/github-user-name') const username = await plugin.call('settings', 'get', 'settings/github-user-name')
const email = await plugin.call('settings' as any, 'get', 'settings/github-email') const email = await plugin.call('settings', 'get', 'settings/github-email')
const token = await plugin.call('settings' as any, 'get', 'settings/gist-access-token') const token = await plugin.call('settings', 'get', 'settings/gist-access-token')
const config = { username, email, token } const config = { username, email, token }
gitDispatch(setGItHubToken(config.token)) gitDispatch(setGItHubToken(config.token))
return config return config

@ -5,7 +5,7 @@ import { CommitObject, ReadBlobResult, ReadCommitResult, StatusRow } from "isomo
export type GitHubUser = Endpoints["GET /user"]["response"]['data'] export type GitHubUser = Endpoints["GET /user"]["response"]['data']
export type RateLimit = Endpoints["GET /rate_limit"]["response"]["data"] export type RateLimit = Endpoints["GET /rate_limit"]["response"]["data"]
export interface customDGitSystem { export interface IGitApi {
events: { events: {
"checkout": () => void "checkout": () => void
"clone": () => void "clone": () => void
@ -140,14 +140,14 @@ export interface repositoriesInput { token: string, page?: number, per_page?: nu
export interface statusInput { ref: string, filepaths?: string[] } export interface statusInput { ref: string, filepaths?: string[] }
export const dGitProfile: LibraryProfile<customDGitSystem> = { export const dGitProfile: LibraryProfile<IGitApi> = {
name: 'dgitApi', name: 'dgitApi',
methods: ['clone', 'branches', 'remotes', 'getCommitChanges', 'log', 'remotecommits'], methods: ['clone', 'branches', 'remotes', 'getCommitChanges', 'log', 'remotecommits'],
} }
export interface customGitApi extends IRemixApi { export interface customGitApi extends IRemixApi {
dgit: customDGitSystem dgit: IGitApi
} }
export type gitState = { export type gitState = {

@ -42,7 +42,7 @@ import { ROOT_PATH, slitherYml, solTestYml, tsSolTestYml } from '../utils/consta
import { IndexedDBStorage } from '../../../../../../apps/remix-ide/src/app/files/filesystems/indexedDB' import { IndexedDBStorage } from '../../../../../../apps/remix-ide/src/app/files/filesystems/indexedDB'
import { getUncommittedFiles } from '../utils/gitStatusFilter' import { getUncommittedFiles } from '../utils/gitStatusFilter'
import { AppModal, ModalTypes } from '@remix-ui/app' import { AppModal, ModalTypes } from '@remix-ui/app'
import { branch, cloneInputType, customDGitSystem } from '@remix-ui/git' import { branch, cloneInputType, IGitApi } from '@remix-ui/git'
import * as templates from '@remix-project/remix-ws-templates' import * as templates from '@remix-project/remix-ws-templates'
import { Plugin } from "@remixproject/engine"; import { Plugin } from "@remixproject/engine";
import { CustomRemixApi } from '@remix-api' import { CustomRemixApi } from '@remix-api'

Loading…
Cancel
Save