-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Move files * Add filtering for tasks inbox * Add filter dropdown for single entity * Minor * Fill empty button * Refine logic for filter dropdown * remove log * Fix unwanted change * Set current user as default filter * Add avatar on filter * Improve initialization of assignee filter * Add story for Tasks page * Add more stories * Add sotry with no tasks * Improve dates * Enh tests --------- Co-authored-by: Charles Bochet <charlesBochet@users.noreply.github.com>
- Loading branch information
1 parent
2128d44
commit 4252a0a
Showing
28 changed files
with
601 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
45 changes: 45 additions & 0 deletions
45
front/src/modules/activities/components/__stories__/TaskList.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { ComponentDecorator } from '~/testing/decorators/ComponentDecorator'; | ||
import { graphqlMocks } from '~/testing/graphqlMocks'; | ||
import { mockedActivities } from '~/testing/mock-data/activities'; | ||
|
||
import { TaskList } from '../TaskList'; | ||
|
||
const meta: Meta<typeof TaskList> = { | ||
title: 'Modules/Activity/TaskList', | ||
component: TaskList, | ||
decorators: [ | ||
(Story) => ( | ||
<MemoryRouter> | ||
<Story /> | ||
</MemoryRouter> | ||
), | ||
ComponentDecorator, | ||
], | ||
args: { | ||
title: 'Tasks', | ||
tasks: mockedActivities, | ||
}, | ||
parameters: { | ||
msw: graphqlMocks, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof TaskList>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
title: 'Tasks', | ||
tasks: mockedActivities, | ||
}, | ||
}; | ||
|
||
export const Empty: Story = { | ||
args: { | ||
title: 'No tasks', | ||
tasks: [], | ||
}, | ||
}; |
File renamed without changes.
22 changes: 22 additions & 0 deletions
22
front/src/modules/activities/hooks/useInitializeTasksFilters.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useEffect } from 'react'; | ||
|
||
import { availableFiltersScopedState } from '@/ui/filter-n-sort/states/availableFiltersScopedState'; | ||
import { FilterDefinition } from '@/ui/filter-n-sort/types/FilterDefinition'; | ||
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState'; | ||
|
||
import { TasksContext } from '../states/TasksContext'; | ||
|
||
export function useInitializeTasksFilters({ | ||
availableFilters, | ||
}: { | ||
availableFilters: FilterDefinition[]; | ||
}) { | ||
const [, setAvailableFilters] = useRecoilScopedState( | ||
availableFiltersScopedState, | ||
TasksContext, | ||
); | ||
|
||
useEffect(() => { | ||
setAvailableFilters(availableFilters); | ||
}, [setAvailableFilters, availableFilters]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { useEffect } from 'react'; | ||
import { DateTime } from 'luxon'; | ||
import { useRecoilState } from 'recoil'; | ||
|
||
import { currentUserState } from '@/auth/states/currentUserState'; | ||
import { filtersScopedState } from '@/ui/filter-n-sort/states/filtersScopedState'; | ||
import { turnFilterIntoWhereClause } from '@/ui/filter-n-sort/utils/turnFilterIntoWhereClause'; | ||
import { activeTabIdScopedState } from '@/ui/tab/states/activeTabIdScopedState'; | ||
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState'; | ||
import { ActivityType, useGetActivitiesQuery } from '~/generated/graphql'; | ||
import { tasksFilters } from '~/pages/tasks/tasks-filters'; | ||
import { parseDate } from '~/utils/date-utils'; | ||
|
||
import { TasksContext } from '../states/TasksContext'; | ||
|
||
import { useInitializeTasksFilters } from './useInitializeTasksFilters'; | ||
|
||
export function useTasks() { | ||
useInitializeTasksFilters({ | ||
availableFilters: tasksFilters, | ||
}); | ||
|
||
const [activeTabId] = useRecoilScopedState( | ||
activeTabIdScopedState, | ||
TasksContext, | ||
); | ||
|
||
const [filters, setFilters] = useRecoilScopedState( | ||
filtersScopedState, | ||
TasksContext, | ||
); | ||
|
||
// If there is no filter, we set the default filter to the current user | ||
const [currentUser] = useRecoilState(currentUserState); | ||
|
||
useEffect(() => { | ||
if (currentUser && !filters.length) { | ||
setFilters([ | ||
{ | ||
field: 'assigneeId', | ||
type: 'entity', | ||
value: currentUser.id, | ||
operand: 'is', | ||
displayValue: currentUser.displayName, | ||
displayAvatarUrl: currentUser.avatarUrl ?? undefined, | ||
}, | ||
]); | ||
} | ||
}, [currentUser, filters, setFilters]); | ||
|
||
const whereFilters = Object.assign( | ||
{}, | ||
...filters.map((filter) => { | ||
return turnFilterIntoWhereClause(filter); | ||
}), | ||
); | ||
|
||
const { data: completeTasksData } = useGetActivitiesQuery({ | ||
variables: { | ||
where: { | ||
type: { equals: ActivityType.Task }, | ||
completedAt: { not: { equals: null } }, | ||
...whereFilters, | ||
}, | ||
}, | ||
}); | ||
|
||
const { data: incompleteTaskData } = useGetActivitiesQuery({ | ||
variables: { | ||
where: { | ||
type: { equals: ActivityType.Task }, | ||
completedAt: { equals: null }, | ||
...whereFilters, | ||
}, | ||
}, | ||
}); | ||
|
||
const tasksData = | ||
activeTabId === 'done' ? completeTasksData : incompleteTaskData; | ||
|
||
const todayOrPreviousTasks = tasksData?.findManyActivities.filter((task) => { | ||
if (!task.dueAt) { | ||
return false; | ||
} | ||
const dueDate = parseDate(task.dueAt).toJSDate(); | ||
const today = DateTime.now().endOf('day').toJSDate(); | ||
return dueDate <= today; | ||
}); | ||
|
||
const upcomingTasks = tasksData?.findManyActivities.filter((task) => { | ||
if (!task.dueAt) { | ||
return false; | ||
} | ||
const dueDate = parseDate(task.dueAt).toJSDate(); | ||
const today = DateTime.now().endOf('day').toJSDate(); | ||
return dueDate > today; | ||
}); | ||
|
||
return { | ||
todayOrPreviousTasks, | ||
upcomingTasks, | ||
}; | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.