Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Social groups UI #438

Merged
merged 23 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
01b8344
Send request to create social group
brmscheiner Jul 14, 2022
d252f23
Get add and delete social groups working
brmscheiner Jul 22, 2022
c2ec574
Edit social group page with name editing
brmscheiner Jul 22, 2022
ba00bf2
Control panel shuffle
brmscheiner Jul 28, 2022
ab4fd74
Social group form
brmscheiner Jul 28, 2022
0d24835
Remove individual from social group functionality
brmscheiner Jul 28, 2022
0f3f508
Table of members on social group page
brmscheiner Jul 29, 2022
adc95aa
Add roles to social group card
brmscheiner Jul 29, 2022
45497ba
Remaining functionality
brmscheiner Jul 29, 2022
f41c9f2
Loading and error states for AddMembersDialog
brmscheiner Jul 29, 2022
d8f4f4a
Loading and error states for RemoveFromSocialGroupDialog
brmscheiner Jul 29, 2022
7f0c3d0
Loading and error states in AddSocialGroupDialog
brmscheiner Jul 29, 2022
11cb758
Loading and error states for AddToSocialGroupDialog
brmscheiner Jul 29, 2022
bfafa71
Improve looks of social group roles setup dialog
brmscheiner Jul 29, 2022
87fe312
Resolve merge conflicts
brmscheiner Jul 29, 2022
6281993
Rename mixed things to Preferences
brmscheiner Aug 5, 2022
456350b
Forward ref to overflow controller
brmscheiner Aug 5, 2022
d012500
Address remaining comments
brmscheiner Aug 5, 2022
e7a8a85
Merge branch 'develop' of https://github.com/WildMeOrg/codex-frontend…
brmscheiner Aug 5, 2022
2318d2a
Address final comments
brmscheiner Aug 9, 2022
b12edef
Fix an eslint error
brmscheiner Aug 10, 2022
43dbfe1
Address PR comments
brmscheiner Aug 11, 2022
c5f84b7
Address QA comments
brmscheiner Aug 12, 2022
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
8 changes: 6 additions & 2 deletions locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
"ANNOTATION_CLASS": "Annotation class",
"INDIVIDUAL_METADATA": "Individual profile",
"COMMIT": "Commit",
"UNNAMED_SOCIAL_GROUP": "Unnamed social group",
"SOCIAL_GROUP_NOT_FOUND": "Social group not found",
"SOCIAL_GROUP_NOT_FOUND_DESCRIPTION": "Social group lookup failed. There may be a problem with the URL or the social group may no longer exist.",
"SOCIAL_GROUP_DELETE_CONFIRMATION": "Are you sure you want to delete this social group? This action cannot be undone.",
"REGION_MATCHING_SET_DESCRIPTION": "Select the region you would like to match against. Sub-regions will be included in the matching set. If no region is selected, all regions will be matched against.",
"CREATED": "Created",
Expand Down Expand Up @@ -193,7 +196,7 @@
"FIRST_NAME": "First name",
"ADOPTION_NAME": "Adoption name",
"ALIAS": "Alias",
"SETTINGS_AND_PRIVACY": "Settings & privacy",
"PREFERENCES": "Preferences",
"SEARCH_ITIS_SPECIES": "Search ITIS species",
"SEARCH_INDIVIDUALS_INSTRUCTION": "Search for an individual by name or guid",
"SEARCH_SIGHTINGS_INSTRUCTION": "Search for a sighting by location, owner or guid",
Expand Down Expand Up @@ -1073,7 +1076,8 @@
"SELECT_RELATIONSHIP_TYPE": "Select relationship type",
"SELECT_RELATIONSHIP_ROLE": "Select role from {ind}'s perspective",
"NO_RELATIONSHIPS": "This individual does not have any relationships.",
"NO_SOCIAL_GROUPS": "This individual is not part of any social groups.",
"NO_SOCIAL_GROUPS_ON_INDIVIDUAL": "This individual is not part of any social groups.",
"NO_SOCIAL_GROUPS_ON_SITE": "There are no social groups on this site.",
"NO_PERMISSIONS_ERROR_SUBTITLE": "Permissions error",
"NOT_AUTHENTICATED_ERROR_SUBTITLE": "Authentication error",
"NO_PERMISSIONS_ERROR_DETAILS": "You do not have permissions to access the requested resource.",
Expand Down
6 changes: 3 additions & 3 deletions src/AuthenticatedSwitch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import AuditLog from './pages/devTools/AuditLog';
import Welcome from './pages/auth/Welcome';
import EmailVerified from './pages/auth/EmailVerified';
import Home from './pages/home/Home';
import Settings from './pages/settings/Settings';
import Preferences from './pages/preferences/Preferences';
import ResendVerificationEmail from './pages/auth/ResendVerificationEmail';
import Footer from './components/Footer';
import { defaultCrossfadeDuration } from './constants/defaults';
Expand Down Expand Up @@ -123,8 +123,8 @@ export default function AuthenticatedSwitch({
<Route path="/settings/social-groups">
<SocialGroups />
</Route>
<Route path="/settings/user-preferences">
<Settings />
<Route path="/settings/preferences">
<Preferences />
</Route>
<Route path="/settings">
<ControlPanel />
Expand Down
14 changes: 5 additions & 9 deletions src/components/cards/CollaborationsCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,18 @@ export default function CollaborationsCard({
htmlId = null,
}) {
const intl = useIntl();
const [activeCollaboration, setActiveCollaboration] = useState(
null,
);
const [activeCollaboration, setActiveCollaboration] =
useState(null);
const [
collabDialogButtonClickLoading,
setCollabDialogButtonClickLoading,
] = useState(false);

const { data, loading } = useGetMe();

useEffect(
() => {
setCollabDialogButtonClickLoading(false);
},
[data],
);
useEffect(() => {
setCollabDialogButtonClickLoading(false);
}, [data]);

const collaborations = get(data, ['collaborations'], []);
const tableData = collaborations.map(collaboration => {
Expand Down
29 changes: 13 additions & 16 deletions src/components/cards/EncountersCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,20 @@ export default function EncountersCard({
const mapModeClicked = () => setShowMapView(true);
const listModeClicked = () => setShowMapView(false);

const encountersWithLocationData = useMemo(
() => {
// hotfix //
if (!encounters) return [];
// hotfix //
const encountersWithLocationData = useMemo(() => {
// hotfix //
if (!encounters) return [];
// hotfix //

return encounters.map(encounter => ({
...encounter,
formattedLocation: formatLocationFromSighting(
encounter,
regionOptions,
intl,
),
}));
},
[get(encounters, 'length')],
);
return encounters.map(encounter => ({
...encounter,
formattedLocation: formatLocationFromSighting(
encounter,
regionOptions,
intl,
),
}));
}, [get(encounters, 'length')]);

const tooFewEncounters = encounters.length <= 1;

Expand Down
4 changes: 2 additions & 2 deletions src/components/cards/RelationshipsCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export default function RelationshipsCard({
relationships = [],
individualGuid,
loading,
noDataMessage = 'NO_RELATIONSHIPS',
noDataMessageId = 'NO_RELATIONSHIPS',
title,
titleId,
}) {
Expand Down Expand Up @@ -359,7 +359,7 @@ export default function RelationshipsCard({
{noRelationships && (
<Text
variant="body2"
id={noDataMessage}
id={noDataMessageId}
style={{ marginTop: 12 }}
/>
)}
Expand Down
29 changes: 13 additions & 16 deletions src/components/cards/SightingsCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,20 @@ export default function SightingsCard({
const mapModeClicked = () => setShowMapView(true);
const listModeClicked = () => setShowMapView(false);

const sightingsWithLocationData = useMemo(
() => {
// hotfix //
if (!sightings) return [];
// hotfix //
const sightingsWithLocationData = useMemo(() => {
// hotfix //
if (!sightings) return [];
// hotfix //

return sightings.map(sighting => ({
...sighting,
formattedLocation: formatLocationFromSighting(
sighting,
regionOptions,
intl,
),
}));
},
[get(sightings, 'length')],
);
return sightings.map(sighting => ({
...sighting,
formattedLocation: formatLocationFromSighting(
sighting,
regionOptions,
intl,
),
}));
}, [get(sightings, 'length')]);

const allColumns = [
{
Expand Down
7 changes: 4 additions & 3 deletions src/components/cards/SocialGroupsCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function SocialGroupsCard({
socialGroups = [],
individualGuid,
loading,
noDataMessage = 'NO_SOCIAL_GROUPS',
noDataMessageId = 'NO_SOCIAL_GROUPS_ON_INDIVIDUAL',
title,
titleId,
}) {
Expand Down Expand Up @@ -44,11 +44,11 @@ export default function SocialGroupsCard({
onClose={() => setAddDialogOpen(false)}
individualGuid={individualGuid}
/>
<Card title={title} titleId={titleId} maxHeight={600}>
<Card title={title} titleId={titleId}>
{noSocialGroups ? (
<Text
variant="body2"
id={noDataMessage}
id={noDataMessageId}
style={{ marginTop: 12 }}
/>
) : (
Expand All @@ -57,6 +57,7 @@ export default function SocialGroupsCard({
data={socialGroups}
loading={loading}
onClickDelete={handleClickDelete}
tableContainerStyles={{ maxHeight: 600 }}
/>
)}

Expand Down
5 changes: 2 additions & 3 deletions src/components/dataDisplays/DataDisplay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,8 @@ export default function DataDisplay({
);
const [filter, setFilter] = useState('');
const [internalSortColumn, setInternalSortColumn] = useState(null);
const [internalSortDirection, setInternalSortDirection] = useState(
null,
);
const [internalSortDirection, setInternalSortDirection] =
useState(null);
const [anchorEl, setAnchorEl] = useState(null);
const filterPopperOpen = Boolean(anchorEl);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import React from 'react';
import React, { forwardRef } from 'react';
import { useIntl } from 'react-intl';
import { get } from 'lodash-es';

import useSiteSettings from '../../../models/site/useSiteSettings';
import Text from '../../Text';
import OverflowController from './OverflowController';

function Core({ value, ...rest }, ref) {
brmscheiner marked this conversation as resolved.
Show resolved Hide resolved
return (
<Text variant="body2" ref={ref} {...rest}>
{value}
</Text>
);
}

const CoreForwardRef = forwardRef(Core);

export default function SocialGroupRoleRenderer({
value,
noWrap = false,
Expand All @@ -16,18 +26,17 @@ export default function SocialGroupRoleRenderer({
const { data } = useSiteSettings();
const roles = get(data, ['social_group_roles', 'value'], []);
const matchingRole = roles.find(role => role?.guid === value);
Emily-Ke marked this conversation as resolved.
Show resolved Hide resolved
brmscheiner marked this conversation as resolved.
Show resolved Hide resolved
const knownRole = value && matchingRole?.label;
const label =
matchingRole?.label || intl.formatMessage({ id: 'UNKNOWN_ROLE' });
knownRole || intl.formatMessage({ id: 'UNKNOWN_ROLE' });

const CoreComponent = <CoreForwardRef value={label} {...rest} />;

return noWrap ? (
brmscheiner marked this conversation as resolved.
Show resolved Hide resolved
<OverflowController title={label}>
Emily-Ke marked this conversation as resolved.
Show resolved Hide resolved
<Text variant="body2" {...rest}>
{label}
</Text>
{CoreComponent}
</OverflowController>
) : (
<Text variant="body2" {...rest}>
{label}
</Text>
CoreComponent
);
}
2 changes: 1 addition & 1 deletion src/components/dialogs/AddToSocialGroupDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default function AddToSocialGroupDialog({
members: newMembers,
affectedIndividualGuids: [individualGuid],
});
if (result.status === 200) handleClose();
if (result?.status === 200) handleClose();
}}
id="ADD"
/>
Expand Down
8 changes: 4 additions & 4 deletions src/components/dialogs/RemoveFromSocialGroupDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ export default function RemoveFromSocialGroupDialog({

const removeIndividualFromSocialGroup = useCallback(async () => {
const safeMembers = get(socialGroup, 'members', {});
const newMembers = omit(safeMembers, individualGuid);
const nextMembers = omit(safeMembers, individualGuid);
const result = await patchSocialGroup({
guid: socialGroup?.guid,
members: newMembers,
members: nextMembers,
affectedIndividualGuids: [individualGuid],
});
if (result.status === 200) onClose();
}, [individualGuid, socialGroup, onClose]);
if (result?.status === 200) handleClose();
}, [individualGuid, socialGroup, handleClose]);

return (
<ConfirmDelete
Expand Down
8 changes: 6 additions & 2 deletions src/constants/queryKeys.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
function sortIfArray(value) {
return Array.isArray(value) ? value.sort() : value;
}

export default {
me: 'me',
settingsConfig: 'settingsConfig',
Expand Down Expand Up @@ -73,8 +77,8 @@ export function getIndividualTermQueryKey(searchTerm) {
return ['individualQuickSearch', searchTerm];
}

export function getIndividualGuidQueryKey(individualGuids) {
return ['individualQuickSearch', individualGuids];
export function getIndividualGuidSearchQueryKey(individualGuids) {
return ['individualQuickSearch', sortIfArray(individualGuids)];
}

export function getSightingTermQueryKey(searchTerm) {
Expand Down
9 changes: 3 additions & 6 deletions src/models/individual/useQueryIndividualsByGuid.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import useFetch from '../../hooks/useFetch';
import { getIndividualGuidQueryKey } from '../../constants/queryKeys';
import { getIndividualGuidSearchQueryKey } from '../../constants/queryKeys';

export default function useQueryIndividualsByGuid(
individualGuids = [],
) {
const query = {
bool: {
minimum_should_match: 1,
should: individualGuids.map(guid => ({ term: { guid } })),
},
terms: { guid: individualGuids },
};

return useFetch({
method: 'post',
url: '/individuals/search',
queryKey: getIndividualGuidQueryKey(individualGuids),
queryKey: getIndividualGuidSearchQueryKey(individualGuids),
data: query,
queryOptions: {
enabled:
Expand Down
10 changes: 7 additions & 3 deletions src/pages/controlPanel/ControlPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,15 @@ const adminPages = [
},
{
icon: PreferencesIcon,
name: 'user-preferences',
labelId: 'SETTINGS_AND_PRIVACY',
href: '/settings/user-preferences',
name: 'preferences',
labelId: 'PREFERENCES',
href: '/settings/preferences',
roles: [
'is_admin',
'is_exporter',
'is_internal',
'is_staff',
'is_data_manager',
'is_user_manager',
'is_researcher',
'is_contributor',
Expand Down
5 changes: 2 additions & 3 deletions src/pages/fieldManagement/settings/CustomFieldTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ export default function CustomFieldTable({
const intl = useIntl();
const [deleteField, setDeleteField] = useState(null);
const [previewField, setPreviewField] = useState(null);
const [previewInitialValue, setPreviewInitialValue] = useState(
null,
);
const [previewInitialValue, setPreviewInitialValue] =
useState(null);
const {
removeCustomField,
needsForce,
Expand Down
25 changes: 14 additions & 11 deletions src/pages/individual/components/SocialGroupsDisplay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,20 @@ export default function SocialGroupsDisplay({
name: 'guid',
labelId: 'ACTIONS',
options: {
customBodyRender: (guid, socialGroup) => [
<ActionIcon
variant="view"
href={`/social-groups/${guid}`}
linkProps={{ newTab: true }}
/>,
<ActionIcon
variant="delete"
onClick={() => onClickDelete(socialGroup)}
/>,
],
customBodyRender: (guid, socialGroup) => (
<>
<ActionIcon
variant="view"
href={`/social-groups/${guid}`}
linkProps={{ newTab: true }}
/>
,
brmscheiner marked this conversation as resolved.
Show resolved Hide resolved
<ActionIcon
variant="delete"
onClick={() => onClickDelete(socialGroup)}
/>
</>
),
},
},
];
Expand Down
Loading