feat(pipelines): 列表添加右键菜单。
This commit is contained in:
parent
60d7d7fe5c
commit
5d01389f3b
@ -2,7 +2,6 @@ import makeStyles from "@mui/styles/makeStyles";
|
|||||||
import { FC, Fragment, useEffect, useRef } from "react";
|
import { FC, Fragment, useEffect, useRef } from "react";
|
||||||
import { useAuth } from "./auth.provider";
|
import { useAuth } from "./auth.provider";
|
||||||
const useStyles = makeStyles((theme) => {
|
const useStyles = makeStyles((theme) => {
|
||||||
debugger;
|
|
||||||
return {
|
return {
|
||||||
iframe: {
|
iframe: {
|
||||||
height: "300px",
|
height: "300px",
|
||||||
|
@ -10,11 +10,13 @@ import {
|
|||||||
Menu,
|
Menu,
|
||||||
MenuItem,
|
MenuItem,
|
||||||
PopoverPosition,
|
PopoverPosition,
|
||||||
|
styled,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { FC, MouseEventHandler, useMemo, useState } from "react";
|
import { FC, MouseEventHandler, useMemo, useState, MouseEvent } from "react";
|
||||||
import { Pipeline, Project } from "../generated/graphql";
|
import { Pipeline, Project } from "../generated/graphql";
|
||||||
import { CallMerge, Edit } from "@mui/icons-material";
|
import { CallMerge, Edit } from "@mui/icons-material";
|
||||||
import { any, values } from "ramda";
|
import { any, values } from "ramda";
|
||||||
|
import { Divider } from "@material-ui/core";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
projectId: string;
|
projectId: string;
|
||||||
@ -47,17 +49,37 @@ export const PipelineList: FC<Props> = ({ projectId }) => {
|
|||||||
}));
|
}));
|
||||||
}, [data]);
|
}, [data]);
|
||||||
|
|
||||||
const [contextMenu, setContextMenu] = useState<PopoverPosition>();
|
const [contextMenu, setContextMenu] = useState<[PopoverPosition, Pipeline]>();
|
||||||
|
const { navigate, url } = useRouter();
|
||||||
|
|
||||||
const handleContextMenu: MouseEventHandler = (event) => {
|
const handleContextMenu = (event: MouseEvent, pipeline: Pipeline | false) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
setContextMenu({ top: event.clientY - 4, left: event.clientX - 2 });
|
if (pipeline) {
|
||||||
|
setContextMenu([
|
||||||
|
{ top: event.clientY - 4, left: event.clientX - 2 },
|
||||||
|
pipeline,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
setContextMenu(undefined);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClose = () => {
|
const handleClose = () => {
|
||||||
setContextMenu(undefined);
|
setContextMenu(undefined);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const modify = () => {
|
||||||
|
navigate({
|
||||||
|
url: url({
|
||||||
|
name: "edit-pipeline",
|
||||||
|
params: {
|
||||||
|
pipelineId: contextMenu![1].id,
|
||||||
|
projectId: contextMenu![1].project.id,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<List>
|
<List>
|
||||||
@ -66,7 +88,7 @@ export const PipelineList: FC<Props> = ({ projectId }) => {
|
|||||||
name="pipeline-commits"
|
name="pipeline-commits"
|
||||||
params={{ pipelineId: pipeline.id, projectId: projectId }}
|
params={{ pipelineId: pipeline.id, projectId: projectId }}
|
||||||
key={pipeline.id}
|
key={pipeline.id}
|
||||||
onContextMenu={handleContextMenu}
|
onContextMenu={(ev) => handleContextMenu(ev, pipeline)}
|
||||||
>
|
>
|
||||||
<Item pipeline={pipeline} />
|
<Item pipeline={pipeline} />
|
||||||
</Link>
|
</Link>
|
||||||
@ -76,33 +98,29 @@ export const PipelineList: FC<Props> = ({ projectId }) => {
|
|||||||
keepMounted
|
keepMounted
|
||||||
open={!!contextMenu}
|
open={!!contextMenu}
|
||||||
onClose={handleClose}
|
onClose={handleClose}
|
||||||
|
onContextMenu={(ev) => handleContextMenu(ev, false)}
|
||||||
anchorReference="anchorPosition"
|
anchorReference="anchorPosition"
|
||||||
anchorPosition={
|
anchorPosition={contextMenu?.[0]}
|
||||||
contextMenu && any(Boolean, values(contextMenu))
|
|
||||||
? contextMenu
|
|
||||||
: undefined
|
|
||||||
}
|
|
||||||
>
|
>
|
||||||
<MenuItem onClick={handleClose}>Copy</MenuItem>
|
<MenuItem onClick={handleClose}>Runtime Config</MenuItem>
|
||||||
<MenuItem onClick={handleClose}>Print</MenuItem>
|
<MenuItem
|
||||||
<MenuItem onClick={handleClose}>Highlight</MenuItem>
|
onClick={() => {
|
||||||
<MenuItem onClick={handleClose}>Email</MenuItem>
|
modify();
|
||||||
|
handleClose();
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Pipeline Config
|
||||||
|
</MenuItem>
|
||||||
|
<Divider />
|
||||||
|
<MenuItem sx={{ color: "error.main" }} onClick={handleClose}>
|
||||||
|
Delete
|
||||||
|
</MenuItem>
|
||||||
</Menu>
|
</Menu>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const Item = ({ pipeline }: { pipeline: Pipeline }) => {
|
const Item = ({ pipeline }: { pipeline: Pipeline }) => {
|
||||||
const { navigate, url } = useRouter();
|
|
||||||
const modify: MouseEventHandler = (ev) => {
|
|
||||||
ev.preventDefault();
|
|
||||||
navigate({
|
|
||||||
url: url({
|
|
||||||
name: "edit-pipeline",
|
|
||||||
params: { pipelineId: pipeline.id, projectId: pipeline.project.id },
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
};
|
|
||||||
return (
|
return (
|
||||||
<ListItem button>
|
<ListItem button>
|
||||||
<ListItemText
|
<ListItemText
|
||||||
@ -114,11 +132,6 @@ const Item = ({ pipeline }: { pipeline: Pipeline }) => {
|
|||||||
</Typography>
|
</Typography>
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
<ListItemSecondaryAction>
|
|
||||||
<IconButton edge="end" aria-label="edit" onClick={modify} size="large">
|
|
||||||
<Edit />
|
|
||||||
</IconButton>
|
|
||||||
</ListItemSecondaryAction>
|
|
||||||
</ListItem>
|
</ListItem>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user