feat: highlight expired date and datetime attributes

This commit is contained in:
2025-04-13 12:11:41 +04:00
parent 0a479fae1c
commit 5487aab274
6 changed files with 40 additions and 18 deletions

View File

@@ -8,6 +8,7 @@ export type AttributeSchema = {
name: string;
isApplicableToGroup: boolean;
isShownOnDashboard: boolean;
isHighlightIfExpired: boolean;
isNullable: boolean;
defaultValue: (boolean | number | string | null);
typeId: number;

View File

@@ -7,6 +7,7 @@ export type BaseAttributeSchema = {
name: string;
isApplicableToGroup: boolean;
isShownOnDashboard: boolean;
isHighlightIfExpired: boolean;
isNullable: boolean;
defaultValue: (boolean | number | string | null);
typeId: number;

View File

@@ -32,9 +32,17 @@ const CardAttributesInSummaryItem = ({ cardSummary }: Props) => {
const isHighlightNeeded = (cardAttr: CardAttributeSchema): boolean => {
const type = cardAttr.attribute.type.type;
if (type !== "datetime") return false;
if (!cardAttr.attribute.isHighlightIfExpired) return false;
if (type !== "datetime" && type !== "date") return false;
const datetime = new Date(cardAttr.value as string);
return datetime < new Date();
const curr = new Date();
if (type === "datetime") {
return datetime < curr;
}
curr.setHours(0, 0, 0, 0);
return datetime < curr;
};
return (

View File

@@ -84,6 +84,12 @@ const Attributes = () => {
enableRowVirtualization: true,
mantineTableContainerProps: { style: { maxHeight: "86vh" } },
displayColumnDefOptions: {
"mrt-row-actions": {
size: 100,
},
},
renderRowActions: ({ row }) => (
<Flex gap="md">
<Tooltip label="Редактировать">

View File

@@ -1,5 +1,5 @@
import { useMemo } from "react";
import { MRT_ColumnDef } from "mantine-react-table";
import { MRT_Cell, MRT_ColumnDef } from "mantine-react-table";
import { AttributeSchema } from "../../../../../client";
import { IconCheck, IconX } from "@tabler/icons-react";
import { formatDate, formatDateTime } from "../../../../../types/utils.ts";
@@ -7,6 +7,12 @@ import { Box } from "@mantine/core";
const useAttributesTableColumns = () => {
const Cell = ({ cell }: { cell: MRT_Cell<AttributeSchema, unknown> }) => cell.getValue() ? (
<IconCheck />
) : (
<IconX />
);
return useMemo<MRT_ColumnDef<AttributeSchema>[]>(
() => [
{
@@ -41,29 +47,22 @@ const useAttributesTableColumns = () => {
{
header: "Синхронизировано в группе",
accessorKey: "isApplicableToGroup",
Cell: ({ cell }) => cell.getValue() ? (
<IconCheck />
) : (
<IconX />
),
Cell,
},
{
header: "Вывод на дашборде",
accessorKey: "isShownOnDashboard",
Cell: ({ cell }) => cell.getValue() ? (
<IconCheck />
) : (
<IconX />
),
Cell,
},
{
header: "Подсветка, если просрочен",
accessorKey: "isHighlightIfExpired",
Cell,
},
{
header: "Может быть пустым",
accessorKey: "isNullable",
Cell: ({ cell }) => cell.getValue() ? (
<IconCheck />
) : (
<IconX />
),
Cell,
},
{
header: "Описаниие",

View File

@@ -34,6 +34,7 @@ const AttributeModal = ({
type: undefined,
isApplicableToGroup: false,
isShownOnDashboard: false,
isHighlightIfExpired: false,
isNullable: false,
defaultValue: null,
description: "",
@@ -148,6 +149,12 @@ const AttributeModal = ({
label={"Значение выводится на дашборде"}
{...form.getInputProps("isShownOnDashboard", { type: "checkbox" })}
/>
{(form.values.type?.type === "datetime" || form.values.type?.type === "date") && (
<Checkbox
label={"Подсветка, если просрочено"}
{...form.getInputProps("isHighlightIfExpired", { type: "checkbox" })}
/>
)}
{isNullableInputShown && (
<Checkbox
label={"Может быть пустым"}