Skip to content

Commit

Permalink
default search columns
Browse files Browse the repository at this point in the history
  • Loading branch information
alnasir7 committed Mar 5, 2021
1 parent b2ec735 commit 7b4d915
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
15 changes: 8 additions & 7 deletions frontend/components/ModelForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ export const ModelTable = ({
})),
[tableFields],
)

tableFields = tableFields.map((column, index) => {
if (column.converter) {
const renderFunction = column.converter
Expand All @@ -167,12 +166,12 @@ export const ModelTable = ({

tableFields.push({
name: 'Actions',
render: (_, index) => (
render: (id) => (
<div className="buttons">
{allowEditing && (
<button
onClick={() => {
return onEdit(objects[index])
return onEdit(objects[id])
}}
className="button is-primary is-small"
>
Expand All @@ -188,18 +187,18 @@ export const ModelTable = ({
`Are you sure you want to ${deleteVerb.toLowerCase()} this ${noun.toLowerCase()}?`,
)
) {
onDelete(objects[index])
onDelete(objects[id])
}
} else {
onDelete(objects[index])
onDelete(objects[id])
}
}}
className="button is-danger is-small"
>
<Icon name="trash" alt="delete" /> {deleteVerb}
</button>
)}
{actions && actions(objects[index])}
{actions && actions(objects[id])}
</div>
),
})
Expand All @@ -211,7 +210,9 @@ export const ModelTable = ({
item.id ? item : { ...item, id: index },
)}
columns={tableFields}
searchableColumns={searchableColumns || []}
searchableColumns={
searchableColumns || tableFields.map((field) => field.name)
}
filterOptions={filterOptions || []}
/>
</>
Expand Down
10 changes: 6 additions & 4 deletions frontend/components/common/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,12 @@ const Table = ({
return true
}
return searchableColumns.some((searchId) => {
const strings = item[searchId].split(' ')
return strings.some((string) =>
string.toLowerCase().startsWith(searchQuery.toLowerCase()),
)
if (typeof item[searchId] === 'string') {
const strings = item[searchId].split(' ')
return strings.some((string) =>
string.toLowerCase().startsWith(searchQuery.toLowerCase()),
)
} else return false
})
})
const filteredData = searchedData.filter((item) => {
Expand Down

0 comments on commit 7b4d915

Please sign in to comment.