Skip to content

feat: support naming on pod and scope #129

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

Merged
merged 1 commit into from
Dec 9, 2022
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
47 changes: 44 additions & 3 deletions ui/src/components/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import ReactFlow, {
import "reactflow/dist/style.css";

import Box from "@mui/material/Box";
import InputBase from "@mui/material/InputBase";
import CircularProgress from "@mui/material/CircularProgress";
import Tooltip from "@mui/material/Tooltip";
import IconButton from "@mui/material/IconButton";
Expand Down Expand Up @@ -71,6 +72,9 @@ const ScopeNode = memo<Props>(({ data, id, isConnectable }) => {
const ref = useRef(null);
const store = useContext(RepoContext);
if (!store) throw new Error("Missing BearContext.Provider in the tree");
const getPod = useStore(store, (state) => state.getPod);
const pod = getPod(id);
const setPodName = useStore(store, (state) => state.setPodName);
const updatePod = useStore(store, (state) => state.updatePod);
const [target, setTarget] = React.useState<any>();
const nodesMap = useStore(store, (state) => state.ydoc.getMap<Node>("pods"));
Expand Down Expand Up @@ -130,7 +134,21 @@ const ScopeNode = memo<Props>(({ data, id, isConnectable }) => {
justifyContent: "center",
}}
>
Scope
<InputBase
defaultValue={pod.name || "Scope"}
onBlur={(e) => {
const name = e.target.value;
if (name === pod.name) return;
setPodName({ id, name });
}}
inputProps={{
style: {
padding: "0px",
textAlign: "center",
textOverflow: "ellipsis",
},
}}
></InputBase>
</Box>
</Grid>
<Grid item xs={4}></Grid>
Expand Down Expand Up @@ -339,6 +357,7 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
const isRightLayout = layout === "right";
const { setNodes } = useReactFlow();
// const selected = useStore(store, (state) => state.selected);
const setPodName = useStore(store, (state) => state.setPodName);
const setPodSelected = useStore(store, (state) => state.setPodSelected);
const setCurrentEditor = useStore(store, (state) => state.setCurrentEditor);
const getPod = useStore(store, (state) => state.getPod);
Expand Down Expand Up @@ -435,6 +454,28 @@ const CodeNode = memo<Props>(({ data, id, isConnectable }) => {
/>
{/* The header of code pods. */}
<Box className="custom-drag-handle">
<Box
sx={{
position: "absolute",
top: "-24px",
width: "50%",
}}
>
<InputBase
defaultValue={pod.name}
onBlur={(e) => {
const name = e.target.value;
if (name === pod.name) return;
setPodName({ id, name });
}}
inputProps={{
style: {
padding: "0px",
textOverflow: "ellipsis",
},
}}
></InputBase>
</Box>
<Box sx={styles["pod-index"]}>[{pod.index}]</Box>
<Box
sx={{
Expand Down Expand Up @@ -581,7 +622,7 @@ export function Canvas() {
const provider = useStore(store, (state) => state.provider);

const getRealNodes = useCallback(
(id, level) => {
(id: string, level: number) => {
let res: any[] = [];
let children = getId2children(id) || [];
const pod = getPod(id);
Expand Down Expand Up @@ -683,7 +724,7 @@ export function Canvas() {
const userColor = useStore(store, (state) => state.user?.color);

const addNode = useCallback(
(x, y, type) => {
(x: number, y: number, type: string) => {
const reactFlowBounds = reactFlowWrapper.current.getBoundingClientRect();
let style;

Expand Down
5 changes: 3 additions & 2 deletions ui/src/lib/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ export interface RepoSlice {
clearError: () => void;
foldAll: () => void;
unfoldAll: () => void;
setPodName: ({ id, name }: { id: string; name: string }) => void;
setPodContent: ({ id, content }: { id: string; content: string }) => void;
addPod: (
client: ApolloClient<object> | null,
Expand Down Expand Up @@ -460,7 +461,7 @@ const createRepoSlice: StateCreator<
// @ts-ignore
"toggleUtility"
),
setName: ({ id, name }) =>
setPodName: ({ id, name }) =>
set(
produce((state) => {
let pod = state.pods[id];
Expand All @@ -469,7 +470,7 @@ const createRepoSlice: StateCreator<
}),
false,
// @ts-ignore
"setName"
"setPodName"
),
setPodLang: ({ id, lang }) =>
set(
Expand Down