Skip to content

Commit

Permalink
fix(table): fixed toRefs() warning (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbud committed Nov 18, 2022
1 parent f3c7768 commit 00fb497
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions packages/anu-vue/src/components/table/ATable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const ATable = defineComponent({
return null
}).filter(i => i) as [keyof typeof props, typeof props[keyof typeof props]][]

return toRefs(Object.fromEntries(cardPropsEntries))
return toRefs(reactive(Object.fromEntries(cardPropsEntries)))
})

// 馃憠 isSST
Expand All @@ -136,6 +136,8 @@ export const ATable = defineComponent({

const fetchRows = () => {
// _search.value, currentPage.value, currentPageSize.value, sortedCols.value
if (typeof props.rows !== 'function')
return

(props.rows as ItemsFunction)({
/* eslint-disable @typescript-eslint/no-use-before-define */
Expand Down Expand Up @@ -163,6 +165,12 @@ export const ATable = defineComponent({
shallSortByAsc: null,
}

// 馃憠 Paginated Rows
const paginatedRows = ref<any[]>([])

// 馃憠 rowsToRender
const rowsToRender = computed(() => isSST.value ? _serverRows.value : paginatedRows.value)

// 馃憠 _columns
// TODO: Improve _columns computation
// If columns are provided via prop
Expand All @@ -173,10 +181,9 @@ export const ATable = defineComponent({

// Else generate columns from first row
: isSST.value
/* eslint-disable @typescript-eslint/no-use-before-define */

? (rowsToRender.value.length
? Object.keys(rowsToRender.value[0])
/* eslint-enable @typescript-eslint/no-use-before-define */
.map(k => ({
...columnDefaults,
name: k,
Expand Down Expand Up @@ -230,9 +237,6 @@ export const ATable = defineComponent({
}),
)

// 馃憠 Paginated Rows
const paginatedRows = ref<any[]>([])

// TODO: Check passing toRef(props, 'pageSize') to useOffsetPagination and use returned `currentPageSize` for reactive pgeSize prop
const currentPageSize = ref(props.pageSize)
const paginateRows = ({ currentPage, currentPageSize }: { currentPage: number; currentPageSize: number }) => {
Expand Down Expand Up @@ -275,9 +279,6 @@ export const ATable = defineComponent({

watch([_search, sortedCols, sortedRows], recalculateCurrentPageData, { deep: true, immediate: true })

// 馃憠 rowsToRender
const rowsToRender = computed(() => isSST.value ? _serverRows.value : paginatedRows.value)

// 馃憠 onRequest
// watch([_search, currentPage, sortedCols], fetchRows, { deep: true, immediate: true })

Expand Down

0 comments on commit 00fb497

Please sign in to comment.