Skip to content

Commit 07e09bd

Browse files
committed
Added the ability to mark guilds as inactive and filter the display based on that flag.
1 parent 2e4bac3 commit 07e09bd

File tree

10 files changed

+81
-88
lines changed

10 files changed

+81
-88
lines changed

server/src/main/java/com/objectcomputing/checkins/services/guild/Guild.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,22 @@ public class Guild {
6464
@Schema(description = "Is the guild a community")
6565
private boolean community;
6666

67-
public Guild(String name, @Nullable String description, @Nullable String link, boolean community) {
68-
this(null, name, description, link, community);
67+
@NotNull
68+
@Column(name = "is_active")
69+
@Schema(description = "whether the guild is active")
70+
private boolean active = true;
71+
72+
public Guild(String name, @Nullable String description, @Nullable String link, boolean community, boolean active) {
73+
this(null, name, description, link, community, active);
6974
}
7075

71-
public Guild(UUID id, String name, @Nullable String description, @Nullable String link, boolean community) {
76+
public Guild(UUID id, String name, @Nullable String description, @Nullable String link, boolean community, boolean active) {
7277
this.id = id;
7378
this.name = name;
7479
this.description = description;
7580
this.link = link;
7681
this.community = community;
82+
this.active = active;
7783
}
7884

7985
@Override
@@ -85,13 +91,14 @@ public boolean equals(Object o) {
8591
Objects.equals(name, guild.name) &&
8692
Objects.equals(description, guild.description) &&
8793
Objects.equals(link, guild.link) &&
88-
Objects.equals(community, guild.community);
94+
Objects.equals(community, guild.community) &&
95+
Objects.equals(active, guild.active);
8996

9097
}
9198

9299
@Override
93100
public int hashCode() {
94-
return Objects.hash(id, name, description, link, community);
101+
return Objects.hash(id, name, description, link, community, active);
95102
}
96103

97104
@Override
@@ -102,6 +109,7 @@ public String toString() {
102109
", description='" + description + '\'' +
103110
", link='" + link +
104111
", community=" + community +
112+
", active=" + active +
105113
'}';
106114
}
107115
}

server/src/main/java/com/objectcomputing/checkins/services/guild/GuildCreateDTO.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,16 @@ public class GuildCreateDTO {
3636
@Schema(description = "Is the guild a community")
3737
private boolean community;
3838

39-
public GuildCreateDTO(String name, @Nullable String description, @Nullable String link, boolean community) {
39+
@NotNull
40+
@Schema(description = "whether the guild is active")
41+
private boolean active;
42+
43+
public GuildCreateDTO(String name, @Nullable String description, @Nullable String link, boolean community, boolean active) {
4044
this.name = name;
4145
this.description = description;
4246
this.link =link;
4347
this.community = community;
48+
this.active = active;
4449
}
4550

4651
@Data

server/src/main/java/com/objectcomputing/checkins/services/guild/GuildRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public interface GuildRepository extends CrudRepository<Guild, UUID> {
2929
@Query(value = "SELECT t_.id, PGP_SYM_DECRYPT(cast(t_.name as bytea),'${aes.key}') as name, " +
3030
"PGP_SYM_DECRYPT(cast(description as bytea),'${aes.key}') as description, " +
3131
"PGP_SYM_DECRYPT(cast(link as bytea),'${aes.key}') as link, " +
32-
"t_.community as community " +
32+
"t_.community as community, is_active " +
3333
"FROM guild t_ " +
3434
"LEFT JOIN guild_member tm_ " +
3535
" ON t_.id = tm_.guildid " +

server/src/main/java/com/objectcomputing/checkins/services/guild/GuildResponseDTO.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,17 @@ public class GuildResponseDTO {
4040
@Schema(description = "Is the guild a community")
4141
private boolean community;
4242

43-
public GuildResponseDTO(UUID id, String name, @Nullable String description, @Nullable String link, boolean community) {
43+
@NotNull
44+
@Schema(description = "whether the guild is active")
45+
private boolean active;
46+
47+
public GuildResponseDTO(UUID id, String name, @Nullable String description, @Nullable String link, boolean community, boolean active) {
4448
this.id = id;
4549
this.name = name;
4650
this.description = description;
4751
this.link = link;
4852
this.community = community;
53+
this.active = active;
4954
}
5055

5156
public List<GuildMemberResponseDTO> getGuildMembers() {

server/src/main/java/com/objectcomputing/checkins/services/guild/GuildServicesImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ private Guild fromDTO(GuildUpdateDTO dto) {
252252
if (dto == null) {
253253
return null;
254254
}
255-
return new Guild(dto.getId(), dto.getName(), dto.getDescription(), dto.getLink(), dto.isCommunity());
255+
return new Guild(dto.getId(), dto.getName(), dto.getDescription(), dto.getLink(), dto.isCommunity(), dto.isActive());
256256
}
257257

258258
private GuildMember fromMemberDTO(GuildCreateDTO.GuildMemberCreateDTO memberDTO, UUID guildId) {
@@ -276,7 +276,7 @@ private GuildResponseDTO fromEntity(Guild entity, List<GuildMemberResponseDTO> m
276276
return null;
277277
}
278278
GuildResponseDTO dto = new GuildResponseDTO(entity.getId(), entity.getName(), entity.getDescription(),
279-
entity.getLink(), entity.isCommunity());
279+
entity.getLink(), entity.isCommunity(), entity.isActive());
280280
dto.setGuildMembers(memberEntities);
281281
return dto;
282282
}
@@ -285,7 +285,7 @@ private Guild fromDTO(GuildCreateDTO dto) {
285285
if (dto == null) {
286286
return null;
287287
}
288-
return new Guild(null, dto.getName(), dto.getDescription(), dto.getLink(), dto.isCommunity());
288+
return new Guild(null, dto.getName(), dto.getDescription(), dto.getLink(), dto.isCommunity(), dto.isActive());
289289
}
290290

291291
private GuildMemberResponseDTO fromMemberEntity(GuildMember guildMember, MemberProfile memberProfile) {

server/src/main/java/com/objectcomputing/checkins/services/guild/GuildUpdateDTO.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,21 @@ public class GuildUpdateDTO {
3737
@Schema(description = "Is the guild a community")
3838
private boolean community;
3939

40-
public GuildUpdateDTO(UUID id, String name, @Nullable String description, @Nullable String link, boolean community) {
40+
@NotNull
41+
@Schema(description = "whether the guild is active")
42+
private boolean active;
43+
44+
public GuildUpdateDTO(UUID id, String name, @Nullable String description, @Nullable String link, boolean community, boolean active) {
4145
this.id = id;
4246
this.name = name;
4347
this.description = description;
4448
this.link = link;
4549
this.community = community;
50+
this.active = active;
4651
}
4752

48-
public GuildUpdateDTO(String id, String name, String description, @Nullable String link, boolean community) {
49-
this(nullSafeUUIDFromString(id), name, description, link, community);
53+
public GuildUpdateDTO(String id, String name, String description, @Nullable String link, boolean community, boolean active) {
54+
this(nullSafeUUIDFromString(id), name, description, link, community, active);
5055
}
5156

5257
public GuildUpdateDTO() {
@@ -75,4 +80,4 @@ public GuildMemberUpdateDTO(UUID id, UUID memberId, Boolean lead) {
7580
this.lead = lead;
7681
}
7782
}
78-
}
83+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE guild ADD COLUMN is_active BOOLEAN DEFAULT TRUE;

web-ui/src/components/guild-results/EditGuildModal.jsx

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,29 @@ const EditGuildModal = ({ guild = {}, open, onSave, onClose, headerText }) => {
156156
<Modal open={open} onClose={close} aria-labelledby="edit-guild-modal-title">
157157
<div className="EditGuildModal">
158158
<h2>{headerText}</h2>
159-
<TextField
160-
id="guild-name-input"
161-
label="Guild Name"
162-
required
163-
className="halfWidth"
164-
placeholder="Awesome Guild"
165-
value={editedGuild.name ? editedGuild.name : ''}
166-
onChange={e => setGuild({ ...editedGuild, name: e.target.value })}
167-
/>
159+
<div>
160+
<TextField
161+
id="guild-name-input"
162+
label="Guild Name"
163+
required
164+
className="halfWidth"
165+
placeholder="Awesome Guild"
166+
value={editedGuild.name ? editedGuild.name : ''}
167+
onChange={e => setGuild({ ...editedGuild, name: e.target.value })}
168+
/>
169+
{guild.id && <FormControlLabel
170+
control={
171+
<Switch
172+
checked={editedGuild.active}
173+
onChange={event => {
174+
const { checked } = event.target;
175+
setGuild({ ...editedGuild, active: checked });
176+
}}
177+
/>
178+
}
179+
label="Active"
180+
/>}
181+
</div>
168182
<div>
169183
<FormControlLabel
170184
control={

web-ui/src/components/guild-results/GuildResults.jsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import PropTypes from 'prop-types';
22
import React, { useContext, useState } from 'react';
33
import GroupIcon from '@mui/icons-material/Group';
4-
import { Button, TextField } from '@mui/material';
4+
import { FormControlLabel, Switch, Button, TextField } from '@mui/material';
55
import { styled } from '@mui/material/styles';
66

77
import { createGuild, getGuildLeaders } from '../../api/guild';
@@ -42,6 +42,7 @@ const GuildResults = () => {
4242
const [addOpen, setAddOpen] = useState(false);
4343
const [openedGuildId, setOpenedGuildId] = useState('');
4444
const [searchText, setSearchText] = useState('');
45+
const [activeGuilds, setActiveGuilds] = useState(true);
4546

4647
useQueryParameters([
4748
{
@@ -93,6 +94,7 @@ const GuildResults = () => {
9394
onClose={handleClose}
9495
onSave={async guild => {
9596
if (csrf) {
97+
guild.active = true;
9698
const res = await createGuild(guild, csrf);
9799
const data =
98100
res.payload?.data && !res.error ? res.payload.data : null;
@@ -110,12 +112,25 @@ const GuildResults = () => {
110112
/>
111113
</>
112114
)}
115+
<FormControlLabel
116+
control={
117+
<Switch
118+
checked={activeGuilds}
119+
onChange={event => {
120+
const { checked } = event.target;
121+
setActiveGuilds(checked);
122+
}}
123+
/>
124+
}
125+
label="Active Guilds Only"
126+
/>
113127
</div>
114128
</div>
115129
<div className="guilds">
116130
{guilds
117131
? guilds.map((guild, index) =>
118-
guild.name.toLowerCase().includes(searchText.toLowerCase()) ? (
132+
guild.name.toLowerCase().includes(searchText.toLowerCase()) &&
133+
((activeGuilds && guild.active) || !activeGuilds) ? (
119134
<GuildSummaryCard
120135
key={`guild-summary-${guild.id}`}
121136
index={index}

web-ui/src/components/guild-results/GuildSummaryCard.jsx

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import {
2323
Tooltip
2424
} from '@mui/material';
2525
import PropTypes from 'prop-types';
26-
import { deleteGuild, updateGuild } from '../../api/guild.js';
27-
import SplitButton from '../split-button/SplitButton';
26+
import { updateGuild } from '../../api/guild.js';
2827

2928
const PREFIX = 'GuildSummaryCard';
3029
const classes = {
@@ -69,7 +68,6 @@ const GuildSummaryCard = ({ guild, index, isOpen, onGuildSelect }) => {
6968
const { state, dispatch } = useContext(AppContext);
7069
const { guilds, userProfile, csrf } = state;
7170
const [open, setOpen] = useState(isOpen);
72-
const [openDelete, setOpenDelete] = useState(false);
7371
const [tooltipIsOpen, setTooltipIsOpen] = useState(false);
7472
const isAdmin =
7573
userProfile && userProfile.role && userProfile.role.includes('ADMIN');
@@ -97,43 +95,6 @@ const GuildSummaryCard = ({ guild, index, isOpen, onGuildSelect }) => {
9795
onGuildSelect('');
9896
};
9997

100-
const handleOpenDeleteConfirmation = () => setOpenDelete(true);
101-
const handleCloseDeleteConfirmation = () => setOpenDelete(false);
102-
103-
const guildId = guild?.id;
104-
const deleteAGuild = useCallback(async () => {
105-
if (guildId && csrf) {
106-
const result = await deleteGuild(guildId, csrf);
107-
if (result && result.payload && result.payload.status === 200) {
108-
window.snackDispatch({
109-
type: UPDATE_TOAST,
110-
payload: {
111-
severity: 'success',
112-
toast: 'Guild deleted'
113-
}
114-
});
115-
let newGuilds = guilds.filter(guild => {
116-
return guild.id !== guildId;
117-
});
118-
dispatch({
119-
type: UPDATE_GUILDS,
120-
payload: newGuilds
121-
});
122-
}
123-
}
124-
}, [guildId, csrf, dispatch, guilds]);
125-
126-
const options =
127-
isAdmin || isGuildLead ? ['Edit Guild', 'Delete Guild'] : ['Edit Guild'];
128-
129-
const handleAction = (e, index) => {
130-
if (index === 0) {
131-
handleOpen();
132-
} else if (index === 1) {
133-
handleOpenDeleteConfirmation();
134-
}
135-
};
136-
13798
const iconStyles = {
13899
position: 'absolute',
139100
bottom: '0.5rem',
@@ -232,28 +193,7 @@ const GuildSummaryCard = ({ guild, index, isOpen, onGuildSelect }) => {
232193
<CardActions>
233194
{(isAdmin || isGuildLead) && (
234195
<>
235-
<SplitButton options={options} onClick={handleAction} />
236-
<Dialog
237-
open={openDelete}
238-
onClose={handleCloseDeleteConfirmation}
239-
aria-labelledby="alert-dialog-title"
240-
aria-describedby="alert-dialog-description"
241-
>
242-
<DialogTitle id="alert-dialog-title">Delete guild?</DialogTitle>
243-
<DialogContent>
244-
<DialogContentText id="alert-dialog-description">
245-
Are you sure you want to delete the guild?
246-
</DialogContentText>
247-
</DialogContent>
248-
<DialogActions>
249-
<Button onClick={handleCloseDeleteConfirmation} color="primary">
250-
Cancel
251-
</Button>
252-
<Button onClick={deleteAGuild} color="primary" autoFocus>
253-
Yes
254-
</Button>
255-
</DialogActions>
256-
</Dialog>
196+
<Button onClick={handleOpen}>Edit Guild</Button>
257197
</>
258198
)}
259199
</CardActions>

0 commit comments

Comments
 (0)