Skip to content

Commit

Permalink
Change components to clients Fix console warning
Browse files Browse the repository at this point in the history
  • Loading branch information
kielbasa-elp committed Feb 19, 2024
1 parent fe1c9bf commit db05758
Show file tree
Hide file tree
Showing 15 changed files with 162 additions and 103 deletions.
6 changes: 2 additions & 4 deletions apps/web-remix/app/components/form/fields/select.field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import {
HiddenField,
useFieldContext,
} from "~/components/form/fields/field.context";
import {
SelectInput,
SelectInputProps,
} from "~/components/form/inputs/select/select.input";
import { SelectInput } from "~/components/form/inputs/select/select.input";
import { SelectInputProps } from "~/components/form/inputs/select/select.input-impl.client";

interface SelectFieldProps extends SelectInputProps {
label?: ReactNode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.rc-select{
@apply w-full
@apply !w-full
}

.rc-select .rc-select-selector{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { Option } from "rc-select";
import "rc-select/assets/index.css";
import React, { Suspense, lazy, useCallback, useEffect, useState } from "react";
import React, { useCallback, useEffect, useState } from "react";
import { useDebounce } from "usehooks-ts";
import { SelectInputProps } from "./select.input-impl";

const AsyncSelectInputComponent = lazy(() => import("./select.input-impl"));
import AsyncSelectInputComponent, {
SelectInputProps,
} from "./select.input-impl.client";
import { ClientOnly } from "remix-utils/client-only";
import "rc-select/assets/index.css";

export const SelectInput: React.FC<SelectInputProps> = ({ ...props }) => {
return (
<Suspense
<ClientOnly
fallback={
<div className="w-full h-[44px] rounded-lg border-[1.5px] border-neutral-200 bg-neutral-800" />
}
>
<AsyncSelectInputComponent {...props} />
</Suspense>
{() => <AsyncSelectInputComponent {...props} />}
</ClientOnly>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import classNames from "classnames";
import RcMenu, { MenuProps } from "rc-menu";
import React from "react";
import classNames from "classnames";
import "rc-menu/assets/index.css";

const Menu: React.FC<MenuProps> = ({ className, ...rest }) => {
export const MenuClient: React.FC<MenuProps> = ({
className,
children,
...rest
}) => {
return (
<RcMenu
className={classNames(
"border border-neutral-100 bg-neutral-700 !rounded-lg !shadow-none !p-0 overflow-hidden divide-y divide-solid",
className,
className
)}
{...rest}
/>
>
{children}
</RcMenu>
);
};

export default Menu;
12 changes: 0 additions & 12 deletions apps/web-remix/app/components/menu/Menu.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
import React, { ReactNode } from "react";
import React from "react";
import { Editor, EditorProps } from "@monaco-editor/react";

interface CodePreviewWrapperProps extends CodePreviewProps {
children?: (value: string) => ReactNode;
}

export const CodePreviewWrapper: React.FC<CodePreviewWrapperProps> = ({
children,
...props
}) => {
return (
<div>
<div className="flex gap-2 justify-end px-1">
{children?.(props.value)}
</div>

<CodePreview {...props} />
</div>
);
};

export interface CodePreviewProps
extends Omit<EditorProps, "height" | "value"> {
value: string;
height: number;
}

export const CodePreview: React.FC<CodePreviewProps> = ({
export const CodePreviewClient: React.FC<CodePreviewProps> = ({
options,
...props
}) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import React, { useMemo, useRef, useState } from "react";
import type { MenuInfo } from "rc-menu/es/interface";
import { useOnClickOutside } from "usehooks-ts";
import { Icon } from "@elpassion/taco";
import { Menu } from "~/components/menu/Menu";
import { MenuClient } from "~/components/menu/Menu.client";
import { MenuItem } from "~/components/menu/MenuItem";
import { CopyCodeButton } from "~/components/actionButtons/CopyCodeButton";
import { CodePreviewWrapper } from "./CodePreview";
import { CodePreviewWrapper } from "./CodePreviewWrapper";
import { ClientOnly } from "remix-utils/client-only";

interface CodePreviewOptionsProps {
options: {
Expand Down Expand Up @@ -50,18 +51,24 @@ export const CodePreviewOptions: React.FC<CodePreviewOptionsProps> = ({
{() => (
<>
<div className="relative w-fit" ref={wrapperRef}>
<Menu
hidden={!showMenu}
activeKey={activeKey}
className="w-[200px] absolute z-10 -top-10 right-0"
onClick={onChange}
>
{options.map((option) => {
return (
<MenuItem key={`${option.id}`}>{option.framework}</MenuItem>
);
})}
</Menu>
<ClientOnly>
{() => (
<MenuClient
hidden={!showMenu}
activeKey={activeKey}
className="w-[200px] absolute z-10 -top-10 right-0"
onClick={onChange}
>
{options.map((option) => {
return (
<MenuItem key={`${option.id}`}>
{option.framework}
</MenuItem>
);
})}
</MenuClient>
)}
</ClientOnly>

<button
onClick={handleShow}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React, { ReactNode } from "react";
import { CodePreviewClient, CodePreviewProps } from "./CodePreview.client";
import { ClientOnly } from "remix-utils/client-only";
interface CodePreviewWrapperProps extends CodePreviewProps {
children?: (value: string) => ReactNode;
}

export const CodePreviewWrapper: React.FC<CodePreviewWrapperProps> = ({
children,
...props
}) => {
return (
<div>
<div className="flex gap-2 justify-end px-1">
{children?.(props.value)}
</div>

<ClientOnly fallback={null}>
{() => <CodePreviewClient {...props} />}
</ClientOnly>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import React, { useMemo } from "react";
import { useLoaderData } from "@remix-run/react";
import startCase from "lodash.startcase";
import { loader } from "../loader";
import { loader } from "../loader.server";
import {
IBlockConfig,
IBlockType,
IBlockTypes,
} from "~/components/pages/pipelines/pipeline.types";
import { Menu } from "~/components/menu/Menu";
import { MenuClient } from "~/components/menu/Menu.client";
import { GroupSubMenu } from "./GroupSubMenu";
import { CreateBlockDraggableItem } from "./CreateBlockDraggableItem";
import { PasteConfigItem } from "./PasteConfigItem";
import { ClientOnly } from "remix-utils/client-only";

interface CreateBlockFloatingMenuProps {
onCreate: (node: IBlockConfig) => void;
Expand Down Expand Up @@ -52,24 +53,28 @@ export const CreateBlockFloatingMenu: React.FC<

return (
<div className="absolute top-1/2 -translate-y-1/2 right-4 h-auto">
<Menu expandIcon={null}>
{/*<ELMenuItem />*/}
<ClientOnly fallback={null}>
{() => (
<MenuClient expandIcon={null}>
{/*<ELMenuItem />*/}

{Object.keys(blockGroups).map((group) => (
<GroupSubMenu
key={group}
title={
<span className="truncate w-full text-center">
{startCase(group)}
</span>
}
>
<SubMenuItems group={group} />
</GroupSubMenu>
))}
{Object.keys(blockGroups).map((group) => (
<GroupSubMenu
key={group}
title={
<span className="truncate w-full text-center">
{startCase(group)}
</span>
}
>
<SubMenuItems group={group} />
</GroupSubMenu>
))}

<PasteConfigItem />
</Menu>
<PasteConfigItem />
</MenuClient>
)}
</ClientOnly>
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { routes } from "~/utils/routes.utils";
import { MetaFunction } from "@remix-run/node";
import { Link, useLoaderData } from "@remix-run/react";
import { CopyCodeButton } from "~/components/actionButtons/CopyCodeButton";
import { CodePreviewWrapper } from "~/components/pages/pipelines/CodePreview/CodePreview";
import { CodePreviewWrapper } from "~/components/pages/pipelines/CodePreview/CodePreviewWrapper";
import { CodePreviewOptions } from "~/components/pages/pipelines/CodePreview/CodePreviewOptions";
import {
PreviewConnector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { routes } from "~/utils/routes.utils";
import { MetaFunction } from "@remix-run/node";
import { Link, useLoaderData } from "@remix-run/react";
import { ChatbotSectionWrapper } from "~/components/pages/pipelines/interface/websiteChatbot/ChatbotSectionWrapper";
import { CodePreviewWrapper } from "~/components/pages/pipelines/CodePreview/CodePreview";
import { CodePreviewWrapper } from "~/components/pages/pipelines/CodePreview/CodePreviewWrapper";
import { CopyCodeButton } from "~/components/actionButtons/CopyCodeButton";
import {
ChatbotSectionHeader,
Expand Down
38 changes: 22 additions & 16 deletions apps/web-remix/app/routes/_dashboard.$organizationId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Modal from "react-modal";
import invariant from "tiny-invariant";
import { useOnClickOutside } from "usehooks-ts";
import { OrganizationApi } from "~/api/organization/OrganizationApi";
import { Menu } from "~/components/menu/Menu";
import { MenuClient } from "~/components/menu/Menu.client";
import { MenuItem } from "~/components/menu/MenuItem";
import { PageOverlay } from "~/components/overlay/PageOverlay";
import {
Expand All @@ -29,8 +29,10 @@ import { loaderBuilder } from "~/utils.server";
import { getCurrentUser } from "~/utils/currentUser.server";
import { routes } from "~/utils/routes.utils";
import { getServerToast, setOrganizationId } from "~/utils/toast.server";
import { ClientOnly } from "remix-utils/client-only";

Modal.setAppElement("#_root");

export async function loader(loaderArgs: DataFunctionArgs) {
return loaderBuilder(async ({ request, params }, { fetch }) => {
await requireLogin(request);
Expand All @@ -41,7 +43,7 @@ export async function loader(loaderArgs: DataFunctionArgs) {
const organizationsResponse = await organizationApi.getOrganizations();

const organization = organizationsResponse.data.data.find(
(org) => org.id === Number(params.organizationId),
(org) => org.id === Number(params.organizationId)
);

let { cookie, ...toasts } = await getServerToast(request);
Expand All @@ -68,7 +70,7 @@ export async function loader(loaderArgs: DataFunctionArgs) {
headers: {
"Set-Cookie": cookie,
},
},
}
);
})(loaderArgs);
}
Expand Down Expand Up @@ -138,7 +140,7 @@ function SidebarMainContent({ isCollapsed }: SidebarContentProps) {
"gap-2 mt-2 transition-all justify-between h-[calc(100%-8px)]",
{
"!px-0": !isCollapsed,
},
}
)}
>
<div className="flex flex-col gap-1">
Expand Down Expand Up @@ -238,18 +240,22 @@ function SidebarTopContent({ isCollapsed }: SidebarContentProps) {
)}
</button>

<Menu
hidden={!showMenu}
activeKey={`${organization.id}`}
className="min-w-[248px] absolute z-[51] top-[60px] left-[30%] max-h-[400px] overflow-y-auto md:left-[85%]"
onClick={handleChangeRoute}
>
<NewOrganizationLink />

{organizations.map((org) => {
return <MenuItem key={`${org.id}`}>{org.name}</MenuItem>;
})}
</Menu>
<ClientOnly fallback={null}>
{() => (
<MenuClient
hidden={!showMenu}
activeKey={`${organization.id}`}
className="min-w-[248px] absolute z-[51] top-[60px] left-[30%] max-h-[400px] overflow-y-auto md:left-[85%]"
onClick={handleChangeRoute}
>
<NewOrganizationLink />

{organizations.map((org) => {
return <MenuItem key={`${org.id}`}>{org.name}</MenuItem>;
})}
</MenuClient>
)}
</ClientOnly>
</div>
</SidebarContentWrapper>
);
Expand Down
1 change: 1 addition & 0 deletions apps/web-remix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"react-select": "^5.7.4",
"react-tooltip": "^5.21.5",
"reactflow": "^11.8.3",
"remix-utils": "^7.5.0",
"remix-validated-form": "^5.1.5",
"source-map-support": "^0.5.21",
"tiny-invariant": "^1.3.1",
Expand Down
Loading

0 comments on commit db05758

Please sign in to comment.