Extract date formatting into separate file

Change-Id: I0004617349253450c6c706e4334d63924203a804
This commit is contained in:
Manuel Stahl 2024-04-22 13:42:53 +02:00
parent 2466af6936
commit 39dd6617de
7 changed files with 11 additions and 69 deletions

View file

@ -21,15 +21,7 @@ import { MXCField } from "./media";
import PageviewIcon from "@mui/icons-material/Pageview"; import PageviewIcon from "@mui/icons-material/Pageview";
import ReportIcon from "@mui/icons-material/Warning"; import ReportIcon from "@mui/icons-material/Warning";
import ViewListIcon from "@mui/icons-material/ViewList"; import ViewListIcon from "@mui/icons-material/ViewList";
import { date_format } from "./date";
const date_format: Intl.DateTimeFormatOptions = {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
};
const ReportPagination = () => ( const ReportPagination = () => (
<Pagination rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} /> <Pagination rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />

View file

@ -22,41 +22,12 @@ import {
Toolbar, Toolbar,
} from "react-admin"; } from "react-admin";
import RegistrationTokenIcon from "@mui/icons-material/ConfirmationNumber"; import RegistrationTokenIcon from "@mui/icons-material/ConfirmationNumber";
import { date_format, dateFormatter, dateParser } from "./date";
const date_format = {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
};
const validateToken = [regex(/^[A-Za-z0-9._~-]{0,64}$/)]; const validateToken = [regex(/^[A-Za-z0-9._~-]{0,64}$/)];
const validateUsesAllowed = [number()]; const validateUsesAllowed = [number()];
const validateLength = [number(), maxValue(64)]; const validateLength = [number(), maxValue(64)];
const dateParser = v => {
const d = new Date(v);
if (isNaN(d)) return 0;
return d.getTime();
};
const dateFormatter = v => {
if (v === undefined || v === null) return;
const d = new Date(v);
const pad = "00";
const year = d.getFullYear().toString();
const month = (pad + (d.getMonth() + 1).toString()).slice(-2);
const day = (pad + d.getDate().toString()).slice(-2);
const hour = (pad + d.getHours().toString()).slice(-2);
const minute = (pad + d.getMinutes().toString()).slice(-2);
// target format yyyy-MM-ddThh:mm
return `${year}-${month}-${day}T${hour}:${minute}`;
};
const registrationTokenFilters = [<BooleanInput source="valid" alwaysOn />]; const registrationTokenFilters = [<BooleanInput source="valid" alwaysOn />];
export const RegistrationTokenList = (props: ListProps) => ( export const RegistrationTokenList = (props: ListProps) => (

View file

@ -1,4 +1,4 @@
export const DATE_FORMAT: Intl.DateTimeFormatOptions = { export const date_format: Intl.DateTimeFormatOptions = {
year: "numeric", year: "numeric",
month: "2-digit", month: "2-digit",
day: "2-digit", day: "2-digit",

View file

@ -29,7 +29,7 @@ import {
useTranslate, useTranslate,
} from "react-admin"; } from "react-admin";
import { DATE_FORMAT } from "./date"; import { date_format } from "./date";
const DestinationPagination = () => ( const DestinationPagination = () => (
<Pagination rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} /> <Pagination rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />
@ -112,8 +112,8 @@ export const DestinationList = (props: ListProps) => {
bulkActionButtons={false} bulkActionButtons={false}
> >
<TextField source="destination" /> <TextField source="destination" />
<DateField source="failure_ts" showTime options={DATE_FORMAT} /> <DateField source="failure_ts" showTime options={date_format} />
<DateField source="retry_last_ts" showTime options={DATE_FORMAT} /> <DateField source="retry_last_ts" showTime options={date_format} />
<TextField source="retry_interval" /> <TextField source="retry_interval" />
<TextField source="last_successful_stream_ordering" /> <TextField source="last_successful_stream_ordering" />
<DestinationReconnectButton /> <DestinationReconnectButton />
@ -133,8 +133,8 @@ export const DestinationShow = (props: ShowProps) => {
<TabbedShowLayout> <TabbedShowLayout>
<Tab label="status" icon={<ViewListIcon />}> <Tab label="status" icon={<ViewListIcon />}>
<TextField source="destination" /> <TextField source="destination" />
<DateField source="failure_ts" showTime options={DATE_FORMAT} /> <DateField source="failure_ts" showTime options={date_format} />
<DateField source="retry_last_ts" showTime options={DATE_FORMAT} /> <DateField source="retry_last_ts" showTime options={date_format} />
<TextField source="retry_interval" /> <TextField source="retry_interval" />
<TextField source="last_successful_stream_ordering" /> <TextField source="last_successful_stream_ordering" />
</Tab> </Tab>

View file

@ -34,17 +34,12 @@ import LockIcon from "@mui/icons-material/Lock";
import LockOpenIcon from "@mui/icons-material/LockOpen"; import LockOpenIcon from "@mui/icons-material/LockOpen";
import FileOpenIcon from "@mui/icons-material/FileOpen"; import FileOpenIcon from "@mui/icons-material/FileOpen";
import { alpha, useTheme } from "@mui/material/styles"; import { alpha, useTheme } from "@mui/material/styles";
import { dateParser } from "./date";
import { getMediaUrl } from "../synapse/synapse"; import { getMediaUrl } from "../synapse/synapse";
const DeleteMediaDialog = ({ open, onClose, onSubmit }) => { const DeleteMediaDialog = ({ open, onClose, onSubmit }) => {
const translate = useTranslate(); const translate = useTranslate();
const dateParser = v => {
const d = new Date(v);
if (isNaN(d)) return 0;
return d.getTime();
};
const DeleteMediaToolbar = (props: ToolbarProps) => ( const DeleteMediaToolbar = (props: ToolbarProps) => (
<Toolbar {...props}> <Toolbar {...props}>
<SaveButton <SaveButton

View file

@ -43,15 +43,7 @@ import {
RoomDirectoryUnpublishButton, RoomDirectoryUnpublishButton,
RoomDirectoryPublishButton, RoomDirectoryPublishButton,
} from "./RoomDirectory"; } from "./RoomDirectory";
import { date_format } from "./date";
const date_format = {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
};
const RoomPagination = () => ( const RoomPagination = () => (
<Pagination rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} /> <Pagination rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />

View file

@ -57,6 +57,7 @@ import {
ProtectMediaButton, ProtectMediaButton,
QuarantineMediaButton, QuarantineMediaButton,
} from "./media"; } from "./media";
import { date_format } from "./date";
const choices_medium = [ const choices_medium = [
{ id: "email", name: "resources.users.email" }, { id: "email", name: "resources.users.email" },
@ -68,15 +69,6 @@ const choices_type = [
{ id: "support", name: "support" }, { id: "support", name: "support" },
]; ];
const date_format: Intl.DateTimeFormatOptions = {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
};
const UserListActions = () => { const UserListActions = () => {
const { isLoading, total } = useListContext(); const { isLoading, total } = useListContext();
return ( return (