Skip to content

Commit bef6bce

Browse files
committed
refactor: use MRT for config relationships
Fixes #2285 fix: typescript error refactor: move to MRT for tables for configs Fixes #2285 fix: fix empty text for default grouping value
1 parent 930f128 commit bef6bce

File tree

10 files changed

+379
-463
lines changed

10 files changed

+379
-463
lines changed

src/components/Configs/ConfigList/Cells/ConfigListChangeCell.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import { ConfigItem } from "@flanksource-ui/api/types/configs";
12
import ChangeCountIcon from "@flanksource-ui/ui/Icons/ChangeCount";
2-
import { CellContext } from "@tanstack/react-table";
3-
import { ConfigItem } from "../../../../api/types/configs";
3+
import { MRTCellProps } from "@flanksource-ui/ui/MRTDataTable/MRTCellProps";
44

55
export default function ConfigListChangeCell({
66
row,
77
column
8-
}: CellContext<ConfigItem, any>) {
8+
}: MRTCellProps<ConfigItem>) {
99
const changes = row?.getValue<ConfigItem["changes"]>(column.id);
1010

1111
if (!changes) {

src/components/Configs/ConfigList/Cells/ConfigListCostCell.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { CellContext, Row } from "@tanstack/react-table";
2+
import { MRT_Row } from "mantine-react-table";
23
import {
34
ConfigItem,
45
ConfigSummary,
@@ -16,14 +17,19 @@ export default function ConfigListCostCell({
1617
* Recursively aggregate costs for a given row and its children, and its children's children, etc.
1718
*
1819
*/
19-
const aggregatedCosts = (
20-
rows: Row<ConfigItem>,
20+
export const aggregatedCosts = (
21+
rows: Row<ConfigItem> | MRT_Row<ConfigItem>,
2122
data: Required<Costs>
2223
): Required<Costs> => {
23-
if (rows.subRows.length === 0) {
24+
const subRows = rows.subRows;
25+
if (!subRows) {
2426
return data;
2527
}
26-
return rows.subRows.reduce((acc, row) => {
28+
if (subRows.length === 0) {
29+
return data;
30+
}
31+
// @ts-ignore
32+
return subRows.reduce((acc, row) => {
2733
if (row.original) {
2834
acc.cost_total_30d! += row.original.cost_total_30d ?? 0;
2935
acc.cost_total_7d! += row.original.cost_total_7d ?? 0;

src/components/Configs/ConfigList/Cells/ConfigListDateCell.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { MRTCellProps } from "@flanksource-ui/ui/MRTDataTable/MRTCellProps";
12
import { CellContext } from "@tanstack/react-table";
23
import { FaTrash } from "react-icons/fa";
34
import { Age } from "../../../../ui/Age";
@@ -22,3 +23,24 @@ export default function ConfigListDateCell<T extends Record<string, any>>({
2223
</div>
2324
);
2425
}
26+
27+
export function MRTConfigListDateCell<T extends Record<string, any>>({
28+
column,
29+
row,
30+
cell
31+
}: MRTCellProps<T>) {
32+
const dateString = cell.getValue();
33+
if (dateString === "0001-01-01T00:00:00") {
34+
return null;
35+
}
36+
const isDeleted = !!row.original.deleted_at;
37+
const value = isDeleted ? row.original.deleted_at : dateString;
38+
return (
39+
<div className="text-xs">
40+
<Age from={value} />
41+
{column.id === "updated_at" && isDeleted && (
42+
<FaTrash className="mx-2 inline h-4 w-4 align-middle text-gray-400" />
43+
)}
44+
</div>
45+
);
46+
}

src/components/Configs/ConfigList/Cells/ConfigListNameCell.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { CellContext } from "@tanstack/react-table";
1+
import { MRTCellProps } from "@flanksource-ui/ui/MRTDataTable/MRTCellProps";
22
import React from "react";
33
import { ConfigItem } from "../../../../api/types/configs";
44
import ConfigsTypeIcon from "../../ConfigsTypeIcon";
55

6-
function ConfigListNameCell({ row, getValue }: CellContext<ConfigItem, any>) {
6+
function ConfigListNameCell({ row, cell }: MRTCellProps<ConfigItem>) {
77
const configType = row.original.type;
88

99
return (
@@ -14,7 +14,7 @@ function ConfigListNameCell({ row, getValue }: CellContext<ConfigItem, any>) {
1414
}}
1515
>
1616
<ConfigsTypeIcon config={{ type: configType }} showPrimaryIcon={false}>
17-
<span>{getValue()}</span>
17+
<span>{cell.getValue<string>()}</span>
1818
</ConfigsTypeIcon>
1919
</div>
2020
);

src/components/Configs/ConfigList/Cells/MRTConfigListTagsCell.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import { useCallback } from "react";
44
import { useSearchParams } from "react-router-dom";
55
import { ConfigItem } from "../../../../api/types/configs";
66

7-
type MRTConfigListTagsCellProps<T extends Pick<ConfigItem, "tags" | "id">> =
8-
Pick<MRTCellProps<T>, "cell" | "row"> & {
9-
hideGroupByView?: boolean;
10-
label?: string;
11-
enableFilterByTag?: boolean;
12-
};
7+
type MRTConfigListTagsCellProps<
8+
T extends {
9+
tags?: Record<string, any>;
10+
id: string;
11+
}
12+
> = MRTCellProps<T> & {
13+
hideGroupByView?: boolean;
14+
enableFilterByTag?: boolean;
15+
};
1316

1417
export default function MRTConfigListTagsCell<
1518
T extends { tags?: Record<string, any>; id: string }

src/components/Configs/ConfigList/ConfigListColumn.tsx

Lines changed: 0 additions & 213 deletions
This file was deleted.

0 commit comments

Comments
 (0)