Skip to content
Snippets Groups Projects
Commit 33387434 authored by Johanna Szepanski's avatar Johanna Szepanski
Browse files

migrated to typescript

parent c0ddf1a2
No related branches found
No related tags found
2 merge requests!612Release 5.0.0,!551CE-3210 Migrate to typescript
Pipeline #200924 passed
import { useContext, useMemo } from "react";
import { apiContext } from "../../api/DeployApi";
import { useAPIMethod } from "@ess-ics/ce-ui-common";
import { Skeleton } from "@mui/material";
import { GitRefTypeIcon } from "../common/Git/GitRefTypeIcon";
export const JobGitRefIcon = ({
gitReference,
gitProjectId,
fontSize = null
}) => {
const client = useContext(apiContext);
const params = useMemo(
() => ({
project_id: gitProjectId,
git_reference: gitReference
}),
[gitReference, gitProjectId]
);
const { value: referenceTypeResponse } = useAPIMethod({
fcn: client.apis.Git.gitReferenceType,
params: params
});
if (!referenceTypeResponse) {
return (
<Skeleton
sx={{ marginLeft: "4px" }}
variant="circular"
width={20}
height={20}
/>
);
}
return (
<GitRefTypeIcon
type={referenceTypeResponse.reference_type}
fontSize={fontSize}
/>
);
};
import { useGitReferenceTypeQuery } from "../../store/deployApi";
import { IconFontType } from "../../types/common";
import { Skeleton } from "@mui/material";
import { GitRefTypeIcon } from "../common/Git/GitRefTypeIcon";
interface JobGitRefIconProps {
gitReference: string;
gitProjectId: number;
fontSize?: IconFontType | undefined | null;
}
export const JobGitRefIcon = ({
gitReference,
gitProjectId,
fontSize = null
}: JobGitRefIconProps) => {
const { data: gitReferenceType, isLoading } = useGitReferenceTypeQuery({
projectId: gitProjectId,
gitReference
});
return (
<>
{isLoading ? (
<Skeleton
sx={{ marginLeft: "4px" }}
variant="circular"
width={20}
height={20}
/>
) : (
<GitRefTypeIcon
type={gitReferenceType?.reference_type}
fontSize={fontSize}
/>
)}
</>
);
};
import { useContext, useMemo } from "react"; import {
useGitProjectDetailsQuery,
useListTagsAndCommitIdsQuery
} from "../../store/deployApi";
import { GitRefLink } from "../common/Git/GitRefLink"; import { GitRefLink } from "../common/Git/GitRefLink";
import { apiContext } from "../../api/DeployApi";
import { useAPIMethod } from "@ess-ics/ce-ui-common";
import { Skeleton } from "@mui/material"; import { Skeleton } from "@mui/material";
interface JobGitRefLinkProps {
gitReference: string;
gitProjectId: number;
disableExternalLinkIcon: boolean;
}
const SHORT_GIT_HASH_LENGTH = 8;
export const JobGitRefLink = ({ export const JobGitRefLink = ({
gitReference, gitReference,
gitProjectId, gitProjectId,
disableExternalLinkIcon = false disableExternalLinkIcon = false
}) => { }: JobGitRefLinkProps) => {
const client = useContext(apiContext); const { data: projectDetails, isLoading: projectDetailsLoading } =
const projectParams = useMemo( useGitProjectDetailsQuery({ projectId: gitProjectId });
() => ({
project_id: gitProjectId
}),
[gitProjectId]
);
const { value: project } = useAPIMethod({ const { data: tagsAndCommitsList, isLoading: tagsAndCommitsListLoading } =
fcn: client.apis.Git.gitProjectDetails, useListTagsAndCommitIdsQuery({
params: projectParams projectId: gitProjectId,
});
const shortRefParams = useMemo(
() => ({
project_id: gitProjectId,
reference: gitReference reference: gitReference
}), });
[gitProjectId, gitReference]
);
const { value: commits } = useAPIMethod({
fcn: client.apis.Git.listTagsAndCommitIds,
params: shortRefParams
});
if (!project || !commits) { if (projectDetailsLoading || tagsAndCommitsListLoading) {
return <Skeleton width={80} />; return <Skeleton width={80} />;
} }
const firstCommit = commits?.at(0); const firstCommit = tagsAndCommitsList?.at(0);
const gitRef = firstCommit?.shortReference ?? gitReference; const gitRef = firstCommit?.short_reference ?? gitReference;
const displayReference = const displayReference =
firstCommit?.type === "TAG" firstCommit?.type === "TAG"
? firstCommit?.reference ? firstCommit?.reference
: firstCommit?.short_reference; : firstCommit?.short_reference;
const shortGitHashLength = 8;
return ( return (
<> <>
{displayReference ? ( {displayReference ? (
<GitRefLink <GitRefLink
url={project?.projectUrl} url={projectDetails?.projectUrl}
revision={gitRef} revision={gitRef}
displayReference={displayReference} displayReference={displayReference}
label={`External Git Link, project ${project.name}, revision ${gitRef}`}
disableExternalLinkIcon={disableExternalLinkIcon} disableExternalLinkIcon={disableExternalLinkIcon}
/> />
) : ( ) : (
<span>{gitRef.slice(0, shortGitHashLength)}</span> <span>{gitRef.slice(0, SHORT_GIT_HASH_LENGTH)}</span>
)} )}
</> </>
); );
......
...@@ -4,7 +4,7 @@ import { JobGitRefLink } from "./JobGitRefLink"; ...@@ -4,7 +4,7 @@ import { JobGitRefLink } from "./JobGitRefLink";
interface JobRevisionChipProps { interface JobRevisionChipProps {
gitReference: string; gitReference: string;
gitProjectId: string; gitProjectId: number;
} }
export const JobRevisionChip = ({ export const JobRevisionChip = ({
......
/**
* GitRefLink
* Component providing link (and tag) to gitlab
*/
import { string } from "prop-types";
import { ExternalLink } from "@ess-ics/ce-ui-common"; import { ExternalLink } from "@ess-ics/ce-ui-common";
const propTypes = { interface GitRefLinkProps {
/** String containing url to gitlab template */ url: string | undefined;
url: string, revision: string;
/** String containing gitlab tag */ displayReference: string;
revision: string disableExternalLinkIcon: boolean;
}; }
export const GitRefLink = ({ url, revision, displayReference, ...props }) => { export const GitRefLink = ({
url,
revision,
displayReference,
disableExternalLinkIcon
}: GitRefLinkProps) => {
// if no git reference has been entered // if no git reference has been entered
if (!url || url.trim === "") { if (!url) {
return <></>; return <></>;
} }
...@@ -35,11 +35,9 @@ export const GitRefLink = ({ url, revision, displayReference, ...props }) => { ...@@ -35,11 +35,9 @@ export const GitRefLink = ({ url, revision, displayReference, ...props }) => {
<ExternalLink <ExternalLink
href={url} href={url}
label={`External Git Link, revision ${revision}`} label={`External Git Link, revision ${revision}`}
{...props} disableExternalLinkIcon={disableExternalLinkIcon}
> >
{displayReference} {displayReference}
</ExternalLink> </ExternalLink>
); );
}; };
GitRefLink.propTypes = propTypes;
import { IconFontType } from "../../../types/common";
import CommitIcon from "@mui/icons-material/Commit"; import CommitIcon from "@mui/icons-material/Commit";
import LabelOutlinedIcon from "@mui/icons-material/LabelOutlined"; import LabelOutlinedIcon from "@mui/icons-material/LabelOutlined";
import QuestionMarkIcon from "@mui/icons-material/QuestionMark"; import QuestionMarkIcon from "@mui/icons-material/QuestionMark";
type FontType = "small" | "inherit" | "medium" | "large";
interface GitRefTypeIconProps { interface GitRefTypeIconProps {
type: string; type: string | undefined;
fontSize?: FontType; fontSize?: IconFontType | undefined | null;
} }
export const GitRefTypeIcon = ({ type, fontSize }: GitRefTypeIconProps) => { export const GitRefTypeIcon = ({ type, fontSize }: GitRefTypeIconProps) => {
if (type === "TAG") { if (type === "TAG") {
return <LabelOutlinedIcon fontSize={fontSize ? fontSize : "small"} />; return <LabelOutlinedIcon fontSize={fontSize || "small"} />;
} }
if (type === "COMMIT") { if (type === "COMMIT") {
return <CommitIcon fontSize={fontSize ? fontSize : "medium"} />; return <CommitIcon fontSize={fontSize || "medium"} />;
} }
return <QuestionMarkIcon fontSize={fontSize ? fontSize : "small"} />; return <QuestionMarkIcon fontSize={fontSize || "small"} />;
}; };
...@@ -47,3 +47,5 @@ export interface ApiResult<T> { ...@@ -47,3 +47,5 @@ export interface ApiResult<T> {
export type FormElements<U extends string> = HTMLFormControlsCollection & export type FormElements<U extends string> = HTMLFormControlsCollection &
Record<U, HTMLInputElement>; Record<U, HTMLInputElement>;
export type IconFontType = "small" | "medium" | "large" | "inherit";
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment