Skip to content

Commit b16e11c

Browse files
committed
UNFIN
1 parent bdf4517 commit b16e11c

File tree

11 files changed

+24
-13
lines changed

11 files changed

+24
-13
lines changed

packages/vue-labs/src/components/FTable/columns/anchor.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,5 @@ export function normalizeAnchorColumn<T, K extends keyof T>(
4545
type: "anchor",
4646
text: getValueFn(column.text, column.key, String, ""),
4747
href: column.href,
48-
sortable: column.key ?? null,
4948
};
5049
}

packages/vue-labs/src/components/FTable/columns/base.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { type MaybeRef, type Ref, ref, toRef } from "vue";
2+
import { getSortable } from "./helpers/get-sortable";
23

34
/**
45
* @public
@@ -14,6 +15,7 @@ export interface TableColumnBase {
1415
header: string | Readonly<Ref<string>>;
1516
description?: string | Readonly<Ref<string | null>>;
1617
size?: TableColumnSize | Readonly<Ref<TableColumnSize | null>>;
18+
sort?: boolean;
1719
enabled?: MaybeRef<boolean>;
1820
}
1921

@@ -41,30 +43,33 @@ export type OmittedNormalizedColumnProperties =
4143
| "id"
4244
| "header"
4345
| "description"
46+
| "sortable"
4447
| "size"
4548
| "component"
4649
| "enabled";
4750

4851
/**
4952
* @internal
5053
*/
51-
export function normalizeBaseColumn(
52-
column: TableColumnBase,
54+
export function normalizeBaseColumn<K = never>(
55+
column: TableColumnBase & { sort?: boolean; key?: K },
5356
): Pick<
54-
NormalizedTableColumnBase<unknown>,
55-
Exclude<OmittedNormalizedColumnProperties, "component">
57+
NormalizedTableColumnBase<K>,
58+
"id" | "header" | "description" | "size" | "enabled" | "sortable"
5659
> {
5760
const id = Symbol();
5861
const header = toRef(column.header);
5962
const description =
6063
column.description !== undefined ? toRef(column.description) : ref("");
6164
const size: Readonly<Ref<TableColumnSize | null>> =
6265
column.size !== undefined ? toRef(column.size) : ref("grow");
66+
const sortable = getSortable(column);
6367

6468
return {
6569
id,
6670
header,
6771
description,
72+
sortable,
6873
size,
6974
enabled: column.enabled ?? true,
7075
};

packages/vue-labs/src/components/FTable/columns/button.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,5 @@ export function normalizeButtonColumn<T, K extends keyof T>(
5454
onClick: column.onClick,
5555
icon: column.icon ?? null,
5656
iconLibrary: column.iconLibrary,
57-
sortable: column.key ?? null,
5857
};
5958
}

packages/vue-labs/src/components/FTable/columns/checkbox.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,5 @@ export function normalizeCheckboxColumn<T, K extends keyof T>(
5757
typeof column.editable === "function"
5858
? column.editable
5959
: () => Boolean(column.editable ?? false),
60-
sortable: column.key ?? null,
6160
};
6261
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* Determines the sortable value for a table column based on the sort property and key.
3+
*
4+
* @param column - An object with sort and key properties
5+
* @returns The key if sorting should be enabled, null otherwise
6+
*
7+
* @internal
8+
*/
9+
export function getSortable<K>(column: { sort?: boolean; key?: K }): K | null {
10+
// If sort is explicitly set to true, use key (or null if no key)
11+
// If sort is explicitly set to false, return null
12+
// If sort is undefined, default to true if key exists, false otherwise
13+
const shouldSort = column.sort ?? !!column.key;
14+
return shouldSort ? (column.key ?? null) : null;
15+
}

packages/vue-labs/src/components/FTable/columns/number.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ export function normalizeNumberColumn<T, K extends keyof T>(
109109
validation: column.validation ?? {},
110110
hasValidation:
111111
column.type.startsWith("text:") || Boolean(column.validation),
112-
sortable: column.key ?? null,
113112
formatter,
114113
parser,
115114
};

packages/vue-labs/src/components/FTable/columns/radio.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,5 @@ export function normalizeRadioColumn<T, K extends keyof T>(
4848
label: getLabelFn(column.label),
4949
checked: getValueFn(column.checked, column.key, Boolean, false),
5050
update: getUpdateFn(column.update, column.key),
51-
sortable: column.key ?? null,
5251
};
5352
}

packages/vue-labs/src/components/FTable/columns/row-header.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,5 @@ export function normalizeRowHeaderColumn<T, K extends keyof T>(
4545
return {
4646
type: "rowheader",
4747
text: getValueFn(column.text, column.key, String, ""),
48-
sortable: column.key ?? null,
4948
};
5049
}

packages/vue-labs/src/components/FTable/columns/select.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,5 @@ export function normalizeSelectColumn<T, K extends keyof T>(
5757
? column.editable
5858
: () => Boolean(column.editable ?? false),
5959
options: column.options,
60-
sortable: column.key ?? null,
6160
};
6261
}

packages/vue-labs/src/components/FTable/columns/simple.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export function normalizeSimpleColumn<T, K extends keyof T>(
3737
/* do nothing */
3838
},
3939
editable: () => false,
40-
sortable: column.key ?? null,
4140
validation: {},
4241
hasValidation: false,
4342
formatter: (value) => value,

0 commit comments

Comments
 (0)