{content}
- {pageSizeChooser}
+
+ {renderSortBy?.()}
+ {pageSizeChooser}
+
);
}
diff --git a/src/components/search/SortBy.jsx b/src/components/search/SortBy.jsx
new file mode 100644
index 000000000..42bcc0348
--- /dev/null
+++ b/src/components/search/SortBy.jsx
@@ -0,0 +1,102 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import { baseComponents as components } from 'cspace-input';
+import {
+ defineMessages, injectIntl, intlShape,
+} from 'react-intl';
+
+import { get } from 'lodash';
+import classNames from 'classnames';
+import styles from '../../../styles/cspace-ui/SortBy.css';
+import { useConfig } from '../config/ConfigProvider';
+
+const { DropdownMenuInput, Button } = components;
+
+const messages = defineMessages({
+ sortBy: {
+ id: 'search.sortBy',
+ defaultMessage: 'Sort By',
+ },
+ ascendingAriaLabel: {
+ id: 'search.sortDir.ascending.label',
+ defaultMessage: 'Current sort: ascending',
+ },
+ descendingAriaLabel: {
+ id: 'search.sortDir.descending.label',
+ defaultMessage: 'Current sort: descending',
+ },
+});
+
+function SortBy({
+ intl,
+ onSortChange,
+ onSortDirChange,
+ recordType,
+ sort,
+}) {
+ const config = useConfig();
+ const sortConfig = get(config, ['recordTypes', recordType, 'sort'])
+ ?? get(config, ['recordTypes', recordType, 'columns', 'default']);
+
+ if (!sortConfig) {
+ return null;
+ }
+
+ const {
+ defaultSortBy = 'updatedAt',
+ defaultSortDir = 'desc',
+ } = sortConfig;
+
+ const options = Object.keys(sortConfig)
+ .filter((key) => sortConfig[key].sortBy !== undefined)
+ .map((key) => {
+ const option = sortConfig[key];
+ const label = intl.formatMessage(option.messages.label) ?? key;
+
+ return {
+ value: key,
+ label,
+ };
+ });
+
+ const [sortBy, sortDir] = sort?.split(' ') ?? [defaultSortBy, defaultSortDir];
+ const input = (
+ onSortChange(value)}
+ />
+ );
+
+ const sortDirClass = sortDir ? styles.descending : styles.ascending;
+ const sortDirLabel = sortDir ? intl.formatMessage(messages.descendingAriaLabel)
+ : intl.formatMessage(messages.ascendingAriaLabel);
+ const sortDirButton = (
+