1
- import groupBy from 'lodash/groupBy' ;
2
-
3
1
import IdBadge from 'sentry/components/idBadge' ;
4
2
import { t } from 'sentry/locale' ;
5
3
import type { Project } from 'sentry/types' ;
@@ -16,16 +14,16 @@ type GroupProjects = (project: Project) => string;
16
14
// projects can be passed as a direct prop as well
17
15
export interface RenderFieldProps extends InputFieldProps {
18
16
avatarSize ?: number ;
19
- /**
20
- * When using groupProjects you can specify the labels of the groups as a
21
- * mapping of the key returned for the groupProjects to the label
22
- */
23
- groupLabels ?: Record < string , React . ReactNode > ;
24
17
/**
25
18
* Controls grouping of projects within the field. Useful to prioritize some
26
19
* projects above others
27
20
*/
28
21
groupProjects ?: GroupProjects ;
22
+ /**
23
+ * When using groupProjects you must specify the labels of the groups as a
24
+ * list of key and label. The ordering determines the order of the groups.
25
+ */
26
+ groups ?: Array < { key : string ; label : React . ReactNode } > ;
29
27
projects ?: Project [ ] ;
30
28
/**
31
29
* Use the slug as the select field value. Without setting this the numeric id
@@ -37,7 +35,7 @@ export interface RenderFieldProps extends InputFieldProps {
37
35
function SentryProjectSelectorField ( {
38
36
projects,
39
37
groupProjects,
40
- groupLabels ,
38
+ groups ,
41
39
avatarSize = 20 ,
42
40
placeholder = t ( 'Choose Sentry project' ) ,
43
41
valueIsSlug,
@@ -61,9 +59,11 @@ function SentryProjectSelectorField({
61
59
const projectOptions =
62
60
projects && groupProjects
63
61
? // Create project groups when groupProjects is in use
64
- Object . entries ( groupBy ( projects , groupProjects ) ) . map ( ( [ key , projectsGroup ] ) => ( {
65
- label : groupLabels ?. [ key ] ?? key ,
66
- options : projectsGroup . map ( projectToOption ) ,
62
+ groups ?. map ( ( { key, label} ) => ( {
63
+ label,
64
+ options : projects
65
+ . filter ( project => groupProjects ( project ) === key )
66
+ . map ( projectToOption ) ,
67
67
} ) )
68
68
: // Otherwise just map projects to the options
69
69
projects ?. map ( projectToOption ) ;
0 commit comments