@@ -16,7 +16,6 @@ import { ChooseOne, Cond } from "components/Conditionals/ChooseOne";
16
16
import { EmptyState } from "components/EmptyState/EmptyState" ;
17
17
import { Loader } from "components/Loader/Loader" ;
18
18
import { Stack } from "components/Stack/Stack" ;
19
- import { StatusIndicator } from "components/StatusIndicator/StatusIndicator" ;
20
19
import {
21
20
TableLoaderSkeleton ,
22
21
TableRowSkeleton ,
@@ -34,7 +33,7 @@ import type { FC } from "react";
34
33
import { MONOSPACE_FONT_FAMILY } from "theme/constants" ;
35
34
import { docs } from "utils/docs" ;
36
35
import { getFormHelpers , onChangeTrimmed } from "utils/formUtils" ;
37
- // import { ExportPolicyButton } from "./ExportPolicyButton";
36
+ import { ExportPolicyButton } from "./ExportPolicyButton" ;
38
37
import { IdpPillList } from "./IdpPillList" ;
39
38
40
39
interface IdpSyncPageViewProps {
@@ -62,11 +61,33 @@ export const IdpSyncPageView: FC<IdpSyncPageViewProps> = ({
62
61
} ) ;
63
62
const getFieldHelpers = getFormHelpers < OrganizationSyncSettings > ( form , error ) ;
64
63
const [ coderOrgs , setCoderOrgs ] = useState < Option [ ] > ( [ ] ) ;
65
- const [ isChecked , setIsChecked ] = useState (
66
- form . initialValues . organization_assign_default ,
67
- ) ;
68
- const organizationMappingCount = organizationSyncSettings ?. mapping
69
- ? Object . entries ( organizationSyncSettings . mapping ) . length
64
+ const [ idpOrgName , setIdpOrgName ] = useState ( "" ) ;
65
+ const [ syncSettings , setSyncSettings ] = useState <
66
+ OrganizationSyncSettings | undefined
67
+ > ( organizationSyncSettings ) ;
68
+ console . log ( { organizationSyncSettings } ) ;
69
+ // const newMapping: Record<string, string[]> =
70
+ // organizationSyncSettings?.mapping !== undefined
71
+ // ? Object.entries(organizationSyncSettings.mapping).reduce(
72
+ // (acc, [key, value]) => {
73
+ // acc[key] = value as string[];
74
+ // return acc;
75
+ // },
76
+ // {} as Record<string, string[]>,
77
+ // )
78
+ // : {};
79
+ // console.log({ newMapping });
80
+ // const [mapping, setMapping] = useState<Record<string, readonly string[]>>(
81
+ // organizationSyncSettings?.mapping || {},
82
+ // );
83
+ // const [isChecked, setIsChecked] = useState(
84
+ // form.initialValues.organization_assign_default,
85
+ // );
86
+ // const organizationMappingCount = organizationSyncSettings?.mapping
87
+ // ? Object.entries(organizationSyncSettings.mapping).length
88
+ // : 0;
89
+ const organizationMappingCount = syncSettings ?. mapping
90
+ ? Object . entries ( syncSettings . mapping ) . length
70
91
: 0 ;
71
92
72
93
if ( error ) {
@@ -82,23 +103,40 @@ export const IdpSyncPageView: FC<IdpSyncPageViewProps> = ({
82
103
value : org . id ,
83
104
} ) ) ;
84
105
106
+ const getOrgNames = ( orgIds : readonly string [ ] ) => {
107
+ return orgIds . map (
108
+ ( orgId ) =>
109
+ organizations . find ( ( org ) => org . id === orgId ) ?. display_name || orgId ,
110
+ ) ;
111
+ } ;
112
+
85
113
return (
86
114
< >
87
115
< Stack spacing = { 2 } >
88
116
< form onSubmit = { form . handleSubmit } >
89
117
< Stack direction = "row" alignItems = "center" >
90
118
< TextField
91
119
{ ...getFieldHelpers ( "field" ) }
120
+ value = { syncSettings ?. field }
92
121
autoFocus
93
122
fullWidth
94
123
label = "Organization Sync Field"
95
124
className = "w-72"
125
+ onChange = { ( event : React . ChangeEvent < HTMLInputElement > ) => {
126
+ setSyncSettings ( {
127
+ ...( syncSettings as OrganizationSyncSettings ) ,
128
+ field : event . target . value ,
129
+ } ) ;
130
+ } }
96
131
/>
97
132
< Switch
98
133
id = "organization-assign-default"
99
- checked = { isChecked }
134
+ checked = { syncSettings ?. organization_assign_default }
100
135
onCheckedChange = { async ( checked ) => {
101
- setIsChecked ( checked ) ;
136
+ setSyncSettings ( {
137
+ ...( syncSettings as OrganizationSyncSettings ) ,
138
+ organization_assign_default : checked ,
139
+ } ) ;
102
140
await form . setFieldValue (
103
141
"organization_assign_default" ,
104
142
checked ,
@@ -115,15 +153,16 @@ export const IdpSyncPageView: FC<IdpSyncPageViewProps> = ({
115
153
justifyContent = "space-between"
116
154
css = { styles . tableInfo }
117
155
>
118
- { /* <ExportPolicyButton
119
- syncSettings={groupSyncSettings}
120
- organization={organization}
121
- type="groups"
122
- /> */ }
156
+ < ExportPolicyButton syncSettings = { syncSettings } />
123
157
</ Stack >
124
158
125
159
< div className = "flex flex-row py-10 gap-2 justify-between" >
126
160
< TextField
161
+ id = "idp-organization-name"
162
+ value = { idpOrgName }
163
+ onChange = { ( event : React . ChangeEvent < HTMLInputElement > ) => {
164
+ setIdpOrgName ( event . target . value ) ;
165
+ } }
127
166
autoFocus
128
167
fullWidth
129
168
label = "Idp organization name"
@@ -144,8 +183,18 @@ export const IdpSyncPageView: FC<IdpSyncPageViewProps> = ({
144
183
/>
145
184
< Button
146
185
className = "mt-px"
147
- onClick = { ( event ) => {
186
+ onClick = { ( ) => {
148
187
console . log ( "add Idp organization" ) ;
188
+
189
+ setSyncSettings ( {
190
+ ...( syncSettings as OrganizationSyncSettings ) ,
191
+ mapping : {
192
+ ...syncSettings ?. mapping ,
193
+ [ idpOrgName ] : coderOrgs . map ( ( org ) => org . value ) ,
194
+ } ,
195
+ } ) ;
196
+ setIdpOrgName ( "" ) ;
197
+ setCoderOrgs ( [ ] ) ;
149
198
} }
150
199
>
151
200
< Plus size = { 14 } />
@@ -155,14 +204,14 @@ export const IdpSyncPageView: FC<IdpSyncPageViewProps> = ({
155
204
156
205
< Stack spacing = { 6 } >
157
206
< IdpMappingTable isEmpty = { organizationMappingCount === 0 } >
158
- { organizationSyncSettings ?. mapping &&
159
- Object . entries ( organizationSyncSettings . mapping )
207
+ { syncSettings ?. mapping &&
208
+ Object . entries ( syncSettings . mapping )
160
209
. sort ( )
161
210
. map ( ( [ idpOrg , organizations ] ) => (
162
211
< OrganizationRow
163
212
key = { idpOrg }
164
213
idpOrg = { idpOrg }
165
- coderOrgs = { organizations }
214
+ coderOrgs = { getOrgNames ( organizations ) }
166
215
/>
167
216
) ) }
168
217
</ IdpMappingTable >
0 commit comments