2024-08-13 14:33:11 +02:00
|
|
|
import type { FC } from 'react';
|
|
|
|
import {
|
|
|
|
StyledProjectCard,
|
|
|
|
StyledDivHeader,
|
|
|
|
StyledBox,
|
|
|
|
StyledCardTitle,
|
|
|
|
StyledDivInfo,
|
|
|
|
StyledProjectCardBody,
|
|
|
|
StyledIconBox,
|
|
|
|
StyledActions,
|
2024-08-27 14:11:07 +02:00
|
|
|
} from './ProjectCard.styles';
|
2024-08-13 14:33:11 +02:00
|
|
|
import { ProjectCardFooter } from './ProjectCardFooter/ProjectCardFooter';
|
|
|
|
import { ProjectModeBadge } from './ProjectModeBadge/ProjectModeBadge';
|
|
|
|
import type { ProjectSchemaOwners } from 'openapi';
|
|
|
|
import { ProjectIcon } from 'component/common/ProjectIcon/ProjectIcon';
|
|
|
|
import { formatDateYMDHM } from 'utils/formatDate';
|
|
|
|
import { useLocationSettings } from 'hooks/useLocationSettings';
|
|
|
|
import { parseISO } from 'date-fns';
|
|
|
|
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
|
|
|
|
import { Box, Link, Tooltip } from '@mui/material';
|
|
|
|
import { Link as RouterLink } from 'react-router-dom';
|
|
|
|
import {
|
|
|
|
DELETE_PROJECT,
|
2024-08-15 09:25:49 +02:00
|
|
|
UPDATE_PROJECT,
|
2024-08-13 14:33:11 +02:00
|
|
|
} from 'component/providers/AccessProvider/permissions';
|
|
|
|
import Undo from '@mui/icons-material/Undo';
|
|
|
|
import PermissionIconButton from 'component/common/PermissionIconButton/PermissionIconButton';
|
|
|
|
import Delete from '@mui/icons-material/Delete';
|
2024-08-15 16:19:29 +02:00
|
|
|
import { Highlighter } from 'component/common/Highlighter/Highlighter';
|
|
|
|
import { useSearchHighlightContext } from 'component/common/Table/SearchHighlightContext/SearchHighlightContext';
|
2024-08-21 12:03:03 +02:00
|
|
|
import { TimeAgo } from 'component/common/TimeAgo/TimeAgo';
|
2024-08-13 14:33:11 +02:00
|
|
|
|
2024-08-15 09:25:49 +02:00
|
|
|
export type ProjectArchiveCardProps = {
|
2024-08-13 14:33:11 +02:00
|
|
|
id: string;
|
|
|
|
name: string;
|
|
|
|
archivedAt?: string;
|
|
|
|
onRevive: () => void;
|
|
|
|
onDelete: () => void;
|
2024-08-15 09:25:49 +02:00
|
|
|
mode?: string;
|
2024-08-13 14:33:11 +02:00
|
|
|
owners?: ProjectSchemaOwners;
|
2024-08-15 09:25:49 +02:00
|
|
|
};
|
2024-08-13 14:33:11 +02:00
|
|
|
|
2024-08-15 09:25:49 +02:00
|
|
|
export const ProjectArchiveCard: FC<ProjectArchiveCardProps> = ({
|
2024-08-13 14:33:11 +02:00
|
|
|
id,
|
|
|
|
name,
|
|
|
|
archivedAt,
|
|
|
|
onRevive,
|
|
|
|
onDelete,
|
|
|
|
mode,
|
|
|
|
owners,
|
|
|
|
}) => {
|
|
|
|
const { locationSettings } = useLocationSettings();
|
2024-08-15 16:19:29 +02:00
|
|
|
const { searchQuery } = useSearchHighlightContext();
|
2024-08-13 14:33:11 +02:00
|
|
|
|
|
|
|
return (
|
2024-08-15 16:19:29 +02:00
|
|
|
<StyledProjectCard disabled data-testid={id}>
|
2024-08-13 14:33:11 +02:00
|
|
|
<StyledProjectCardBody>
|
|
|
|
<StyledDivHeader>
|
|
|
|
<StyledIconBox>
|
|
|
|
<ProjectIcon color='action' />
|
|
|
|
</StyledIconBox>
|
|
|
|
<StyledBox data-loading>
|
2024-08-19 15:33:00 +02:00
|
|
|
<Tooltip title={`id: ${id}`} arrow>
|
|
|
|
<StyledCardTitle>
|
|
|
|
<Highlighter search={searchQuery}>
|
|
|
|
{name}
|
|
|
|
</Highlighter>
|
|
|
|
</StyledCardTitle>
|
|
|
|
</Tooltip>
|
2024-08-13 14:33:11 +02:00
|
|
|
</StyledBox>
|
|
|
|
<ProjectModeBadge mode={mode} />
|
|
|
|
</StyledDivHeader>
|
|
|
|
<StyledDivInfo>
|
|
|
|
<ConditionallyRender
|
|
|
|
condition={Boolean(archivedAt)}
|
|
|
|
show={
|
|
|
|
<Tooltip
|
|
|
|
title={formatDateYMDHM(
|
|
|
|
parseISO(archivedAt as string),
|
|
|
|
locationSettings.locale,
|
|
|
|
)}
|
|
|
|
arrow
|
|
|
|
>
|
|
|
|
<Box
|
|
|
|
sx={(theme) => ({
|
|
|
|
color: theme.palette.text.secondary,
|
|
|
|
})}
|
|
|
|
>
|
|
|
|
<p data-loading>
|
2024-08-19 14:22:58 +02:00
|
|
|
Archived:{' '}
|
2024-08-13 14:33:11 +02:00
|
|
|
<TimeAgo
|
2024-08-21 12:03:03 +02:00
|
|
|
date={archivedAt}
|
|
|
|
refresh={false}
|
2024-08-13 14:33:11 +02:00
|
|
|
/>
|
|
|
|
</p>
|
|
|
|
</Box>
|
|
|
|
</Tooltip>
|
|
|
|
}
|
|
|
|
/>
|
2024-08-19 11:24:39 +02:00
|
|
|
<Link
|
|
|
|
component={RouterLink}
|
|
|
|
to={`/archive?search=project%3A${encodeURI(id)}`}
|
|
|
|
>
|
|
|
|
<p>View archived flags</p>
|
|
|
|
</Link>
|
2024-08-13 14:33:11 +02:00
|
|
|
</StyledDivInfo>
|
|
|
|
</StyledProjectCardBody>
|
2024-08-15 09:25:49 +02:00
|
|
|
<ProjectCardFooter id={id} disabled owners={owners}>
|
|
|
|
<StyledActions>
|
|
|
|
<PermissionIconButton
|
|
|
|
onClick={onRevive}
|
|
|
|
projectId={id}
|
|
|
|
permission={UPDATE_PROJECT}
|
2024-08-19 15:33:00 +02:00
|
|
|
tooltipProps={{ title: 'Revive project' }}
|
2024-08-15 09:25:49 +02:00
|
|
|
data-testid={`revive-feature-flag-button`}
|
|
|
|
>
|
|
|
|
<Undo />
|
|
|
|
</PermissionIconButton>
|
|
|
|
<PermissionIconButton
|
|
|
|
permission={DELETE_PROJECT}
|
|
|
|
projectId={id}
|
|
|
|
tooltipProps={{ title: 'Permanently delete project' }}
|
|
|
|
onClick={onDelete}
|
|
|
|
>
|
|
|
|
<Delete />
|
|
|
|
</PermissionIconButton>
|
|
|
|
</StyledActions>
|
2024-08-13 14:33:11 +02:00
|
|
|
</ProjectCardFooter>
|
|
|
|
</StyledProjectCard>
|
|
|
|
);
|
|
|
|
};
|