Skip to content

Commit

Permalink
feat: Add created_at and updated_at to cases
Browse files Browse the repository at this point in the history
  • Loading branch information
daryllimyt committed Mar 23, 2024
1 parent e721d3f commit 7482ce6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions frontend/src/components/cases/columns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ export const columns: ColumnDef<Case>[] = [
return value.includes(row.getValue<Case["id"]>(id))
},
},
{
accessorKey: "created_at",
header: ({ column }) => (
<DataTableColumnHeader column={column} title="Created At" />
),
cell: ({ row }) => row.getValue<Case["created_at"]>("created_at"),
filterFn: (row, id, value) => {
return value.includes(row.getValue<Case["id"]>(id))
},
},
{
accessorKey: "title",
header: ({ column }) => (
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/types/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ export const caseSchema = z.object({
context: z.record(z.string()).nullable().or(z.string()),
action: z.string().nullable(),
suppression: z.record(z.boolean()).nullable(),
created_at: z.string(),
updated_at: z.string(),
})

export type Case = z.infer<typeof caseSchema>
Expand Down
7 changes: 7 additions & 0 deletions tracecat/types/cases.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import UTC, datetime
from typing import Any, Literal, Self
from uuid import uuid4

Expand All @@ -21,6 +22,8 @@ class Case(BaseModel):
context: dict[str, str] | None = None
action: str | None = None
suppression: dict[str, bool] | None = None
created_at: datetime = Field(default_factory=lambda: datetime.now(UTC))
updated_at: datetime = Field(default_factory=lambda: datetime.now(UTC))

def flatten(self) -> dict[str, Any]:
"""Flattens nested object by JSON serializing object fields."""
Expand All @@ -42,6 +45,8 @@ def flatten(self) -> dict[str, Any]:
"suppression": orjson.dumps(self.suppression).decode("utf-8")
if self.suppression
else None,
"created_at": self.created_at,
"updated_at": self.updated_at,
}

@classmethod
Expand All @@ -65,6 +70,8 @@ def from_flattened(cls, flat_dict: dict[str, Any]) -> Self:
suppression=orjson.loads(flat_dict["suppression"])
if flat_dict["suppression"]
else None,
created_at=flat_dict["created_at"],
updated_at=flat_dict["updated_at"],
)

@classmethod
Expand Down

0 comments on commit 7482ce6

Please sign in to comment.