Skip to content

Commit 3b04776

Browse files
committed
Added the ability to define possible values for settings, defined a set of possible values for the "Pluse Email Frequency" and use those on the client side to render a drop-down.
1 parent 437283b commit 3b04776

File tree

6 files changed

+50
-18
lines changed

6 files changed

+50
-18
lines changed

server/src/main/java/com/objectcomputing/checkins/services/settings/SettingOption.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,26 @@
1616
@JsonDeserialize(using = SettingOptionDeserializer.class)
1717
public enum SettingOption {
1818
LOGO_URL("The logo url", Category.THEME, Type.FILE),
19-
PULSE_EMAIL_FREQUENCY("The Pulse Email Frequency (weekly, bi-weekly, monthly)", Category.CHECK_INS, Type.STRING);
19+
PULSE_EMAIL_FREQUENCY("The Pulse Email Frequency", Category.CHECK_INS, Type.STRING, List.of("weekly", "bi-weekly", "monthly"));
2020

2121
private final String description;
2222
private final Category category;
2323
private final Type type;
24+
private final List<String> values;
2425

2526
SettingOption(String description, Category category, Type type) {
2627
this.description = description;
2728
this.category = category;
2829
this.type = type;
30+
this.values = List.of();
2931
}
3032

31-
public String getDescription() {
32-
return description;
33-
}
34-
35-
public Category getCategory() {
36-
return category;
37-
}
38-
39-
public Type getType() {
40-
return type;
33+
SettingOption(String description, Category category, Type type,
34+
List<String> values) {
35+
this.description = description;
36+
this.category = category;
37+
this.type = type;
38+
this.values = values;
4139
}
4240

4341
public static List<SettingOption> getOptions(){

server/src/main/java/com/objectcomputing/checkins/services/settings/SettingOptionSerializer.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
66

77
import java.io.IOException;
8+
import java.util.List;
89

910
public class SettingOptionSerializer extends StdSerializer<SettingOption> {
1011

@@ -28,6 +29,15 @@ public void serialize(
2829
generator.writeString(settingOption.getCategory().name());
2930
generator.writeFieldName("type");
3031
generator.writeString(settingOption.getType().name());
32+
List<String> values = settingOption.getValues();
33+
if (!values.isEmpty()) {
34+
generator.writeFieldName("values");
35+
generator.writeStartArray(values.size());
36+
for(String value : values) {
37+
generator.writeString(value);
38+
}
39+
generator.writeEndArray();
40+
}
3141
generator.writeEndObject();
3242
}
33-
}
43+
}

server/src/main/java/com/objectcomputing/checkins/services/settings/SettingsController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,8 @@ public SettingsResponseDTO findByName(@PathVariable @NotNull String name) {
7676
public List<SettingsResponseDTO> getOptions() {
7777
List<SettingOption> options = SettingOption.getOptions();
7878
return options.stream().map(option -> {
79-
// Default to an empty value and "invalid" UUID.
80-
// This can be used by the client to determine pre-existance.
8179
String value = "";
82-
UUID uuid = new UUID(0, 0);
80+
UUID uuid = null;
8381
try {
8482
Setting s = settingsServices.findByName(option.name());
8583
uuid = s.getId();
@@ -89,6 +87,7 @@ public List<SettingsResponseDTO> getOptions() {
8987
return new SettingsResponseDTO(
9088
uuid, option.name(), option.getDescription(),
9189
option.getCategory(), option.getType(),
90+
option.getValues(),
9291
value);
9392
}).toList();
9493
}
@@ -150,6 +149,7 @@ private SettingsResponseDTO fromEntity(Setting entity) {
150149
dto.setDescription(option.getDescription());
151150
dto.setCategory(option.getCategory());
152151
dto.setType(option.getType());
152+
dto.setValues(option.getValues());
153153
dto.setValue(entity.getValue());
154154
return dto;
155155
}

server/src/main/java/com/objectcomputing/checkins/services/settings/SettingsResponseDTO.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import lombok.Setter;
1010

1111
import java.util.UUID;
12+
import java.util.List;
1213

1314
@Setter
1415
@Getter
@@ -36,6 +37,10 @@ public class SettingsResponseDTO {
3637
@Schema(description = "type of the setting")
3738
private SettingOption.Type type;
3839

40+
@NotNull
41+
@Schema(description = "possible values for the setting")
42+
private List<String> values;
43+
3944
@NotBlank
4045
@Schema(description = "value of the setting")
4146
private String value;

web-ui/src/components/settings/types/string.jsx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import React from 'react';
2-
import { Input, Typography } from '@mui/material';
2+
import {
3+
Select,
4+
MenuItem,
5+
ListItemText,
6+
Input,
7+
Typography
8+
} from '@mui/material';
39
import { createLabelId } from '../../../helpers/strings.js';
410

511
/**
@@ -17,6 +23,7 @@ import { createLabelId } from '../../../helpers/strings.js';
1723
const SettingsString = ({
1824
name,
1925
description,
26+
values,
2027
value,
2128
placeholder,
2229
handleChange
@@ -31,14 +38,26 @@ const SettingsString = ({
3138
</Typography>
3239
</label>
3340
{description && <p>{description}</p>}
41+
{values && values.length > 0 ?
42+
<Select
43+
labelId={labelId}
44+
value={value}
45+
onChange={handleChange}
46+
>
47+
{values.map((option) => (
48+
<MenuItem key={option} value={option}>
49+
<ListItemText primary={option} />
50+
</MenuItem>
51+
))}
52+
</Select> :
3453
<Input
3554
id={labelId}
3655
className="settings-control"
3756
type="text"
3857
value={value}
3958
placeholder={placeholder ?? `Enter ${name}`}
4059
onChange={handleChange}
41-
/>
60+
/>}
4261
</div>
4362
);
4463
};

web-ui/src/pages/SettingsPage.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const SettingsPage = () => {
4848
// This information is necessary to know since we must use POST to
4949
// create new settings and PUT to modify existing settings.
5050
for (let option of allOptions) {
51-
option.exists = option?.id != '00000000-0000-0000-0000-000000000000';
51+
option.exists = option?.id != null;
5252
}
5353
}
5454

0 commit comments

Comments
 (0)