Files
directus/app/src/utils/format-collection-items-count.ts
Gerard Lamusse 9c104519f0 Initial interface of O2M & M2M Table View (#12820)
* Fix lint issues
Merge in main

* Add support for resizing columns.
Disable sorting on json columns

* Replaced static text with translations

* remove unused variables

* add no collection/fields states to system-fields

* turn columns to notice when creating list-m2m

* tweak system-fields no fields background color

* add danger styling for deselect in table layout

* add tooltips

* prevent linking to items without ID yet

* fix launch icon for list layout

* tweak padding for per page

* Update missing types

* resolve ::v-deep to :deep warning

* minor style tweaks

* fix search

* fix destructuring crashing when no permissions

* remove unused variables

Co-authored-by: Azri Kahar <42867097+azrikahar@users.noreply.github.com>
2022-08-19 03:16:20 +08:00

31 lines
624 B
TypeScript

import { useI18n } from 'vue-i18n';
export function formatCollectionItemsCount(
totalItems: number,
currentPage: number,
perPage: number,
isFiltered = false
) {
const { t, n } = useI18n();
const opts = {
start: n((+currentPage - 1) * perPage + 1),
end: n(Math.min(currentPage * perPage, totalItems || 0)),
count: n(totalItems || 0),
};
if (isFiltered) {
if (totalItems === 1) {
return t('one_filtered_item');
}
return t('start_end_of_count_filtered_items', opts);
}
if (totalItems > perPage) {
return t('start_end_of_count_items', opts);
}
return t('item_count', { count: totalItems });
}