Skip to content

Commit

Permalink
feat(zimbra): add ongoing tasks list
Browse files Browse the repository at this point in the history
ref: MANAGER-15261

Signed-off-by: Tristan WAGNER <[email protected]>
  • Loading branch information
tristanwagner committed Nov 26, 2024
1 parent fa696d5 commit 5ee2d16
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"zimbra_dashboard_tile_status_ongoingTask": "Tâches en cours",
"zimbra_dashboard_tile_status_ongoingTask_viewMore": "Voir plus",
"zimbra_dashboard_tile_status_ongoingTask_viewLess": "Voir moins",
"zimbra_dashboard_tile_status_ongoingTask_none": "Aucune tâche en cours",
"zimbra_dashboard_tile_serviceConsumption_title": "Statistiques",
"zimbra_dashboard_tile_serviceConsumption_accountOffer": "Compte par offre",
"zimbra_dashboard_tile_serviceConsumption_noAccountOffer": "Vous ne possedez actuellement aucune boite email.",
Expand Down
9 changes: 0 additions & 9 deletions packages/manager/apps/zimbra/src/api/api.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ export type ErrorResponse = {
};
};

export type TaskErrorMessage = {
message: string;
};

export type TaskProgressStatus = {
name: string;
status: string;
};

export enum ResourceStatus {
CREATING = 'CREATING',
DELETING = 'DELETING',
Expand Down
19 changes: 17 additions & 2 deletions packages/manager/apps/zimbra/src/api/task/type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
import { TaskErrorMessage, TaskProgressStatus } from '../api.type';
export enum TaskStatus {
DONE = 'DONE',
ERROR = 'ERROR',
PENDING = 'PENDING',
RUNNING = 'RUNNING',
SCHEDULED = 'SCHEDULED',
}

export type TaskErrorMessage = {
message: string;
};

export type TaskProgressStatus = {
name: string;
status: TaskStatus;
};

export type TaskType = {
createdAt: string;
Expand All @@ -9,7 +24,7 @@ export type TaskType = {
message: string;
progress: TaskProgressStatus[];
startedAt: string;
status: string;
status: TaskStatus;
type: string;
updatedAt: string;
};
5 changes: 5 additions & 0 deletions packages/manager/apps/zimbra/src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ ods-button.action-menu-item::part(button) {
ods-modal::part(dialog) {
max-height: 100vh;
}

.tile-block-description {
display: flex;
flex-direction: column;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { GuideLinks, GUIDES_LIST } from '@/guides.constants';
import { IAM_ACTIONS } from '@/utils/iamAction.constants';
import GuideLink from '@/components/GuideLink';
import { BadgeStatus } from '@/components/BadgeStatus';
import { OngoingTasks } from './OngoingTasks';

function GeneralInformation() {
const { t } = useTranslation('dashboard');
Expand Down Expand Up @@ -44,15 +45,14 @@ function GeneralInformation() {
: []),
{
id: 'ongoing-task',
label: t(
'Coming Soon',
) /* label={t('zimbra_dashboard_tile_status_ongoingTask')} */,
label: t('zimbra_dashboard_tile_status_ongoingTask'),
value: platformUrn && (
<ManagerText
className="w-full"
urn={platformUrn}
iamActions={[IAM_ACTIONS.platform.get]}
iamActions={[IAM_ACTIONS.task.get]}
>
Coming Soon
<OngoingTasks />
</ManagerText>
),
},
Expand Down
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>
);
};

0 comments on commit 5ee2d16

Please sign in to comment.