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 .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ module.exports = {
'import/no-named-default': 'error',
'import/no-anonymous-default-export': 'error',
'import/dynamic-import-chunkname': 'error',
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
'@typescript-eslint/no-unused-vars': [
'error',
{ argsIgnorePattern: '^_', varsIgnorePattern: '^_' },
],
},
settings: {
react: {
Expand Down
44 changes: 24 additions & 20 deletions pages/accountLists/[accountListId]/tasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,21 @@ import Head from 'next/head';
import { GetServerSideProps } from 'next';
import { getSession } from 'next-auth/client';
import { useTranslation } from 'react-i18next';
import { castArray, pick } from 'lodash/fp';
import { parse } from 'query-string';
import { useRouter } from 'next/router';
import { useApp } from '../../../src/components/App';
import TaskHome from '../../../src/components/Task/Home';
import { TaskFilter } from '../../../src/components/Task/List/List';
import reduceObject from '../../../src/lib/reduceObject';

export const initialFilterFromPath = (path: string): TaskFilter => {
let initialFilter = {};
let initialFilter: TaskFilter = {};
const queryString = path.split('?')[1];

if (queryString) {
const filter = parse(queryString);

initialFilter = reduceObject(
(result: TaskFilter, value: string | string[], key: string) => {
initialFilter = Object.entries(filter).reduce(
(result: TaskFilter, [key, value]) => {
switch (key) {
case 'completed':
result.completed = value === 'true';
Expand All @@ -36,28 +34,34 @@ export const initialFilterFromPath = (path: string): TaskFilter => {
result.startAt.min = value.toString();
break;
default:
result[key.replace('[]', '')] = castArray(value);
result[key.replace('[]', '')] = Array.isArray(value)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I know you didn't write any of this but it's some weird code...

The reduceObject around this is the only usage of reduceObject... And the current implementation throws away all types with the cast to any. Maybe we should just remove it?

We could probably use an Object.entries(filter).reduce((result, [key, value]) => {...}, {}).

I'm not sure I understand this default case... I think using the bracket arrayFormat on the parse https://github.com/sindresorhus/query-string#arrayformat might clean up the [] in the key but looks like it although it always returns an array, the types don't know that...

? value
: [value];
}
return result;
},
{},
filter,
);

initialFilter = pick(
[
'userIds',
'tags',
'contactIds',
'activityType',
'completed',
'wildcardSearch',
'startAt',
],
initialFilter,
);
const {
userIds,
tags,
contactIds,
activityType,
completed,
wildcardSearch,
startAt,
} = initialFilter;

return initialFilter;
return {
userIds,
tags,
contactIds,
activityType,
completed,
wildcardSearch,
startAt,
};
}
};

Expand Down
23 changes: 12 additions & 11 deletions src/components/App/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import React, {
Dispatch,
} from 'react';
import { v4 as uuidv4 } from 'uuid';
import { omit, remove, find } from 'lodash/fp';
import TaskDrawer, { TaskDrawerProps } from '../Task/Drawer/Drawer';
import theme from '../../theme';
import rootReducer, { Action, AppState } from './rootReducer';
Expand Down Expand Up @@ -39,12 +38,10 @@ const AppProvider = ({ initialState, children }: Props): ReactElement => {
const id = uuidv4();
if (
!taskDrawerProps.taskId ||
!find(
{
taskId: taskDrawerProps.taskId,
showCompleteForm: taskDrawerProps.showCompleteForm,
},
taskDrawers,
!taskDrawers.find(
({ taskId, showCompleteForm }) =>
taskId === taskDrawerProps.taskId &&
showCompleteForm === taskDrawerProps.showCompleteForm,
)
) {
setTaskDrawers([
Expand All @@ -56,7 +53,9 @@ const AppProvider = ({ initialState, children }: Props): ReactElement => {
taskDrawerProps.onClose && taskDrawerProps.onClose();
setTimeout(
() =>
setTaskDrawers((taskDrawers) => remove({ id }, taskDrawers)),
setTaskDrawers((taskDrawers) =>
taskDrawers.filter(({ id: taskId }) => taskId !== id),
),
theme.transitions.duration.leavingScreen,
);
},
Expand All @@ -74,9 +73,11 @@ const AppProvider = ({ initialState, children }: Props): ReactElement => {
return (
<AppContext.Provider value={value}>
{children}
{taskDrawers.map((props: TaskDrawerPropsWithId) => (
<TaskDrawer key={props.id} {...omit('id', props)} />
))}
{taskDrawers.map((props: TaskDrawerPropsWithId) => {
const { id, ...taskDrawerProps } = props;

return <TaskDrawer key={id} {...taskDrawerProps} />;
})}
</AppContext.Provider>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import CakeIcon from '@material-ui/icons/Cake';
import FavoriteIcon from '@material-ui/icons/Favorite';
import { Skeleton } from '@material-ui/lab';
import { motion } from 'framer-motion';
import { uniqBy } from 'lodash/fp';
import uniqBy from 'lodash/fp/uniqBy';
import { useTranslation } from 'react-i18next';
import Link from 'next/link';
import { dayMonthFormat } from '../../../../lib/intlFormat';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
import { Skeleton } from '@material-ui/lab';
import React, { ReactElement } from 'react';
import { useTranslation } from 'react-i18next';
import { cloneDeep, isFunction } from 'lodash/fp';
import { isSameMonth } from 'date-fns';
import { AcknowledgeUserNotificationMutation } from '../../../../../../../types/AcknowledgeUserNotificationMutation';
import {
Expand Down Expand Up @@ -102,14 +101,19 @@ const NotificationMenuItem = ({
after: null,
},
};
const data = cloneDeep(cache.readQuery<GetNotificationsQuery>(query));
const dataFromCache = cache.readQuery<GetNotificationsQuery>(query);
const data = {
userNotifications: {
...dataFromCache.userNotifications,
},
};
data.userNotifications.unreadCount--;
cache.writeQuery({ ...query, data });
optimisticResponse = false;
},
});
}
if (isFunction(onClick)) onClick();
if (typeof onClick === 'function') onClick();
};

let message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import React, { ReactElement, useEffect, useState } from 'react';
import NotificationsIcon from '@material-ui/icons/Notifications';
import { gql, useMutation, useLazyQuery } from '@apollo/client';
import { useTranslation } from 'react-i18next';
import { cloneDeep } from 'lodash/fp';
import { useApp } from '../../../../App';
import { GetNotificationsQuery } from '../../../../../../types/GetNotificationsQuery';
import { AcknowledgeAllUserNotificationsMutation } from '../../../../../../types/AcknowledgeAllUserNotificationsMutation';
Expand Down Expand Up @@ -105,7 +104,12 @@ const NotificationMenu = (): ReactElement => {
after: null,
},
};
const data = cloneDeep(cache.readQuery<GetNotificationsQuery>(query));
const dataFromCache = cache.readQuery<GetNotificationsQuery>(query);
const data = {
userNotifications: {
...dataFromCache.userNotifications,
},
};
data.userNotifications.unreadCount = 0;
data.userNotifications.edges = data.userNotifications.edges.map(
({ node }) => ({
Expand Down
9 changes: 4 additions & 5 deletions src/components/Layouts/Primary/TopBar/TopBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import MenuIcon from '@material-ui/icons/Menu';
import clsx from 'clsx';
import { useTranslation } from 'react-i18next';
import { signout } from 'next-auth/client';
import { compact } from 'lodash/fp';
import NextLink from 'next/link';
import { GetTopBarQuery } from '../../../../../types/GetTopBarQuery';
import { SIDE_BAR_MINIMIZED_WIDTH, SIDE_BAR_WIDTH } from '../SideBar/SideBar';
Expand Down Expand Up @@ -366,9 +365,9 @@ const TopBar = ({ open, handleOpenChange }: Props): ReactElement => {
<Avatar>{data.user.firstName[0]}</Avatar>
</ListItemAvatar>
<ListItemText
primary={compact([data.user.firstName, data.user.lastName]).join(
' ',
)}
primary={[data.user.firstName, data.user.lastName]
.filter(Boolean)
.join(' ')}
secondary={data.user.keyAccounts[0]?.email}
/>
</MenuItem>
Expand Down Expand Up @@ -400,7 +399,7 @@ const TopBar = ({ open, handleOpenChange }: Props): ReactElement => {
</MenuItem>
</HandoffLink>
{(data?.user?.admin ||
!!data?.user?.administrativeOrganizations?.nodes?.length) && (
data?.user?.administrativeOrganizations?.nodes?.length) && (
<HandoffLink path="/preferences/organizations">
<MenuItem onClick={handleProfileMenuClose} component="a">
<ListItemText primary={t('Manage Organizations')} />
Expand Down
37 changes: 15 additions & 22 deletions src/components/Task/Drawer/CommentList/CommentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { ReactElement, useRef, useEffect } from 'react';
import { makeStyles, Theme, Box, Card, CardContent } from '@material-ui/core';
import { useTranslation } from 'react-i18next';
import { gql, useQuery } from '@apollo/client';
import { reduce } from 'lodash/fp';
import { GetCommentsForTaskDrawerCommentListQuery } from '../../../../../types/GetCommentsForTaskDrawerCommentListQuery';
import illustration4 from '../../../../images/drawkit/grape/drawkit-grape-pack-illustration-4.svg';
import TaskDrawerCommentListItem from './Item';
Expand Down Expand Up @@ -104,27 +103,21 @@ const TaskDrawerCommentList = ({
</Card>
)}
{data.task.comments.nodes.length > 0 &&
reduce(
(result, comment) => {
return [
...result,
<Box
data-testid={`TaskDrawerCommentListItem-${comment.id}`}
key={comment.id}
>
<TaskDrawerCommentListItem
comment={comment}
reverse={comment.me}
nextComment={
data.task.comments.nodes[result.length + 1]
}
/>
</Box>,
];
},
[],
data.task.comments.nodes,
)}
data.task.comments.nodes.reduce((result, comment) => {
return [
...result,
<Box
data-testid={`TaskDrawerCommentListItem-${comment.id}`}
key={comment.id}
>
<TaskDrawerCommentListItem
comment={comment}
reverse={comment.me}
nextComment={data.task.comments.nodes[result.length + 1]}
/>
</Box>,
];
}, [])}
</>
)}
</Box>
Expand Down
28 changes: 18 additions & 10 deletions src/components/Task/Drawer/CommentList/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as yup from 'yup';
import SendIcon from '@material-ui/icons/Send';
import { useMutation, gql } from '@apollo/client';
import { motion } from 'framer-motion';
import { cloneDeep, reject } from 'lodash/fp';
import reject from 'lodash/fp/reject';
import { v4 as uuidv4 } from 'uuid';
import { CreateTaskCommentMutation } from '../../../../../../types/CreateTaskCommentMutation';
import { TaskCommentCreateInput } from '../../../../../../types/globalTypes';
Expand Down Expand Up @@ -125,16 +125,24 @@ const Form = ({ accountListId, taskId }: Props): ReactElement => {
taskId,
},
};
const data = cloneDeep(
cache.readQuery<GetCommentsForTaskDrawerCommentListQuery>(query),
const dataFromCache = cache.readQuery<GetCommentsForTaskDrawerCommentListQuery>(
query,
);
data.task.comments.nodes = [
...reject(
({ id: commentId }) => id === commentId,
data.task.comments.nodes,
),
comment,
];
const data = {
task: {
...dataFromCache.task,
comments: {
...dataFromCache.task.comments,
nodes: [
...reject(
({ id: commentId }) => id === commentId,
dataFromCache.task.comments.nodes,
),
Comment on lines +137 to +140
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Still couldn't get the filter method I created to replace this reject to not break the test suite. It works fine in the browser but not in the tests for some reason.

{ ...comment },
],
},
},
};
cache.writeQuery({ ...query, data });
},
});
Expand Down
7 changes: 4 additions & 3 deletions src/components/Task/Drawer/CommentList/Item/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
Slide,
} from '@material-ui/core';
import { formatDistanceToNow, isSameHour } from 'date-fns';
import { compact } from 'lodash/fp';
import { Skeleton } from '@material-ui/lab';
import { GetCommentsForTaskDrawerCommentListQuery_task_comments_nodes as Comment } from '../../../../../../types/GetCommentsForTaskDrawerCommentListQuery';

Expand Down Expand Up @@ -103,11 +102,13 @@ const TaskDrawerCommentListItem = ({
return (
<Slide direction={reverse ? 'left' : 'right'} in={true}>
<Box
className={compact([
className={[
classes.container,
reverse && classes.reverse,
nextCommentMatches && classes.compact,
Comment thread
TheNoodleMoose marked this conversation as resolved.
]).join(' ')}
]
.filter(Boolean)
.join(' ')}
>
{!reverse && (
<Box>
Expand Down
21 changes: 11 additions & 10 deletions src/components/Task/Drawer/ContactList/ContactList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
} from '@material-ui/core';
import { useTranslation } from 'react-i18next';
import { gql, useLazyQuery } from '@apollo/client';
import { sortBy } from 'lodash/fp';
import { GetContactsForTaskDrawerContactListQuery } from '../../../../../types/GetContactsForTaskDrawerContactListQuery';
import illustration4 from '../../../../images/drawkit/grape/drawkit-grape-pack-illustration-4.svg';
import TaskDrawerContactListItem from './Item';
Expand Down Expand Up @@ -144,15 +143,17 @@ const TaskDrawerContactList = ({
)}
{data?.contacts?.nodes && data.contacts.nodes.length > 0 && (
<Grid container spacing={2} direction="column">
{sortBy('name', data.contacts.nodes).map((contact) => (
<Grid
item
key={contact.id}
data-testid={`TaskDrawerContactListItem-${contact.id}`}
>
<TaskDrawerContactListItem contact={contact} />
</Grid>
))}
{[...data.contacts.nodes]
.sort((a, b) => a.name.localeCompare(b.name))
.map((contact) => (
<Grid
item
key={contact.id}
data-testid={`TaskDrawerContactListItem-${contact.id}`}
>
<TaskDrawerContactListItem contact={contact} />
</Grid>
))}
</Grid>
)}
</>
Expand Down
Loading