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

isom-1659 internal links for folders #865

Open
wants to merge 118 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
118 commits
Select commit Hold shift + click to select a range
7256309
make standalone UI work
adriangohjw Nov 7, 2024
c9754c7
integrate to handle onChange
adriangohjw Nov 7, 2024
5dc5fd8
update getAncestry to getAncestryWithSelf
adriangohjw Nov 7, 2024
81dc97a
show existing link location on open
adriangohjw Nov 7, 2024
d71e3e1
lint LinkEditorModal
adriangohjw Nov 7, 2024
dc3e5c8
refactor - remove moveItem (use ResourceItem instead)
adriangohjw Nov 7, 2024
7d71c37
refactor: reuse ResourceSelector
adriangohjw Nov 7, 2024
a63bce0
add gap
adriangohjw Nov 7, 2024
058c030
Merge branch 'main' of https://github.com/opengovsg/isomer into adria…
adriangohjw Nov 12, 2024
368f5cd
Merge remote-tracking branch 'origin/main' into adriangohjw/isom-1659…
adriangohjw Nov 12, 2024
fb65e93
use Resource.type for checking instead
adriangohjw Nov 12, 2024
4e9e5d1
make isHighlighted compulsory
adriangohjw Nov 12, 2024
917f299
ensure api returns desired type
adriangohjw Nov 12, 2024
153f69b
better typecheck of values from trpc.resource
adriangohjw Nov 12, 2024
1346700
update to use onlyShowFolders instead
adriangohjw Nov 12, 2024
995d73c
Merge remote-tracking branch 'origin/main' into adriangohjw/isom-1659…
adriangohjw Nov 15, 2024
37021b4
fix - display full permalink
adriangohjw Nov 15, 2024
7aab61f
Merge remote-tracking branch 'origin/main' into adriangohjw/isom-1659…
adriangohjw Nov 19, 2024
9bf96e0
update from div to Box
adriangohjw Nov 19, 2024
23bdd3c
replace to use import from generatedEnums
adriangohjw Nov 19, 2024
5667910
refactor - use single source of truth getIcon
adriangohjw Nov 19, 2024
ce11463
update schema name to getAncestryWithSelfSchema to be consistent
adriangohjw Nov 19, 2024
1ca9ef9
fix mock - getAncestry to getAncestryWithSelf
adriangohjw Nov 19, 2024
787aca8
remove "undefined" from "type"
adriangohjw Nov 19, 2024
118ebb8
remove "null" from acceptable type value
adriangohjw Nov 19, 2024
bb4d651
refactor - do a 1-for-1 abstraction to useResourceStack
adriangohjw Nov 19, 2024
9514000
abstract away more stuff + usememo/usecallback for perf
adriangohjw Nov 19, 2024
6c4868c
add missing dependencies in addToStack
adriangohjw Nov 19, 2024
1690a82
refactor - move logic into ResourceItem
adriangohjw Nov 19, 2024
74e4e7a
more explicit about the props
adriangohjw Nov 19, 2024
a692eff
remove unused import
adriangohjw Nov 19, 2024
9a5ab6b
return flatten item
adriangohjw Nov 19, 2024
4f8fd16
pass in fullPermalink instead
adriangohjw Nov 19, 2024
5b10f41
undo absttracting away into useResourceStack
adriangohjw Nov 19, 2024
8b677c2
add gap
adriangohjw Nov 19, 2024
9ac2fd4
exclude index page from showing up in search
adriangohjw Nov 20, 2024
99ed3fd
Merge branch 'main' of https://github.com/opengovsg/isomer into adria…
adriangohjw Nov 25, 2024
9b6388f
Merge branch 'main' of https://github.com/opengovsg/isomer into adria…
adriangohjw Nov 28, 2024
e2ac2ab
fix - full width issue
adriangohjw Nov 28, 2024
5459a2e
add searchbar skeleton
adriangohjw Nov 28, 2024
096b062
update resourceItem UI
adriangohjw Nov 28, 2024
526b3a1
refactor headers out
adriangohjw Nov 28, 2024
9f7d42f
abstract logic away
adriangohjw Nov 28, 2024
804e2b8
add "results count" state
adriangohjw Nov 28, 2024
4ecd178
option for additional padding based on whether user is using search
adriangohjw Nov 28, 2024
0122f7e
set fixed height to 280px
adriangohjw Nov 28, 2024
12dc2f8
fix text alignment issue
adriangohjw Nov 28, 2024
86f049c
fix "back to home" padding
adriangohjw Nov 28, 2024
c347f69
refactor into new file + add "NoItemsInFolderResult"
adriangohjw Nov 28, 2024
492f4b7
refactor - move all logic into ResourceSelector to reduce number of p…
adriangohjw Nov 28, 2024
ff2fe71
rename to ResourceSelectorContent
adriangohjw Nov 28, 2024
f2ae9b2
clear searchbar on clicking clear search button
adriangohjw Nov 28, 2024
80027d8
allow passing in of resourcetypes into search query
adriangohjw Nov 28, 2024
b1b62a1
extract into useSearchQuery
adriangohjw Nov 28, 2024
181b549
use useSearchQuery instead
adriangohjw Nov 28, 2024
77d0c00
reduce API call by passing in siteId
adriangohjw Nov 28, 2024
a6e944b
move useSearchQuery out of useResourceStack
adriangohjw Nov 28, 2024
4419bc1
add loading state
adriangohjw Nov 29, 2024
6547e6c
remove unused import
adriangohjw Nov 29, 2024
52a8014
prep: abstract logic into useResourceStack for easier refactoring
adriangohjw Nov 29, 2024
9797551
refactor into getAncestryWithSelf + add getBatchAncestryWithSelf endp…
adriangohjw Nov 29, 2024
88cffc6
fix - use handleOnClick directly
adriangohjw Nov 29, 2024
bfc2c7b
fix - make resourceTypes optional for search endpoint
adriangohjw Nov 29, 2024
c538e90
fix test
adriangohjw Nov 29, 2024
ab64810
standardize types into 1
adriangohjw Nov 29, 2024
14db37f
hide logic in hook + fix search
adriangohjw Nov 30, 2024
18c3fbe
add comment
adriangohjw Nov 30, 2024
d1eff5b
set higher height for Skeleton
adriangohjw Nov 30, 2024
de9403f
remove unused type export
adriangohjw Nov 30, 2024
5147212
fix nested use hooks issue
adriangohjw Nov 30, 2024
55073f3
fix navigation
adriangohjw Nov 30, 2024
a1f1235
fix padding on "load more" button
adriangohjw Nov 30, 2024
18b2f17
fix - overwrite returned functions for search by query
adriangohjw Nov 30, 2024
097c9a4
extract lastResourceItemInAncestryStack into standalone utils file
adriangohjw Nov 30, 2024
2a5d410
usecallback everything + pass out clearSearchValue
adriangohjw Nov 30, 2024
cbbd1b2
clearSearchValue() onChange current
adriangohjw Nov 30, 2024
600f8f0
fix typo in query
adriangohjw Dec 1, 2024
d282f00
fix test
adriangohjw Dec 1, 2024
4fddb68
fix - incorrect header shown when using query
adriangohjw Dec 1, 2024
55fdfb7
fix - remove conditional for hook
adriangohjw Dec 1, 2024
78a0d16
Merge branch 'main' into adriangohjw/isom-1659-internal-links-for-fol…
adriangohjw Dec 1, 2024
985b52f
remove accidental .only commit
adriangohjw Dec 1, 2024
c86ec42
enforce using output schema instead
adriangohjw Dec 1, 2024
8b7408f
fix stories
adriangohjw Dec 1, 2024
ed812fa
add stories
adriangohjw Dec 2, 2024
3d42fc7
Merge branch 'main' of https://github.com/opengovsg/isomer into adria…
adriangohjw Dec 2, 2024
0773fab
fix lint
adriangohjw Dec 2, 2024
e3352f9
slight refactoring - move isResourceItemDisabled into hook
adriangohjw Dec 3, 2024
fad12e6
add getNestedFolderChildrenOf endpoint
adriangohjw Dec 3, 2024
a3dcec4
update isResourceItemDisabled to return true for nested children
adriangohjw Dec 3, 2024
fc2cc72
lint + use useMemo to improve perf
adriangohjw Dec 3, 2024
9f46bd4
Merge branch 'main' of https://github.com/opengovsg/isomer into adria…
adriangohjw Dec 3, 2024
55bea71
allow passing in of file explorer height + update skeleton height and…
adriangohjw Dec 3, 2024
d9fa0ea
Update apps/studio/src/server/modules/resource/resource.service.ts
adriangohjw Dec 10, 2024
15f14a3
Merge branch 'main' into adriangohjw/isom-1659-internal-links-for-fol…
adriangohjw Dec 10, 2024
a187575
chore: refactor and fix based on comments
adriangohjw Dec 16, 2024
493a550
Merge branch 'main' of https://github.com/opengovsg/isomer into HEAD
adriangohjw Dec 16, 2024
6025a4f
chore: fix query
adriangohjw Dec 16, 2024
4ab39ef
Merge commit '6025a4f1' into adriangohjw/isom-1659-internal-links-for…
adriangohjw Dec 16, 2024
0073f9c
fix - missing comma
adriangohjw Dec 16, 2024
b13da2c
add output schema
adriangohjw Dec 16, 2024
6247ac7
add output schema
adriangohjw Dec 16, 2024
c30eb05
replace [0]
adriangohjw Dec 16, 2024
781add0
replace with Error
adriangohjw Dec 16, 2024
7eb3705
rename to matchedResources
adriangohjw Dec 16, 2024
7aa99d8
fix - use the correct resource
adriangohjw Dec 17, 2024
9453968
Merge branch 'main' of https://github.com/opengovsg/isomer into adria…
adriangohjw Dec 17, 2024
be0c1a0
fix - suspend header and content for better UX
adriangohjw Dec 17, 2024
f522727
break useResourceStack into useResourceSelector hook
adriangohjw Dec 17, 2024
1e649ec
split into useResourceQuery
adriangohjw Dec 17, 2024
32e9b2c
Merge branch 'main' of https://github.com/opengovsg/isomer into adria…
adriangohjw Dec 25, 2024
046c718
update preview-tw
adriangohjw Dec 25, 2024
abb3dec
remove compute to DB
adriangohjw Dec 25, 2024
93f0f75
fix lint
adriangohjw Dec 25, 2024
39d4cd6
replace with recursive CTE
adriangohjw Dec 25, 2024
3f4d35b
fix suspense (searcbar should not suspense)
adriangohjw Dec 25, 2024
f9d476d
use "interactionType"
adriangohjw Dec 25, 2024
caf24be
fix getBatchAncestryWithSelfQuery
adriangohjw Dec 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions apps/studio/public/assets/css/preview-tw.css
Original file line number Diff line number Diff line change
Expand Up @@ -1418,10 +1418,6 @@ video {
-webkit-line-clamp: 3;
}

