Skip to content

Commit

Permalink
Fixing issues with Tree and Navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Duncid committed Jan 2, 2025
1 parent 440e5d0 commit 199e983
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 174 deletions.
25 changes: 11 additions & 14 deletions front/components/assistant/conversation/SidebarMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
NavigationListLabel,
PlusIcon,
RobotIcon,
ScrollArea,
TrashIcon,
XMarkIcon,
} from "@dust-tt/sparkle";
Expand Down Expand Up @@ -278,7 +277,7 @@ export function AssistantSidebarMenu({ owner }: AssistantSidebarMenuProps) {
Error loading conversations
</Label>
)}
<ScrollArea className="w-full px-2">
<NavigationList className="w-full px-2">
{conversationsByDate &&
Object.keys(conversationsByDate).map((dateLabel) => (
<RenderConversations
Expand All @@ -292,7 +291,7 @@ export function AssistantSidebarMenu({ owner }: AssistantSidebarMenuProps) {
owner={owner}
/>
))}
</ScrollArea>
</NavigationList>
</div>
</div>
</div>
Expand All @@ -318,18 +317,16 @@ const RenderConversations = ({
}

return (
<div>
<>
<NavigationListLabel label={dateLabel} />
<NavigationList>
{conversations.map((conversation) => (
<RenderConversation
key={conversation.sId}
conversation={conversation}
{...props}
/>
))}
</NavigationList>
</div>
{conversations.map((conversation) => (
<RenderConversation
key={conversation.sId}
conversation={conversation}
{...props}
/>
))}
</>
);
};

Expand Down
28 changes: 14 additions & 14 deletions front/components/navigation/NavigationSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ export const NavigationSidebar = React.forwardRef<
/>
))}
</TabsList>
{navs.map((tab) => (
<TabsContent key={tab.id} value={tab.id}>
{subNavigation && tab.isCurrent(activePath) && (
<>
{subNavigation.map((nav) => (
<div key={nav.id} className="px-2">
<NavigationList>
<NavigationList className="px-2">
{navs.map((tab) => (
<TabsContent key={tab.id} value={tab.id}>
{subNavigation && tab.isCurrent(activePath) && (
<>
{subNavigation.map((nav) => (
<div key={nav.id}>
{nav.label && (
<NavigationListLabel
label={nav.label}
Expand Down Expand Up @@ -136,13 +136,13 @@ export const NavigationSidebar = React.forwardRef<
)}
</React.Fragment>
))}
</NavigationList>
</div>
))}
</>
)}
</TabsContent>
))}
</div>
))}
</>
)}
</TabsContent>
))}
</NavigationList>
</Tabs>
</div>
)}
Expand Down
108 changes: 49 additions & 59 deletions front/components/spaces/SpaceSideBarMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
NavigationList,
NavigationListLabel,
PlusIcon,
ScrollArea,
Tree,
} from "@dust-tt/sparkle";
import type {
Expand Down Expand Up @@ -106,74 +105,65 @@ export default function SpaceSideBarMenu({
return spaces.map((space) => (
<Fragment key={`space-${space.sId}`}>
{space.kind === "system" ? (
<NavigationList>
<SystemSpaceMenu owner={owner} space={space} />
</NavigationList>
<SystemSpaceMenu owner={owner} space={space} />
) : (
<NavigationList>
<SpaceMenu
owner={owner}
space={space}
isMember={!!spacesAsUser.find((v) => v.sId === space.sId)}
/>
</NavigationList>
<SpaceMenu
owner={owner}
space={space}
isMember={!!spacesAsUser.find((v) => v.sId === space.sId)}
/>
)}
</Fragment>
));
};

return (
<div className="flex h-0 min-h-full w-full overflow-y-auto">
<ScrollArea className="w-full">
<div className="px-2 pb-2">
<NavigationList>
{sortedGroupedSpaces.map(({ section, spaces }, index) => {
if (section === "public" && !spaces.length) {
return null;
}

if (section === "restricted" && !spaces.length && !isAdmin) {
return null;
}

const sectionDetails = getSpaceSectionDetails(section);

return (
<Fragment key={`space-section-${index}`}>
<div className="flex items-center justify-between pr-1">
<NavigationListLabel
label={sectionDetails.label}
variant="secondary"
<NavigationList className="w-full px-2 pb-2">
{sortedGroupedSpaces.map(({ section, spaces }, index) => {
if (section === "public" && !spaces.length) {
return null;
}

if (section === "restricted" && !spaces.length && !isAdmin) {
return null;
}

const sectionDetails = getSpaceSectionDetails(section);

return (
<Fragment key={`space-section-${index}`}>
<div className="flex items-center justify-between pr-1">
<NavigationListLabel
label={sectionDetails.label}
variant="secondary"
/>
{sectionDetails.displayCreateSpaceButton &&
isAdmin &&
openSpaceCreationModal && (
<Button
className="mt-4"
size="xs"
variant="ghost"
label="New"
icon={PlusIcon}
onClick={() =>
openSpaceCreationModal({
defaultRestricted: sectionDetails.defaultRestricted,
})
}
/>
{sectionDetails.displayCreateSpaceButton &&
isAdmin &&
openSpaceCreationModal && (
<Button
className="mt-4"
size="xs"
variant="ghost"
label="New"
icon={PlusIcon}
onClick={() =>
openSpaceCreationModal({
defaultRestricted:
sectionDetails.defaultRestricted,
})
}
/>
)}
</div>
{renderSpaceItems(
spaces.toSorted(compareSpaces),
spacesAsUser,
owner
)}
</Fragment>
);
})}
</NavigationList>
</div>
</ScrollArea>
</div>
{renderSpaceItems(
spaces.toSorted(compareSpaces),
spacesAsUser,
owner
)}
</Fragment>
);
})}
</NavigationList>
</div>
);
}
Expand Down
4 changes: 2 additions & 2 deletions sparkle/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sparkle/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dust-tt/sparkle",
"version": "0.2.350",
"version": "0.2.351",
"scripts": {
"build": "rm -rf dist && npm run tailwind && npm run build:esm && npm run build:cjs",
"tailwind": "tailwindcss -i ./src/styles/tailwind.css -o dist/sparkle.css",
Expand Down
49 changes: 19 additions & 30 deletions sparkle/src/components/NavigationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,28 @@ import { Button } from "@sparkle/components/Button";
import { MoreIcon } from "@sparkle/icons";
import { cn } from "@sparkle/lib/utils";

const listStyles = cva("s-flex", {
variants: {
layout: {
container: "s-gap-1 s-relative s-flex-col s-overflow-hidden",
item: cn(
"s-box-border s-items-center s-w-full s-flex s-gap-1.5 s-cursor-pointer s-select-none s-items-center s-outline-none s-rounded-xl s-text-sm s-px-3 s-py-2 s-transition-colors s-duration-300",
"data-[disabled]:s-pointer-events-none data-[disabled]:s-text-muted-foreground",
"hover:s-text-foreground hover:s-bg-structure-150"
),
const NavigationListItemStyles = cva(
"s-box-border s-flex s-items-center s-w-full s-gap-1.5 s-cursor-pointer s-select-none s-items-center s-outline-none s-rounded-xl s-text-sm s-px-3 s-py-2 s-transition-colors s-duration-300 data-[disabled]:s-pointer-events-none data-[disabled]:s-text-muted-foreground hover:s-text-foreground hover:s-bg-structure-150",
{
variants: {
state: {
active: "active:s-bg-structure-200",
selected: "s-text-foreground s-font-medium s-bg-structure-150",
unselected: "s-text-muted-foreground",
},
},
state: {
active: "active:s-bg-structure-200",
selected: "s-text-foreground s-font-medium s-bg-structure-150",
unselected: "s-text-muted-foreground",
defaultVariants: {
state: "unselected",
},
},
defaultVariants: {
layout: "container",
state: "unselected",
},
});

const labelStyles = cva(
"s-font-semibold s-pt-6 s-pb-2 s-text-xs s-whitespace-nowrap s-overflow-hidden s-text-ellipsis"
}
);

const NavigationList = React.forwardRef<
React.ElementRef<typeof ScrollAreaPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof ScrollAreaPrimitive.Root>
>(({ className, children, ...props }, ref) => (
<ScrollArea
ref={ref}
className={cn(listStyles({ layout: "container" }), className)}
{...props}
>
{children}
<ScrollArea ref={ref} className={className} {...props}>
<div className="s-flex s-flex-col s-gap-0.5">{children}</div>
<ScrollBar />
</ScrollArea>
));
Expand Down Expand Up @@ -109,8 +95,7 @@ const NavigationListItem = React.forwardRef<
<div
className={cn(
"s-peer/menu-button",
listStyles({
layout: "item",
NavigationListItemStyles({
state: selected
? "selected"
: isPressed
Expand Down Expand Up @@ -181,6 +166,10 @@ const variantStyles = cva("", {
},
});

const labelStyles = cva(
"s-font-semibold s-pt-4 s-pb-2 s-text-xs s-whitespace-nowrap s-overflow-hidden s-text-ellipsis"
);

interface NavigationListLabelProps
extends React.HTMLAttributes<HTMLDivElement>,
VariantProps<typeof variantStyles> {
Expand Down
11 changes: 5 additions & 6 deletions sparkle/src/components/Tree.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React, { ComponentType, ReactNode, useState } from "react";

import Spinner from "@sparkle/components/Spinner";
import { Button, Spinner } from "@sparkle/components/";
import { ArrowDownSIcon, ArrowRightSIcon } from "@sparkle/icons";
import { cn } from "@sparkle/lib/utils";

import { Checkbox, CheckboxProps } from "./Checkbox";
import { Icon } from "./Icon";
import { IconButton } from "./IconButton";

export interface TreeProps {
children?: ReactNode;
Expand Down Expand Up @@ -64,9 +63,9 @@ export function Tree({
}

const treeItemStyleClasses = {
base: "s-group/tree s-flex s-cursor-default s-flex-row s-items-center s-gap-2 s-py-2",
base: "s-group/tree s-flex s-cursor-default s-flex-row s-items-center s-gap-2 s-h-9",
isNavigatableBase:
"s-rounded-xl s-pl-1.5 s-pr-3 s-transition-colors s-duration-300 s-ease-out s-cursor-pointer",
"s-rounded-xl s-pl-1 s-pr-3 s-transition-colors s-duration-300 s-ease-out s-cursor-pointer",
isNavigatableUnselected: "s-bg-structure-150/0 hover:s-bg-structure-150",
isNavigatableSelected: "s-font-medium s-bg-structure-150",
};
Expand Down Expand Up @@ -160,10 +159,10 @@ Tree.Item = function ({
onClick={onItemClick}
>
{type === "node" && (
<IconButton
<Button
icon={isExpanded ? ArrowDownSIcon : ArrowRightSIcon}
size="xs"
variant="outline"
variant="ghost-secondary"
onClick={(e) => {
e.stopPropagation();
if (effectiveOnChevronClick) {
Expand Down
Loading

0 comments on commit 199e983

Please sign in to comment.