1
- import { useOrganizationTags } from '@app-builder/services/organization/organization-tags' ;
2
1
import { type Tag } from 'marble-api' ;
3
2
import { matchSorter } from 'match-sorter' ;
4
3
import * as React from 'react' ;
5
4
import { useTranslation } from 'react-i18next' ;
6
- import { Input , Tooltip } from 'ui-design-system' ;
5
+ import { Input , SelectWithCombobox , Tooltip } from 'ui-design-system' ;
7
6
8
- import { FormSelectWithCombobox } from '../Form/FormSelectWithCombobox' ;
9
7
import { casesI18n } from './cases-i18n' ;
10
8
11
- export function CaseTags ( { caseTagIds } : { caseTagIds : string [ ] } ) {
9
+ export function CaseTags ( { caseTagIds, orgTags } : { caseTagIds : string [ ] ; orgTags : Tag [ ] } ) {
12
10
const { t } = useTranslation ( casesI18n ) ;
11
+
13
12
return (
14
13
< Tooltip . Default
15
14
content = {
16
15
< div className = "flex max-w-sm flex-wrap gap-1" >
17
16
{ caseTagIds . map ( ( caseTagId ) => (
18
- < CaseTag key = { caseTagId } tagId = { caseTagId } />
17
+ < CaseTag key = { caseTagId } tag = { orgTags . find ( ( t ) => t . id === caseTagId ) } />
19
18
) ) }
20
19
</ div >
21
20
}
22
21
>
23
22
< div className = "flex w-fit flex-wrap items-center gap-1" >
24
23
{ caseTagIds . slice ( 0 , 3 ) . map ( ( caseTagId ) => (
25
- < CaseTag key = { caseTagId } tagId = { caseTagId } />
24
+ < CaseTag key = { caseTagId } tag = { orgTags . find ( ( t ) => t . id === caseTagId ) } />
26
25
) ) }
27
26
{ caseTagIds . length > 3 ? (
28
27
< div className = "text-grey-00 bg-grey-95 flex h-6 items-center rounded-s px-2 text-xs font-normal" >
@@ -36,12 +35,9 @@ export function CaseTags({ caseTagIds }: { caseTagIds: string[] }) {
36
35
) ;
37
36
}
38
37
39
- export function CaseTag ( { tagId } : { tagId : string } ) {
40
- const { getTagById } = useOrganizationTags ( ) ;
38
+ export function CaseTag ( { tag } : { tag ?: Tag } ) {
41
39
const { t } = useTranslation ( casesI18n ) ;
42
40
43
- const tag = getTagById ( tagId ) ;
44
-
45
41
return (
46
42
< div
47
43
className = "bg-grey-95 flex h-6 items-center rounded px-2"
@@ -54,14 +50,16 @@ export function CaseTag({ tagId }: { tagId: string }) {
54
50
) ;
55
51
}
56
52
57
- export function FormSelectCaseTags ( {
58
- selectedTagIds ,
53
+ export function SelectCaseTags ( {
54
+ name ,
59
55
orgTags,
60
- onOpenChange,
56
+ selectedTagIds,
57
+ onChange,
61
58
} : {
62
- selectedTagIds : string [ ] ;
59
+ name ? : string ;
63
60
orgTags : Tag [ ] ;
64
- onOpenChange ?: ( open : boolean ) => void ;
61
+ selectedTagIds : string [ ] ;
62
+ onChange ?: ( value : string [ ] ) => void ;
65
63
} ) {
66
64
const { t } = useTranslation ( [ 'cases' ] ) ;
67
65
const [ searchValue , setSearchValue ] = React . useState ( '' ) ;
@@ -73,35 +71,31 @@ export function FormSelectCaseTags({
73
71
) ;
74
72
75
73
return (
76
- < FormSelectWithCombobox . Root
74
+ < SelectWithCombobox . Root
77
75
selectedValue = { selectedTagIds }
78
76
searchValue = { searchValue }
79
77
onSearchValueChange = { setSearchValue }
80
- onOpenChange = { onOpenChange }
78
+ onSelectedValueChange = { onChange }
81
79
>
82
- < FormSelectWithCombobox . Select className = "w-full" >
83
- < CaseTags caseTagIds = { selectedTagIds } />
84
- < FormSelectWithCombobox . Arrow />
85
- </ FormSelectWithCombobox . Select >
86
- < FormSelectWithCombobox . Popover className = "z-50 flex flex-col gap-2 p-2" >
87
- < FormSelectWithCombobox . Combobox
88
- render = { < Input className = "shrink-0" /> }
89
- autoSelect
90
- autoFocus
91
- />
92
- < FormSelectWithCombobox . ComboboxList >
80
+ < SelectWithCombobox . Select name = { name } className = "w-full" >
81
+ < CaseTags caseTagIds = { selectedTagIds } orgTags = { orgTags } />
82
+ < SelectWithCombobox . Arrow />
83
+ </ SelectWithCombobox . Select >
84
+ < SelectWithCombobox . Popover className = "z-50 flex flex-col gap-2 p-2" >
85
+ < SelectWithCombobox . Combobox render = { < Input className = "shrink-0" /> } autoSelect autoFocus />
86
+ < SelectWithCombobox . ComboboxList >
93
87
{ matches . map ( ( tag ) => (
94
- < FormSelectWithCombobox . ComboboxItem key = { tag . id } value = { tag . id } >
95
- < CaseTag tagId = { tag . id } />
96
- </ FormSelectWithCombobox . ComboboxItem >
88
+ < SelectWithCombobox . ComboboxItem key = { tag . id } value = { tag . id } >
89
+ < CaseTag tag = { tag } />
90
+ </ SelectWithCombobox . ComboboxItem >
97
91
) ) }
98
92
{ matches . length === 0 ? (
99
93
< p className = "text-grey-50 flex items-center justify-center p-2" >
100
94
{ t ( 'cases:case_detail.tags.empty_matches' ) }
101
95
</ p >
102
96
) : null }
103
- </ FormSelectWithCombobox . ComboboxList >
104
- </ FormSelectWithCombobox . Popover >
105
- </ FormSelectWithCombobox . Root >
97
+ </ SelectWithCombobox . ComboboxList >
98
+ </ SelectWithCombobox . Popover >
99
+ </ SelectWithCombobox . Root >
106
100
) ;
107
101
}
0 commit comments