Skip to content

Commit

Permalink
Merge pull request #345 from PrestaShopCorp/344-pagination-loader-var…
Browse files Browse the repository at this point in the history
…iant-refacto-itemcount

fix #344 - handle items count and loader btn behaviors internally
BC - remove itemCount and ButtonDisabled prop
  • Loading branch information
mattgoud authored Jun 19, 2024
2 parents 51f1b5f + 080486b commit 565a49b
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 35 deletions.
1 change: 0 additions & 1 deletion packages/components/pagination/src/pagination-large.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export interface PaginationLargeProps {
disabled?: boolean
totalItem: number
maxPage: number
itemCount?: number
label?: string
dataTest?: string
}
Expand Down
4 changes: 1 addition & 3 deletions packages/components/pagination/src/pagination-large.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ import { type PaginationLargeProps } from './pagination-large';
defineOptions({
name: 'PuikPaginationLarge'
});
const props = withDefaults(defineProps<PaginationLargeProps>(), {
itemCount: 0
});
const props = defineProps<PaginationLargeProps>();
const emit = defineEmits<{
'update:page': [value: number];
'update:itemsPerPage': [value: number];
Expand Down
1 change: 0 additions & 1 deletion packages/components/pagination/src/pagination-medium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export interface PaginationMediumProps {
disabled?: boolean
totalItem: number
maxPage: number
itemCount?: number
label?: string
dataTest?: string
}
Expand Down
3 changes: 1 addition & 2 deletions packages/components/pagination/src/pagination-medium.vue
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ defineOptions({
});
const props = withDefaults(defineProps<PaginationMediumProps>(), {
modelValue: 1,
itemCount: 0
modelValue: 1
});
const emit = defineEmits<{(e: 'update:modelValue', value: number): void}>();
Expand Down
2 changes: 0 additions & 2 deletions packages/components/pagination/src/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ export interface PaginationProps {
itemsPerPage?: number
itemsPerPageOptions?: number[]
page: number
itemCount?: number
label?: string
loaderButtonLabel?: string
loaderButtonDisabled?: boolean
dataTest?: string
}

Expand Down
8 changes: 5 additions & 3 deletions packages/components/pagination/src/pagination.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ defineOptions({
const props = withDefaults(defineProps<PaginationProps>(), {
variant: PuikPaginationVariants.Medium,
itemsPerPage: 5,
itemsPerPageOptions: () => [5, 10, 15],
itemCount: 0
itemsPerPageOptions: () => [5, 10, 15]
});
const emit = defineEmits<{
'update:page': [value: number]
Expand All @@ -88,6 +87,9 @@ const currentPage = computed({
set: (page: number) => emit('update:page', page)
});
const itemCount = computed(() => props.page * props.itemsPerPage);
const loaderButtonDisabled = computed(() => itemCount.value === props.totalItem);
const maxPage = computed(() => {
return Math.ceil(props.totalItem / props.itemsPerPage);
});
Expand All @@ -112,7 +114,7 @@ const currentLabel = computed(() => {
});
default:
return t(path, {
itemCount: props.itemCount,
itemCount: itemCount.value,
totalItem: props.totalItem
});
}
Expand Down
13 changes: 0 additions & 13 deletions packages/components/pagination/stories/pagination.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,6 @@ export default {
}
}
},
itemCount: {
control: 'number',
description: 'Set the current item count',
table: {
type: {
summary: 'number'
},
defaultValue: {
summary: '0'
}
}
},
label: {
control: 'text',
description: 'Set the label',
Expand Down Expand Up @@ -107,7 +95,6 @@ export default {
args: {
variant: PuikPaginationVariants.Medium,
totalItem: 500,
itemCount: 25,
label: '',
loaderButtonLabel: undefined
}
Expand Down
15 changes: 5 additions & 10 deletions packages/components/pagination/test/pagination.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ describe('Pagination tests', () => {
const propsData = {
page: 5,
itemsPerPage: 10,
totalItem: 500,
itemCount: 50
totalItem: 500
};

it('should be a vue instance', () => {
Expand Down Expand Up @@ -153,8 +152,7 @@ describe('Pagination tests', () => {
factory({
page: 10,
itemsPerPage: 20,
totalItem: 500,
itemCount: 50
totalItem: 500
});
expect(findSeparators().length).toBe(2);
});
Expand All @@ -163,8 +161,7 @@ describe('Pagination tests', () => {
factory({
page: 10,
itemsPerPage: 50,
totalItem: 500,
itemCount: 50
totalItem: 500
});
expect(findSeparators().length).toBe(1);
});
Expand All @@ -173,8 +170,7 @@ describe('Pagination tests', () => {
factory({
page: 2,
itemsPerPage: 20,
totalItem: 500,
itemCount: 50
totalItem: 500
});
expect(findSeparators().length).toBe(1);
});
Expand All @@ -183,8 +179,7 @@ describe('Pagination tests', () => {
factory({
page: 3,
itemsPerPage: 100,
totalItem: 500,
itemCount: 50
totalItem: 500
});
expect(findSeparators().length).toBe(0);
});
Expand Down

0 comments on commit 565a49b

Please sign in to comment.