Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion web-ui/src/components/guild-results/EditGuildModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ const EditGuildModal = ({ guild = {}, open, onSave, onClose, headerText }) => {
? editedGuild.guildMembers.filter(guildMember => guildMember.lead)
: []
}
isOptionEqualToValue={(option, value) =>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prop was missing and I think it is required to compare options to the selected value, just like it is used in the next AutoComplete.

value && option.id === value.memberId
}
onChange={onLeadsChange}
getOptionLabel={option => option.name}
renderInput={params => (
Expand All @@ -211,7 +214,7 @@ const EditGuildModal = ({ guild = {}, open, onSave, onClose, headerText }) => {
onChange={onGuildMembersChange}
getOptionLabel={option => option.name}
isOptionEqualToValue={(option, value) =>
value ? value.id === option.id : false
value && option.id === value.memberId
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure we want to compare against the memberId property in the value object rather than the id property.

}
renderInput={params => (
<TextField
Expand Down
81 changes: 71 additions & 10 deletions web-ui/src/components/guild-results/GuildResults.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import React, { useContext, useState } from 'react';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reordered some of the imports.


import PropTypes from 'prop-types';
import React, { useContext, useEffect, useState } from 'react';
import GroupIcon from '@mui/icons-material/Group';
import { Button, TextField } from '@mui/material';
import { styled } from '@mui/material/styles';
import GuildSummaryCard from './GuildSummaryCard';

import { createGuild } from '../../api/guild';
import { ADD_GUILD } from '../../context/actions';
import { AppContext } from '../../context/AppContext';
import GuildsActions from './GuildsActions';
import PropTypes from 'prop-types';
import { TextField } from '@mui/material';
import './GuildResults.css';
import AddGuildModal from './EditGuildModal';
import GuildSummaryCard from './GuildSummaryCard';
import SkeletonLoader from '../skeleton_loader/SkeletonLoader';
import { useQueryParameters } from '../../helpers/query-parameters';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a new import.

import './GuildResults.css';

const PREFIX = 'GuildResults';
const classes = {
Expand All @@ -33,10 +37,39 @@ const propTypes = {
const displayName = 'GuildResults';

const GuildResults = () => {
const { state } = useContext(AppContext);
const { guilds } = state;
const { dispatch, state } = useContext(AppContext);
const { csrf, guilds, userProfile } = state;
const [addOpen, setAddOpen] = useState(false);
const [openedGuildId, setOpenedGuildId] = useState('');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This maintains state used by GuildSummaryCard.

const [searchText, setSearchText] = useState('');

useQueryParameters([
{
name: 'addOpen',
default: false,
value: addOpen,
setter: setAddOpen
},
{
name: 'guild',
default: '',
value: openedGuildId,
setter: setOpenedGuildId
},
{
name: 'search',
default: '',
value: searchText,
setter: setSearchText
}
]);

const handleOpen = () => setAddOpen(true);

const handleClose = () => setAddOpen(false);

const isAdmin = userProfile?.role?.includes('ADMIN');

return (
<Root>
<div className="guild-search">
Expand All @@ -49,7 +82,33 @@ const GuildResults = () => {
setSearchText(e.target.value);
}}
/>
<GuildsActions />
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This GuildActions component was very small and only used here. To simplify communication between that code and this code, I copied the code into here and deleted that component.

<div className="guild-actions">
{isAdmin && (
<>
<Button startIcon={<GroupIcon />} onClick={handleOpen}>
Add Guild
</Button>
<AddGuildModal
open={addOpen}
onClose={handleClose}
onSave={async guild => {
if (csrf) {
let res = await createGuild(guild, csrf);
let data =
res.payload && res.payload.data && !res.error
? res.payload.data
: null;
if (data) {
dispatch({ type: ADD_GUILD, payload: data });
}
handleClose();
}
}}
headerText="Add A New Guild"
/>
</>
)}
</div>
</div>
<div className="guilds">
{guilds?.length
Expand All @@ -59,6 +118,8 @@ const GuildResults = () => {
key={`guild-summary-${guild.id}`}
index={index}
guild={guild}
isOpen={guild.id === openedGuildId}
onGuildSelect={setOpenedGuildId}
/>
) : null
)
Expand Down
14 changes: 10 additions & 4 deletions web-ui/src/components/guild-results/GuildSummaryCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ const propTypes = {

const displayName = 'GuildSummaryCard';

const GuildSummaryCard = ({ guild, index }) => {
const GuildSummaryCard = ({ guild, index, isOpen, onGuildSelect }) => {
const { state, dispatch } = useContext(AppContext);
const { guilds, userProfile, csrf } = state;
const [open, setOpen] = useState(false);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value of this state is now passed in a prop.

const [open, setOpen] = useState(isOpen);
const [openDelete, setOpenDelete] = useState(false);
const [tooltipIsOpen, setTooltipIsOpen] = useState(false);
const isAdmin =
Expand All @@ -80,8 +80,14 @@ const GuildSummaryCard = ({ guild, index }) => {
? false
: leads.some(lead => lead.memberId === userProfile.memberProfile.id);

const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
const handleOpen = () => {
setOpen(true);
onGuildSelect(guild.id);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary to inform the parent component of the change.

};
const handleClose = () => {
setOpen(false);
onGuildSelect('');
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary to inform the parent component of the change.

};

const handleOpenDeleteConfirmation = () => setOpenDelete(true);
const handleCloseDeleteConfirmation = () => setOpenDelete(false);
Expand Down
60 changes: 0 additions & 60 deletions web-ui/src/components/guild-results/GuildsActions.jsx

This file was deleted.

39 changes: 0 additions & 39 deletions web-ui/src/components/guild-results/GuildsActions.test.jsx

This file was deleted.