-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(zimbra): add ongoing tasks list
ref: MANAGER-15261 Signed-off-by: Tristan WAGNER <[email protected]>
- Loading branch information
1 parent
fa696d5
commit 5ee2d16
Showing
6 changed files
with
73 additions
and
41 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
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
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
70 changes: 45 additions & 25 deletions
70
packages/manager/apps/zimbra/src/pages/dashboard/GeneralInformation/OngoingTasks.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 |
---|---|---|
@@ -1,45 +1,65 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { OdsIcon, OdsLink } from '@ovhcloud/ods-components/react'; | ||
import { ODS_ICON_NAME, ODS_LINK_COLOR } from '@ovhcloud/ods-components'; | ||
import { OdsLink, OdsText } from '@ovhcloud/ods-components/react'; | ||
import { | ||
ODS_ICON_NAME, | ||
ODS_LINK_COLOR, | ||
ODS_SPINNER_SIZE, | ||
ODS_TEXT_PRESET, | ||
} from '@ovhcloud/ods-components'; | ||
import { useTasks } from '@/hooks'; | ||
import Loading from '@/components/Loading/Loading'; | ||
import { TaskType, TaskStatus } from '@/api/task'; | ||
|
||
const defaultNumberToShow = 5; | ||
const isOngoing = (task: TaskType) => | ||
![TaskStatus.DONE, TaskStatus.ERROR].includes(task.status); | ||
|
||
export const OngoingTasks: React.FC = () => { | ||
const { t } = useTranslation('dashboard'); | ||
const [loadMore, setLoadMore] = useState(false); | ||
const [tasksDiplayed, setTasksDiplayed] = useState([]); | ||
const { data } = useTasks(); | ||
const [tasks, setTasks] = useState([]); | ||
const { data, isError, isPending } = useTasks(); | ||
|
||
useEffect(() => { | ||
setTasksDiplayed(loadMore ? data : data?.slice(0, 5)); | ||
const ongoingTasks = data?.filter(isOngoing); | ||
setTasks( | ||
loadMore ? ongoingTasks : ongoingTasks?.slice(0, defaultNumberToShow), | ||
); | ||
}, [loadMore, data]); | ||
|
||
return ( | ||
<div data-testid="ongoingtasks" className="flex flex-col"> | ||
{tasksDiplayed?.map((task) => ( | ||
<span key={task.id}>{`${task.type} ${task.message}`}</span> | ||
))} | ||
{data?.length > 5 && ( | ||
<ul className="pl-9 flex flex-col gap-3"> | ||
{tasks?.map((task) => ( | ||
<li key={task.id}> | ||
<OdsText preset={ODS_TEXT_PRESET.span}>{task.message}</OdsText> | ||
</li> | ||
))} | ||
</ul> | ||
{tasks?.length > defaultNumberToShow && ( | ||
<OdsLink | ||
className="mt-5" | ||
className="mt-5 ml-9" | ||
color={ODS_LINK_COLOR.primary} | ||
onClick={() => setLoadMore(!loadMore)} | ||
onClick={(e) => { | ||
e?.preventDefault(); | ||
setLoadMore(!loadMore); | ||
}} | ||
href="#" | ||
> | ||
<span slot="start"></span> | ||
{!loadMore | ||
? t('zimbra_dashboard_tile_status_ongoingTask_viewMore') | ||
: t('zimbra_dashboard_tile_status_ongoingTask_viewLess')} | ||
<span slot="end"> | ||
<OdsIcon | ||
className="ml-3" | ||
name={ | ||
!loadMore ? ODS_ICON_NAME.chevronDown : ODS_ICON_NAME.chevronUp | ||
} | ||
></OdsIcon> | ||
</span> | ||
</OdsLink> | ||
label={ | ||
!loadMore | ||
? t('zimbra_dashboard_tile_status_ongoingTask_viewMore') | ||
: t('zimbra_dashboard_tile_status_ongoingTask_viewLess') | ||
} | ||
icon={!loadMore ? ODS_ICON_NAME.chevronDown : ODS_ICON_NAME.chevronUp} | ||
></OdsLink> | ||
)} | ||
{(!tasks?.length || isError) && !isPending && ( | ||
<OdsText preset={ODS_TEXT_PRESET.paragraph}> | ||
{t('zimbra_dashboard_tile_status_ongoingTask_none')} | ||
</OdsText> | ||
)} | ||
{isPending && <Loading size={ODS_SPINNER_SIZE.xs} />} | ||
</div> | ||
); | ||
}; |