Skip to content

Commit 9a795d6

Browse files
committed
add configuration file format radio buttons
See gh-1883 Signed-off-by: devysf <[email protected]>
1 parent 7bd3574 commit 9a795d6

File tree

6 files changed

+121
-44
lines changed

6 files changed

+121
-44
lines changed

start-client/dev/api.mock.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{
22
"_links": {
33
"maven-project": {
4-
"href": "https://start.spring.io/starter.zip?type=maven-project{&dependencies,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
4+
"href": "https://start.spring.io/starter.zip?type=maven-project{&dependencies,packaging,configurationFileFormat,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
55
"templated": true
66
},
77
"maven-build": {
8-
"href": "https://start.spring.io/pom.xml?type=maven-build{&dependencies,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
8+
"href": "https://start.spring.io/pom.xml?type=maven-build{&dependencies,packaging,configurationFileFormat,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
99
"templated": true
1010
},
1111
"gradle-project": {
12-
"href": "https://start.spring.io/starter.zip?type=gradle-project{&dependencies,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
12+
"href": "https://start.spring.io/starter.zip?type=gradle-project{&dependencies,packaging,configurationFileFormat,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
1313
"templated": true
1414
},
1515
"gradle-build": {
16-
"href": "https://start.spring.io/build.gradle?type=gradle-build{&dependencies,packaging,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
16+
"href": "https://start.spring.io/build.gradle?type=gradle-build{&dependencies,packaging,configurationFileFormat,javaVersion,language,bootVersion,groupId,artifactId,version,name,description,packageName}",
1717
"templated": true
1818
},
1919
"dependencies": {
@@ -1393,6 +1393,14 @@
13931393
{ "id": "war", "name": "War" }
13941394
]
13951395
},
1396+
"configurationFileFormat": {
1397+
"type": "single-select",
1398+
"default": "properties",
1399+
"values": [
1400+
{ "id": "properties", "name": "Properties" },
1401+
{ "id": "yaml", "name": "YAML" }
1402+
]
1403+
},
13961404
"javaVersion": {
13971405
"type": "single-select",
13981406
"default": "1.8",

start-client/src/components/common/builder/Fields.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ function Fields({
108108
</FieldError>
109109
)}
110110
</Control>
111+
<Control text='Configuration File Format'>
112+
<Radio
113+
name='configurationFileFormat'
114+
selected={get(values, 'configurationFileFormat')}
115+
options={get(config, 'lists.configurationFileFormat')}
116+
onChange={value => {
117+
update({ configurationFileFormat: value })
118+
}}
119+
/>
120+
</Control>
111121
<Control text='Project Metadata'>
112122
<FieldInput
113123
id='input-group'

start-client/src/components/reducer/Initializr.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const defaultInitializrContext = {
1010
project: '',
1111
language: '',
1212
boot: '',
13+
configurationFileFormat: '',
1314
meta: {
1415
name: '',
1516
group: '',
@@ -41,6 +42,8 @@ const getPersistedOrDefault = json => {
4142
language:
4243
localStorage.getItem('language') || get(json, 'defaultValues').language,
4344
boot: get(json, 'defaultValues').boot,
45+
configurationFileFormat:
46+
localStorage.getItem('configurationFileFormat') || get(json, 'defaultValues').configurationFileFormat,
4447
meta: {
4548
name: get(json, 'defaultValues.meta').name,
4649
group: get(json, 'defaultValues.meta').group,
@@ -55,7 +58,7 @@ const getPersistedOrDefault = json => {
5558
},
5659
dependencies: [],
5760
}
58-
const checks = ['project', 'language', 'meta.java', 'meta.packaging']
61+
const checks = ['project', 'language', 'meta.java', 'meta.packaging', 'configurationFileFormat',]
5962
checks.forEach(key => {
6063
const item = get(json, `lists.${key}`)?.find(
6164
it => it.key === get(values, key)
@@ -80,6 +83,9 @@ const persist = changes => {
8083
if (get(changes, 'meta.java')) {
8184
localStorage.setItem('java', get(changes, 'meta.java'))
8285
}
86+
if (get(changes, 'configurationFileFormat')) {
87+
localStorage.setItem('configurationFileFormat', get(changes, 'configurationFileFormat'))
88+
}
8389
}
8490

8591
export function reducer(state, action) {

start-client/src/components/reducer/__tests__/Initializr.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ describe('COMPLETE action', () => {
2323
project: '',
2424
language: '',
2525
boot: '',
26+
configurationFileFormat: '',
2627
meta: {
2728
name: '',
2829
group: '',
@@ -47,7 +48,7 @@ describe('COMPLETE action', () => {
4748
},
4849
})
4950
expect(get(result, 'share')).toBe(
50-
'type=maven-project&language=java&platformVersion=2.2.0.RELEASE&packaging=jar&jvmVersion=1.8&groupId=com.example&artifactId=demo&name=demo&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.demo&dependencies='
51+
'type=maven-project&language=java&platformVersion=2.2.0.RELEASE&packaging=jar&configurationFileFormat=properties&jvmVersion=1.8&groupId=com.example&artifactId=demo&name=demo&description=Demo%20project%20for%20Spring%20Boot&packageName=com.example.demo&dependencies='
5152
)
5253
expect(get(result, 'values.project')).toBe('maven-project')
5354
expect(get(result, 'values.language')).toBe('java')
@@ -181,6 +182,15 @@ describe('UPDATE action', () => {
181182
})
182183
expect(get(result, 'values.meta.packaging')).toBe('war')
183184
})
185+
it('should reduce the state (configuration file format)', () => {
186+
const result = reducer(state, {
187+
type: 'UPDATE',
188+
payload: {
189+
configurationFileFormat: 'yaml',
190+
},
191+
})
192+
expect(get(result, 'values.configurationFileFormat')).toBe('yaml')
193+
})
184194
it('should reduce the state (meta packageName)', () => {
185195
const result = reducer(state, {
186196
type: 'UPDATE',
@@ -217,6 +227,7 @@ describe('LOAD action', () => {
217227
description: 'Demo1 project for Spring Boot',
218228
groupId: 'com.example1',
219229
jvmVersion: '1.8',
230+
configurationFileFormat: 'yaml',
220231
language: 'java',
221232
name: 'demo1',
222233
packageName: 'com.example1.demo1',
@@ -239,6 +250,7 @@ describe('LOAD action', () => {
239250
expect(get(result, 'values.meta.packaging')).toBe('war')
240251
expect(get(result, 'values.meta.packageName')).toBe('com.example1.demo1')
241252
expect(get(result, 'values.meta.java')).toBe('1.8')
253+
expect(get(result, 'values.configurationFileFormat')).toBe('yaml')
242254
expect(get(result, 'values.dependencies').length).toBe(0)
243255
expect(Object.keys(get(result, 'errors')).length).toBe(0)
244256
expect(Object.keys(get(result, 'warnings')).length).toBe(0)

start-client/src/components/utils/ApiUtils.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const PROPERTIES_MAPPING_URL = {
1010
language: 'language',
1111
platformVersion: 'boot',
1212
packaging: 'meta.packaging',
13+
configurationFileFormat: 'configurationFileFormat',
1314
jvmVersion: 'meta.java',
1415
groupId: 'meta.group',
1516
artifactId: 'meta.artifact',
@@ -24,7 +25,7 @@ export const getInfo = function getInfo(url) {
2425
fetch(`${url}`, {
2526
method: 'GET',
2627
headers: {
27-
Accept: 'application/vnd.initializr.v2.2+json',
28+
Accept: 'application/vnd.initializr.v2.3+json',
2829
},
2930
})
3031
.then(
@@ -82,6 +83,7 @@ export const parseParams = (values, queryParams, lists) => {
8283
case 'project':
8384
case 'language':
8485
case 'meta.packaging':
86+
case 'configurationFileFormat':
8587
case 'meta.java': {
8688
const list = get(lists, key, [])
8789
const res = list.find(a => a.key.toLowerCase() === value)
@@ -229,6 +231,10 @@ export const getLists = json => {
229231
text: `${packaging.name}`,
230232
})),
231233
},
234+
configurationFileFormat: get(json, 'configurationFileFormat.values', []).map(configurationFileFormat => ({
235+
key: `${configurationFileFormat.id}`,
236+
text: `${configurationFileFormat.name}`,
237+
})),
232238
dependencies: deps,
233239
}
234240
}
@@ -238,6 +244,7 @@ export const getDefaultValues = json => {
238244
project: get(json, 'type.default'),
239245
language: get(json, 'language.default'),
240246
boot: get(json, 'bootVersion.default'),
247+
configurationFileFormat: get(json, 'configurationFileFormat.default') || 'properties',
241248
meta: {
242249
name: get(json, 'name.default'),
243250
group: get(json, 'groupId.default'),
@@ -281,6 +288,7 @@ export const getProject = function getProject(url, values, config) {
281288
packageName: get(values, 'meta.packageName'),
282289
packaging: get(values, 'meta.packaging'),
283290
javaVersion: get(values, 'meta.java'),
291+
configurationFileFormat: get(values, 'configurationFileFormat'),
284292
})
285293
let paramsDependencies = get(values, 'dependencies', [])
286294
.map(dependency => {

0 commit comments

Comments
 (0)