pull/4791/head
filip mertens 6 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 { 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 {
dgitApi: customDGitSystem
dgitApi: IGitApi
config: IConfigApi
notification: INotificationApi
settings: ISettings
}
export declare type CustomRemixApi = Readonly<ICustomRemixApi>

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

@ -2,7 +2,7 @@ import { ViewPlugin } from "@remixproject/engine-web";
import { ReadBlobResult, ReadCommitResult } from "isomorphic-git";
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 { 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 { disableCallBacks, enableCallBacks } from "./listeners";
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
["deleted,unstaged", 1, 0, 1], // deleted, unstaged
["deleted,staged", 1, 0, 0],
//["deleted", 1, 1, 0], // deleted, staged
["unmodified", 1, 1, 3],
["deleted,not in git", 0, 0, 3],
["unstaged,modified", 1, 2, 0]
@ -162,10 +161,10 @@ export const getCommitFromRef = async (ref: string) => {
}
const settingsWarning = async () => {
const username = await plugin.call('config' as any, 'getAppParameter', 'settings/github-user-name')
const email = await plugin.call('config' as any, 'getAppParameter', 'settings/github-email')
const username = await plugin.call('config', 'getAppParameter', 'settings/github-user-name')
const email = await plugin.call('config', 'getAppParameter', 'settings/github-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;
} else {
return {
@ -198,7 +197,7 @@ export const commit = async (message: string = "") => {
})
} 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) {
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`
})
} 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();
} 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)
gitlog();
} catch (e) {
plugin.call('notification' as any, 'toast', `${e}`)
plugin.call('notification', 'toast', `${e}`)
}
await enableCallBacks();
}
@ -376,7 +375,7 @@ const parseError = async (e: any) => {
console.trace(e)
// if message conttains 401 Unauthorized, show token warning
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',
message: 'Please check the GitHub token and try again. Error: 401 Unauthorized',
okLabel: 'Go to settings',
@ -387,7 +386,7 @@ const parseError = async (e: any) => {
}
// if message contains 404 Not Found, show repo not found
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',
message: 'Please check the URL and try again.',
okLabel: 'Go to settings',
@ -397,7 +396,7 @@ const parseError = async (e: any) => {
}
// if message contains 403 Forbidden
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',
message: 'Please check the GitHub token and try again. Error: 403 Forbidden',
okLabel: 'Go to settings',
@ -405,14 +404,14 @@ const parseError = async (e: any) => {
type: ModalTypes.confirm
})
} 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',
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',
type: ModalTypes.alert
})
} else {
await plugin.call('notification' as any, 'alert' as any, {
await plugin.call('notification', 'alert' as any, {
title: 'Error',
message: e.message
})
@ -439,7 +438,7 @@ export const repositories = async () => {
}
} else {
plugin.call('notification' as any, 'alert', {
plugin.call('notification', 'alert', {
title: 'Error getting repositories',
message: `Please check your GitHub token in the GitHub settings... cannot connect to GitHub`
})
@ -447,7 +446,7 @@ export const repositories = async () => {
}
} catch (e) {
console.log(e)
plugin.call('notification' as any, 'alert', {
plugin.call('notification', 'alert', {
title: 'Error getting repositories',
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++
}
} else {
plugin.call('notification' as any, 'alert', {
plugin.call('notification', 'alert', {
title: 'Error getting 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) {
console.log(e)
plugin.call('notification' as any, 'alert', {
plugin.call('notification', 'alert', {
title: 'Error',
message: e.message
})
@ -516,7 +515,7 @@ export const remoteCommits = async (url: string, branch: string, length: number)
}
} catch (e) {
console.log(e)
plugin.call('notification' as any, 'alert', {
plugin.call('notification', 'alert', {
title: 'Error',
message: e.message
})

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

@ -5,7 +5,7 @@ import { CommitObject, ReadBlobResult, ReadCommitResult, StatusRow } from "isomo
export type GitHubUser = Endpoints["GET /user"]["response"]['data']
export type RateLimit = Endpoints["GET /rate_limit"]["response"]["data"]
export interface customDGitSystem {
export interface IGitApi {
events: {
"checkout": () => 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 const dGitProfile: LibraryProfile<customDGitSystem> = {
export const dGitProfile: LibraryProfile<IGitApi> = {
name: 'dgitApi',
methods: ['clone', 'branches', 'remotes', 'getCommitChanges', 'log', 'remotecommits'],
}
export interface customGitApi extends IRemixApi {
dgit: customDGitSystem
dgit: IGitApi
}
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 { getUncommittedFiles } from '../utils/gitStatusFilter'
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 { Plugin } from "@remixproject/engine";
import { CustomRemixApi } from '@remix-api'

Loading…
Cancel
Save