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

Fix inconsistent studio dashboard layout #964

Merged
merged 13 commits into from
Jan 16, 2025
Merged
2 changes: 1 addition & 1 deletion apps/studio/src/components/CmsSidebar/CmsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function CmsContainer({
{sidenav}
</Box>
</GridItem>
<GridItem as="main" area="main" overflow="auto">
<GridItem as="main" area="main" overflow="hidden">
adriangohjw marked this conversation as resolved.
Show resolved Hide resolved
<Box
height={0}
minH="100%"
Expand Down
7 changes: 6 additions & 1 deletion apps/studio/src/components/Datatable/Datatable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ export const Datatable = <T extends object>({
const styles = useMultiStyleConfig("Table", tableProps)

return (
<Flex flexDirection="column" layerStyle="shadow" pos="relative">
<Flex
width="100%"
flexDirection="column"
layerStyle="shadow"
pos="relative"
>
{isFetching && (
<>
<Flex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const CollectionBanner = (): JSX.Element | null => {

return (
<Stack
width="100%"
justify="space-between"
flexDir="row"
bg="interaction.success-subtle.default"
Expand Down
106 changes: 106 additions & 0 deletions apps/studio/src/features/dashboard/components/DashboardLayout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import type { ReactNode } from "react"
import NextLink from "next/link"
import {
Box,
BreadcrumbItem,
BreadcrumbLink,
Flex,
HStack,
Text,
VStack,
} from "@chakra-ui/react"
import { Breadcrumb } from "@opengovsg/design-system-react"

export const DashboardLayout = ({
breadcrumbs,
icon,
title,
buttons,
children,
}: {
breadcrumbs: {
href: string
label: string
}[]
icon: ReactNode
title: string
buttons: ReactNode
children: ReactNode
}) => {
const allBreadcrumbsExceptLast = breadcrumbs.slice(0, -1)
const lastBreadcrumb = breadcrumbs[breadcrumbs.length - 1]
return (
<VStack
w="100%"
p="1.75rem"
gap="1rem"
height="0"
overflow="auto"
minH="100%"
>
<VStack w="100%" align="start">
<Breadcrumb
size="sm"
w="100%"
minH="1.25rem" // maintain height even when single breadcrumb
display="flex"
alignItems="center"
>
{allBreadcrumbsExceptLast.map(({ href, label }, index) => {
return (
<BreadcrumbItem key={index}>
<BreadcrumbLink href={href} as={NextLink}>
<Text
textStyle="caption-2"
color="interaction.links.default"
noOfLines={1}
w="max-content"
>
{label}
</Text>
</BreadcrumbLink>
</BreadcrumbItem>
)
})}
<BreadcrumbItem
key={lastBreadcrumb?.href}
overflow="hidden"
whiteSpace="nowrap"
>
<Text
textStyle="caption-2"
color="base.content.default"
overflow="hidden"
textOverflow="ellipsis"
>
{lastBreadcrumb?.label}
</Text>
</BreadcrumbItem>
</Breadcrumb>
<Flex w="full" flexDir="row">
<HStack mr="1.25rem" overflow="auto" gap="0.75rem" flex={1}>
<Box
aria-hidden
bg="brand.secondary.100"
p="0.5rem"
borderRadius="6px"
>
{icon}
</Box>
<Text
noOfLines={1}
as="h3"
textStyle="h3"
textOverflow="ellipsis"
wordBreak="break-all"
>
{title}
</Text>
</HStack>
<HStack>{buttons}</HStack>
</Flex>
</VStack>
{children}
</VStack>
)
}
72 changes: 23 additions & 49 deletions apps/studio/src/pages/sites/[siteId]/collections/[resourceId].tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
import NextLink from "next/link"
import {
Box,
BreadcrumbItem,
BreadcrumbLink,
HStack,
Stack,
Text,
useDisclosure,
} from "@chakra-ui/react"
import { Breadcrumb, Button } from "@opengovsg/design-system-react"
import { useDisclosure } from "@chakra-ui/react"
import { Button } from "@opengovsg/design-system-react"
import { useSetAtom } from "jotai"
import { BiData } from "react-icons/bi"
import { z } from "zod"
Expand All @@ -17,6 +8,7 @@ import { PermissionsBoundary } from "~/components/AuthWrappers"
import { folderSettingsModalAtom } from "~/features/dashboard/atoms"
import { CollectionBanner } from "~/features/dashboard/components/CollectionBanner"
import { CollectionTable } from "~/features/dashboard/components/CollectionTable"
import { DashboardLayout } from "~/features/dashboard/components/DashboardLayout"
import { DeleteResourceModal } from "~/features/dashboard/components/DeleteResourceModal/DeleteResourceModal"
import { FolderSettingsModal } from "~/features/dashboard/components/FolderSettingsModal"
import { PageSettingsModal } from "~/features/dashboard/components/PageSettingsModal"
Expand Down Expand Up @@ -49,38 +41,21 @@ const CollectionResourceListPage: NextPageWithLayout = () => {

return (
<>
<Stack w="100%" p="1.75rem" gap="1rem" height="$100vh" overflow="auto">
<Breadcrumb size="sm">
<BreadcrumbItem>
<BreadcrumbLink href={`/sites/${siteId}`} as={NextLink}>
<Text textStyle="caption-2" color="interaction.links.default">
Home
</Text>
</BreadcrumbLink>
</BreadcrumbItem>
<BreadcrumbItem>
<BreadcrumbLink isCurrentPage>
<Text textStyle="caption-2" color="base.content.default">
{metadata.title}
</Text>
</BreadcrumbLink>
</BreadcrumbItem>
</Breadcrumb>
<HStack w="100%" gap="1.5rem">
<HStack gap="0.75rem" flex={1}>
<Box
aria-hidden
bg="brand.secondary.100"
p="0.5rem"
borderRadius="6px"
>
<BiData />
</Box>
<Text wordBreak="break-word" noOfLines={1} as="h3" textStyle="h3">
{metadata.title}
</Text>
</HStack>
<HStack align="center" gap="0.75rem">
<DashboardLayout
breadcrumbs={[
{
href: `/sites/${siteId}`,
label: "Home",
},
{
href: `/sites/${siteId}/collections/${resourceId}`,
label: metadata.title,
},
]}
icon={<BiData />}
title={metadata.title}
buttons={
<>
<Button
variant="outline"
size="md"
Expand All @@ -95,13 +70,12 @@ const CollectionResourceListPage: NextPageWithLayout = () => {
<Button onClick={onPageCreateModalOpen} size="md">
Add new item
</Button>
</HStack>
</HStack>
</>
}
>
<CollectionBanner />
<Box width="100%">
<CollectionTable resourceId={resourceId} siteId={siteId} />
</Box>
</Stack>
<CollectionTable resourceId={resourceId} siteId={siteId} />
</DashboardLayout>
<CreateCollectionPageModal
isOpen={isPageCreateModalOpen}
onClose={onPageCreateModalClose}
Expand Down
Loading
Loading