Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update fabrix packages #12

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ dist-ssr
*.njsproj
*.sln
*.sw?

*.tsbuildinfo
1 change: 1 addition & 0 deletions eslint.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = tsEslint.config(
"**/package.json",
"**/tsconfig.json",
"**/tsconfig.tsbuildinfo",
"src/components/ui/**",
],
},
eslint.configs.recommended,
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
"node": "22.x"
},
"dependencies": {
"@chakra-ui/react": "^2.8.2",
"@emotion/css": "^11.13.0",
"@emotion/react": "^11.13.0",
"@emotion/styled": "^11.13.0",
"@fabrix-framework/chakra-ui": "0.1.1",
"@fabrix-framework/fabrix": "0.1.1",
"@fabrix-framework/graphql-config": "0.1.0",
"@chakra-ui/react": "^3.3.1",
"@emotion/css": "^11.13.5",
"@emotion/react": "^11.14.0",
"@fabrix-framework/chakra-ui": "^0.4.0",
"@fabrix-framework/fabrix": "^0.4.0",
"@fabrix-framework/graphql-config": "^0.1.0",
"@graphiql/plugin-explorer": "^3.2.2",
"@graphiql/react": "^0.26.2",
"@graphiql/toolkit": "^0.9.2",
Expand All @@ -33,11 +32,12 @@
"graphql-editor": "^7.2.16",
"graphql-tag": "^2.12.6",
"monaco-editor": "^0.50.0",
"next-themes": "^0.4.4",
"openai": "^4.56.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-error-boundary": "^4.0.13",
"react-icons": "^5.2.1",
"react-icons": "^5.3.0",
"react-markdown": "^9.0.1",
"remeda": "^2.6.0",
"urql": "^4.1.0"
Expand Down
2,530 changes: 1,092 additions & 1,438 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

39 changes: 22 additions & 17 deletions src/builder/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ import {
Heading,
Input,
Button,
useDisclosure,
Drawer,
DrawerOverlay,
DrawerContent,
DrawerCloseButton,
DrawerHeader,
DrawerBody,
Text,
Divider,
HStack,
} from "@chakra-ui/react";
import { DocumentNode, parse } from "graphql";
import { CombinedError } from "urql";
import { useContext, useState, useMemo } from "react";
import * as R from "remeda";
import {
DrawerBackdrop,
DrawerBody,
DrawerContent,
DrawerHeader,
DrawerRoot,
} from "../components/ui/drawer";
import FabrixIcon from "../icons/logo.svg?react";
import { FabrixBuilderContext } from "./context";
import { EditorPane } from "./panes/Editor";
Expand All @@ -31,7 +30,7 @@ export const FabrixEditor = () => {
const [response, setResponse] = useState<
Record<string, unknown> | CombinedError | undefined
>();
const { isOpen, onOpen, onClose } = useDisclosure();
const [isOpen, setOpen] = useState(false);

return (
<Flex height="100vh" width="100%">
Expand All @@ -55,20 +54,26 @@ export const FabrixEditor = () => {
</Text>
</HStack>
</HStack>
<Button colorScheme="blue" onClick={onOpen} size="sm">
<Button colorScheme="blue" onClick={() => setOpen(true)} size="sm">
Setting
</Button>
</Flex>
</Stack>

{/* Setting drawer */}
<Drawer isOpen={isOpen} placement="right" onClose={onClose} size="md">
<DrawerOverlay />
<DrawerRoot
open={isOpen}
placement="end"
onOpenChange={(e) => setOpen(e.open)}
size="md"
>
<DrawerBackdrop />
<DrawerContent>
<DrawerCloseButton />
<DrawerHeader>Setting</DrawerHeader>
<DrawerHeader fontSize="lg" fontWeight="bold">
Setting
</DrawerHeader>
<hr />
<DrawerBody>
<Divider />
<Stack paddingY={7}>
<Heading size="sm">Open AI token</Heading>
<Text>
Expand All @@ -85,7 +90,7 @@ export const FabrixEditor = () => {
</Stack>
</DrawerBody>
</DrawerContent>
</Drawer>
</DrawerRoot>

{/* Content */}
<Flex height={"100%"} overflowY="auto">
Expand Down Expand Up @@ -117,7 +122,7 @@ const useEditor = () => {

const trimComment = (query: string) => {
return query.replace(/#.*\n/g, "").trim();
}
};

const updatePreview = useMemo(
() =>
Expand Down
1 change: 0 additions & 1 deletion src/builder/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export const FabrixBuilderProvider = (
>
<FabrixProvider
url={schemaURL}
serverSchema={schemaURL}
componentRegistry={props.componentRegistry}
prependExchanges={[additionalHeaderExchange(additionalHeader)]}
>
Expand Down
105 changes: 54 additions & 51 deletions src/builder/panes/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
import {
Tabs,
TabList,
Tab,
TabPanels,
TabPanel,
VStack,
InputGroup,
InputLeftAddon,
Input,
} from "@chakra-ui/react";
import { Tabs, VStack, Group, InputAddon, Input } from "@chakra-ui/react";
import { useFabrixClient } from "@fabrix-framework/fabrix";
import { FetcherParams, createGraphiQLFetcher } from "@graphiql/toolkit";
import GraphiQL from "graphiql";
Expand Down Expand Up @@ -111,50 +101,63 @@ export const EditorPane = (props: EditorPaneProps) => {
builderContext.openAIToken && builderContext.openAIToken.length > 0;

return (
<Tabs sx={baseFlexStyle} variant="enclosed-colored" size="sm" isLazy>
<TabList sx={{ bg: "gray.50", borderTop: "transparent" }}>
<Tab>Editor</Tab>
</TabList>
<TabPanels
sx={{
<Tabs.Root
css={baseFlexStyle}
variant="outline"
size="sm"
defaultValue="editor"
lazyMount
>
<Tabs.List css={{ bg: "gray.50", borderTop: "transparent" }}>
<Tabs.Trigger value="editor">Editor</Tabs.Trigger>
</Tabs.List>
<Tabs.Content
value="editor"
css={{
...baseFlexStyle,
height: "calc(100% - 40px)",
}}
>
<TabPanel
sx={{
...baseFlexStyle,
margin: 2,
marginTop: 3,
padding: 0,
}}
>
<ChatProvider schema={builderContext.schema}>
<VStack flexGrow={1} height={"100%"}>
<InputGroup size="sm">
<InputLeftAddon>Schema</InputLeftAddon>
<Input
value={builderContext.schemaURL}
onChange={(e) => {
builderContext.setSchemaURL(e.target.value);
props.updatePreview(props.query);
}}
/>
</InputGroup>
<GraphiQL
fetcher={fetcher}
disableTabs={true}
onEditQuery={onEditQuery}
onEditHeaders={onEditHeaders}
plugins={[explorer, ...(hasOpenAIToken ? [openAIChat] : [])]}
defaultQuery={props.query}
schema={builderContext.schema}
defaultTheme={"light"}
<ChatProvider schema={builderContext.schema}>
<VStack flexGrow={1} height={"100%"}>
<Group
attached
css={{
width: "100%",
}}
>
<InputAddon
style={{
borderRadius: 0,
}}
>
Schema
</InputAddon>
<Input
size="sm"
style={{
borderRadius: 0,
}}
value={builderContext.schemaURL}
onChange={(e) => {
builderContext.setSchemaURL(e.target.value);
props.updatePreview(props.query);
}}
/>
</VStack>
</ChatProvider>
</TabPanel>
</TabPanels>
</Tabs>
</Group>
<GraphiQL
fetcher={fetcher}
disableTabs={true}
onEditQuery={onEditQuery}
onEditHeaders={onEditHeaders}
plugins={[explorer, ...(hasOpenAIToken ? [openAIChat] : [])]}
defaultQuery={props.query}
schema={builderContext.schema}
defaultTheme={"light"}
/>
</VStack>
</ChatProvider>
</Tabs.Content>
</Tabs.Root>
);
};
70 changes: 28 additions & 42 deletions src/builder/panes/Preview.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
import {
Alert,
AlertIcon,
Tabs,
TabList,
Tab,
TabPanels,
TabPanel,
Text,
Box,
} from "@chakra-ui/react";
import { Tabs, Text, Flex } from "@chakra-ui/react";
import { FabrixComponent } from "@fabrix-framework/fabrix";
import {
EditorContextProvider,
Expand All @@ -20,6 +10,7 @@ import { DocumentNode } from "graphql";
import { useContext } from "react";
import { ErrorBoundary } from "react-error-boundary";
import { CombinedError } from "urql";
import { Alert } from "../../components/ui/alert";
import { FabrixBuilderContext } from "../context";
import { baseFlexStyle } from "./shared";

Expand All @@ -34,20 +25,12 @@ export const PreviewPane = (props: {

const showPreview = () => {
if (error) {
return (
<Alert status="error">
<AlertIcon />
Error: {error.message}
</Alert>
);
return <Alert status="error">Error: {error.message}</Alert>;
} else if (!query) {
return (
<Box>
<Alert status="warning">
<AlertIcon />
<Text>Add your query in the editor first</Text>
</Alert>
</Box>
<Alert status="warning">
<Text>Add your query in the editor first</Text>
</Alert>
);
}

Expand All @@ -66,37 +49,40 @@ export const PreviewPane = (props: {
};

return (
<Tabs
sx={baseFlexStyle}
<Tabs.Root
css={baseFlexStyle}
overflowY={"auto"}
isLazy
isFitted
variant="enclosed-colored"
variant="outline"
defaultValue="preview"
size="sm"
fitted
lazyMount
>
<TabList sx={{ bg: "gray.50", borderTop: "transparent" }}>
<Tab>Preview</Tab>
<Tab>Response</Tab>
</TabList>
<TabPanels
sx={{
<Tabs.List css={{ bg: "gray.50", borderTop: "transparent" }}>
<Tabs.Trigger value="preview">Preview</Tabs.Trigger>
<Tabs.Trigger value="response">Response</Tabs.Trigger>
</Tabs.List>
<Flex
css={{
...baseFlexStyle,
overflowY: "auto",
borderLeft: "1px solid var(--chakra-colors-chakra-border-color)",
}}
>
<TabPanel
sx={{
<Tabs.Content
value="preview"
css={{
...baseFlexStyle,
margin: 2,
marginTop: 3,
padding: 0,
}}
>
{showPreview()}
</TabPanel>
<TabPanel
sx={{
</Tabs.Content>
<Tabs.Content
value="response"
css={{
...baseFlexStyle,
padding: 2,
paddingTop: 3,
Expand Down Expand Up @@ -130,8 +116,8 @@ export const PreviewPane = (props: {
</div>
</SchemaContextProvider>
</EditorContextProvider>
</TabPanel>
</TabPanels>
</Tabs>
</Tabs.Content>
</Flex>
</Tabs.Root>
);
};
Loading
Loading