feat: highlight expired date and datetime attributes
This commit is contained in:
@@ -8,6 +8,7 @@ export type AttributeSchema = {
|
|||||||
name: string;
|
name: string;
|
||||||
isApplicableToGroup: boolean;
|
isApplicableToGroup: boolean;
|
||||||
isShownOnDashboard: boolean;
|
isShownOnDashboard: boolean;
|
||||||
|
isHighlightIfExpired: boolean;
|
||||||
isNullable: boolean;
|
isNullable: boolean;
|
||||||
defaultValue: (boolean | number | string | null);
|
defaultValue: (boolean | number | string | null);
|
||||||
typeId: number;
|
typeId: number;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export type BaseAttributeSchema = {
|
|||||||
name: string;
|
name: string;
|
||||||
isApplicableToGroup: boolean;
|
isApplicableToGroup: boolean;
|
||||||
isShownOnDashboard: boolean;
|
isShownOnDashboard: boolean;
|
||||||
|
isHighlightIfExpired: boolean;
|
||||||
isNullable: boolean;
|
isNullable: boolean;
|
||||||
defaultValue: (boolean | number | string | null);
|
defaultValue: (boolean | number | string | null);
|
||||||
typeId: number;
|
typeId: number;
|
||||||
|
|||||||
@@ -32,9 +32,17 @@ const CardAttributesInSummaryItem = ({ cardSummary }: Props) => {
|
|||||||
|
|
||||||
const isHighlightNeeded = (cardAttr: CardAttributeSchema): boolean => {
|
const isHighlightNeeded = (cardAttr: CardAttributeSchema): boolean => {
|
||||||
const type = cardAttr.attribute.type.type;
|
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);
|
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 (
|
return (
|
||||||
|
|||||||
@@ -84,6 +84,12 @@ const Attributes = () => {
|
|||||||
enableRowVirtualization: true,
|
enableRowVirtualization: true,
|
||||||
mantineTableContainerProps: { style: { maxHeight: "86vh" } },
|
mantineTableContainerProps: { style: { maxHeight: "86vh" } },
|
||||||
|
|
||||||
|
displayColumnDefOptions: {
|
||||||
|
"mrt-row-actions": {
|
||||||
|
size: 100,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
renderRowActions: ({ row }) => (
|
renderRowActions: ({ row }) => (
|
||||||
<Flex gap="md">
|
<Flex gap="md">
|
||||||
<Tooltip label="Редактировать">
|
<Tooltip label="Редактировать">
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useMemo } from "react";
|
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 { AttributeSchema } from "../../../../../client";
|
||||||
import { IconCheck, IconX } from "@tabler/icons-react";
|
import { IconCheck, IconX } from "@tabler/icons-react";
|
||||||
import { formatDate, formatDateTime } from "../../../../../types/utils.ts";
|
import { formatDate, formatDateTime } from "../../../../../types/utils.ts";
|
||||||
@@ -7,6 +7,12 @@ import { Box } from "@mantine/core";
|
|||||||
|
|
||||||
|
|
||||||
const useAttributesTableColumns = () => {
|
const useAttributesTableColumns = () => {
|
||||||
|
const Cell = ({ cell }: { cell: MRT_Cell<AttributeSchema, unknown> }) => cell.getValue() ? (
|
||||||
|
<IconCheck />
|
||||||
|
) : (
|
||||||
|
<IconX />
|
||||||
|
);
|
||||||
|
|
||||||
return useMemo<MRT_ColumnDef<AttributeSchema>[]>(
|
return useMemo<MRT_ColumnDef<AttributeSchema>[]>(
|
||||||
() => [
|
() => [
|
||||||
{
|
{
|
||||||
@@ -41,29 +47,22 @@ const useAttributesTableColumns = () => {
|
|||||||
{
|
{
|
||||||
header: "Синхронизировано в группе",
|
header: "Синхронизировано в группе",
|
||||||
accessorKey: "isApplicableToGroup",
|
accessorKey: "isApplicableToGroup",
|
||||||
Cell: ({ cell }) => cell.getValue() ? (
|
Cell,
|
||||||
<IconCheck />
|
|
||||||
) : (
|
|
||||||
<IconX />
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: "Вывод на дашборде",
|
header: "Вывод на дашборде",
|
||||||
accessorKey: "isShownOnDashboard",
|
accessorKey: "isShownOnDashboard",
|
||||||
Cell: ({ cell }) => cell.getValue() ? (
|
Cell,
|
||||||
<IconCheck />
|
},
|
||||||
) : (
|
{
|
||||||
<IconX />
|
header: "Подсветка, если просрочен",
|
||||||
),
|
accessorKey: "isHighlightIfExpired",
|
||||||
|
Cell,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: "Может быть пустым",
|
header: "Может быть пустым",
|
||||||
accessorKey: "isNullable",
|
accessorKey: "isNullable",
|
||||||
Cell: ({ cell }) => cell.getValue() ? (
|
Cell,
|
||||||
<IconCheck />
|
|
||||||
) : (
|
|
||||||
<IconX />
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
header: "Описаниие",
|
header: "Описаниие",
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ const AttributeModal = ({
|
|||||||
type: undefined,
|
type: undefined,
|
||||||
isApplicableToGroup: false,
|
isApplicableToGroup: false,
|
||||||
isShownOnDashboard: false,
|
isShownOnDashboard: false,
|
||||||
|
isHighlightIfExpired: false,
|
||||||
isNullable: false,
|
isNullable: false,
|
||||||
defaultValue: null,
|
defaultValue: null,
|
||||||
description: "",
|
description: "",
|
||||||
@@ -148,6 +149,12 @@ const AttributeModal = ({
|
|||||||
label={"Значение выводится на дашборде"}
|
label={"Значение выводится на дашборде"}
|
||||||
{...form.getInputProps("isShownOnDashboard", { type: "checkbox" })}
|
{...form.getInputProps("isShownOnDashboard", { type: "checkbox" })}
|
||||||
/>
|
/>
|
||||||
|
{(form.values.type?.type === "datetime" || form.values.type?.type === "date") && (
|
||||||
|
<Checkbox
|
||||||
|
label={"Подсветка, если просрочено"}
|
||||||
|
{...form.getInputProps("isHighlightIfExpired", { type: "checkbox" })}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
{isNullableInputShown && (
|
{isNullableInputShown && (
|
||||||
<Checkbox
|
<Checkbox
|
||||||
label={"Может быть пустым"}
|
label={"Может быть пустым"}
|
||||||
|
|||||||
Reference in New Issue
Block a user