()
| 17 | import SchemaList from "./schema-sidebar-list"; |
| 18 | |
| 19 | export default function SchemaView() { |
| 20 | const [search, setSearch] = useState(""); |
| 21 | const { databaseDriver, extensions } = useStudioContext(); |
| 22 | const { currentSchemaName } = useSchema(); |
| 23 | const [isCreateSchema, setIsCreateSchema] = useState(false); |
| 24 | |
| 25 | const contentMenu = useMemo(() => { |
| 26 | const items: StudioExtensionMenuItem[] = []; |
| 27 | |
| 28 | const flags = databaseDriver.getFlags(); |
| 29 | |
| 30 | if (flags.supportCreateUpdateTable) { |
| 31 | items.push({ |
| 32 | title: "Create Table", |
| 33 | key: "create-table", |
| 34 | onClick: () => { |
| 35 | scc.tabs.openBuiltinSchema({ schemaName: currentSchemaName }); |
| 36 | }, |
| 37 | }); |
| 38 | } |
| 39 | |
| 40 | if (flags.supportCreateUpdateDatabase) { |
| 41 | items.push({ |
| 42 | title: "Create Database/Schema", |
| 43 | key: "create-schema", |
| 44 | onClick: () => { |
| 45 | setIsCreateSchema(true); |
| 46 | }, |
| 47 | }); |
| 48 | } |
| 49 | |
| 50 | return [...items, ...extensions.getResourceCreateMenu()]; |
| 51 | }, [databaseDriver, currentSchemaName, extensions]); |
| 52 | |
| 53 | const activatorButton = useMemo(() => { |
| 54 | if (contentMenu.length === 0) return null; |
| 55 | |
| 56 | if (contentMenu.length === 1) { |
| 57 | return ( |
| 58 | <button |
| 59 | className={cn( |
| 60 | buttonVariants({ |
| 61 | size: "icon", |
| 62 | }), |
| 63 | "h-8 w-8 rounded-full bg-neutral-800 dark:bg-neutral-200" |
| 64 | )} |
| 65 | onClick={contentMenu[0].onClick} |
| 66 | > |
| 67 | <Plus size={16} weight="bold" /> |
| 68 | </button> |
| 69 | ); |
| 70 | } |
| 71 | |
| 72 | return ( |
| 73 | <DropdownMenu> |
| 74 | <DropdownMenuTrigger asChild> |
| 75 | <button |
| 76 | className={cn( |
nothing calls this directly
no test coverage detected