Correction for merge

This commit is contained in:
Lucas Oliveira 2023-02-22 23:05:53 -03:00
commit 96ae8916d5
2 changed files with 69 additions and 43 deletions

View file

@ -4,39 +4,47 @@ import { ReactFlowProvider } from "reactflow";
import FlowPage from ".."; import FlowPage from "..";
import { TabsContext } from "../../../contexts/tabsContext"; import { TabsContext } from "../../../contexts/tabsContext";
import TabComponent from "./tabComponent"; import TabComponent from "./tabComponent";
import { PlusIcon } from '@heroicons/react/24/outline'; import { PlusIcon } from "@heroicons/react/24/outline";
var _ = require("lodash"); var _ = require("lodash");
export function TabsManager() { export function TabsManager() {
const { flows, addFlow, tabIndex, setTabIndex } = useContext(TabsContext); const { flows, addFlow, tabIndex, setTabIndex } = useContext(TabsContext);
const [inputMode,setInputMode] = useState(false) useEffect(() => {
useEffect(() => { if (flows.length === 0) {
if (flows.length === 0) { const id = _.uniqueId();
const id = _.uniqueId() addFlow({ name: "flow " + id, data: null, id });
addFlow({ name: "flow "+id, data: null, id }); }
} }, []);
}, []);
return ( return (
<div className="h-full w-full flex flex-col"> <div className="h-full w-full flex flex-col">
<div className="w-full flex pr-2 flex-row text-center items-center"> <div className="w-full flex pr-2 flex-row text-center items-center bg-gray-100">
{flows.map((flow, index) => { {flows.map((flow, index) => {
console.log(tabIndex) console.log(tabIndex);
return ( return (
<TabComponent onClick={() => setTabIndex(index)} selected={index === tabIndex} key={index} id={flow.id}> <TabComponent
<div onClick={()=>setInputMode(true)}>{flow.name}</div> onClick={() => setTabIndex(index)}
</TabComponent> selected={index === tabIndex}
); key={index}
})} flow={flow}
<div onClick={()=>{ />
const id = _.uniqueId() );
addFlow({ name: "flow"+id, data: null, id})}} className="cursor-pointer"><PlusIcon color="black" width={24}></PlusIcon></div> })}
</div> <TabComponent
<div className="w-full h-full"> onClick={() => {
<ReactFlowProvider> const id = _.uniqueId();
<FlowPage flow={flows[tabIndex]}></FlowPage> addFlow({ name: "flow" + id, data: null, id });
</ReactFlowProvider> }}
</div> selected={false}
</div> key={0}
); flow={null}
/>
</div>
<div className="w-full h-full">
<ReactFlowProvider>
<FlowPage flow={flows[tabIndex]}></FlowPage>
</ReactFlowProvider>
</div>
</div>
);
} }

View file

@ -1,31 +1,49 @@
import { PlusIcon, XMarkIcon } from "@heroicons/react/24/solid"; import { PlusIcon, XMarkIcon } from "@heroicons/react/24/solid";
import { useContext } from "react"; import { useContext } from "react";
import { TabsContext } from "../../../../contexts/tabsContext"; import { TabsContext } from "../../../../contexts/tabsContext";
import { classNames } from "../../../../utils";
export default function TabComponent({ selected, flow, id, onClick}) { export default function TabComponent({ selected, flow, onClick }) {
const { removeFlow, flows } = useContext(TabsContext); const { removeFlow } = useContext(TabsContext);
return ( return (
<> <>
{flow ? ( {flow ? (
selected ? ( !selected ? (
<button <div
className="px-4 my-2 mt-3 border-l border-gray-300 -ml-px" className="flex justify-between select-none w-36 items-center px-4 my-2 mt-3 border-x border-gray-300 -ml-px"
onClick={onClick} onClick={onClick}
> >
{flow.name} {flow.name}
</button> <button
onClick={(e) => {
e.stopPropagation();
removeFlow(flow.id);
}}
>
<XMarkIcon className="h-4" />
</button>
</div>
) : ( ) : (
<div className="bg-white pt-3 pointer-events-none border border-b-0 border-gray-300 px-4 py-2 rounded-t-xl"> <div className="bg-white flex select-none justify-between w-36 items-center pt-3 border border-b-0 border-gray-300 px-4 py-2 rounded-t-xl -ml-px">
{flow.name} {flow.name}
<button
onClick={() => {
removeFlow(flow.id);
}}
>
<XMarkIcon className="h-4" />
</button>
</div> </div>
) )
) : ( ) : (
<div className="h-full py-2 pt-3 flex justify-center items-center"> <div className="h-full py-2 pt-3 flex justify-center items-center">
<button className="px-3 h-full border-l border-gray-300 -ml-px"> <button
className="px-3 h-full border-gray-300 -ml-px"
onClick={onClick}
>
<PlusIcon className="h-5" /> <PlusIcon className="h-5" />
</button> </button>
</div> </div>
)} )}
</> </>
)} );
}