Skip to content

Commit

Permalink
[fix]: Tab 'Outstanding' should have (#2687)
Browse files Browse the repository at this point in the history
Estimated time (overall tasks); Total tasks (display how many)
  • Loading branch information
Innocent-Akim authored Jul 6, 2024
1 parent 88332dd commit 2ba0b09
Show file tree
Hide file tree
Showing 11 changed files with 444 additions and 119 deletions.
2 changes: 1 addition & 1 deletion apps/web/app/hooks/features/useTaskStatistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export function useTaskStatistics(addSeconds = 0) {
Math.min(
Math.floor(
(((_task?.totalWorkedTime || timeSheet?.duration || 0) + addSeconds) * 100) /
(estimate || _task?.estimate || 0)
(estimate || _task?.estimate || 0)
),
100
),
Expand Down
4 changes: 2 additions & 2 deletions apps/web/components/ui/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const SelectContent = React.forwardRef<
className={cn(
'relative z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2',
position === 'popper' &&
'data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1',
'data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1',
className
)}
position={position}
Expand All @@ -51,7 +51,7 @@ const SelectContent = React.forwardRef<
className={cn(
'p-1',
position === 'popper' &&
'h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]'
'h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]'
)}
>
{children}
Expand Down
1 change: 0 additions & 1 deletion apps/web/lib/components/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ export function ConfirmDropdown({
return (
<Popover className="relative">
<Popover.Button>{children}</Popover.Button>

<Transition
enter="transition duration-100 ease-out"
enterFrom="transform scale-95 opacity-0"
Expand Down
4 changes: 4 additions & 0 deletions apps/web/lib/features/task/daily-plan/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export * from './outstanding';
export * from './past-tasks';
export * from './future-tasks';
export * from './outstanding-all';
export * from './task-estimated-count';
export * from './outstanding-date';
export * from './task-estimated-count'
50 changes: 50 additions & 0 deletions apps/web/lib/features/task/daily-plan/outstanding-all.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { EmptyPlans } from 'lib/features/user-profile-plans';
import { TaskCard } from '../task-card';
import { useDailyPlan } from '@app/hooks';
import { TaskEstimatedcount } from '.';

Check warning on line 4 in apps/web/lib/features/task/daily-plan/outstanding-all.tsx

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (Estimatedcount)

interface OutstandingAll {
profile: any,
}
export function OutstandingAll({ profile }: OutstandingAll) {
const { outstandingPlans } = useDailyPlan();
const displayedTaskId = new Set();
return (
<div className="flex flex-col gap-6">
<TaskEstimatedcount outstandingPlans={outstandingPlans} />

Check warning on line 14 in apps/web/lib/features/task/daily-plan/outstanding-all.tsx

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (Estimatedcount)
{outstandingPlans?.length > 0 ? (
<>
{outstandingPlans?.map((plan) => (
<>
{/* <PlanHeader plan={plan} planMode="Outstanding" /> */}
<ul className="flex flex-col gap-2">
{plan?.tasks?.map((task) => {
//If the task is already displayed, skip it
if (displayedTaskId.has(task.id)) { return null; }
// Add the task to the Set to avoid displaying it again
displayedTaskId.add(task.id);
return <TaskCard
key={`${task.id}${plan.id}`}
isAuthUser={true}
activeAuthTask={true}
viewType={'dailyplan'}
task={task}
profile={profile}
type="HORIZONTAL"
taskBadgeClassName={`rounded-sm`}
taskTitleClassName="mt-[0.0625rem]"
planMode="Outstanding"
/>
}
)}
</ul>
</>
))}
</>

) : (
<EmptyPlans planMode="Outstanding" />
)}
</div>
);
}
61 changes: 61 additions & 0 deletions apps/web/lib/features/task/daily-plan/outstanding-date.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { formatDayPlanDate } from '@app/helpers';
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@components/ui/accordion';
import { EmptyPlans, PlanHeader } from 'lib/features/user-profile-plans';
import { TaskCard } from '../task-card';
import { useDailyPlan } from '@app/hooks';

interface IOutstandingFieltreDate {

Check warning on line 7 in apps/web/lib/features/task/daily-plan/outstanding-date.tsx

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (Fieltre)
profile: any
}
export function OutstandingFieltreDate({ profile }: IOutstandingFieltreDate) {

Check warning on line 10 in apps/web/lib/features/task/daily-plan/outstanding-date.tsx

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (Fieltre)

Check warning on line 10 in apps/web/lib/features/task/daily-plan/outstanding-date.tsx

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (Fieltre)
const { outstandingPlans } = useDailyPlan();
return (
<div className="flex flex-col gap-6">
{outstandingPlans?.length > 0 ? (
<Accordion
type="multiple"
className="text-sm"
defaultValue={outstandingPlans?.map((plan) => new Date(plan.date).toISOString().split('T')[0])}
>
{outstandingPlans?.map((plan) => (
<AccordionItem
value={plan.date.toString().split('T')[0]}
key={plan.id}
className="dark:border-slate-600"
>
<AccordionTrigger className="hover:no-underline">
<div className="text-lg">
{formatDayPlanDate(plan.date.toString())} ({plan.tasks?.length})
</div>
</AccordionTrigger>
<AccordionContent className="bg-light--theme border-none dark:bg-dark--theme pb-12">
{/* Plan header */}
<PlanHeader plan={plan} planMode="Outstanding" />

{/* Plan tasks list */}
<ul className="flex flex-col gap-2">
{plan.tasks?.map((task) => (
<TaskCard
key={`${task.id}${plan.id}`}
isAuthUser={true}
activeAuthTask={true}
viewType={'dailyplan'}
task={task}
profile={profile}
type="HORIZONTAL"
taskBadgeClassName={`rounded-sm`}
taskTitleClassName="mt-[0.0625rem]"
planMode="Outstanding"
/>
))}
</ul>
</AccordionContent>
</AccordionItem>
))}
</Accordion>
) : (
<EmptyPlans planMode="Outstanding" />
)}
</div>
);
}
62 changes: 5 additions & 57 deletions apps/web/lib/features/task/daily-plan/outstanding.tsx
Original file line number Diff line number Diff line change
@@ -1,58 +1,6 @@
import { formatDayPlanDate } from '@app/helpers';
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@components/ui/accordion';
import { EmptyPlans, PlanHeader } from 'lib/features/user-profile-plans';
import { TaskCard } from '../task-card';
import { useDailyPlan } from '@app/hooks';

export function Outstanding({ profile }: { profile: any }) {
const { outstandingPlans } = useDailyPlan();
return (
<div className="flex flex-col gap-6">
{outstandingPlans?.length > 0 ? (
<Accordion
type="multiple"
className="text-sm"
defaultValue={outstandingPlans?.map((plan) => new Date(plan.date).toISOString().split('T')[0])}
>
{outstandingPlans?.map((plan) => (
<AccordionItem
value={plan.date.toString().split('T')[0]}
key={plan.id}
className="dark:border-slate-600"
>
<AccordionTrigger className="hover:no-underline">
<div className="text-lg">
{formatDayPlanDate(plan.date.toString())} ({plan.tasks?.length})
</div>
</AccordionTrigger>
<AccordionContent className="bg-light--theme border-none dark:bg-dark--theme pb-12">
{/* Plan header */}
<PlanHeader plan={plan} planMode="Outstanding" />

{/* Plan tasks list */}
<ul className="flex flex-col gap-2">
{plan.tasks?.map((task) => (
<TaskCard
key={`${task.id}${plan.id}`}
isAuthUser={true}
activeAuthTask={true}
viewType={'dailyplan'}
task={task}
profile={profile}
type="HORIZONTAL"
taskBadgeClassName={`rounded-sm`}
taskTitleClassName="mt-[0.0625rem]"
planMode="Outstanding"
/>
))}
</ul>
</AccordionContent>
</AccordionItem>
))}
</Accordion>
) : (
<EmptyPlans planMode="Outstanding" />
)}
</div>
);
interface IOutstanding {
filtre?: any;

Check warning on line 2 in apps/web/lib/features/task/daily-plan/outstanding.tsx

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (filtre)
}
export function Outstanding({ filtre }: IOutstanding) {

Check warning on line 4 in apps/web/lib/features/task/daily-plan/outstanding.tsx

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (filtre)
return (<>{filtre}</>);

Check warning on line 5 in apps/web/lib/features/task/daily-plan/outstanding.tsx

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (filtre)
}
44 changes: 44 additions & 0 deletions apps/web/lib/features/task/daily-plan/task-estimated-count.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { secondsToTime } from '@app/helpers';
import { IDailyPlan } from '@app/interfaces';
import { VerticalSeparator } from 'lib/components'
import React from 'react'

interface ITaskEstimatedcount {

Check warning on line 6 in apps/web/lib/features/task/daily-plan/task-estimated-count.tsx

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (Estimatedcount)
outstandingPlans: any[]
}
export function TaskEstimatedcount({ outstandingPlans }: ITaskEstimatedcount) {

Check warning on line 9 in apps/web/lib/features/task/daily-plan/task-estimated-count.tsx

View workflow job for this annotation

GitHub Actions / Cspell

Unknown word (Estimatedcount)
const element = outstandingPlans?.map((plan: IDailyPlan) => plan.tasks?.map((task) => task));
const { timesEstemated, totalTasks } = estimatedTotalTime(element || []);
const { h: hour, m: minute } = secondsToTime((timesEstemated || 0));
return (
<div className='flex space-x-10'>
<div className='flex space-x-2'>
<span className='text-slate-600'>Estimated:</span>
<span className='text-slate-900 font-semibold text-[12px]'>{hour}h{minute}m</span>
</div>
<VerticalSeparator className="border-slate-400" />
<div className='flex space-x-2'>
<span className='text-slate-600'>Total tasks:</span>
<span className='text-slate-900 font-semibold text-[12px]'>{totalTasks}</span>
</div>
</div>
)
}


export function estimatedTotalTime(data: any) {
// Flatten the data and reduce to calculate the sum of estimates without duplicates
const uniqueTasks = data.flat().reduce((acc: any, task: any) => {
if (!acc[task.id]) {
acc[task.id] = task.estimate;
}
return acc;
}, {});

// Calculate the total of estimates
const timesEstemated = Object.values(uniqueTasks)?.reduce((total: number, estimate: any) => total + estimate, 0);
// Calculate the total of tasks
const totalTasks = Object.values(uniqueTasks)?.length;

return { timesEstemated, totalTasks };
}
Loading

0 comments on commit 2ba0b09

Please sign in to comment.