-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): add command details on variants commands panel
- Loading branch information
Showing
9 changed files
with
141 additions
and
37 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
83 changes: 83 additions & 0 deletions
83
...nts/App/Singlestudy/Commands/Edition/DraggableCommands/CommandListItem/CommandDetails.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,83 @@ | ||
/** | ||
* Copyright (c) 2024, RTE (https://www.rte-france.com) | ||
* | ||
* See AUTHORS.txt | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
* | ||
* SPDX-License-Identifier: MPL-2.0 | ||
* | ||
* This file is part of the Antares project. | ||
*/ | ||
|
||
import { Fragment } from "react"; | ||
import { Box, Typography, Divider, Tooltip } from "@mui/material"; | ||
import { CommandItem } from "../../commandTypes"; | ||
import { PersonOutlineOutlined, UpdateOutlined } from "@mui/icons-material"; | ||
import { format, formatDistanceToNow, parseISO } from "date-fns"; | ||
import { enUS, fr } from "date-fns/locale"; | ||
import { useTranslation } from "react-i18next"; | ||
import { getCurrentLanguage } from "@/utils/i18nUtils"; | ||
|
||
interface Props { | ||
item: CommandItem; | ||
} | ||
|
||
const formatDate = (dateStr: string) => { | ||
const date = parseISO(dateStr); | ||
return format(date, "dd/MM/yyyy HH:mm"); | ||
}; | ||
|
||
const formatDateWithLocale = (dateStr: string) => { | ||
const date = parseISO(dateStr); | ||
const lang = getCurrentLanguage(); | ||
const locale = lang.startsWith("fr") ? fr : enUS; | ||
|
||
return formatDistanceToNow(date, { | ||
addSuffix: true, | ||
locale, | ||
}); | ||
}; | ||
|
||
function CommandDetails({ item }: Props) { | ||
const [t] = useTranslation(); | ||
const details = [ | ||
{ | ||
icon: <PersonOutlineOutlined sx={{ fontSize: 20 }} />, | ||
text: item.user || t("global.unknown"), | ||
}, | ||
{ | ||
icon: <UpdateOutlined sx={{ fontSize: 20 }} />, | ||
text: item.updatedAt ? formatDate(item.updatedAt) : t("global.unknown"), | ||
tooltip: item.updatedAt | ||
? formatDateWithLocale(item.updatedAt) | ||
: t("global.unknown"), | ||
}, | ||
]; | ||
|
||
return ( | ||
<Box sx={{ display: "flex" }}> | ||
{details.map((detail, index) => ( | ||
<Fragment key={index}> | ||
{index > 0 && ( | ||
<Divider orientation="vertical" flexItem sx={{ mx: 1 }} /> | ||
)} | ||
<Box sx={{ display: "flex", alignItems: "center", gap: "4px" }}> | ||
{detail.icon} | ||
{detail.tooltip ? ( | ||
<Tooltip title={detail.tooltip}> | ||
<Typography sx={{ fontSize: "12px" }}>{detail.text}</Typography> | ||
</Tooltip> | ||
) : ( | ||
<Typography sx={{ fontSize: "12px" }}>{detail.text}</Typography> | ||
)} | ||
</Box> | ||
</Fragment> | ||
))} | ||
</Box> | ||
); | ||
} | ||
|
||
export default CommandDetails; |
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
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