Skip to content

Commit

Permalink
small things
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianP8701 committed Sep 30, 2024
1 parent 01e549c commit 6832adc
Show file tree
Hide file tree
Showing 34 changed files with 545 additions and 442 deletions.
4 changes: 1 addition & 3 deletions client/codegen.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
overwrite: true
schema: "../server/src/graphql/schema.gql"
documents:
- "src/graphql/queries.gql"
- "src/graphql/fragments.gql"
- "src/graphql/subscriptions.gql"
- "src/graphql/**/*.gql"
generates:
src/graphql/generated/graphql.ts:
plugins:
Expand Down
2 changes: 1 addition & 1 deletion client/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PropsWithChildren } from "react";
import { BrowserRouter, Route, Routes } from 'react-router-dom';
import { ClerkProvider, ClerkLoaded } from '@clerk/clerk-react';
import { TooltipProvider } from "@radix-ui/react-tooltip";
import { TooltipProvider } from "@/components/ui/tooltip";
import './App.css';
import HomePage from './views/HomePage';
import { ApolloClientProvider } from "./providers/ApolloClientProvider";
Expand Down
48 changes: 48 additions & 0 deletions client/src/components/custom/ButtonWithTooltipWhenDisabled.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Button, ButtonProps } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";

interface ButtonWithTooltipWhenDisabledProps extends ButtonProps {
onClick: () => void;
tooltipText: string;
ariaLabel: string;
disabled: boolean;
}

export default function ButtonWithTooltipWhenDisabled({
children,
className,
variant = "ghost",
size = "icon",
ariaLabel,
onClick,
tooltipText,
disabled
}: ButtonWithTooltipWhenDisabledProps) {
const button = (
<Button
variant={variant}
size={size}
className={className}
aria-label={ariaLabel}
onClick={onClick}
disabled={disabled}
>
{children}
</Button>
);

if (!disabled) {
return button;
}

return (
<Tooltip>
<TooltipTrigger asChild>
{button}
</TooltipTrigger>
<TooltipContent side="right" sideOffset={5}>
{tooltipText}
</TooltipContent>
</Tooltip>
);
}
2 changes: 1 addition & 1 deletion client/src/components/custom/PopoverButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const PopoverButton = React.forwardRef<
variant='outline'
onClick={togglePopover}
>
<div className='overflow-hidden max-w-[180px] truncate text-left'>{title}</div>
<div className='overflow-hidden max-w-[180px] truncate text-left font-normal'>{title}</div>
<ChevronsUpDown className='w-4 h-4 ml-2 flex-shrink-0' />
</Button>
))
Expand Down
29 changes: 0 additions & 29 deletions client/src/components/custom/TooltipButton.tsx

This file was deleted.

16 changes: 8 additions & 8 deletions client/src/graphql/fragments.gql
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fragment InformationGraph on InformationGraph {
...InformationNode
}
edges {
...InformationNodeEdge
...informationEdge
}
}

Expand All @@ -47,7 +47,7 @@ fragment InformationNode on InformationNode {
title
}

