nested reactFlow inside tab
This commit is contained in:
parent
bf678e5f86
commit
90974d9ef4
5 changed files with 39 additions and 44 deletions
|
|
@ -12,6 +12,8 @@ import { locationContext } from "./contexts/locationContext";
|
||||||
import FlowPage from "./pages/FlowPage";
|
import FlowPage from "./pages/FlowPage";
|
||||||
import Sidebar from "./components/SidebarComponent";
|
import Sidebar from "./components/SidebarComponent";
|
||||||
import Header from "./components/HeaderComponent";
|
import Header from "./components/HeaderComponent";
|
||||||
|
import { TabsProvider } from "./contexts/tabsContext";
|
||||||
|
import { TabsManager } from "./pages/FlowPage/flowManager";
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
@ -108,7 +110,9 @@ export default function App() {
|
||||||
<main className="min-w-0 flex-1 border-t border-gray-200 flex">
|
<main className="min-w-0 flex-1 border-t border-gray-200 flex">
|
||||||
{/* Primary column */}
|
{/* Primary column */}
|
||||||
<div className="w-full h-full">
|
<div className="w-full h-full">
|
||||||
<FlowPage />
|
<TabsProvider>
|
||||||
|
<TabsManager></TabsManager>
|
||||||
|
</TabsProvider>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -23,14 +23,18 @@ export const TabsContext = createContext<TabsContextType>(TabsContextInitialValu
|
||||||
|
|
||||||
export function TabsProvider({children}){
|
export function TabsProvider({children}){
|
||||||
const [tabIndex,setTabIndex] = useState(0)
|
const [tabIndex,setTabIndex] = useState(0)
|
||||||
const [flows,setFlows] = useState<Array<flow>>([])
|
const [flows,setFlows] = useState<Array<flow>>(JSON.parse(window.sessionStorage.getItem('tabs'))??[])
|
||||||
function removeFlow(index:number){
|
function removeFlow(index:number){
|
||||||
let newFlows = flows
|
let newFlows = flows
|
||||||
newFlows.splice(index)
|
newFlows.splice(index)
|
||||||
|
window.sessionStorage.setItem('tabs',JSON.stringify(newFlows))
|
||||||
setFlows(newFlows)
|
setFlows(newFlows)
|
||||||
}
|
}
|
||||||
function addFlow(newFlow:flow){
|
function addFlow(newFlow:flow){
|
||||||
setFlows([...flows,newFlow])
|
let newFlows = [...flows,newFlow]
|
||||||
|
window.sessionStorage.setItem('tabs',JSON.stringify(newFlows))
|
||||||
|
setFlows(newFlows)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return(
|
return(
|
||||||
|
|
|
||||||
|
|
@ -1,52 +1,27 @@
|
||||||
import { useState } from 'react';
|
import { useContext, useState } from 'react';
|
||||||
import { Tab, Tabs, TabList, TabPanel } from 'react-tabs';
|
import { Tab, Tabs, TabList, TabPanel } from 'react-tabs';
|
||||||
import FlowPage from '..';
|
import FlowPage from '..';
|
||||||
import 'react-tabs/style/react-tabs.css';
|
import { TabsContext } from '../../../contexts/tabsContext';
|
||||||
|
import TabComponent from './tabComponent';
|
||||||
|
var _ = require("lodash");
|
||||||
|
|
||||||
interface FlowTabProps {
|
export function TabsManager(){
|
||||||
flow:any;
|
const {flows,addFlow} = useContext(TabsContext);
|
||||||
}
|
if(flows.length===0){
|
||||||
|
addFlow({name:"untitled",flow:null,id:_.uniqueId()})
|
||||||
function FlowTab() {
|
|
||||||
return (
|
|
||||||
<FlowPage></FlowPage>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function App() {
|
|
||||||
const [flows, setFlows] = useState([]); // Start with one flow
|
|
||||||
const [activeIndex, setActiveIndex] = useState(0);
|
|
||||||
|
|
||||||
function onElementsChange(flowIndex: number, elements: any[]) {
|
|
||||||
setFlows((prevFlows) => {
|
|
||||||
const newFlows = [...prevFlows];
|
|
||||||
newFlows[flowIndex] = elements;
|
|
||||||
return newFlows;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function addTab() {
|
|
||||||
setFlows([...flows, []]); // Add a new flow to the state
|
|
||||||
setActiveIndex(flows.length); // Activate the new tab
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return(
|
return(
|
||||||
<Tabs selectedIndex={activeIndex} onSelect={setActiveIndex}>
|
<Tabs className="h-full w-full flex flex-col">
|
||||||
<TabList>
|
<TabList>
|
||||||
{flows.map((flow, index) => (
|
{flows.map(flow=><Tab key={flow.id}><TabComponent>{flow.name}</TabComponent></Tab>)}
|
||||||
<Tab key={index}>Flow {index + 1}</Tab>
|
<Tab><button>+</button></Tab>
|
||||||
))}
|
|
||||||
<button onClick={addTab}>+</button> {/* Render the plus button */}
|
|
||||||
</TabList>
|
</TabList>
|
||||||
|
{flows.map(flow=><TabPanel key={flow.id} className="h-full w-full"><FlowPage></FlowPage></TabPanel>)}
|
||||||
{flows.map((flow, index) => (
|
|
||||||
<TabPanel key={index}>
|
|
||||||
<FlowTab />
|
|
||||||
</TabPanel>
|
|
||||||
))}
|
|
||||||
</Tabs>
|
</Tabs>
|
||||||
);
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
tabs initial logic
|
tabs initial logic
|
||||||
TO DO
|
TO DO
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,12 @@
|
||||||
|
type tabProps = {
|
||||||
|
name:string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export default function TabComponent({children}){
|
||||||
|
return(
|
||||||
|
<div className="bg-blue-400 w-2">
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue