PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
give / src / Views / Components / ListTable / ListTableRows / index.tsx

index.tsx in GiveWP – Donation Plugin and Fundraising Platform 4.16.9, at src/Views/Components/ListTable/ListTableRows/index.tsx

106 lines 4.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import styles from './ListTableRows.module.scss';
2 import {__} from '@wordpress/i18n';
3 import cx from 'classnames';
4 import {useEffect, useState} from 'react';
5 import TableCell from '../TableCell';
6 import {BulkActionCheckbox} from '@givewp/components/ListTable/BulkActions/BulkActionCheckbox';
7 import InterweaveSSR from '@givewp/components/ListTable/InterweaveSSR';
8 import ListTableApi from '@givewp/components/ListTable/api';
9
10 export default function ListTableRows({columns, data, isLoading, rowActions, setUpdateErrors, parameters, singleName, columnFilters, includeBulkActionsCheckbox = false, tableId, apiSettings}) {
11 const [removed, setRemoved] = useState([]);
12 const [added, setAdded] = useState([]);
13
14 useEffect(() => {
15 if (added.length && !isLoading) {
16 const timeouts = [];
17 timeouts[0] = setTimeout(() => {
18 const addedItem = document.getElementsByClassName(styles.duplicated);
19 if (addedItem.length == 1) {
20 addedItem[0].scrollIntoView({behavior: 'smooth', block: 'center'});
21 }
22 }, 100);
23 timeouts[1] = setTimeout(() => {
24 setAdded([]);
25 }, 600);
26 return () => {
27 timeouts.forEach((timeout) => clearTimeout(timeout));
28 };
29 }
30 }, [added, isLoading]);
31
32 function removeRow(removeCallback) {
33 return async (event) => {
34 const id = event.target.dataset.actionid;
35 setRemoved([id]);
36 await removeCallback(id);
37 setRemoved([]);
38 };
39 }
40
41 function addRow(addCallback) {
42 return async (event) => {
43 const id = event.target.dataset.actionid;
44 const addedItem = await addCallback(id);
45 setAdded([...addedItem.successes]);
46 };
47 }
48
49 function columnGetFilter(columnId) {
50 return columnFilters.filter(definition => definition.column === columnId)
51 }
52
53 if (!data) {
54 return null;
55 }
56
57 return data?.items.map((item) => (
58 <tr
59 key={item.id}
60 className={cx(styles.tableRow, {
61 [styles.deleted]: removed.indexOf(item.id) > -1,
62 [styles.duplicated]: added.indexOf(parseInt(item.id)) > -1,
63 })}
64 >
65 {includeBulkActionsCheckbox && (
66 <TableCell>
67 <BulkActionCheckbox
68 id={item.id}
69 name={item?.donor ?? item?.title ?? item?.donorInformation}
70 singleName={singleName}
71 />
72 </TableCell>
73 )}
74 <>
75 {columns?.map((column) => {
76 const columnFilter = columnGetFilter(column.id);
77
78 return (
79 <TableCell key={column.id} heading={columns[0].id === column.id} columnId={`${tableId}-${column.id}`}>
80 {columnFilter.length > 0 ? (
81 columnFilter[0].filter(item, column, data)
82 ) : (
83 <InterweaveSSR column={column} item={item} />
84 )}
85
86 {columns[0].id === column.id && !isLoading && rowActions && (
87 <div role="group" aria-label={__('Actions', 'give')} className={styles.tableRowActions}>
88 {rowActions({
89 data,
90 item,
91 removeRow,
92 addRow,
93 setUpdateErrors,
94 parameters,
95 listTableApi: new ListTableApi(apiSettings),
96 })}
97 </div>
98 )}
99 </TableCell>
100 );
101 })}
102 </>
103 </tr>
104 ));
105 }
106