Skip to content

Commit 4e4cafb

Browse files
committed
fixes
1 parent 2e86dce commit 4e4cafb

File tree

4 files changed

+182
-167
lines changed

4 files changed

+182
-167
lines changed

packages/ui/src/views/delegates/components/delegate-connectivity-list.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ export function DelegateConnectivityList({
3636
return (
3737
<Table.Root
3838
className={isLoading ? '[mask-image:linear-gradient(to_bottom,black_30%,transparent_100%)]' : ''}
39+
tableClassName="table-fixed"
3940
variant="asStackedList"
4041
>
4142
<Table.Header>
4243
<Table.Row>
43-
<Table.Head style={{ width: 184 }}>Delegate</Table.Head>
44-
<Table.Head>Heartbeat</Table.Head>
45-
<Table.Head>Tags</Table.Head>
46-
<Table.Head style={{ width: 57 }}>Selected</Table.Head>
44+
<Table.Head className="w-3/12">Delegate</Table.Head>
45+
<Table.Head className="w-3/12">Heartbeat</Table.Head>
46+
<Table.Head className="w-4/12">Tags</Table.Head>
47+
<Table.Head className="w-2/12">Selected</Table.Head>
4748
</Table.Row>
4849
</Table.Header>
4950
{isLoading ? (
@@ -61,7 +62,7 @@ export function DelegateConnectivityList({
6162
}) => {
6263
return (
6364
<Table.Row key={groupId}>
64-
<Table.Cell className="max-w-80 content-center truncate" style={{ width: 184, maxWidth: 184 }}>
65+
<Table.Cell className="content-center truncate">
6566
<div className="flex items-center gap-2.5">
6667
<Title title={groupName} />
6768
</div>
@@ -85,7 +86,7 @@ export function DelegateConnectivityList({
8586
</StatusBadge>
8687
))}
8788
</Table.Cell>
88-
<Table.Cell className="content-center" style={{ width: 57 }}>
89+
<Table.Cell className="content-center justify-items-center">
8990
{isDelegateSelected(
9091
[...defaultTo(groupImplicitSelectors, []), ...defaultTo(groupCustomSelectors, [])],
9192
selectedTags || []
Lines changed: 70 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
1-
import { FC } from 'react'
1+
import { FC, useCallback, useMemo, useState } from 'react'
22

33
import { TranslationStore } from '@/views'
4+
import { Button } from '@components/button'
5+
import { ButtonGroup } from '@components/button-group'
46
import { Drawer } from '@components/drawer'
7+
import { ControlGroup } from '@components/form-primitives'
8+
import { Icon } from '@components/icon'
9+
import { ScrollArea } from '@components/scroll-area'
10+
import { StyledLink } from '@components/styled-link'
511

612
import { DelegateItem } from '../types'
7-
import { getMatchedDelegatesCount, isDelegateSelected } from '../utils'
8-
import { DelegateSelectorForm, DelegateSelectorFormFields } from './delegate-selector-form'
13+
import { getDefaultFormValues, getMatchedDelegatesCount, isDelegateSelected } from '../utils'
14+
import { DelegateSelectionTypes, DelegateSelectorForm, type DelegateSelectorFormFields } from './delegate-selector-form'
915

1016
interface DrawerProps {
1117
open: boolean
@@ -27,26 +33,64 @@ export const DelegateSelectorDrawer: FC<DrawerProps> = ({
2733
useTranslationStore,
2834
onSubmit,
2935
disableAnyDelegate
30-
}) => (
31-
<Drawer.Root open={open} onOpenChange={setOpen} direction="right">
32-
<Drawer.Content className="flex h-full flex-col p-0" style={{ width: 716 }}>
33-
<Drawer.Header className="border-cn-borders-3 sticky top-0 border-b px-6 py-5">
34-
<Drawer.Title className="text-cn-foreground-1 text-xl font-medium">Delegate selector</Drawer.Title>
35-
<Drawer.Close onClick={() => setOpen(false)} className="sr-only" />
36-
</Drawer.Header>
37-
38-
<DelegateSelectorForm
39-
delegates={delegates}
40-
tagsList={tagsList}
41-
useTranslationStore={useTranslationStore}
42-
isLoading={false}
43-
onFormSubmit={onSubmit}
44-
onBack={() => setOpen(false)}
45-
isDelegateSelected={isDelegateSelected}
46-
getMatchedDelegatesCount={getMatchedDelegatesCount}
47-
preSelectedTags={preSelectedTags}
48-
disableAnyDelegate={disableAnyDelegate}
49-
/>
50-
</Drawer.Content>
51-
</Drawer.Root>
52-
)
36+
}) => {
37+
const [{ type: delegateType, tags: selectedTags }, setFormState] = useState(
38+
getDefaultFormValues(preSelectedTags, disableAnyDelegate)
39+
)
40+
41+
const matchedDelegates = useMemo(
42+
() => getMatchedDelegatesCount(delegates, selectedTags?.map(tag => tag.id) ?? []),
43+
[delegates, selectedTags]
44+
)
45+
46+
const handleBack = useCallback(() => setOpen(false), [setOpen])
47+
const handleChangeFields = useCallback(data => {
48+
setFormState(data)
49+
}, [])
50+
51+
return (
52+
<Drawer.Root open={open} onOpenChange={setOpen} direction="right">
53+
<Drawer.Content className="flex h-full w-[716px] flex-col p-0">
54+
<Drawer.Header className="border-cn-borders-3 sticky top-0 border-b px-6 py-5">
55+
<Drawer.Title className="text-cn-foreground-1 text-xl font-medium">Delegate selector</Drawer.Title>
56+
<Drawer.Close onClick={handleBack} className="sr-only" />
57+
</Drawer.Header>
58+
59+
<ScrollArea scrollThumbClassName="bg-sidebar-background-8">
60+
<div className="px-6 py-5">
61+
<span className="text-cn-foreground-4 mr-1">Haven&apos;t installed a delegate yet?</span>
62+
<StyledLink className="inline-flex flex-row items-center" variant="accent" to="#">
63+
Install delegate <Icon name="attachment-link" className="ml-1" size={12} />
64+
</StyledLink>
65+
</div>
66+
<DelegateSelectorForm
67+
delegates={delegates}
68+
tagsList={tagsList}
69+
useTranslationStore={useTranslationStore}
70+
isLoading={false}
71+
onFormSubmit={onSubmit}
72+
isDelegateSelected={isDelegateSelected}
73+
preSelectedTags={preSelectedTags}
74+
disableAnyDelegate={disableAnyDelegate}
75+
onChangeFields={handleChangeFields}
76+
/>
77+
</ScrollArea>
78+
79+
<div className="bg-cn-background-2 border-cn-borders-3 sticky bottom-0 z-10 border-t px-6 py-5 shadow-md">
80+
<ControlGroup>
81+
<ButtonGroup className="flex flex-row justify-between">
82+
<Button type="button" variant="outline" onClick={handleBack}>
83+
Back
84+
</Button>
85+
<Button type="submit" form="delegate-selector-form">
86+
Connect&nbsp;
87+
{delegateType === DelegateSelectionTypes.TAGS ? matchedDelegates : 'any'}&nbsp;
88+
{delegateType === DelegateSelectionTypes.TAGS && matchedDelegates > 1 ? 'delegates' : 'delegate'}
89+
</Button>
90+
</ButtonGroup>
91+
</ControlGroup>
92+
</div>
93+
</Drawer.Content>
94+
</Drawer.Root>
95+
)
96+
}

0 commit comments

Comments
 (0)