From 221fcf77dcd84c57aeff2d8a3e22037e39cbfa33 Mon Sep 17 00:00:00 2001 From: Jesper Hodge <19345795+jesperhodge@users.noreply.github.com> Date: Fri, 27 Oct 2023 10:25:51 -0400 Subject: [PATCH] feat: change filter status text (#657) Changed the filter status text on the files and uploads table to display also the number of files, even when a filter is applied. https://2u-internal.atlassian.net/browse/TNL-11086 (internal ticket) I just copied most of paragon's FilterStatus component, made some adjustments, and then overrode the default component. --- src/files-and-uploads/FilesAndUploads.jsx | 2 + .../table-components/FilterStatus.jsx | 69 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/files-and-uploads/table-components/FilterStatus.jsx diff --git a/src/files-and-uploads/FilesAndUploads.jsx b/src/files-and-uploads/FilesAndUploads.jsx index 97f48cfc9..c8aafcefc 100644 --- a/src/files-and-uploads/FilesAndUploads.jsx +++ b/src/files-and-uploads/FilesAndUploads.jsx @@ -42,6 +42,7 @@ import { AccessColumn, MoreInfoColumn, ThumbnailColumn } from './table-component import ApiStatusToast from './ApiStatusToast'; import { clearErrors } from './data/slice'; import getPageHeadTitle from '../generic/utils'; +import FilterStatus from './table-components/FilterStatus'; const FilesAndUploads = ({ courseId, @@ -297,6 +298,7 @@ const FilesAndUploads = ({ itemCount={totalCount} pageCount={Math.ceil(totalCount / 50)} data={assets} + FilterStatusComponent={FilterStatus} > {isEmpty(assets) && loadingStatus !== RequestStatus.IN_PROGRESS ? ( { + const { + setAllFilters, RowStatusComponent, page, rows, + } = useContext(DataTableContext); + if (!setAllFilters) { + return null; + } + + const RowStatus = RowStatusComponent; + + const pageSize = page?.length || rows?.length; + + return ( +
+
+ Filters applied + {!!pageSize && ' ('} + + {!!pageSize && ')'} +
+ +
+ ); +}; + +FilterStatus.defaultProps = { + /** Specifies class name to append to the base element. */ + className: null, + /** Specifies class name to append to the button. */ + buttonClassName: 'pgn__smart-status-button', + /** The visual style of the `FilterStatus`. */ + variant: 'link', + /** The size of the `FilterStatus`. */ + size: 'inline', + /** A text that appears on the `Clear filters` button, defaults to 'Clear filters'. */ + clearFiltersText: undefined, +}; + +FilterStatus.propTypes = { + className: PropTypes.string, + buttonClassName: PropTypes.string, + variant: PropTypes.string, + size: PropTypes.string, + clearFiltersText: PropTypes.oneOfType([PropTypes.element, PropTypes.string]), +}; + +export default FilterStatus;