Skip to content

Commit 3b2fd15

Browse files
committed
formatted
1 parent f8d6e34 commit 3b2fd15

File tree

3 files changed

+72
-53
lines changed

3 files changed

+72
-53
lines changed

src/oauth2-client-editor/ClientForm.js

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,85 +27,86 @@ const validateClientID = async (v) => {
2727
const ClientForm = ({ clientModel, onUpdate, onSave, onCancel }) => {
2828
const [formErrors, setFormErrors] = useState({
2929
clientId: false,
30-
redirectUris: false
31-
});
30+
redirectUris: false,
31+
})
3232

3333
// Handle both string and array types for authorizationGrantTypes
34-
let authGrantTypesArray = [];
34+
let authGrantTypesArray = []
3535

3636
if (clientModel && clientModel.authorizationGrantTypes) {
3737
// If it's a string (from backend), split it
3838
if (typeof clientModel.authorizationGrantTypes === 'string') {
3939
authGrantTypesArray = clientModel.authorizationGrantTypes
4040
.split(',')
41-
.map(type => type.trim())
42-
.filter(Boolean);
41+
.map((type) => type.trim())
42+
.filter(Boolean)
4343
}
4444
// If it's already an array (from form update)
4545
else if (Array.isArray(clientModel.authorizationGrantTypes)) {
46-
authGrantTypesArray = clientModel.authorizationGrantTypes;
46+
authGrantTypesArray = clientModel.authorizationGrantTypes
4747
}
4848
}
4949

50-
const grantTypes = authGrantTypesArray.reduce(
51-
(curr, prev) => {
52-
curr[prev] = true
53-
return curr
54-
},
55-
{}
56-
)
50+
const grantTypes = authGrantTypesArray.reduce((curr, prev) => {
51+
curr[prev] = true
52+
return curr
53+
}, {})
5754

5855
// Format redirectUris for display in the form
59-
let formattedRedirectUris = '';
56+
let formattedRedirectUris = ''
6057
if (clientModel && clientModel.redirectUris) {
6158
if (Array.isArray(clientModel.redirectUris)) {
6259
// If it's an array, join with newlines for display
63-
formattedRedirectUris = clientModel.redirectUris.join('\n');
60+
formattedRedirectUris = clientModel.redirectUris.join('\n')
6461
} else if (typeof clientModel.redirectUris === 'string') {
6562
// If it's a comma-separated string, replace commas with newlines for display
66-
formattedRedirectUris = clientModel.redirectUris.split(',')
67-
.map(uri => uri.trim())
63+
formattedRedirectUris = clientModel.redirectUris
64+
.split(',')
65+
.map((uri) => uri.trim())
6866
.filter(Boolean)
69-
.join('\n');
67+
.join('\n')
7068
}
7169
}
7270

7371
const handleSave = () => {
7472
// Check fields and show errors if needed
75-
const clientIdEmpty = !clientModel.clientId || clientModel.clientId.trim() === '';
76-
const redirectUrisEmpty = !formattedRedirectUris || formattedRedirectUris.trim() === '';
73+
const clientIdEmpty =
74+
!clientModel.clientId || clientModel.clientId.trim() === ''
75+
const redirectUrisEmpty =
76+
!formattedRedirectUris || formattedRedirectUris.trim() === ''
7777

7878
setFormErrors({
7979
clientId: clientIdEmpty,
80-
redirectUris: redirectUrisEmpty
81-
});
80+
redirectUris: redirectUrisEmpty,
81+
})
8282

8383
// Only save if both fields are valid
8484
if (!clientIdEmpty && !redirectUrisEmpty) {
85-
onSave();
85+
onSave()
8686
}
87-
};
87+
}
8888

8989
// Handle field updates and clear errors
9090
const handleFieldUpdate = (fieldName, value) => {
9191
// Clear the error for this field if it has a value
9292
if (value) {
9393
// Check if value is a string before using trim()
94-
const isValid = typeof value === 'string'
95-
? value.trim().length > 0
96-
: Boolean(value);
94+
const isValid =
95+
typeof value === 'string'
96+
? value.trim().length > 0
97+
: Boolean(value)
9798

9899
if (isValid) {
99-
setFormErrors(prev => ({
100+
setFormErrors((prev) => ({
100101
...prev,
101-
[fieldName]: false
102-
}));
102+
[fieldName]: false,
103+
}))
103104
}
104105
}
105106

106107
// Call the original onUpdate function
107-
onUpdate(fieldName, value);
108-
};
108+
onUpdate(fieldName, value)
109+
}
109110

