-
Notifications
You must be signed in to change notification settings - Fork 1
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
adriangohjw
wants to merge
118
commits into
main
Choose a base branch
from
adriangohjw/isom-1659-internal-links-for-folders
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,621
−704
Open
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 c9754c7
integrate to handle onChange
adriangohjw 5dc5fd8
update getAncestry to getAncestryWithSelf
adriangohjw 81dc97a
show existing link location on open
adriangohjw d71e3e1
lint LinkEditorModal
adriangohjw dc3e5c8
refactor - remove moveItem (use ResourceItem instead)
adriangohjw 7d71c37
refactor: reuse ResourceSelector
adriangohjw a63bce0
add gap
adriangohjw 058c030
Merge branch 'main' of https://github.com/opengovsg/isomer into adria…
adriangohjw 368f5cd
Merge remote-tracking branch 'origin/main' into adriangohjw/isom-1659…
adriangohjw fb65e93
use Resource.type for checking instead
adriangohjw 4e9e5d1
make isHighlighted compulsory
adriangohjw 917f299
ensure api returns desired type
adriangohjw 153f69b
better typecheck of values from trpc.resource
adriangohjw 1346700
update to use onlyShowFolders instead
adriangohjw 995d73c
Merge remote-tracking branch 'origin/main' into adriangohjw/isom-1659…
adriangohjw 37021b4
fix - display full permalink
adriangohjw 7aab61f
Merge remote-tracking branch 'origin/main' into adriangohjw/isom-1659…
adriangohjw 9bf96e0
update from div to Box
adriangohjw 23bdd3c
replace to use import from generatedEnums
adriangohjw 5667910
refactor - use single source of truth getIcon
adriangohjw ce11463
update schema name to getAncestryWithSelfSchema to be consistent
adriangohjw 1ca9ef9
fix mock - getAncestry to getAncestryWithSelf
adriangohjw 787aca8
remove "undefined" from "type"
adriangohjw 118ebb8
remove "null" from acceptable type value
adriangohjw bb4d651
refactor - do a 1-for-1 abstraction to useResourceStack
adriangohjw 9514000
abstract away more stuff + usememo/usecallback for perf
adriangohjw 6c4868c
add missing dependencies in addToStack
adriangohjw 1690a82
refactor - move logic into ResourceItem
adriangohjw 74e4e7a
more explicit about the props
adriangohjw a692eff
remove unused import
adriangohjw 9a5ab6b
return flatten item
adriangohjw 4f8fd16
pass in fullPermalink instead
adriangohjw 5b10f41
undo absttracting away into useResourceStack
adriangohjw 8b677c2
add gap
adriangohjw 9ac2fd4
exclude index page from showing up in search
adriangohjw 99ed3fd
Merge branch 'main' of https://github.com/opengovsg/isomer into adria…
adriangohjw 9b6388f
Merge branch 'main' of https://github.com/opengovsg/isomer into adria…
adriangohjw e2ac2ab
fix - full width issue
adriangohjw 5459a2e
add searchbar skeleton
adriangohjw 096b062
update resourceItem UI
adriangohjw 526b3a1
refactor headers out
adriangohjw 9f7d42f
abstract logic away
adriangohjw 804e2b8
add "results count" state
adriangohjw 4ecd178
option for additional padding based on whether user is using search
adriangohjw 0122f7e
set fixed height to 280px
adriangohjw 12dc2f8
fix text alignment issue
adriangohjw 86f049c
fix "back to home" padding
adriangohjw c347f69
refactor into new file + add "NoItemsInFolderResult"
adriangohjw 492f4b7
refactor - move all logic into ResourceSelector to reduce number of p…
adriangohjw ff2fe71
rename to ResourceSelectorContent
adriangohjw f2ae9b2
clear searchbar on clicking clear search button
adriangohjw 80027d8
allow passing in of resourcetypes into search query
adriangohjw b1b62a1
extract into useSearchQuery
adriangohjw 181b549
use useSearchQuery instead
adriangohjw 77d0c00
reduce API call by passing in siteId
adriangohjw a6e944b
move useSearchQuery out of useResourceStack
adriangohjw 4419bc1
add loading state
adriangohjw 6547e6c
remove unused import
adriangohjw 52a8014
prep: abstract logic into useResourceStack for easier refactoring
adriangohjw 9797551
refactor into getAncestryWithSelf + add getBatchAncestryWithSelf endp…
adriangohjw 88cffc6
fix - use handleOnClick directly
adriangohjw bfc2c7b
fix - make resourceTypes optional for search endpoint
adriangohjw c538e90
fix test
adriangohjw ab64810
standardize types into 1
adriangohjw 14db37f
hide logic in hook + fix search
adriangohjw 18c3fbe
add comment
adriangohjw d1eff5b
set higher height for Skeleton
adriangohjw de9403f
remove unused type export
adriangohjw 5147212
fix nested use hooks issue
adriangohjw 55073f3
fix navigation
adriangohjw a1f1235
fix padding on "load more" button
adriangohjw 18b2f17
fix - overwrite returned functions for search by query
adriangohjw 097c9a4
extract lastResourceItemInAncestryStack into standalone utils file
adriangohjw 2a5d410
usecallback everything + pass out clearSearchValue
adriangohjw cbbd1b2
clearSearchValue() onChange current
adriangohjw 600f8f0
fix typo in query
adriangohjw d282f00
fix test
adriangohjw 4fddb68
fix - incorrect header shown when using query
adriangohjw 55fdfb7
fix - remove conditional for hook
adriangohjw 78a0d16
Merge branch 'main' into adriangohjw/isom-1659-internal-links-for-fol…
adriangohjw 985b52f
remove accidental .only commit
adriangohjw c86ec42
enforce using output schema instead
adriangohjw 8b7408f
fix stories
adriangohjw ed812fa
add stories
adriangohjw 3d42fc7
Merge branch 'main' of https://github.com/opengovsg/isomer into adria…
adriangohjw 0773fab
fix lint
adriangohjw e3352f9
slight refactoring - move isResourceItemDisabled into hook
adriangohjw fad12e6
add getNestedFolderChildrenOf endpoint
adriangohjw a3dcec4
update isResourceItemDisabled to return true for nested children
adriangohjw fc2cc72
lint + use useMemo to improve perf
adriangohjw 9f46bd4
Merge branch 'main' of https://github.com/opengovsg/isomer into adria…
adriangohjw 55bea71
allow passing in of file explorer height + update skeleton height and…
adriangohjw d9fa0ea
Update apps/studio/src/server/modules/resource/resource.service.ts
adriangohjw 15f14a3
Merge branch 'main' into adriangohjw/isom-1659-internal-links-for-fol…
adriangohjw a187575
chore: refactor and fix based on comments
adriangohjw 493a550
Merge branch 'main' of https://github.com/opengovsg/isomer into HEAD
adriangohjw 6025a4f
chore: fix query
adriangohjw 4ab39ef
Merge commit '6025a4f1' into adriangohjw/isom-1659-internal-links-for…
adriangohjw 0073f9c
fix - missing comma
adriangohjw b13da2c
add output schema
adriangohjw 6247ac7
add output schema
adriangohjw c30eb05
replace [0]
adriangohjw 781add0
replace with Error
adriangohjw 7eb3705
rename to matchedResources
adriangohjw 7aa99d8
fix - use the correct resource
adriangohjw 9453968
Merge branch 'main' of https://github.com/opengovsg/isomer into adria…
adriangohjw be0c1a0
fix - suspend header and content for better UX
adriangohjw f522727
break useResourceStack into useResourceSelector hook
adriangohjw 1e649ec
split into useResourceQuery
adriangohjw 32e9b2c
Merge branch 'main' of https://github.com/opengovsg/isomer into adria…
adriangohjw 046c718
update preview-tw
adriangohjw abb3dec
remove compute to DB
adriangohjw 93f0f75
fix lint
adriangohjw 39d4cd6
replace with recursive CTE
adriangohjw 3f4d35b
fix suspense (searcbar should not suspense)
adriangohjw f9d476d
use "interactionType"
adriangohjw caf24be
fix getBatchAncestryWithSelfQuery
adriangohjw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 57 additions & 88 deletions
145
apps/studio/src/components/ResourceSelector/ResourceItem.tsx
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. key changes
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
context
You selected /{resource.fullPermalink}
as it's handled byResourceSelector