Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions packages/vue-labs/src/components/FTable/get-meta-rows.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { setItemIdentifiers } from "@fkui/vue";
import { getMetaRows } from "./get-meta-rows";

const rows = [
{
name: "A",
},
{
name: "B",
expandable: [],
},
{
name: "C",
expandable: [
{
name: "C1",
},
],
},
];

it("should only mark rows with non-empty children as expandable", () => {
const keyedRows = setItemIdentifiers(rows, "name", "expandable");
const result = getMetaRows(keyedRows, new Set(), "expandable");

expect(result).toHaveLength(3);

expect(result[0].isExpandable).toBe(false);

expect(result[1].isExpandable).toBe(false);

expect(result[2].isExpandable).toBe(true);
});
4 changes: 3 additions & 1 deletion packages/vue-labs/src/components/FTable/get-meta-rows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ export function getMetaRows<T>(
walk(keyedRows, expandableAttribute, (row, level) => {
const key = getItemIdentifier(row);
const isExpandable = Boolean(
expandableAttribute && row[expandableAttribute],
expandableAttribute &&
Array.isArray(row[expandableAttribute]) &&
row[expandableAttribute].length > 0,
);
const isExpanded = isExpandable && expandedKeys.has(key);

Expand Down
Loading