Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix table bugs #417

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
25 changes: 17 additions & 8 deletions frontend/components/ClubEditPage/EventsCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Field } from 'formik'
import moment from 'moment'
import React, { ReactElement, useState } from 'react'
import CreatableSelect from 'react-select/creatable'
import TimeAgo from 'react-timeago'
import styled from 'styled-components'

Expand Down Expand Up @@ -297,7 +296,22 @@ const eventTableFields = [
{
name: 'is_ics_event',
label: 'ICS',
converter: (a: boolean): ReactElement => <Icon name={a ? 'check' : 'x'} />,
converter: (a: boolean): ReactElement => (
<Icon
className={`${a ? 'has-text-success' : 'has-text-danger'}`}
name={a ? 'check' : 'x'}
/>
),
},
]

const eventTableFilter = [
{
label: 'Types',
options: EVENT_TYPES.map((obj) => {
return { key: obj.value, label: obj.label }
}),
filterFunction: (selection, object) => object.type === selection,
},
]

Expand Down Expand Up @@ -343,12 +357,6 @@ const eventFields = (
placeholder="Type your event description here!"
as={RichTextField}
/>
<CreatableSelect
name="multiple_choice"
as={SelectField}
isMulti
creatable
/>
</>
)

Expand Down Expand Up @@ -415,6 +423,7 @@ export default function EventsCard({ club }: EventsCardProps): ReactElement {
fields={eventFields}
fileFields={['image']}
tableFields={eventTableFields}
filterOptions={eventTableFilter}
noun="Event"
currentTitle={(obj) => (obj != null ? obj.name : 'Deleted Event')}
onChange={(obj) => {
Expand Down
9 changes: 9 additions & 0 deletions frontend/components/ClubEditPage/MembersCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,16 @@ export default function MembersCard({ club }: MembersCardProps): ReactElement {
],
filterFunction: (selection, object) => object.role === selection,
},
{
label: 'Active',
options: [
{ key: true, label: 'Active' },
{ key: false, label: 'Inactive' },
],
filterFunction: (selection, object) => object.active === selection,
},
]}
searchableColumns={['name', 'email']}
currentTitle={(obj) =>
obj != null ? `${obj.name} (${obj.email})` : 'Kicked Member'
}
Expand Down
17 changes: 12 additions & 5 deletions frontend/components/ModelForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type ModelFormProps = {
fields: any
tableFields?: TableField[]
filterOptions?: FilterOption[]
searchableColumns?: string[]
currentTitle?: (object: ModelObject) => ReactElement | string
noun?: string
deleteVerb?: string
Expand Down Expand Up @@ -111,6 +112,7 @@ export const doFormikInitialValueFixes = (currentObject: {
type ModelTableProps = {
tableFields: TableField[]
filterOptions?: FilterOption[]
searchableColumns?: string[]
objects: ModelObject[]
allowEditing?: boolean
allowDeletion?: boolean
Expand All @@ -130,6 +132,7 @@ type ModelTableProps = {
export const ModelTable = ({
tableFields,
filterOptions,
searchableColumns,
objects,
allowEditing = false,
allowDeletion = false,
Expand All @@ -150,16 +153,16 @@ export const ModelTable = ({
})),
[tableFields],
)

tableFields = tableFields.map((column, index) => {
if (column.converter) {
const renderFunction = column.converter
return {
...column,
render: (id, _) => {
const obj = objects?.[id]
render: (id) => {
const obj =
objects?.filter((item) => item.id === id)[0] || objects?.[id]
const value = obj?.[column.name]
return obj && value ? renderFunction(value, obj) : 'N/A'
return obj && value !== null ? renderFunction(value, obj) : 'None'
},
}
} else return column
Expand Down Expand Up @@ -215,7 +218,9 @@ export const ModelTable = ({
<Table
data={objects}
columns={tableFields}
searchableColumns={['name']}
searchableColumns={
searchableColumns || tableFields.map((field) => field.name)
}
filterOptions={filterOptions || []}
draggable={draggable}
onDragEnd={onDragEnd}
Expand Down Expand Up @@ -255,6 +260,7 @@ export const ModelForm = (props: ModelFormProps): ReactElement => {
fields,
tableFields,
filterOptions,
searchableColumns,
onUpdate,
currentTitle,
noun = 'Object',
Expand Down Expand Up @@ -464,6 +470,7 @@ export const ModelForm = (props: ModelFormProps): ReactElement => {
noun={noun}
tableFields={tableFields}
filterOptions={filterOptions}
searchableColumns={searchableColumns}
objects={objects}
allowDeletion={allowDeletion}
confirmDeletion={confirmDeletion}
Expand Down
2 changes: 1 addition & 1 deletion frontend/components/PaginatedClubDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const PaginatedClubDisplay = ({
/>
)}
{isLoading && <Loading delay={0} />}
{clubs && clubs.length <= 0 && (
{(clubs == null || clubs.length <= 0) && (
<EmptyState>
<img
src="/static/img/button.svg"
Expand Down
Loading