Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mlmoravek committed Jun 7, 2024
1 parent 17d951e commit cec3eec
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
4 changes: 2 additions & 2 deletions packages/docs/components/Table.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ title: Table

| Prop name | Description | Type | Values | Default |
| ---------------- | ---------------------------------------------------------------- | -------------------------------------------- | --------------------------- | ----------------------------------------------------------- |
| customSearch | Define a custom filter funtion for the search | (row: T, filter: string) => boolean | - | |
| customSort | Define a custom sort function | (a: T, b: T, isAsc: boolean) => number | - | |
| display | Provide a display function to edit the output | (value: unknown, row: T) => string | - | |
| doSearch | Define a custom filter funtion for the search | (row: T, filter: string) => boolean | - | |
| doSort | Define a custom sort function | (a: T, b: T, isAsc: boolean) => number | - | |
| field | Define an object property key if data is an object | string | - | |
| headerSelectable | Make header selectable | boolean | - | <code style='white-space: nowrap; padding: 0;'>false</code> |
| label | Define the column label | string | - | |
Expand Down
26 changes: 10 additions & 16 deletions packages/oruga/src/components/table/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1013,8 +1013,8 @@ function isRowFiltered(row: T): boolean {
// get column for filter
const column = tableColumns.value.find((c) => c.field === key);

Check warning on line 1014 in packages/oruga/src/components/table/Table.vue

View check run for this annotation

Codecov / codecov/patch

packages/oruga/src/components/table/Table.vue#L1014

Added line #L1014 was not covered by tests
// if column has onSearch return result
if (typeof column?.doSearch === "function")
return column.doSearch(row, filter);
if (typeof column?.customSearch === "function")
return column.customSearch(row, filter);

Check warning on line 1017 in packages/oruga/src/components/table/Table.vue

View check run for this annotation

Codecov / codecov/patch

packages/oruga/src/components/table/Table.vue#L1017

Added line #L1017 was not covered by tests
const value = getValueByPath(row, key);

Check warning on line 1019 in packages/oruga/src/components/table/Table.vue

View check run for this annotation

Codecov / codecov/patch

packages/oruga/src/components/table/Table.vue#L1019

Added line #L1019 was not covered by tests
if (value == null) return false;
Expand Down Expand Up @@ -1124,8 +1124,8 @@ function sortByColumn(rows: TableRow<T>[]): TableRow<T>[] {
return sortBy<TableRow<T>>(

Check warning on line 1124 in packages/oruga/src/components/table/Table.vue

View check run for this annotation

Codecov / codecov/patch

packages/oruga/src/components/table/Table.vue#L1124

Added line #L1124 was not covered by tests
rows,
column?.field ? "value." + column.field : undefined,

Check warning on line 1126 in packages/oruga/src/components/table/Table.vue

View check run for this annotation

Codecov / codecov/patch

packages/oruga/src/components/table/Table.vue#L1126

Added line #L1126 was not covered by tests
column?.doSort
? (a, b, asc): number => column.doSort(a.value, b.value, asc)
column?.customSort
? (a, b, asc): number => column.customSort(a.value, b.value, asc)
: undefined,

Check warning on line 1129 in packages/oruga/src/components/table/Table.vue

View check run for this annotation

Codecov / codecov/patch

packages/oruga/src/components/table/Table.vue#L1128-L1129

Added lines #L1128 - L1129 were not covered by tests
isAsc.value,
);
Expand Down Expand Up @@ -1672,7 +1672,7 @@ defineExpose({ rows: tableData });
<!-- row data columns -->
<th
v-for="(column, index) in visibleColumns"
:key="column.identifier + ':' + index + 'header'"
:key="`${column.identifier}_${index}_header`"
v-bind="column.thAttrsData"
:class="thClasses(column)"
:style="isMobileActive ? {} : column.style"
Expand Down Expand Up @@ -1754,9 +1754,7 @@ defineExpose({ rows: tableData });
<!-- row data columns -->
<th
v-for="(column, index) in visibleColumns"
:key="
column.identifier + ':' + index + 'searchable'
"
:key="`${column.identifier}_${index}_searchable`"
v-bind="column.thAttrsData"
:class="thClasses(column)"
:style="isMobileActive ? {} : column.style">
Expand Down Expand Up @@ -1793,9 +1791,7 @@ defineExpose({ rows: tableData });
<!-- row data columns -->
<th
v-for="(column, index) in visibleColumns"
:key="
column.identifier + ':' + index + 'subheading'
"
:key="`${column.identifier}_${index}_subheading`"
:style="isMobileActive ? {} : column.style"
:class="[...thBaseClasses, ...thSubheadingClasses]">
<template v-if="column.$slots?.subheading">
Expand All @@ -1816,7 +1812,7 @@ defineExpose({ rows: tableData });
<tbody>
<template
v-for="(row, index) in visibleRows"
:key="row.key + ':' + index + '_row'">
:key="`${row.key}_${index}_row`">
<tr
:class="rowClasses(row, index)"
:draggable="canDragRow"
Expand Down Expand Up @@ -1875,9 +1871,7 @@ defineExpose({ rows: tableData });
<!-- row data columns -->
<o-slot-component
v-for="(column, colindex) in visibleColumns"
:key="
column.identifier + index + ':' + colindex
"
:key="`${column.identifier}_${index}_${colindex}`"
v-bind="column.tdAttrsData[index]"
:component="column.$el"
name="default"
Expand Down Expand Up @@ -1935,7 +1929,7 @@ defineExpose({ rows: tableData });
:index="index" />
<tr
v-else
:key="row.key + '_detail'"
:key="`${row.key}_detail`"
:class="detailedClasses">
<td :colspan="columnCount">
<!--
Expand Down
4 changes: 2 additions & 2 deletions packages/oruga/src/components/table/TableColumn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ const props = defineProps({
/** Make header selectable */
headerSelectable: { type: Boolean, default: false },
/** Define a custom sort function */
doSort: {
customSort: {
type: Function as PropType<(a: T, b: T, isAsc: boolean) => number>,
default: undefined,
},
/** Define a custom filter funtion for the search */
doSearch: {
customSearch: {
type: Function as PropType<(row: T, filter: string) => boolean>,
default: undefined,
},
Expand Down

0 comments on commit cec3eec

Please sign in to comment.