Skip to content

Commit a0d5b15

Browse files
committed
add active Tile indicator, update delete prompt
1 parent 7b2148a commit a0d5b15

File tree

2 files changed

+134
-43
lines changed

2 files changed

+134
-43
lines changed

packages/frontend/src/pages/Tiles/components/TileList.tsx

Lines changed: 70 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ import { MdOutlineRemoveRedEye } from 'react-icons/md'
55
import { Link } from 'react-router-dom'
66
import { useMutation } from '@apollo/client'
77
import {
8+
AlertDialog,
9+
AlertDialogBody,
10+
AlertDialogContent,
11+
AlertDialogFooter,
12+
AlertDialogHeader,
13+
AlertDialogOverlay,
814
Box,
15+
Button,
916
Divider,
1017
Flex,
1118
Icon,
@@ -22,7 +29,6 @@ import {
2229
useToast,
2330
} from '@opengovsg/design-system-react'
2431

25-
import MenuAlertDialog from '@/components/MenuAlertDialog'
2632
import * as URLS from '@/config/urls'
2733
import type { TableMetadata } from '@/graphql/__generated__/graphql'
2834
import { DELETE_TABLE } from '@/graphql/mutations/tiles/delete-table'
@@ -31,6 +37,14 @@ import { toPrettyDateString } from '@/helpers/dateTime'
3137

3238
import { TileConnections } from '..'
3339

40+
import {
41+
flexStyles,
42+
linkStyles,
43+
pulsingDotStyles,
44+
tagStyles,
45+
textStyles,
46+
} from './style'
47+
3448
const TileListItem = ({
3549
isConnectionsLoading,
3650
numConnections,
@@ -81,46 +95,32 @@ const TileListItem = ({
8195

8296
return (
8397
<Link to={URLS.TILE(table.id)}>
84-
<Flex
85-
px={8}
86-
py={6}
87-
w="100%"
88-
justifyContent="space-between"
89-
alignItems="center"
90-
_hover={{
91-
bg: 'interaction.muted.neutral.hover',
92-
'& .hover-remove-button': {
93-
visibility: 'visible',
94-
},
95-
}}
96-
_active={{
97-
bg: 'interaction.muted.neutral.active',
98-
}}
99-
>
98+
<Flex {...linkStyles}>
10099
<Box>
101-
<Text textStyle="h6">{table.name}</Text>
102-
<Flex gap={1} textStyle="body-2" color="base.content.medium">
103-
<Text>Last opened {toPrettyDateString(+table.lastAccessedAt)}</Text>
104-
{table.role !== 'viewer' && numConnections && (
105-
<>
106-
<Icon as={BsDot} fontSize="1.5em" />
107-
<Skeleton isLoaded={!isConnectionsLoading}>
100+
<Flex alignItems="center">
101+
<Text textStyle="h6">{table.name}</Text>
102+
</Flex>
103+
<Flex {...flexStyles.container}>
104+
<Text {...textStyles.lastOpened}>
105+
Last opened {toPrettyDateString(+table.lastAccessedAt)}
106+
</Text>
107+
{table.role !== 'viewer' && numConnections > 0 && (
108+
<Skeleton isLoaded={!isConnectionsLoading}>
109+
<Flex {...flexStyles.usedInPipes}>
110+
<Icon
111+
as={BsDot}
112+
color="interaction.success.default"
113+
sx={pulsingDotStyles}
114+
/>
108115
<Text>Used in {numConnections} pipes</Text>
109-
</Skeleton>
110-
</>
116+
</Flex>
117+
</Skeleton>
111118
)}
112119
</Flex>
113120
</Box>
114121
<Flex alignItems="center" gap={4}>
115122
{table.role === 'viewer' && (
116-
<Tag
117-
colorScheme="secondary"
118-
size="xs"
119-
variant="subtle"
120-
py={2}
121-
gap={1}
122-
pointerEvents="none"
123-
>
123+
<Tag {...tagStyles}>
124124
<TagLeftIcon as={MdOutlineRemoveRedEye} />
125125
<TagLabel>View only</TagLabel>
126126
</Tag>
@@ -137,15 +137,42 @@ const TileListItem = ({
137137
)}
138138
</Flex>
139139
</Flex>
140-
<MenuAlertDialog
141-
isDialogOpen={isDialogOpen}
142-
cancelRef={cancelRef}
143-
onDialogClose={onDialogClose}
144-
dialogHeader="Tile"
145-
dialogType="delete"
146-
onClick={deleteTile}
147-
isLoading={isDeletingTable}
148-
/>
140+
<AlertDialog
141+
isOpen={isDialogOpen}
142+
leastDestructiveRef={cancelRef}
143+
onClose={onDialogClose}
144+
>
145+
<AlertDialogOverlay>
146+
<AlertDialogContent>
147+
<AlertDialogHeader>Delete Tile</AlertDialogHeader>
148+
149+
<AlertDialogBody>
150+
{numConnections > 0
151+
? `Are you sure? This Tile is used in ${numConnections} pipe(s). You can't undo this action afterwards.`
152+
: "Are you sure? You can't undo this action afterwards."}
153+
</AlertDialogBody>
154+
155+
<AlertDialogFooter>
156+
<Button
157+
ref={cancelRef}
158+
onClick={onDialogClose}
159+
variant="clear"
160+
colorScheme="secondary"
161+
>
162+
Cancel
163+
</Button>
164+
<Button
165+
colorScheme="critical"
166+
onClick={deleteTile}
167+
ml={3}
168+
isLoading={isDeletingTable}
169+
>
170+
Delete
171+
</Button>
172+
</AlertDialogFooter>
173+
</AlertDialogContent>
174+
</AlertDialogOverlay>
175+
</AlertDialog>
149176
</Link>
150177
)
151178
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { FlexProps } from '@chakra-ui/react'
2+
3+
export const flexStyles = {
4+
container: {
5+
color: 'base.content.medium',
6+
direction: {
7+
base: 'column',
8+
md: 'row',
9+
} as FlexProps['direction'],
10+
textStyle: 'body-2',
11+
},
12+
usedInPipes: {
13+
alignItems: 'center',
14+
marginLeft: { base: 0, md: '-0.25em' },
15+
},
16+
}
17+
18+
export const linkStyles = {
19+
px: 8,
20+
py: 6,
21+
w: '100%',
22+
justifyContent: 'space-between',
23+
alignItems: 'center',
24+
_hover: {
25+
bg: 'interaction.muted.neutral.hover',
26+
'& .hover-remove-button': {
27+
visibility: 'visible',
28+
},
29+
},
30+
_active: {
31+
bg: 'interaction.muted.neutral.active',
32+
},
33+
}
34+
35+
export const pulsingDotStyles = {
36+
animation: 'pulse 2s infinite',
37+
fontSize: '3em',
38+
marginLeft: { base: '-0.4em', md: 0 },
39+
marginTop: '-0.5em',
40+
marginBottom: '-0.5em',
41+
'@keyframes pulse': {
42+
'0%': { opacity: 0.4 },
43+
'50%': { opacity: 1 },
44+
'100%': { opacity: 0.4 },
45+
},
46+
}
47+
48+
export const tagStyles = {
49+
colorScheme: 'secondary',
50+
size: 'xs',
51+
variant: 'subtle',
52+
py: 2,
53+
gap: 1,
54+
pointerEvents: 'none' as const,
55+
}
56+
57+
export const textStyles = {
58+
lastOpened: {
59+
width: {
60+
base: 'full',
61+
md: '17.5em',
62+
},
63+
},
64+
}

0 commit comments

Comments
 (0)