make name default searchColumn for ProjectJobTemplatesList. also add helpful error message to tell you this is the issue

This commit is contained in:
John Mitchell 2020-08-05 11:48:22 -04:00 committed by John Mitchell
parent f24654fb26
commit f8bd8abc82
2 changed files with 16 additions and 1 deletions

View File

@ -43,7 +43,17 @@ function Search({
}) {
const [isSearchDropdownOpen, setIsSearchDropdownOpen] = useState(false);
const [searchKey, setSearchKey] = useState(
columns.find(col => col.isDefault).key
(() => {
const defaultColumn = columns.filter(col => col.isDefault);
if (defaultColumn.length !== 1) {
throw new Error(
'One (and only one) searchColumn must be marked isDefault: true'
);
}
return defaultColumn[0]?.key;
})()
);
const [searchValue, setSearchValue] = useState('');
const [isFilterDropdownOpen, setIsFilterDropdownOpen] = useState(false);

View File

@ -102,6 +102,11 @@ function ProjectJobTemplatesList({ i18n }) {
qsConfig={QS_CONFIG}
onRowClick={handleSelect}
toolbarSearchColumns={[
{
name: i18n._(t`Name`),
key: 'name__icontains',
isDefault: true,
},
{
name: i18n._(t`Created By (Username)`),
key: 'created_by__username__icontains',