@material-ui/core#TableFooter TypeScript Examples
The following examples show how to use
@material-ui/core#TableFooter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CartTable.tsx From storefront with MIT License | 5 votes |
CartTable: React.VFC<Props> = ({ cart, loading, onUpdate }) => {
const styles = useStyles();
return (
<Table className={styles.root}>
<TableHead sx={{ display: { xs: 'none', sm: 'table-header-group' } }}>
<TableRow>
<TableCell colSpan={2}>Product</TableCell>
<TableCell>Price</TableCell>
<TableCell>Quantity</TableCell>
<TableCell colSpan={2}>Total Price</TableCell>
</TableRow>
</TableHead>
<TableBody sx={{ display: { xs: 'block', sm: 'table-row-group' } }}>
{cart.contents?.nodes?.map(
(item) =>
item != null && (
<CartTableRow key={item.key} item={item} loading={loading} onUpdate={onUpdate} />
),
)}
</TableBody>
<TableFooter className={styles.footer}>
<TableRow>
<TableCell colSpan={3} />
<TableCell>
<Typography>Subtotal</Typography>
</TableCell>
<TableCell colSpan={2}>
<Price>{cart.subtotal}</Price>
</TableCell>
</TableRow>
{(cart.appliedCoupons?.length ?? 0) > 0 && (
<TableRow>
<TableCell colSpan={3} />
<TableCell>
<Typography>Discount</Typography>
</TableCell>
<TableCell colSpan={2}>
<Price color="error">{`-${cart.discountTotal}`}</Price>
</TableCell>
</TableRow>
)}
</TableFooter>
</Table>
);
}
Example #2
Source File: MTable.tsx From crossfeed with Creative Commons Zero v1.0 Universal | 5 votes |
MTable = <T extends object>(props: Props<T>) => { const { instance, footerRows, ...rest } = props; const classes = useStyles(); return ( <Table {...instance.getTableProps} {...rest}> <TableHead classes={{ root: classes.head }}> {instance.headerGroups.map((group) => ( <TableRow {...group.getHeaderGroupProps()} key={group.id}> {group.headers.map((column) => ( <TableCell {...column.getHeaderProps()} key={column.id} classes={{ root: classes.cell }} > {column.render('Header')} </TableCell> ))} </TableRow> ))} </TableHead> <TableBody {...instance.getTableBodyProps()}> {instance.rows.map((row) => { instance.prepareRow(row); const { key, ...rest } = row.getRowProps(); return ( <React.Fragment key={key}> <TableRow {...rest}> {row.cells.map((cell) => ( <TableCell {...cell.getCellProps()} key={`${cell.row},${cell.column}`} classes={{ root: classes.cell }} > {cell.render('Cell')} </TableCell> ))} </TableRow> </React.Fragment> ); })} </TableBody> {footerRows && <TableFooter>{footerRows}</TableFooter>} </Table> ); }
Example #3
Source File: Pager.tsx From glific-frontend with GNU Affero General Public License v3.0 | 5 votes |
Pager: React.SFC<PagerProps> = (props) => {
const {
data,
columnStyles,
showCheckbox,
columnNames,
tableVals,
listItemName,
handleTableChange,
totalRows,
collapseOpen,
collapseRow,
removeSortBy = [],
} = props;
const rows = createRows(data, columnStyles, showCheckbox, collapseRow, collapseOpen);
const tableHead = tableHeadColumns(
columnNames,
columnStyles,
tableVals,
handleTableChange,
showCheckbox,
listItemName,
removeSortBy
);
const tablePagination = pagination(columnNames, totalRows, handleTableChange, tableVals);
return (
<div className={styles.TableContainer}>
<Table className={styles.Table} data-testid="table">
<TableHead className={styles.TagListHeader} data-testid="tableHead">
{tableHead}
</TableHead>
<TableBody data-testid="tableBody">{rows}</TableBody>
<TableFooter className={styles.TableFooter} data-testid="tableFooter">
<TableRow>{tablePagination}</TableRow>
</TableFooter>
</Table>
</div>
);
}
Example #4
Source File: TreasuryTable.tsx From lobis-frontend with MIT License | 4 votes |
function TreasuryTable() {
const isAppLoading = useSelector<IReduxState, boolean>(state => state.app.loading);
const app = useSelector<IReduxState, IAppSlice>(state => state.app);
const crvPerLobi = app.crvTreasuryBalance / (app.totalSupply - app.multisigLobiBalance);
const crvUSDPerLobi = (app.crvTreasuryBalance * app.crvPrice) / (app.totalSupply - app.multisigLobiBalance);
const fxsPerLobi = app.fraxTreasuryBalance / (app.totalSupply - app.multisigLobiBalance);
const fxsUSDPerLobi = (app.fraxTreasuryBalance * app.fxsPrice) / (app.totalSupply - app.multisigLobiBalance);
const tokePerLobi = app.tokeTreasuryBalance / (app.totalSupply - app.multisigLobiBalance);
const tokeUSDPerLobi = (app.tokeTreasuryBalance * app.tokePrice) / (app.totalSupply - app.multisigLobiBalance);
const sdtPerLobi = app.treasurySdtBalance / (app.totalSupply - app.multisigLobiBalance);
const sdtUSDPerLobi = (app.treasurySdtBalance * app.sdtPrice) / (app.totalSupply - app.multisigLobiBalance);
const anglePerLobi = app.angleTreasuryBalance / (app.totalSupply - app.multisigLobiBalance);
const angleUSDPerLobi = (app.angleTreasuryBalance * app.anglePrice) / (app.totalSupply - app.multisigLobiBalance);
const gOhmPerLobi = app.gOhmTreasuryBalance / (app.totalSupply - app.multisigLobiBalance);
const gOhmUSDPerLobi = (app.gOhmTreasuryBalance * app.gOhmPrice) / (app.totalSupply - app.multisigLobiBalance);
const totalUSDPerLobi = crvUSDPerLobi + fxsUSDPerLobi + tokeUSDPerLobi;
return (
<Grid container item>
<TableContainer className="treasury-balance-view-card-table">
<Table>
<TableHead>
<TableRow>
<TableCell align="left">
<p className="treasury-balance-view-card-table-title">Token</p>
</TableCell>
<TableCell align="center">
<p className="treasury-balance-view-card-table-title">Treasury</p>
</TableCell>
<TableCell align="center">
<p className="treasury-balance-view-card-table-title">Token Price (USD)</p>
</TableCell>
<TableCell align="center">
<p className="treasury-balance-view-card-table-title">Reserve Values (USD)</p>
</TableCell>
<TableCell align="center">
<p className="treasury-balance-view-card-table-title">Backing Per LOBI (votes)</p>
</TableCell>
<TableCell align="center">
<p className="treasury-balance-view-card-table-title">Backing Per LOBI (USD)</p>
</TableCell>
<TableCell align="right"></TableCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow className="data-row">
<TableCell align="left" className="token-name-title">
CRV
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 0,
minimumFractionDigits: 0,
}).format(app.crvTreasuryBalance)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 2,
minimumFractionDigits: 0,
}).format(app.crvPrice)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 0,
minimumFractionDigits: 0,
}).format(app.crvTreasuryBalance * app.crvPrice)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 2,
minimumFractionDigits: 0,
}).format(crvPerLobi)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 2,
minimumFractionDigits: 0,
}).format(crvUSDPerLobi)}`}
</TableCell>
</TableRow>
<TableRow>
<TableCell align="left" className="token-name-title">
FXS
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 0,
minimumFractionDigits: 0,
}).format(app.fraxTreasuryBalance)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 2,
minimumFractionDigits: 0,
}).format(app.fxsPrice)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 0,
minimumFractionDigits: 0,
}).format(app.fraxTreasuryBalance * app.fxsPrice)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 2,
minimumFractionDigits: 0,
}).format(fxsPerLobi)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 2,
minimumFractionDigits: 0,
}).format(fxsUSDPerLobi)}`}
</TableCell>
</TableRow>
<TableRow>
<TableCell align="left" className="token-name-title">
TOKE
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 0,
minimumFractionDigits: 0,
}).format(app.tokeTreasuryBalance)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 2,
minimumFractionDigits: 0,
}).format(app.tokePrice)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 0,
minimumFractionDigits: 0,
}).format(app.tokeTreasuryBalance * app.tokePrice)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 2,
minimumFractionDigits: 0,
}).format(tokePerLobi)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 2,
minimumFractionDigits: 0,
}).format(tokeUSDPerLobi)}`}
</TableCell>
</TableRow>
<TableRow>
<TableCell align="left" className="token-name-title">
SDT
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 0,
minimumFractionDigits: 0,
}).format(app.treasurySdtBalance)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 2,
minimumFractionDigits: 0,
}).format(app.sdtPrice)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 0,
minimumFractionDigits: 0,
}).format(app.treasurySdtBalance * app.sdtPrice)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 2,
minimumFractionDigits: 0,
}).format(sdtPerLobi)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 2,
minimumFractionDigits: 0,
}).format(sdtUSDPerLobi)}`}
</TableCell>
</TableRow>
<TableRow>
<TableCell align="left" className="token-name-title">
ANGLE
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 0,
minimumFractionDigits: 0,
}).format(app.angleTreasuryBalance)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 2,
minimumFractionDigits: 0,
}).format(app.anglePrice)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 0,
minimumFractionDigits: 0,
}).format(app.angleTreasuryBalance * app.anglePrice)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 2,
minimumFractionDigits: 0,
}).format(anglePerLobi)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 2,
minimumFractionDigits: 0,
}).format(angleUSDPerLobi)}`}
</TableCell>
</TableRow>
<TableRow>
<TableCell align="left" className="token-name-title">
gOHM
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 0,
minimumFractionDigits: 0,
}).format(app.gOhmTreasuryBalance)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 2,
minimumFractionDigits: 0,
}).format(app.gOhmPrice)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 0,
minimumFractionDigits: 0,
}).format(app.gOhmTreasuryBalance * app.gOhmPrice)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 2,
minimumFractionDigits: 0,
}).format(gOhmPerLobi)}`}
</TableCell>
<TableCell align="center" className="token-name-title">
{`${new Intl.NumberFormat("en-US", {
maximumFractionDigits: 2,
minimumFractionDigits: 0,
}).format(gOhmUSDPerLobi)}`}
</TableCell>
</TableRow>
</TableBody>
<TableFooter>
{" "}
<TableRow>
<TableCell align="left" className="treasury-balance-view-card-table-title-footer">
<p className="treasury-balance-view-card-table-title"></p>
</TableCell>
<TableCell align="center" className="treasury-balance-view-card-table-title-footer"></TableCell>
<TableCell align="center" className="treasury-balance-view-card-table-title-footer"></TableCell>
<TableCell align="center" className="treasury-balance-view-card-table-title-footer">
{`${new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
maximumFractionDigits: 0,
minimumFractionDigits: 0,
}).format(app.treasuryBalance)}`}
</TableCell>
<TableCell align="center" className="treasury-balance-view-card-table-title-footer"></TableCell>
<TableCell align="center" className="treasury-balance-view-card-table-title-footer">
{`${new Intl.NumberFormat("en-US", {
style: "currency",
currency: "USD",
maximumFractionDigits: 2,
minimumFractionDigits: 0,
}).format(totalUSDPerLobi)}`}
</TableCell>
</TableRow>
</TableFooter>
</Table>
</TableContainer>
</Grid>
);
}
Example #5
Source File: List.tsx From glific-frontend with GNU Affero General Public License v3.0 | 4 votes |
List: React.SFC<ListProps> = ({
columnNames = [],
countQuery,
listItem,
listIcon,
filterItemsQuery,
deleteItemQuery,
listItemName,
dialogMessage = '',
secondaryButton,
pageLink,
columns,
columnStyles,
title,
dialogTitle,
filterList,
listOrder = 'asc',
removeSortBy = null,
button = {
show: true,
label: 'Add New',
},
showCheckbox,
deleteModifier = { icon: 'normal', variables: null, label: 'Delete' },
editSupport = true,
searchParameter = ['label'],
filters = null,
displayListType = 'list',
cardLink = null,
additionalAction = [],
backLinkButton,
restrictedAction,
collapseOpen = false,
collapseRow = undefined,
defaultSortBy,
noItemText = null,
isDetailsPage = false,
customStyles,
}: ListProps) => {
const { t } = useTranslation();
// DialogBox states
const [deleteItemID, setDeleteItemID] = useState<number | null>(null);
const [deleteItemName, setDeleteItemName] = useState<string>('');
const [newItem, setNewItem] = useState(false);
const [searchVal, setSearchVal] = useState('');
// check if the user has access to manage collections
const userRolePermissions = getUserRolePermissions();
const capitalListItemName = listItemName
? listItemName[0].toUpperCase() + listItemName.slice(1)
: '';
let defaultColumnSort = columnNames[0];
// check if there is a default column set for sorting
if (defaultSortBy) {
defaultColumnSort = defaultSortBy;
}
// get the last sort column value from local storage if exist else set the default column
const getSortColumn = (listItemNameValue: string, columnName: string) => {
// set the column name
let columnnNameValue;
if (columnName) {
columnnNameValue = columnName;
}
// check if we have sorting stored in local storage
const sortValue = getLastListSessionValues(listItemNameValue, false);
// update column name from the local storage
if (sortValue) {
columnnNameValue = sortValue;
}
return setColumnToBackendTerms(listItemName, columnnNameValue);
};
// get the last sort direction value from local storage if exist else set the default order
const getSortDirection = (listItemNameValue: string) => {
let sortDirection: any = listOrder;
// check if we have sorting stored in local storage
const sortValue = getLastListSessionValues(listItemNameValue, true);
if (sortValue) {
sortDirection = sortValue;
}
return sortDirection;
};
// Table attributes
const [tableVals, setTableVals] = useState<TableVals>({
pageNum: 0,
pageRows: 50,
sortCol: getSortColumn(listItemName, defaultColumnSort),
sortDirection: getSortDirection(listItemName),
});
let userRole: any = getUserRole();
const handleTableChange = (attribute: string, newVal: any) => {
let updatedList;
let attributeValue = newVal;
if (attribute === 'sortCol') {
attributeValue = setColumnToBackendTerms(listItemName, newVal);
updatedList = getUpdatedList(listItemName, newVal, false);
} else {
updatedList = getUpdatedList(listItemName, newVal, true);
}
// set the sort criteria in local storage
setListSession(JSON.stringify(updatedList));
setTableVals({
...tableVals,
[attribute]: attributeValue,
});
};
let filter: any = {};
if (searchVal !== '') {
searchParameter.forEach((parameter: string) => {
filter[parameter] = searchVal;
});
}
filter = { ...filter, ...filters };
const filterPayload = useCallback(() => {
let order = 'ASC';
if (tableVals.sortDirection) {
order = tableVals.sortDirection.toUpperCase();
}
return {
filter,
opts: {
limit: tableVals.pageRows,
offset: tableVals.pageNum * tableVals.pageRows,
order,
orderWith: tableVals.sortCol,
},
};
}, [searchVal, tableVals, filters]);
// Get the total number of items here
const {
loading: l,
error: e,
data: countData,
refetch: refetchCount,
} = useQuery(countQuery, {
variables: { filter },
});
// Get item data here
const [fetchQuery, { loading, error, data, refetch: refetchValues }] = useLazyQuery(
filterItemsQuery,
{
variables: filterPayload(),
fetchPolicy: 'cache-and-network',
}
);
// Get item data here
const [fetchUserCollections, { loading: loadingCollections, data: userCollections }] =
useLazyQuery(GET_CURRENT_USER);
const checkUserRole = () => {
userRole = getUserRole();
};
useEffect(() => {
refetchCount();
}, [filterPayload, searchVal, filters]);
useEffect(() => {
if (userRole.length === 0) {
checkUserRole();
} else {
if (!userRolePermissions.manageCollections && listItem === 'collections') {
// if user role staff then display collections related to login user
fetchUserCollections();
}
fetchQuery();
}
}, [userRole]);
let deleteItem: any;
// Make a new count request for a new count of the # of rows from this query in the back-end.
if (deleteItemQuery) {
[deleteItem] = useMutation(deleteItemQuery, {
onCompleted: () => {
checkUserRole();
refetchCount();
if (refetchValues) {
refetchValues(filterPayload());
}
},
});
}
const showDialogHandler = (id: any, label: string) => {
setDeleteItemName(label);
setDeleteItemID(id);
};
const closeDialogBox = () => {
setDeleteItemID(null);
};
const deleteHandler = (id: number) => {
const variables = deleteModifier.variables ? deleteModifier.variables(id) : { id };
deleteItem({ variables });
setNotification(`${capitalListItemName} deleted successfully`);
};
const handleDeleteItem = () => {
if (deleteItemID !== null) {
deleteHandler(deleteItemID);
}
setDeleteItemID(null);
};
const useDelete = (message: string | any) => {
let component = {};
const props = { disableOk: false, handleOk: handleDeleteItem };
if (typeof message === 'string') {
component = message;
} else {
/**
* Custom component to render
* message should contain 3 params
* 1. component: Component to render
* 2. isConfirm: To check true or false value
* 3. handleOkCallback: Callback action to delete item
*/
const {
component: componentToRender,
isConfirmed,
handleOkCallback,
} = message(deleteItemID, deleteItemName);
component = componentToRender;
props.disableOk = !isConfirmed;
props.handleOk = () => handleOkCallback({ refetch: fetchQuery, setDeleteItemID });
}
return {
component,
props,
};
};
let dialogBox;
if (deleteItemID) {
const { component, props } = useDelete(dialogMessage);
dialogBox = (
<DialogBox
title={
dialogTitle || `Are you sure you want to delete the ${listItemName} "${deleteItemName}"?`
}
handleCancel={closeDialogBox}
colorOk="secondary"
alignButtons="center"
{...props}
>
<div className={styles.DialogText}>
<div>{component}</div>
</div>
</DialogBox>
);
}
if (newItem) {
return <Redirect to={`/${pageLink}/add`} />;
}
if (loading || l || loadingCollections) return <Loading />;
if (error || e) {
if (error) {
setErrorMessage(error);
} else if (e) {
setErrorMessage(e);
}
return null;
}
// Reformat all items to be entered in table
function getIcons(
// id: number | undefined,
item: any,
label: string,
isReserved: boolean | null,
listItems: any,
allowedAction: any | null
) {
// there might be a case when we might want to allow certain actions for reserved items
// currently we don't allow edit or delete for reserved items. hence return early
const { id } = item;
if (isReserved) {
return null;
}
let editButton = null;
if (editSupport) {
editButton = allowedAction.edit && (
<Link to={`/${pageLink}/${id}/edit`}>
<IconButton aria-label={t('Edit')} color="default" data-testid="EditIcon">
<Tooltip title={t('Edit')} placement="top">
<EditIcon />
</Tooltip>
</IconButton>
</Link>
);
}
const deleteButton = (Id: any, text: string) =>
allowedAction.delete ? (
<IconButton
aria-label={t('Delete')}
color="default"
data-testid="DeleteIcon"
onClick={() => showDialogHandler(Id, text)}
>
<Tooltip title={`${deleteModifier.label}`} placement="top">
{deleteModifier.icon === 'cross' ? <CrossIcon /> : <DeleteIcon />}
</Tooltip>
</IconButton>
) : null;
if (id) {
return (
<div className={styles.Icons}>
{additionalAction.map((action: any, index: number) => {
if (allowedAction.restricted) {
return null;
}
// check if we are dealing with nested element
let additionalActionParameter: any;
const params: any = additionalAction[index].parameter.split('.');
if (params.length > 1) {
additionalActionParameter = listItems[params[0]][params[1]];
} else {
additionalActionParameter = listItems[params[0]];
}
const key = index;
if (action.link) {
return (
<Link to={`${action.link}/${additionalActionParameter}`} key={key}>
<IconButton
color="default"
className={styles.additonalButton}
data-testid="additionalButton"
>
<Tooltip title={`${action.label}`} placement="top">
{action.icon}
</Tooltip>
</IconButton>
</Link>
);
}
if (action.dialog) {
return (
<IconButton
color="default"
data-testid="additionalButton"
className={styles.additonalButton}
id="additionalButton-icon"
onClick={() => action.dialog(additionalActionParameter, item)}
key={key}
>
<Tooltip title={`${action.label}`} placement="top" key={key}>
{action.icon}
</Tooltip>
</IconButton>
);
}
if (action.button) {
return action.button(listItems, action, key, fetchQuery);
}
return null;
})}
{/* do not display edit & delete for staff role in collection */}
{userRolePermissions.manageCollections || listItems !== 'collections' ? (
<>
{editButton}
{deleteButton(id, label)}
</>
) : null}
</div>
);
}
return null;
}
function formatList(listItems: Array<any>) {
return listItems.map(({ ...listItemObj }) => {
const label = listItemObj.label ? listItemObj.label : listItemObj.name;
const isReserved = listItemObj.isReserved ? listItemObj.isReserved : null;
// display only actions allowed to the user
const allowedAction = restrictedAction
? restrictedAction(listItemObj)
: { chat: true, edit: true, delete: true };
return {
...columns(listItemObj),
operations: getIcons(listItemObj, label, isReserved, listItemObj, allowedAction),
recordId: listItemObj.id,
};
});
}
const resetTableVals = () => {
setTableVals({
pageNum: 0,
pageRows: 50,
sortCol: getSortColumn(listItemName, defaultColumnSort),
sortDirection: getSortDirection(listItemName),
});
};
const handleSearch = (searchError: any) => {
searchError.preventDefault();
const searchValInput = searchError.target.querySelector('input').value.trim();
setSearchVal(searchValInput);
resetTableVals();
};
// Get item data and total number of items.
let itemList: any = [];
if (data) {
itemList = formatList(data[listItem]);
}
if (userCollections) {
if (listItem === 'collections') {
itemList = formatList(userCollections.currentUser.user.groups);
}
}
let itemCount: number = tableVals.pageRows;
if (countData) {
itemCount = countData[`count${listItem[0].toUpperCase()}${listItem.slice(1)}`];
}
let displayList;
if (displayListType === 'list') {
displayList = (
<Pager
columnStyles={columnStyles}
removeSortBy={removeSortBy !== null ? removeSortBy : []}
columnNames={columnNames}
data={itemList}
listItemName={listItemName}
totalRows={itemCount}
handleTableChange={handleTableChange}
tableVals={tableVals}
showCheckbox={showCheckbox}
collapseOpen={collapseOpen}
collapseRow={collapseRow}
/>
);
} else if (displayListType === 'card') {
/* istanbul ignore next */
displayList = (
<>
<ListCard data={itemList} link={cardLink} />
<table>
<TableFooter className={styles.TableFooter} data-testid="tableFooter">
<TableRow>
<TablePagination
className={styles.FooterRow}
colSpan={columnNames.length}
count={itemCount}
onPageChange={(event, newPage) => {
handleTableChange('pageNum', newPage);
}}
onRowsPerPageChange={(event) => {
handleTableChange('pageRows', parseInt(event.target.value, 10));
}}
page={tableVals.pageNum}
rowsPerPage={tableVals.pageRows}
rowsPerPageOptions={[50, 75, 100, 150, 200]}
/>
</TableRow>
</TableFooter>
</table>
</>
);
}
const backLink = backLinkButton ? (
<div className={styles.BackLink}>
<Link to={backLinkButton.link}>
<BackIcon />
{backLinkButton.text}
</Link>
</div>
) : null;
let buttonDisplay;
if (button.show) {
let buttonContent;
if (button.action) {
buttonContent = (
<Button
color="primary"
variant="contained"
onClick={() => button.action && button.action()}
>
{button.label}
</Button>
);
} else if (!button.link) {
buttonContent = (
<Button
color="primary"
variant="contained"
onClick={() => setNewItem(true)}
data-testid="newItemButton"
>
{button.label}
</Button>
);
} else {
buttonContent = (
<Link to={button.link}>
<Button color="primary" variant="contained" data-testid="newItemLink">
{button.label}
</Button>
</Link>
);
}
buttonDisplay = <div className={styles.AddButton}>{buttonContent}</div>;
}
const noItemsText = (
<div className={styles.NoResults}>
{searchVal ? (
<div>{t('Sorry, no results found! Please try a different search.')}</div>
) : (
<div>
There are no {noItemText || listItemName}s right now.{' '}
{button.show && t('Please create one.')}
</div>
)}
</div>
);
let headerSize = styles.Header;
if (isDetailsPage) {
headerSize = styles.DetailsPageHeader;
}
return (
<>
<div className={headerSize} data-testid="listHeader">
<Typography variant="h5" className={styles.Title}>
<IconButton disabled className={styles.Icon}>
{listIcon}
</IconButton>
{title}
</Typography>
{filterList}
<div className={styles.Buttons}>
<SearchBar
handleSubmit={handleSearch}
onReset={() => {
setSearchVal('');
resetTableVals();
}}
searchVal={searchVal}
handleChange={(err: any) => {
// reset value only if empty
if (!err.target.value) setSearchVal('');
}}
searchMode
/>
</div>
<div>
{dialogBox}
<div className={styles.ButtonGroup}>
{buttonDisplay}
{secondaryButton}
</div>
</div>
</div>
<div className={`${styles.Body} ${customStyles}`}>
{backLink}
{/* Rendering list of items */}
{itemList.length > 0 ? displayList : noItemsText}
</div>
</>
);
}