Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:/update Api config #132

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
550 changes: 378 additions & 172 deletions src/lib/api/interface/Api.ts

Large diffs are not rendered by default.

53 changes: 30 additions & 23 deletions src/lib/components/repository/changestree.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {FaDownload} from "react-icons/fa";
import {CommitInfoCard} from "./commits";
import { useRouter } from "../../hooks/router";
import { object } from "../../../lib/api/interface/index";
import { getActions } from "../../../util/changes";

export const humanSize = (bytes) => {
if (!bytes) return "0.0 B";
Expand Down Expand Up @@ -315,7 +316,7 @@ export const EntryRow = ({ repo, reference, path, entry, onDelete, showActions }
}

let size;
if (entry.diff_type === "removed" || entry.path_type === "common_prefix") {
if (entry.action === 2) {
size = <Na />;
} else {
size = (
Expand All @@ -329,7 +330,7 @@ export const EntryRow = ({ repo, reference, path, entry, onDelete, showActions }
}

let modified;
if (entry.diff_type === "removed" || entry.path_type === "common_prefix") {
if (entry.action ===2) {
modified = <Na />;
} else {
modified = (
Expand All @@ -347,8 +348,10 @@ export const EntryRow = ({ repo, reference, path, entry, onDelete, showActions }
}

let diffIndicator;
switch (entry.diff_type) {
case "removed":
let diffstyle;
switch (entry.action) {
case 2:
diffstyle = "diif-remove"
diffIndicator = (
<OverlayTrigger
placement="bottom"
Expand All @@ -360,7 +363,8 @@ export const EntryRow = ({ repo, reference, path, entry, onDelete, showActions }
</OverlayTrigger>
);
break;
case "added":
case 1:
diffstyle = "diif-add"
diffIndicator = (
<OverlayTrigger
placement="bottom"
Expand All @@ -372,7 +376,8 @@ export const EntryRow = ({ repo, reference, path, entry, onDelete, showActions }
</OverlayTrigger>
);
break;
case "changed":
case 3:
diffstyle = "diif-change"
diffIndicator = (
<OverlayTrigger
placement="bottom"
Expand All @@ -385,6 +390,7 @@ export const EntryRow = ({ repo, reference, path, entry, onDelete, showActions }
);
break;
default:
diffstyle = "tree-path"
break;
}

Expand All @@ -404,22 +410,22 @@ export const EntryRow = ({ repo, reference, path, entry, onDelete, showActions }

return (
<>
<tr className={rowClass}>
<td className="diff-indicator">{diffIndicator}</td>
<td className="tree-path">
{entry.is_dir === true ? (
<GoFileDirectoryFill style={{fontSize:'18px',color:'blue'}}/>
) : (
<FileIcon />
)}{" "}
{button}
</td>
<td className="tree-size">{entry.is_dir?'Directory':size}</td>
<td className="tree-modified">{modified}</td>
<td className={"change-entry-row-actions"}>{entryActions}</td>
</tr>
</>
);
<tr className={rowClass}>
<td className="diff-indicator">{diffIndicator}</td>
<td className={diffstyle}>
<span>{entry.is_dir === true ? (
<GoFileDirectoryFill style={{fontSize:'18px',color:'blue'}}/>
) : (
<FileIcon />
)}{" "}
{button}</span>
</td>
<td className="tree-size">{entry.is_dir?'Directory':size}</td>
<td className="tree-modified">{modified}</td>
<td className={"change-entry-row-actions"}>{entryActions}</td>
</tr>
</>
);
};

function pathParts(path, isPathToFile) {
Expand Down Expand Up @@ -613,6 +619,7 @@ const GetStarted = ({ onUpload, onImport }) => {
export const Tree = ({
repo,
reference,
changes,
results,
after,
onPaginate,
Expand All @@ -624,7 +631,7 @@ export const Tree = ({
path = "",
}) => {
let body;

if(results && changes) getActions(changes,results)
if (results.length === 0 && path === "" && reference.type === RefTypeBranch) {
// empty state!
body = (
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/repository/refDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {Nav, Badge,Form,Button,Alert,Overlay,Popover } from "react-bootstrap";
import {RefTypeBranch, RefTypeCommit, RefTypeTag} from "../../../constants";
import { CommitListProps, RefDropdownProps, RefEntryProps, RefSelectorProps, ref, RepoPaginatorProps, ResponseProps } from "../interface/comp_interface";
import { Commit } from "../../../pages/repositories/interface/repo_interface";
import { repos } from "../../api/interface/Api";
import { repos } from "../../api/interface";


const RefSelector:React.FC<RefSelectorProps> = ({ repo, selected, selectRef, withWorkspace, withTags, amount = 300 }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/hooks/conf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {createContext, useContext, useMemo} from "react";

import {useAPI} from "./api";
import { LoginConfigProviderProps } from "../components/interface/comp_interface";
import { setup } from "../api/interface/Api";
import { setup } from "../api/interface";


export const LoginConfigContext = createContext({});
Expand Down
2 changes: 1 addition & 1 deletion src/lib/hooks/repo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, {useContext, useState, createContext, useEffect} from "react";
import { NotFoundError, BadRequestError, cache} from "../api";
import {useRouter} from "./router";
import {RefTypeBranch} from "../../constants";
import { repos } from "../api/interface/Api";
import { repos } from "../api/interface";


export const resolveRef = async (user,repoId:string, refId:string) => {
Expand Down
26 changes: 2 additions & 24 deletions src/pages/repositories/repository/repo-comp/changes/changes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ChangesBrowserProps, CommitButtonProps, Pair, ResultsState, RevertButto
import { object, repos, wip } from "../../../../../lib/api/interface/index";
import { UploadButton } from "../objects/uplodaButton";
import ChangeList from "../../commits/commit/changesrow";
import { getActions } from "../../../../../util/changes";


const CommitButton: React.FC<CommitButtonProps> = ({repo, onCommit, enabled = false}) => {
Expand Down Expand Up @@ -158,9 +159,6 @@ const ChangesBrowser: React.FC<ChangesBrowserProps> = ({repo, reference, prefix,
done: false,
};
const [deleteState, setDeleteState] = useState(initialState);
// const getMoreUncommittedChanges:GetMoreUncommittedChanges = (afterUpdated, path, useDelimiter= true, amount = -1) => {
// return wip.getWipChanges(user,repo.name,{refName:reference.name})
// }
const {loading:loaded} = useAPI(()=>wip.getWip(repo.name,user,{refName:reference.name}))
const { response,loading:load} = useAPI(async() =>
{return await repos.getEntriesInRef(user,repo.name,{ref:reference.name,type:'wip',path:path?path:'/'})}
Expand Down Expand Up @@ -192,28 +190,7 @@ const ChangesBrowser: React.FC<ChangesBrowserProps> = ({repo, reference, prefix,
})
}

// let onNavigate = (entry: { path: string; }) => {
// return {
// pathname: `/repositories/:user/:repoId/changes`,
// params: {repoId: repo.name,user},
// query: {
// ref: reference.name,
// prefix: entry.path,
// }
// }
// }

// const uriNavigator = <URINavigator path={prefix} reference={reference} repo={repo}
// pathURLBuilder={(params, query) => {
// return {
// pathname: '/repositories/:user/:repoId/changes',
// params: params,
// query: { ref: reference.name, prefix: query.path ?? "" },
// };
// } } downloadUrl={undefined}/>
const changesTreeMessage = <p>Showing changes for branch <strong>{reference.name}</strong></p>
// const committedRef = reference.id + "@"
// const uncommittedRef = reference.id

const actionErrorDisplay = (actionError) ?
<AlertError error={actionError} onDismiss={() => setActionError(null)}/> : <></>
Expand Down Expand Up @@ -276,6 +253,7 @@ const ChangesBrowser: React.FC<ChangesBrowserProps> = ({repo, reference, prefix,
{deleteState.error && <AlertError error={deleteState.error} onDismiss={() => setDeleteState(initialState)}/>}
<Tree
repo={repo}
changes={results}
reference={reference}
path={(path) ? path : ""}
showActions={true}
Expand Down
21 changes: 2 additions & 19 deletions src/pages/repositories/repository/repo-comp/objects/obj_comps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {cache} from "../../../../../lib/api";
import {useAPI} from "../../../../../lib/hooks/api";
import {NoGCRulesWarningProps} from "../../../interface/repo_interface";
import { object, repos } from "../../../../../lib/api/interface/index";
import { getActions } from "../../../../../util/changes";

const README_FILE_NAME = "README.md";
const REPOSITORY_AGE_BEFORE_GC = 14;
Expand Down Expand Up @@ -55,25 +56,7 @@ export const TreeContainer= ({
const [deleteState, setDeleteState] = useState(initialState);
if (loading || load) return <Loading/>;
if(commitId){
for (let i = 0; i < response.data.length; i++) {
let found = changes.data.find(item => item.path === response.data[i].name);
if (found) {
response.data[i].action = found.action;
}
}
for (let i = 0; i < changes.data.length; i++) {
let found = response.data.find(item => item.name === changes.data[i].path);
if (!found) {
let newObj = {...changes.data[i]};
newObj.name = newObj.path
for (let key in response.data[0]) {
if (!newObj.hasOwnProperty(key)) {
newObj[key] = '';
}
}
response.data.push(newObj);
}
}
getActions(changes,response)
}

if (error) return <AlertError error={error}/>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import { object } from "../../../../../lib/api/interface/index";
const MAX_PARALLEL_UPLOADS = 1;

const destinationPath = (path: string | undefined, file: _File) => {
return `${path ? path : ""}${file.path.replace(/\\/g, '/').replace(/^\//, '')}`;
return `${path ? path : ""}/${file.path.replace(/\\/g, '/').replace(/^\//, '')}`;
};

const UploadCandidate = ({ repoId, path, file, state,setUploadPath,onRemove = null }) => {
const fpath = destinationPath(path, file)
const fpath = destinationPath(path, file)
useEffect(()=>{
setUploadPath(fpath)
},[path])
Expand All @@ -43,7 +43,7 @@ const destinationPath = (path: string | undefined, file: _File) => {
<Row className={`upload-item upload-item-${state ? state.status : "none"}`}>
<Col>
<span className="path">
jzfs:/{repoId}{fpath}
jzfs:/{repoId}/{fpath}
</span>
</Col>
<Col xs md="2">
Expand Down Expand Up @@ -107,7 +107,6 @@ export const UploadButton = ({repoId, reference, path,wipID, onDone, onClick, on

useEffect(() => {
setCurrentPath(path)

}, [path])
useEffect(() =>{
files.length>1? setInputStuts(false):''
Expand Down
16 changes: 16 additions & 0 deletions src/util/changes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export function getActions(arr1,arr2){
let Arr1 = getData(arr1);
let Arr2 = getData(arr2);
for (let i = 0; i < Arr2.length; i++) {
let found = Arr1.find(item => item.to_hash === Arr2[i].hash);
if (found) {
Arr2[i].action = found.action;
let fdir = found.path.split('/')
Arr2[i].dir = fdir > 2?fdir.filter((item,index)=>{return index<fdir.length-1} ).join(''):fdir[0];
}
}
}

function getData(arr){
return arr.data?arr.data:arr
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["./src/**/*"],
"include": ["./src/**/*", "src/lib/api/interface/Api.ts"],
"references": [{ "path": "./tsconfig.node.json" }]
}
Loading