.\!block {
display: block !important;
}

.block {
display: block;
}
Expand Down Expand Up @@ -3156,11 +3152,6 @@ video {
color: rgb(26 86 229 / var(--tw-text-opacity));
}

.text-link-hover {
--tw-text-opacity: 1;
color: rgb(21 71 190 / var(--tw-text-opacity));
}

.text-site-secondary {
--tw-text-opacity: 1;
color: rgb(78 69 65 / var(--tw-text-opacity));
Expand Down Expand Up @@ -5510,12 +5501,6 @@ video {
margin-top: 2.25rem;
}

.\[\&\:not\(\:first-child\)\]\:first-of-type\:mt-7:first-of-type:not(
:first-child
) {
margin-top: 1.75rem;
}

.\[\&\:not\(\:last-child\)\]\:mb-0:not(:last-child) {
margin-bottom: 0px;
}
Expand Down
35 changes: 9 additions & 26 deletions apps/studio/src/components/PageEditor/LinkEditorModal.tsx
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context

  • no longer require the query and text You selected /{resource.fullPermalink} as it's handled by ResourceSelector

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
ModalFooter,
ModalHeader,
ModalOverlay,
Text,
} from "@chakra-ui/react"
import {
Button,
Expand All @@ -29,7 +28,6 @@ import {
import { useQueryParse } from "~/hooks/useQueryParse"
import { useZodForm } from "~/lib/form"
import { getReferenceLink, getResourceIdFromReferenceLink } from "~/utils/link"
import { trpc } from "~/utils/trpc"
import { ResourceSelector } from "../ResourceSelector"
import { FileAttachment } from "./FileAttachment"

Expand All @@ -44,31 +42,16 @@ interface PageLinkElementProps {

const PageLinkElement = ({ value, onChange }: PageLinkElementProps) => {
const { siteId } = useQueryParse(editSiteSchema)

const selectedResourceId = getResourceIdFromReferenceLink(value)

const { data: resource } = trpc.resource.getWithFullPermalink.useQuery({
resourceId: selectedResourceId,
})

return (
<>
<ResourceSelector
siteId={String(siteId)}
onChange={(resourceId) =>
onChange(getReferenceLink({ siteId: String(siteId), resourceId }))
}
selectedResourceId={selectedResourceId}
/>

{!!resource && (
<Box bg="utility.feedback.info-subtle" p="0.75rem" w="full" mt="0.5rem">
<Text textStyle="caption-1">
You selected /{resource.fullPermalink}
</Text>
</Box>
)}
</>
<ResourceSelector
interactionType="link"
siteId={siteId}
onChange={(resourceId) =>
onChange(getReferenceLink({ siteId: String(siteId), resourceId }))
}
selectedResourceId={getResourceIdFromReferenceLink(value)}
fileExplorerHeight={12}
/>
)
}

Expand Down
145 changes: 57 additions & 88 deletions apps/studio/src/components/ResourceSelector/ResourceItem.tsx
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key changes

  • added Skeleton for loading state
  • refactoring to use getIcon for reusability and single source of truth
  • moving changes from MoveItem.tsx and deleting that instead

Original file line number Diff line number Diff line change
@@ -1,108 +1,77 @@
import type { IconType } from "react-icons"
import { Suspense, useMemo } from "react"
import { Box, HStack, Icon, Skeleton, Text } from "@chakra-ui/react"
import type { ButtonProps } from "@opengovsg/design-system-react"
import { Icon, Skeleton, Text, VStack } from "@chakra-ui/react"
import { dataAttr } from "@chakra-ui/utils"
import { Button } from "@opengovsg/design-system-react"
import { QueryErrorResetBoundary } from "@tanstack/react-query"
import { ResourceType } from "~prisma/generated/generatedEnums"
import { ErrorBoundary } from "react-error-boundary"
import { BiData, BiFile, BiFolder, BiLink, BiLockAlt } from "react-icons/bi"

import type { RouterOutput } from "~/utils/trpc"
import type { ResourceItemContent } from "~/schemas/resource"
import { getIcon } from "~/utils/resources"

type ResourceItemProps = Pick<
RouterOutput["resource"]["getChildrenOf"]["items"][number],
"permalink" | "type"
> & {
isSelected: boolean
isDisabled: boolean
onResourceItemSelect: () => void
interface ResourceItemProps {
item: ResourceItemContent
isDisabled?: boolean
isHighlighted?: boolean
handleOnClick?: () => void
hasAdditionalLeftPadding?: boolean
isLoading?: boolean
}

const SuspendableResourceItem = ({
permalink,
type,
isSelected,
isDisabled,
onResourceItemSelect,
}: ResourceItemProps) => {
const icon: IconType = useMemo(() => {
switch (type) {
case ResourceType.CollectionLink:
return BiLink
case ResourceType.Folder:
return BiFolder
case ResourceType.CollectionPage:
case ResourceType.Page:
return BiFile
case ResourceType.Collection:
return BiData
}
}, [type])

const ResourceItemContainer = (props: ButtonProps) => {
return (
<Button
variant="clear"
w="full"
justifyContent="flex-start"
color="base.content.default"
isDisabled={isDisabled}
data-selected={dataAttr(isSelected)}
color={"base.content.default"}
height="fit-content"
alignItems="flex-start"
gap="0.25rem"
{...props}
/>
)
}

export const ResourceItemSkeleton = () => {
return (
<ResourceItemContainer isDisabled>
<VStack alignItems="flex-start" textAlign="left" gap="0.25rem">
<Skeleton width="12rem" height="1.125rem" variant="pulse" />
<Skeleton width="18rem" height="1.125rem" variant="pulse" />
</VStack>
</ResourceItemContainer>
)
}

export const ResourceItem = ({
item,
isDisabled,
isHighlighted = false,
handleOnClick,
hasAdditionalLeftPadding = false,
}: ResourceItemProps) => {
return (
<ResourceItemContainer
data-selected={dataAttr(isHighlighted)}
_selected={{
color: "interaction.main.default",
bgColor: "interaction.muted.main.active",
_hover: {
bgColor: "unset",
},
}}
_active={{
bgColor: "interaction.tinted.main.active",
}}
_disabled={{
color: "interaction.support.disabled-content",
bgColor: "unset",
cursor: "not-allowed",
bg: "interaction.muted.main.active",
_hover: {
bgColor: "unset",
color: "interaction.main.default",
bg: "interaction.muted.main.active",
},
}}
_hover={{
bgColor: "interaction.muted.main.hover",
}}
pl="2.25rem"
py="0.375rem"
borderRadius="0.25rem"
onClick={onResourceItemSelect}
leftIcon={<Icon as={icon} />}
{...(hasAdditionalLeftPadding && { pl: "2.25rem" })}
onClick={handleOnClick}
leftIcon={<Icon as={getIcon(item.type)} />}
isDisabled={isDisabled}
>
<HStack align="start" w="full" justify="space-between">
<Text textStyle="caption-1" noOfLines={1}>
/{permalink}
<VStack alignItems="flex-start" textAlign="left" gap="0.25rem">
<Text noOfLines={1} textStyle="caption-1">
{item.title}
</Text>
{isDisabled && <Icon as={BiLockAlt} fontSize="0.75rem" />}
</HStack>
</Button>
)
}

export const ResourceItem = (props: ResourceItemProps) => {
return (
<QueryErrorResetBoundary>
{({ reset }) => (
<ErrorBoundary
onReset={reset}
fallbackRender={({ resetErrorBoundary }) => (
<Box>
There was an error!
<Button onClick={() => resetErrorBoundary()}>Try again</Button>
</Box>
)}
>
<Suspense fallback={<Skeleton />}>
<SuspendableResourceItem {...props} />
</Suspense>
</ErrorBoundary>
)}
</QueryErrorResetBoundary>
<Text noOfLines={1} textStyle="caption-2">
{`/${item.permalink}`}
</Text>
</VStack>
</ResourceItemContainer>
)
}
Loading
Loading