Files
d633ced97d Feat/new project creation experiment (#31237)
* some early ideas

* better approach

* fix globe stuff

* add initial step

* reset and submit button for chat

* cleanup

* remove www

* more clean up

* mobile and more cleanup

* fixes

* update advanced and security

* fix project checks

* connect form

* fix reset and tidied up other things

* add layout options

* a/b test

* add offset

* add ab test

* remove www packages

* remove www

* package

* update coordinates

* feat: create ProjectCreationInitialStepSubmittedEvent

* feat: add event for capturing intention of prompting

* fix: bring pnpm-lock up to date

* fix ts errors

* fix globe

* fix globe animation

* fix ts

* remove imports and tools

* update module resolution

* global redirect

* delay rendering

* Update apps/studio/pages/new/[slug].tsx

Co-authored-by: Alaister Young <alaister@users.noreply.github.com>

* take directly to v2 via project create dropdown

* move redirect to useEffect

* feat: distinguish events between initial and second step

* feat: emit an event when create project is clicked on new/v2

* fix: correct event type defs

* remove unused imports

* Various clean ups

* improvements

* Minor refactors

* clean up

* ts fixes

---------

Co-authored-by: Long Hoang <1732217+loong@users.noreply.github.com>
Co-authored-by: Alaister Young <alaister@users.noreply.github.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-01-17 09:59:21 +10:00

87 lines
2.1 KiB
TypeScript

import { useCallback, useEffect, useMemo } from 'react'
import {
applyNodeChanges,
Background,
BackgroundVariant,
Edge,
Node,
NodeChange,
NodeProps,
ReactFlow,
useEdgesState,
useNodesState,
useReactFlow,
} from 'reactflow'
import { TableNode, TableNodeData } from '../Database/Schemas/SchemaTableNode'
export const TABLE_NODE_WIDTH = 640
export const TABLE_NODE_ROW_HEIGHT = 80
interface SchemaFlowProps {
nodes: Node[]
edges: Edge[]
}
export const SchemaFlow = ({ nodes: initialNodes, edges: initialEdges }: SchemaFlowProps) => {
const [nodes, setNodes] = useNodesState(initialNodes)
const [edges, setEdges] = useEdgesState(initialEdges)
const nodeTypes = useMemo(
() => ({ table: (props: NodeProps<TableNodeData>) => <TableNode {...props} placeholder /> }),
[]
)
const reactFlowInstance = useReactFlow<TableNodeData>()
useEffect(() => {
setNodes(initialNodes)
setEdges(initialEdges)
}, [initialNodes, initialEdges, setNodes, setEdges])
useEffect(() => {
reactFlowInstance.fitView()
}, [reactFlowInstance, nodes, edges])
const onNodesChange = useCallback(
(changes: NodeChange[]) => {
setNodes((nds) => applyNodeChanges(changes, nds))
},
[setNodes]
)
return (
<div
style={{ maskImage: 'linear-gradient(to right, transparent 2%, black 13%)' }}
className="absolute inset-0"
>
<ReactFlow
nodes={nodes}
edges={edges}
nodeTypes={nodeTypes}
onNodesChange={onNodesChange}
defaultEdgeOptions={{
type: 'smoothstep',
animated: true,
deletable: false,
style: {
stroke: 'hsl(var(--border-stronger))',
strokeWidth: 0.5,
},
}}
fitView
minZoom={0.8}
maxZoom={1.8}
proOptions={{ hideAttribution: true }}
panOnScroll
panOnScrollSpeed={1}
>
<Background
gap={16}
className="[&>*]:stroke-foreground-muted opacity-[25%]"
variant={BackgroundVariant.Dots}
color={'inherit'}
/>
</ReactFlow>
</div>
)
}