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

Dev/m.2 #157

Merged
merged 3 commits into from
Aug 6, 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
27 changes: 6 additions & 21 deletions src/lib/components/repository/refDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {RefTypeBranch, RefTypeCommit, RefTypeTag} from "../../../constants";
import { CommitListProps, RefDropdownProps, RefEntryProps, RefSelectorProps, ref, RepoPaginatorProps, ResponseProps } from "../interface/comp_interface";
import { Commit } from "../../../lib/api/interface/Api"
import { repos } from "../../api/interface";
import { useRouter } from "../../hooks/router";


const RefSelector:React.FC<RefSelectorProps> = ({ repo, selected, selectRef, withWorkspace, withTags, amount = 300 }) => {
Expand Down Expand Up @@ -166,7 +167,8 @@ const CommitList:React.FC<CommitListProps> = ({ commits, selectRef, reset, branc
);
};

const RefEntry:React.FC<RefEntryProps> = ({repo, namedRef, refType, selectRef, selected, logCommits}) => {
const RefEntry:React.FC<RefEntryProps> = ({repo, namedRef, refType, selectRef, selected}) => {

return (
<li className="list-group-item" key={namedRef}>
{(!!selected && namedRef === selected.name) ?
Expand All @@ -177,33 +179,16 @@ const RefEntry:React.FC<RefEntryProps> = ({repo, namedRef, refType, selectRef, s
}
<div className="actions">
{(refType === RefTypeBranch && namedRef === repo.head) ? (<Badge variant="info">Default</Badge>) : <span/>}
<Button onClick={logCommits} size="sm" variant="link">
<Button onClick={() => {
selectRef({id: namedRef, type: refType});
}} size="sm" variant="link">
<ChevronRightIcon/>
</Button>
</div>
</li>
);
};

const Paginator:React.FC<RepoPaginatorProps> = ({ pagination, onPaginate, results, from }) => {
const next = (results.length) ? results[results.length-1].id : "";

if (!pagination.has_more && from === "") return (<span/>);

return (
<p className="ref-paginator">
{(from !== "") ?
(<Button size={"sm"} variant="link" onClick={() => { onPaginate(""); }}>Reset</Button>) :
(<span/>)
}
{' '}
{(pagination.has_more) ?
(<Button size={"sm"} variant="link" onClick={() => { onPaginate(next?next:''); }}>Next...</Button>) :
(<span/>)
}
</p>
);
};

const RefDropdown:React.FC<RefDropdownProps> = ({ repo, selected, selectRef, onCancel, variant="light", prefix = '', emptyText = '', withCommits = true, withWorkspace = true, withTags = true,commitId}) => {

Expand Down
20 changes: 13 additions & 7 deletions src/lib/hooks/repo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ import {RefTypeBranch} from "../../constants";
import { repos } from "../api/interface";


export const resolveRef = async (user,repoId:string, refId:string) => {
// try branch
export const resolveRef = async (user,repoId:string, refId:string,type = 'branch') => {
// try branch
try {
const branch = await repos.getBranch(user,repoId, {refName:refId});
if(type == 'tag'){
const branch = await repos.getTag(user,repoId,{refName:refId});
return {...branch.data,type: type};
}else{
const branch = await repos.getBranch(user,repoId, {refName:refId});
return {...branch.data,type: RefTypeBranch};
}

return {...branch.data,type: RefTypeBranch};
} catch(error) {
if (!(error instanceof NotFoundError) && !(error instanceof BadRequestError)) {
throw error;
Expand Down Expand Up @@ -43,7 +48,8 @@ const refContextInitialState = {
export const RefContextProvider = ({ children }) => {
const router = useRouter();
const { repoId } = router.params;
const {ref, compare} = router.query;
const {ref, compare,type} = router.query;

const [refState, setRefState] = useState(refContextInitialState);
const user = cache.get('user')
useEffect(() => {
Expand All @@ -52,8 +58,8 @@ export const RefContextProvider = ({ children }) => {
if (!repoId) return;
try {
const repo = await repos.getRepository( user, repoId)
const reference = await resolveRef(user,repoId, ref?ref:'main');
const comparedRef = await resolveRef(user,repoId, ref?ref:'main');
const reference = await resolveRef(user,repoId, ref?ref:'main',type)
const comparedRef = await resolveRef(user,repoId, ref?ref:'main',type);
setRefState({...refContextInitialState, loading: false, repo: repo.data,reference, compare: comparedRef});
} catch (err) {
setRefState({...refContextInitialState, loading: false, error: err});
Expand Down
15 changes: 8 additions & 7 deletions src/pages/repositories/repos-comp/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Repository } from "../../../lib/api/interface/Api";
type Order = 'asc' | 'desc';
type SortBy = 'name' | 'created_at';
dayjs.extend(relativeTime);

let rArr:Repository[] = []
export const CreateRepositoryButton: React.FC<CreateRepositoryButtonProps> = ({variant = "success", enabled = false, onClick,word= 'New Repository',style={}}) => {
return (
<Button variant={variant} disabled={!enabled} onClick={onClick} style={style}>
Expand Down Expand Up @@ -62,6 +62,7 @@ export const RepositoryList = ({refresh,setRepoAmount,search,filter='',sortBy,or
}
let sortField;
if (sortBy == "name") {
sortField = "name"
} else if (sortBy == "created_at") {
sortField = "created_at";
} else {
Expand All @@ -76,8 +77,8 @@ export const RepositoryList = ({refresh,setRepoAmount,search,filter='',sortBy,or
}

return data.sort((a, b) => {
const valueA = a[sortField];
const valueB = b[sortField];
const valueA =sortBy=="name"? a[sortField].toLowerCase() : a[sortField];
const valueB =sortBy=="name"? b[sortField].toLowerCase() : b[sortField];
if (valueA < valueB) {
return -sortOrder;
} else if (valueA > valueB) {
Expand All @@ -87,9 +88,9 @@ export const RepositoryList = ({refresh,setRepoAmount,search,filter='',sortBy,or
});
}
useEffect(()=>{
sortData(repoArr,order,sortBy)
setRepoArr(repoArr)
}, [refresh,search,filter,sortBy,order])
rArr && sortData(rArr,order,sortBy)
setRepoArr(rArr)
}, [rArr,refresh,search,filter,sortBy,order])

const Storage = ({storage})=>{
return(
Expand All @@ -109,7 +110,7 @@ export const RepositoryList = ({refresh,setRepoAmount,search,filter='',sortBy,or
})
}
setRepoAmount(results.data.results.length)
setRepoArr(results.data.results)
rArr=results.data.results
return results
})
}, [refresh,search,filter]);
Expand Down
29 changes: 17 additions & 12 deletions src/pages/repositories/repository/repo-comp/objects/objects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import RefDropdown from "../../../../../lib/components/repository/refDropdown";
import {
ActionGroup,
ActionsBar,
AlertError,
Loading,
} from "../../../../../lib/components/controls";
import {useRefs} from "../../../../../lib/hooks/repo";
Expand All @@ -17,13 +18,14 @@ import { Link } from "../../../../../lib/components/nav";
import { cache } from "../../../../../lib/api";
import { ActivepageContext } from "../../../../../lib/hooks/conf";
import { repos } from "../../../../../lib/api/interface";
import { useAPI } from "../../../../../lib/hooks/api";


const ObjectsBrowser = () => {
const router = useRouter();
const { path, after, importDialog,commitId} = router.query ;
const { repo, reference, loading, error } = useRefs();

const [err,setErr] = useState<Error | null>(null)
const [showUpload, setShowUpload] = useState(false);
const [showImport, setShowImport] = useState(false);
const [filepath,setFilepath] = useState(path);
Expand All @@ -35,21 +37,22 @@ const ObjectsBrowser = () => {
const refresh = () => setRefreshToken(!refreshToken);
const [ZipSrc, setZipSrc] = useState<string>('');
const [CarSrc, setCarSrc] = useState<string>('');

const parts = (path && path.split("/")) || [];
let searchPrefix = parts.join("/");
const user = cache.get('user')
searchPrefix = searchPrefix && searchPrefix + "/";
const ShowTagForm=()=>{
setShow(!show)
}
const handleSubmit=async ()=>{
await repos.createTag(user,repo.name,{
name:TagName,
target:TagType,
message:TagMessage
})
const handleSubmit= async ()=>{
await repos.createTag(user,repo.name,{name:TagName,target:TagType,message:TagMessage}).then(()=>{
ShowTagForm()
}).catch((err)=>{
setErr(err)
})
console.log(err);

}
useEffect(() => {
const fetchImage = async () => {
Expand Down Expand Up @@ -179,7 +182,7 @@ const ObjectsBrowser = () => {
repoId: repo.name,
user
},
query: { ref:ref.id},
query: { ref:ref.id,type: ref.type},
})} onCancel={undefined}
/>
</ActionGroup>
Expand All @@ -201,6 +204,7 @@ const ObjectsBrowser = () => {

</Dropdown.Menu>
</Dropdown>
{ reference.type !=='tag' && <>
<Button
variant={"light"}
>
Expand All @@ -217,7 +221,8 @@ const ObjectsBrowser = () => {
>
<UploadIcon />Create Tag
</Button>

</>
}
</ActionGroup>
</ActionsBar>

Expand Down Expand Up @@ -296,8 +301,8 @@ const ObjectsBrowser = () => {

</Row>
</Form>

</Modal.Body>
{ err && <AlertError error={err} />}
</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={(e) => {
e.preventDefault();
Expand Down
Loading