Skip to content

Commit

Permalink
feat(frontend): brain studio interface (#2712)
Browse files Browse the repository at this point in the history
# Description

Please include a summary of the changes and the related issue. Please
also include relevant motivation and context.

## Checklist before requesting a review

Please delete options that are not relevant.

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented hard-to-understand areas
- [ ] I have ideally added tests that prove my fix is effective or that
my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged

## Screenshots (if appropriate):
  • Loading branch information
Zewed authored Jun 24, 2024
1 parent 131eef7 commit a4ce869
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
@use "styles/Spacings.module.scss";

.menu_icon {
width: IconSizes.$large;
height: IconSizes.$large;
width: IconSizes.$normal;
height: IconSizes.$normal;
cursor: pointer;

&:hover {
color: var(--accent);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,63 @@
padding-inline: Spacings.$spacing05;
overflow: hidden;
display: flex;
gap: Spacings.$spacing02;
justify-content: space-between;
flex-direction: column;
gap: Spacings.$spacing03;
align-items: center;
cursor: pointer;
margin-block: Spacings.$spacing03;
border: 1px solid var(--border-1);
border-radius: Radius.$normal;
padding-block: Spacings.$spacing03;
padding-block: Spacings.$spacing04;
position: relative;
overflow: visible;
overflow: hidden;
height: 100%;

&:hover {
border-color: var(--primary-0);
background-color: var(--background-special-0);
color: var(--text-3);
}

.dark_image {
filter: invert(100%);
.brain_header {
display: flex;
justify-content: space-between;
width: 100%;
align-items: center;

.left {
display: flex;
gap: Spacings.$spacing03;
@include Typography.H2;
align-items: center;
}
}

.brain_info_wrapper {
padding-block: Spacings.$spacing03;
padding-left: Spacings.$spacing03;
.model {
display: flex;
overflow: hidden;
gap: Spacings.$spacing05;
overflow: hidden;
flex: 1;
gap: Spacings.$spacing03;
align-items: center;
font-size: Typography.$small;
width: 100%;

.name {
@include Typography.EllipsisOverflow;
width: 200px;
color: var(--text-3);
.title {
font-weight: 500;
}

.description {
@include Typography.EllipsisOverflow;
flex: 1;
color: var(--text-2);
.model_type {
color: var(--text-4);
}
}

@media (max-width: ScreenSizes.$small) {
.name {
width: auto;
}

.description {
display: none;
}
}
.description {
width: 100%;
font-style: italic;
font-size: Typography.$tiny;
display: -webkit-box;
-webkit-box-orient: vertical;
-webkit-line-clamp: 5;
overflow: hidden;
text-overflow: ellipsis;
color: var(--text-4);
}

.options_modal {
Expand All @@ -67,4 +74,4 @@
z-index: ZIndexes.$modal;
padding-bottom: Spacings.$spacing01;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import Image from "next/image";
import Link from "next/link";
import { useEffect, useRef, useState } from "react";

import { DeleteOrUnsubscribeConfirmationModal } from "@/app/studio/[brainId]/BrainManagementTabs/components/DeleteOrUnsubscribeModal/DeleteOrUnsubscribeConfirmationModal";
import { useBrainFetcher } from "@/app/studio/[brainId]/BrainManagementTabs/hooks/useBrainFetcher";
import { useBrainManagementTabs } from "@/app/studio/[brainId]/BrainManagementTabs/hooks/useBrainManagementTabs";
import { getBrainPermissions } from "@/app/studio/[brainId]/BrainManagementTabs/utils/getBrainPermissions";
import Icon from "@/lib/components/ui/Icon/Icon";
Expand Down Expand Up @@ -33,6 +32,7 @@ export const BrainItem = ({ brain, even }: BrainItemProps): JSX.Element => {
brainId: brain.id,
userAccessibleBrains: allBrains,
});
const { brain: fetchedBrain } = useBrainFetcher({ brainId: brain.id });
const { isDarkMode } = useUserSettingsContext();

const iconRef = useRef<HTMLDivElement | null>(null);
Expand Down Expand Up @@ -73,46 +73,45 @@ export const BrainItem = ({ brain, even }: BrainItemProps): JSX.Element => {

return (
<>
<div
<a
className={`
${even ? styles.even : styles.odd}
${styles.brain_item_wrapper}
`}
href={`/studio/${brain.id}`}
>
<Image
className={isDarkMode ? styles.dark_image : ""}
src={
brain.integration_logo_url
? brain.integration_logo_url
: "/default_brain_image.png"
}
alt="logo_image"
width={18}
height={18}
/>

<Link
className={styles.brain_info_wrapper}
href={`/studio/${brain.id}`}
>
<span className={styles.name}>{brain.name}</span>
<span className={styles.description}>{brain.description}</span>
</Link>
<div>
<div className={styles.brain_header}>
<div className={styles.left}>
<Icon name="brain" color="primary" size="large" />
<span className={styles.name}>{brain.name}</span>
</div>
<div
ref={iconRef}
onClick={(event: React.MouseEvent<HTMLElement>) => {
event.nativeEvent.stopImmediatePropagation();
event.stopPropagation();
event.preventDefault();
setOptionsOpened(!optionsOpened);
}}
className={styles.icon}
>
<Icon
name="options"
size="normal"
size="small"
color="black"
handleHover={true}
/>
</div>
</div>
<div className={styles.model}>
<span className={styles.title}>Model:</span>
<span className={styles.model_type}>
{fetchedBrain?.model ?? "gpt-3.5-turbo-0125"}
</span>
</div>

<span className={styles.description}>{brain.description}</span>
<div>
<DeleteOrUnsubscribeConfirmationModal
isOpen={isDeleteOrUnsubscribeModalOpened}
setOpen={setIsDeleteOrUnsubscribeModalOpened}
Expand All @@ -126,7 +125,7 @@ export const BrainItem = ({ brain, even }: BrainItemProps): JSX.Element => {
<div ref={optionsRef} className={styles.options_modal}>
{optionsOpened && <OptionsModal options={options} />}
</div>
</div>
</a>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,14 @@
@use "styles/Typography.module.scss";

.brains_wrapper {
display: flex;
flex-direction: column;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
row-gap: Spacings.$spacing04;
column-gap: Spacings.$spacing04;
border-radius: Radius.$big;
overflow: hidden;
width: 100%;
overflow-y: scroll;

.columns {
@include Typography.H3;
display: flex;
padding: Spacings.$spacing05;
gap: Spacings.$spacing05;
background-color: var(--background-1);
margin-bottom: Spacings.$spacing03;
padding-left: Spacings.$spacing09;

.name {
width: 200px;
}

.description {
color: var(--text-2);
}

@media (max-width: ScreenSizes.$small) {
.description {
display: none;
}
}
}
}
padding: Spacings.$spacing01;
padding-bottom: Spacings.$spacing07;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ type BrainsListProps = {
export const BrainsList = ({ brains }: BrainsListProps): JSX.Element => {
return (
<div className={styles.brains_wrapper}>
<div className={styles.columns}>
<span className={styles.name}>Name</span>
<span className={styles.description}>Description</span>
</div>
{brains.map((brain, index) => (
<div key={brain.id}>
<BrainItem brain={brain} even={!(index % 2)} />
Expand Down
15 changes: 8 additions & 7 deletions frontend/lib/components/ui/OptionsModal/OptionsModal.module.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@use "styles/BoxShadow.module.scss";
@use "styles/Radius.module.scss";
@use "styles/Spacings.module.scss";
@use "styles/Typography.module.scss";
@use "styles/ZIndexes.module.scss";

.options_modal_wrapper {
Expand All @@ -11,21 +12,21 @@
width: fit-content;

.option {
padding: Spacings.$spacing03;
padding: Spacings.$spacing02;
padding-inline: Spacings.$spacing05;
display: flex;
gap: Spacings.$spacing05;
align-items: center;
cursor: pointer;
justify-content: space-between;
overflow: hidden;

&:not(:first-child) {
border-top: 1px solid var(--border-2);
}
font-size: Typography.$small;
border: 1px solid transparent;
border-radius: Radius.$normal;

&:hover {
background-color: var(--background-special-0);
border-color: var(--primary-0);
color: var(--primary-0);
}

&.disabled {
Expand All @@ -34,4 +35,4 @@
opacity: 0.5;
}
}
}
}
5 changes: 4 additions & 1 deletion frontend/lib/components/ui/OptionsModal/OptionsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export const OptionsModal = ({ options }: OptionsModalProps): JSX.Element => {
option.disabled ? styles.disabled : ""
}`}
key={index}
onClick={option.onClick}
onClick={(event) => {
event.preventDefault();
option.onClick();
}}
onMouseEnter={() => handleMouseEnter(index)}
onMouseLeave={() => handleMouseLeave(index)}
>
Expand Down
4 changes: 1 addition & 3 deletions frontend/lib/components/ui/Toast/components/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import * as ToastPrimitive from "@radix-ui/react-toast";
import { AnimatePresence, motion } from "framer-motion";
import { ReactNode } from "react";
import { useTranslation } from "react-i18next";

import { cn } from "@/lib/utils";

Expand All @@ -19,7 +18,6 @@ export const Toast = ({
children?: ReactNode;
} & ToastPrimitive.ToastProviderProps): JSX.Element => {
const { publish, toasts, toggleToast } = useToastBuilder();
const { t } = useTranslation();

return (
<ToastPrimitive.Provider {...toastProviderProps}>
Expand Down Expand Up @@ -54,7 +52,7 @@ export const Toast = ({
</ToastPrimitive.Description>
<ToastPrimitive.Close asChild>
<Button variant={"tertiary"} className="text-white">
{t("toastDismiss")}
dismiss
</Button>
</ToastPrimitive.Close>
</motion.div>
Expand Down

0 comments on commit a4ce869

Please sign in to comment.