Skip to content

Commit

Permalink
fix: pagination will restore (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
aa900031 authored Jan 12, 2025
1 parent ae9f8a1 commit 3d5d7c7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 24 deletions.
24 changes: 19 additions & 5 deletions packages/core/src/controller/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -644,10 +644,19 @@ export function resolveSorters(
permanent: Sorters | undefined,
value: Sorters | undefined,
): Sorters | undefined {
if (permanent || value) {
return unionWith(permanent, value, compareSort)
.filter(filterSort)
}
if (permanent == null && value == null)
return

const result = unionWith(
permanent,
value,
compareSort,
).filter(filterSort)

if (result.length === 0)
return DEFAULT_SORTERS

return result
}

export interface GetDataProps<
Expand Down Expand Up @@ -751,12 +760,17 @@ export function resolveFilters(
value: Filters | undefined,
prev?: Filters,
): Filters | undefined {
return unionWith(
const result = unionWith(
permanent,
value,
prev,
compareFilter,
).filter(filterFilter)

if (result.length === 0)
return DEFAULT_FILTERS

return result
}

function checkFiltersValue(
Expand Down
16 changes: 10 additions & 6 deletions stories/vue/src/ListFilters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { Post } from './api/posts'
import { FilterOperator } from '@ginjou/core'
import { useList } from '@ginjou/vue'
import { reactive, watchPostEffect } from 'vue'
import { reactive, unref, watch } from 'vue'
import { useRoute } from 'vue-router'
const route = useRoute()
Expand All @@ -19,23 +19,27 @@ const formData = reactive({
id: '',
})
watchPostEffect(() => {
watch(() => unref(formData), (data) => {
filters.value = [
formData.title
data.title
? {
field: 'title',
operator: FilterOperator.contains,
value: formData.title,
value: data.title,
}
: undefined as any,
formData.id
data.id
? {
field: 'id',
operator: FilterOperator.eq,
value: formData.id,
value: data.id,
}
: undefined as any,
].filter(Boolean)
}, {
flush: 'post',
deep: true,
immediate: true,
})
</script>

Expand Down
34 changes: 21 additions & 13 deletions stories/vue/src/ListSorters.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import type { Post } from './api/posts'
import { useList } from '@ginjou/vue'
import { reactive, watchPostEffect } from 'vue'
import { reactive, unref, watch } from 'vue'
import { useRoute } from 'vue-router'
const route = useRoute()
Expand All @@ -14,21 +14,29 @@ const {
})
const formData = reactive({
id: false,
title: true,
id: undefined,
title: undefined,
})
watchPostEffect(() => {
watch(() => unref(formData), (data) => {
sorters.value = [
{
field: 'title',
order: formData.title ? 'asc' : 'desc',
},
{
field: 'id',
order: formData.id ? 'asc' : 'desc',
},
]
data.title != null
? {
field: 'title',
order: data.title ? 'asc' : 'desc',
}
: undefined as any,
data.id != null
? {
field: 'id',
order: data.id ? 'asc' : 'desc',
}
: undefined as any,
].filter(Boolean)
}, {
flush: 'post',
deep: true,
immediate: true,
})
</script>

Expand Down

0 comments on commit 3d5d7c7

Please sign in to comment.