2024-09-02 08:43:10 +02:00
|
|
|
import React from 'react';
|
|
|
|
|
import { LocalNode } from '@/types/nodes';
|
|
|
|
|
import { DatabaseContext } from '@/contexts/database';
|
|
|
|
|
import { DatabaseViews } from './database-views';
|
|
|
|
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
2024-09-10 08:11:29 +02:00
|
|
|
import { useDatabaseQuery } from '@/queries/use-database-query';
|
2024-09-02 08:43:10 +02:00
|
|
|
|
|
|
|
|
interface DatabaseContainerNodeProps {
|
|
|
|
|
node: LocalNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const DatabaseContainerNode = ({ node }: DatabaseContainerNodeProps) => {
|
2024-09-10 08:11:29 +02:00
|
|
|
const { data, isPending } = useDatabaseQuery(node.id);
|
2024-09-02 08:43:10 +02:00
|
|
|
|
|
|
|
|
if (isPending) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-10 08:11:29 +02:00
|
|
|
if (!data) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2024-09-02 08:43:10 +02:00
|
|
|
|
|
|
|
|
return (
|
2024-09-10 08:11:29 +02:00
|
|
|
<DatabaseContext.Provider
|
|
|
|
|
value={{ id: node.id, name: data?.name, fields: data?.fields }}
|
|
|
|
|
>
|
2024-09-02 08:43:10 +02:00
|
|
|
<ScrollArea className="h-full max-h-full w-full overflow-y-auto px-10 pb-12">
|
2024-09-10 08:11:29 +02:00
|
|
|
<DatabaseViews key={node.id} views={data.views} />
|
2024-09-02 08:43:10 +02:00
|
|
|
</ScrollArea>
|
|
|
|
|
</DatabaseContext.Provider>
|
|
|
|
|
);
|
|
|
|
|
};
|