fragment InformationNodeEdge on InformationNodeEdge {
fragment informationEdge on informationEdge {
id
startNodeId
endNodeId
Expand All @@ -59,7 +59,7 @@ fragment AgentGraph on AgentGraph {
...AgentNode
}
edges {
...AgentNodeEdge
...AgentEdge
}
}

Expand All @@ -68,7 +68,7 @@ fragment AgentNode on AgentNode {
title
}

fragment AgentNodeEdge on AgentNodeEdge {
fragment AgentEdge on AgentEdge {
id
type
startNodeId
Expand Down Expand Up @@ -106,7 +106,7 @@ fragment ToolGraph on ToolGraph {
...ToolNode
}
edges {
...ToolNodeEdge
...ToolEdge
}
}

Expand All @@ -115,7 +115,7 @@ fragment ToolNode on ToolNode {
title
}

fragment ToolNodeEdge on ToolNodeEdge {
fragment ToolEdge on ToolEdge {
id
startNodeId
endNodeId
Expand All @@ -127,11 +127,11 @@ fragment ActionGraph on ActionGraph {
...ActionNode
}
edges {
...ActionNodeEdge
...ActionEdge
}
}

fragment ActionNodeEdge on ActionNodeEdge {
fragment ActionEdge on ActionEdge {
id
startNodeId
endNodeId
Expand Down
23 changes: 23 additions & 0 deletions client/src/graphql/mutations.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
mutation CreateSwarm($input: CreateSwarmRequest!) {
swarmMutation {
createSwarm(input: $input) {
...User
}
}
}

mutation CreateInformationGraph($input: CreateInformationGraphRequest!) {
informationGraphMutation {
createInformationGraph(input: $input) {
...User
}
}
}

mutation SendMessage($input: SendMessageRequest!) {
chatMutation {
sendMessage(input: $input) {
...Chat
}
}
}
30 changes: 0 additions & 30 deletions client/src/graphql/queries.gql
Original file line number Diff line number Diff line change
Expand Up @@ -21,33 +21,3 @@ query FetchActionGraph {
...ActionGraph
}
}

mutation CreateSwarm($input: CreateSwarmRequest!) {
swarmMutation {
createSwarm(input: $input) {
...User
}
}
}

mutation CreateInformationGraph($input: CreateInformationGraphRequest!) {
informationGraphMutation {
createInformationGraph(input: $input) {
...User
}
}
}

mutation SendMessage($input: SendMessageRequest!) {
chatMutation {
sendMessage(input: $input) {
...Chat
}
}
}

subscription MessageSent($chatId: ID!) {
messageSent(chatId: $chatId) {
...Message
}
}
2 changes: 1 addition & 1 deletion client/src/graphql/subscriptions.gql
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ subscription NewMessage($chatId: ID!) {
messageSent(chatId: $chatId) {
...Message
}
}
}
19 changes: 14 additions & 5 deletions client/src/hooks/fetchUser.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import { useFetchUserQuery } from "../graphql/generated/graphql";
import { ApolloError } from "@apollo/client";
import { FetchUserQueryResult, useFetchUserQuery, User } from "../graphql/generated/graphql";

export function useFetchUser() {
const { data, loading, error } = useFetchUserQuery();
export function useFetchUser(): {
user: User | null;
loading: boolean;
error: ApolloError | null;
refetch: () => Promise<FetchUserQueryResult>;
} {
const { data, loading, error, refetch } = useFetchUserQuery({
fetchPolicy: 'cache-and-network',
});

return {
user: data?.user,
user: data?.user || null,
loading,
error
error: error || null,
refetch: refetch as () => Promise<FetchUserQueryResult>
};
}
72 changes: 72 additions & 0 deletions client/src/views/Dialogs/CreateInformationGraphDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { useState } from "react";
import { Dialog, DialogContent } from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import { CreateInformationGraphRequest, useCreateInformationGraphMutation } from "../../graphql/generated/graphql";
import { useFetchUser } from "../../hooks/fetchUser";
import ButtonWithTooltipWhenDisabled from "@/components/custom/ButtonWithTooltipWhenDisabled";

interface CreateInformationDialogProps {
open: boolean;
onOpenChange: (open: boolean) => void;
}

const initialCreateInformationGraphRequest: CreateInformationGraphRequest = {
title: '',
}

export function CreateInformationDialog({ open, onOpenChange }: CreateInformationDialogProps) {
const [createInformationGraphRequest, setCreateInformationGraphRequest] = useState<CreateInformationGraphRequest>(initialCreateInformationGraphRequest)
const [createInformationGraph] = useCreateInformationGraphMutation();
const { refetch } = useFetchUser();

const handleCreateInformationGraph = async () => {
try {
const result = await createInformationGraph({
variables: { input: createInformationGraphRequest },
});
console.log(result);
await refetch(); // Refetch user data after creating a new information graph
onOpenChange(false);
setCreateInformationGraphRequest(initialCreateInformationGraphRequest);
} catch (error) {
console.error("Error creating information graph:", error);
}
};

const isCreateButtonDisabled = !createInformationGraphRequest.title

const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (!isCreateButtonDisabled) {
handleCreateInformationGraph();
}
};

return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="bg-background border-secondary border-2 rounded-2xl">
<form onSubmit={handleSubmit}>
<div className="grid gap-4 py-4 px-20 mt-2">
<Input
className="bg-secondary rounded-2xl"
placeholder="Title"
value={createInformationGraphRequest.title}
onChange={(e) => setCreateInformationGraphRequest({ ...createInformationGraphRequest, title: e.target.value })}
/>
</div>
<div className="flex justify-end">
<ButtonWithTooltipWhenDisabled
type="submit"
disabled={isCreateButtonDisabled}
onClick={() => {}} // This is needed because the onClick prop is required
tooltipText="Please enter a title"
ariaLabel="Create information graph"
>
Create
</ButtonWithTooltipWhenDisabled>
</div>
</form>
</DialogContent>
</Dialog>
);
}
53 changes: 0 additions & 53 deletions client/src/views/Dialogs/CreateMemoryDialog.tsx

This file was deleted.

Loading

0 comments on commit 6832adc

Please sign in to comment.