UNPKG

@backstage/plugin-techdocs

Version:

The Backstage plugin that renders technical documentation for your components

70 lines (67 loc) 2.15 kB
import { jsx } from 'react/jsx-runtime'; import { useState, useEffect } from 'react'; import { Table } from '@backstage/core-components'; import { useTranslationRef } from '@backstage/core-plugin-api/alpha'; import { techdocsTranslationRef } from '../../../translation.esm.js'; import { useEntityList, EntityTextFilter } from '@backstage/plugin-catalog-react'; function OffsetPaginatedDocsTable(props) { const { actions, columns, data, isLoading, options, title } = props; const { updateFilters, setLimit, setOffset, limit, totalItems, offset } = useEntityList(); const { t } = useTranslationRef(techdocsTranslationRef); const [page, setPage] = useState( offset && limit ? Math.floor(offset / limit) : 0 ); useEffect(() => { if (totalItems && page * limit >= totalItems) { setOffset(Math.max(0, totalItems - limit)); } else { setOffset(Math.max(0, page * limit)); } }, [setOffset, page, limit, totalItems]); return /* @__PURE__ */ jsx( Table, { title, columns, data, options: { paginationPosition: "both", pageSizeOptions: [5, 10, 20, 50, 100], pageSize: limit, emptyRowsWhenPaging: false, actionsColumnIndex: -1, ...options }, actions, onSearchChange: (searchText) => updateFilters({ text: searchText ? new EntityTextFilter(searchText) : void 0 }), page, onPageChange: (newPage) => { setPage(newPage); }, onRowsPerPageChange: (pageSize) => { setLimit(pageSize); }, totalCount: totalItems, localization: { header: { actions: t("table.header.actions") }, toolbar: { searchPlaceholder: t("table.toolbar.searchPlaceholder") }, pagination: { labelDisplayedRows: "", labelRowsSelect: t("table.pagination.labelRowsSelect") }, body: { emptyDataSourceMessage: t("table.body.emptyDataSourceMessage") } }, isLoading } ); } export { OffsetPaginatedDocsTable }; //# sourceMappingURL=OffsetPaginatedDocsTable.esm.js.map