Skip to content

Commit 3c448be

Browse files
committed
chore: refactor tag to show source
1 parent b511048 commit 3c448be

File tree

4 files changed

+70
-39
lines changed

4 files changed

+70
-39
lines changed

packages/frontend/src/components/AttachmentSuggestions/components/Checkbox.tsx

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface CheckboxVariable extends Variable {
1818
updatedAt?: string | number
1919
size?: number
2020
uploaded?: boolean
21+
source?: string
2122
}
2223

2324
interface CheckboxProps {
@@ -31,7 +32,22 @@ interface CheckboxProps {
3132

3233
function Checkbox(props: CheckboxProps) {
3334
const { variable, isChecked, onClick, allowDelete, onDelete } = props
34-
const { displayedValue, size, value, updatedAt = null, uploaded } = variable
35+
const {
36+
displayedValue,
37+
label,
38+
size,
39+
value,
40+
updatedAt = null,
41+
uploaded,
42+
} = variable
43+
44+
const getInfoText = (info?: number | string | null) => {
45+
return (
46+
<Text textStyle="body-2" noOfLines={1} color="base.content.medium">
47+
{info ?? ''}
48+
</Text>
49+
)
50+
}
3551

3652
// Note: removes the outline around the checkbox that is last focused
3753
const handleBlur = (e: ChangeEvent<HTMLInputElement>) => e.target.blur()
@@ -52,20 +68,20 @@ function Checkbox(props: CheckboxProps) {
5268
>
5369
<Flex alignItems="center" justify="space-between" maxW="100%">
5470
<Flex direction="column">
55-
<TouchableTooltip label={displayedValue}>
56-
<Text noOfLines={1}>{displayedValue}</Text>
71+
<TouchableTooltip label={uploaded ? displayedValue : label}>
72+
<Text noOfLines={1}>{uploaded ? displayedValue : label}</Text>
5773
</TouchableTooltip>
58-
{uploaded && (
59-
<Flex direction="row" alignItems="center">
60-
<Text textStyle="body-2" noOfLines={1}>
61-
{size ? formatFileSizeToStr(size) : ''}
62-
</Text>
63-
<Icon as={BsDot} />
64-
<Text textStyle="body-2" noOfLines={1}>
65-
{toPrettyDateString(updatedAt, 'iso')}
66-
</Text>
67-
</Flex>
68-
)}
74+
<Flex direction="row" alignItems="center">
75+
{uploaded ? (
76+
<Flex direction="row" alignItems="center">
77+
{getInfoText(size ? formatFileSizeToStr(size) : '')}
78+
<Icon as={BsDot} />
79+
{getInfoText(toPrettyDateString(updatedAt, 'iso'))}
80+
</Flex>
81+
) : (
82+
getInfoText(displayedValue)
83+
)}
84+
</Flex>
6985
</Flex>
7086
{allowDelete && (
7187
<IconButton

packages/frontend/src/components/AttachmentSuggestions/components/Suggestions.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,23 @@ export default function Suggestions(props: SuggestionsProps) {
9292
/>
9393
)}
9494
<Box data-test="attachment-group" maxH={64} overflowY="auto">
95-
{output?.map((variable) => (
96-
<Checkbox
97-
key={variable.name}
98-
variable={variable}
99-
allowDelete={addNew}
100-
isChecked={selectedNames.includes(variable.name)}
101-
onClick={(variable, checked) => {
102-
onSuggestionClick(variable, checked, onChange, values)
103-
}}
104-
onDelete={onDelete}
105-
/>
106-
))}
95+
{output?.map((variable) => {
96+
return (
97+
<Checkbox
98+
key={variable.name}
99+
variable={{
100+
...variable,
101+
source: option.name,
102+
}}
103+
allowDelete={addNew}
104+
isChecked={selectedNames.includes(variable.name)}
105+
onClick={(variable, checked) => {
106+
onSuggestionClick(variable, checked, onChange, values)
107+
}}
108+
onDelete={onDelete}
109+
/>
110+
)
111+
})}
107112
</Box>
108113
</Collapse>
109114
)

packages/frontend/src/components/AttachmentSuggestions/components/TagList.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Tag, TagCloseButton, TagLabel } from '@chakra-ui/react'
1+
import { Tag, TagCloseButton, TagLabel, Tooltip } from '@chakra-ui/react'
22

33
interface TagsProps {
44
selectedOptions: any[]
@@ -8,17 +8,27 @@ interface TagsProps {
88
function TagList(props: TagsProps) {
99
const { onClick, selectedOptions } = props
1010

11+
const getLabel = (option: any, tooltip?: boolean) => {
12+
const { displayedValue, label, source, uploaded } = option
13+
14+
if (tooltip) {
15+
return uploaded ? displayedValue : label
16+
}
17+
18+
return uploaded ? `[Uploaded] ${displayedValue}` : `[${source}] ${label}`
19+
}
20+
1121
if (selectedOptions.length === 0) {
1222
return <></>
1323
}
1424

1525
return (
1626
<>
1727
{selectedOptions?.map((option) => {
18-
const { displayedValue, value } = option
28+
const { label, value } = option
1929
return (
2030
<Tag
21-
key={value as string}
31+
key={`${label}-${value}`}
2232
size="md"
2333
colorScheme="primary"
2434
borderRadius="md"
@@ -27,14 +37,11 @@ function TagList(props: TagsProps) {
2737
maxW="200px"
2838
flex="0 1 auto"
2939
>
30-
<TagLabel
31-
isTruncated
32-
flex="1 1 auto"
33-
minW="0"
34-
title={displayedValue}
35-
>
36-
{displayedValue}
37-
</TagLabel>
40+
<Tooltip hasArrow label={getLabel(option, true)}>
41+
<TagLabel isTruncated flex="1 1 auto" minW="0">
42+
{getLabel(option)}
43+
</TagLabel>
44+
</Tooltip>
3845
<TagCloseButton onClick={() => onClick(option)} />
3946
</Tag>
4047
)

packages/frontend/src/components/AttachmentSuggestions/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ function AttachmentSuggestions(props: AttachmentSuggestionsProps) {
100100
const variableType = variable.type ?? 'text'
101101
return variableTypes?.includes(variableType) ?? false
102102
},
103-
)
103+
).map((v) => ({
104+
...v,
105+
// NOTE: add the source to display in the tag
106+
output: v.output.map((o) => ({ ...o, source: v.name })),
107+
}))
104108

105109
const selectedFromVars = filteredVars.reduce(
106110
(acc: CheckboxVariable[], v) => {
@@ -193,7 +197,6 @@ function AttachmentSuggestions(props: AttachmentSuggestionsProps) {
193197
field: { onChange, value: values },
194198
fieldState: { error },
195199
}) => {
196-
console.log('error', error)
197200
return (
198201
<FormControl isInvalid={!!error} ref={wrapperRef}>
199202
{label && (

0 commit comments

Comments
 (0)