110111
const fields = [
111112
{
@@ -170,7 +171,9 @@ const ClientForm = ({ clientModel, onUpdate, onSave, onCancel }) => {
170171
multiLine: true,
171172
style: formFieldStyle,
172173
changeEvent: 'onBlur',
173-
errorText: formErrors.redirectUris ? i18n.t('This field should contain a list of URLs') : null,
174+
errorText: formErrors.redirectUris
175+
? i18n.t('This field should contain a list of URLs')
176+
: null,
174177
},
175178
validators: [
176179
{

src/oauth2-client-editor/OAuth2ClientEditor.component.js

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -77,30 +77,38 @@ class OAuth2ClientEditor extends Component {
7777

7878
saveAction = () => {
7979
// Validation is now handled in the ClientForm component
80-
80+
8181
this.clientModel.name = this.clientModel.name || ''
8282
this.clientModel.cid = this.clientModel.cid || ''
83-
83+
8484
// Ensure authorizationGrantTypes is a comma-separated string
85-
if (this.clientModel.authorizationGrantTypes && Array.isArray(this.clientModel.authorizationGrantTypes)) {
86-
this.clientModel.authorizationGrantTypes = this.clientModel.authorizationGrantTypes.join(',')
85+
if (
86+
this.clientModel.authorizationGrantTypes &&
87+
Array.isArray(this.clientModel.authorizationGrantTypes)
88+
) {
89+
this.clientModel.authorizationGrantTypes =
90+
this.clientModel.authorizationGrantTypes.join(',')
8791
}
88-
92+
8993
// First ensure redirectUris is an array
90-
if (this.clientModel.redirectUris && typeof this.clientModel.redirectUris === 'string') {
94+
if (
95+
this.clientModel.redirectUris &&
96+
typeof this.clientModel.redirectUris === 'string'
97+
) {
9198
this.clientModel.redirectUris = this.clientModel.redirectUris
9299
.split('\n')
93-
.map(uri => uri.trim())
100+
.map((uri) => uri.trim())
94101
.filter(Boolean)
95102
} else if (!this.clientModel.redirectUris) {
96103
this.clientModel.redirectUris = []
97104
}
98-
105+
99106
// Then convert the array to a comma-separated string
100107
if (Array.isArray(this.clientModel.redirectUris)) {
101-
this.clientModel.redirectUris = this.clientModel.redirectUris.join(',')
108+
this.clientModel.redirectUris =
109+
this.clientModel.redirectUris.join(',')
102110
}
103-
111+
104112
this.setState({ saving: true })
105113
this.clientModel
106114
.save()
@@ -128,16 +136,17 @@ class OAuth2ClientEditor extends Component {
128136
if (field === 'redirectUris') {
129137
if (typeof v === 'string') {
130138
// Convert newline-separated string to array, then to comma-separated string
131-
const uriArray = v.split('\n')
132-
.map(uri => uri.trim())
133-
.filter(Boolean);
134-
value = uriArray.join(',');
139+
const uriArray = v
140+
.split('\n')
141+
.map((uri) => uri.trim())
142+
.filter(Boolean)
143+
value = uriArray.join(',')
135144
} else if (Array.isArray(v)) {
136145
// If it's already an array, convert to comma-separated string
137-
value = v.join(',');
146+
value = v.join(',')
138147
} else {
139148
// Default to empty string
140-
value = '';
149+
value = ''
141150
}
142151
}
143152
if (field === 'authorizationGrantTypes' && Array.isArray(v)) {

src/oauth2-client-editor/oauth2Client.actions.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,24 @@ oa2Actions.load.subscribe(() => {
1717
oa2Store.setState(
1818
oa2ClientCollection.toArray().map((oa2c) => {
1919
// Ensure redirectUris is a string, not an array
20-
if (oa2c.redirectUris && Array.isArray(oa2c.redirectUris)) {
20+
if (
21+
oa2c.redirectUris &&
22+
Array.isArray(oa2c.redirectUris)
23+
) {
2124
oa2c.redirectUris = oa2c.redirectUris.join(',')
2225
}
23-
26+
2427
return Object.assign(oa2c, {
2528
refresh_token:
26-
oa2c.authorizationGrantTypes && oa2c.authorizationGrantTypes.indexOf('refresh_token') !== -1
29+
oa2c.authorizationGrantTypes &&
30+
oa2c.authorizationGrantTypes.indexOf(
31+
'refresh_token'
32+
) !== -1
2733
? yes
2834
: no,
2935
authorization_code:
30-
oa2c.authorizationGrantTypes && oa2c.authorizationGrantTypes.indexOf(
36+
oa2c.authorizationGrantTypes &&
37+
oa2c.authorizationGrantTypes.indexOf(
3138
'authorization_code'
3239
) !== -1
3340
? yes

0 commit comments

Comments
 (0)