-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathContactListTableDesktop.jsx
More file actions
169 lines (163 loc) · 4.26 KB
/
ContactListTableDesktop.jsx
File metadata and controls
169 lines (163 loc) · 4.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
// React Imports
import React from 'react';
// Material UI Imports
import DeleteOutlineOutlinedIcon from '@mui/icons-material/DeleteOutlineOutlined';
import EditOutlined from '@mui/icons-material/EditOutlined';
import SendIcon from '@mui/icons-material/Send';
import { useTheme } from '@mui/material/styles';
import {
DataGrid,
GridToolbarContainer,
GridActionsCellItem,
GridToolbarFilterButton,
GridToolbarDensitySelector
} from '@mui/x-data-grid';
// Component Imports
import ContactProfileIcon from './ContactProfileIcon';
const CustomToolbar = () => (
<GridToolbarContainer>
<GridToolbarFilterButton />
<GridToolbarDensitySelector />
</GridToolbarContainer>
);
/**
* @typedef {object} Contact
* @property {string} webId - The Web ID of the contact
* @property {string} givenName - The given name of the contact
* @property {string} familyName - The family name of the contact
*/
/**
* ContactListTableDesktop - Component for displaying contacts in a DataGrid
*
* @memberof Contacts
* @name ContactListTableDesktop
* @param {object} Props - The props for ContactListTableDesktop
* @param {Contact[]} Props.contacts - The list of contacts to display
* @param {Function} Props.deleteContact - Function to delete a contact
* @param {Function} Props.editContact - Function to edit a contact
* @param {Function} Props.handleSendMessage - Function to handle sending a message
* @param {string} Props.'data-testid' - Test ID
* @returns {React.JSX.Element} The ContactListTableDesktop component
*/
const ContactListTableDesktop = ({
contacts,
deleteContact,
editContact,
handleSendMessage,
'data-testid': dataTestId
}) => {
const theme = useTheme();
const columnTitlesArray = [
{
field: 'First Name',
minWidth: 120,
flex: 1,
headerAlign: 'center',
align: 'center'
},
{
field: 'Last Name',
minWidth: 120,
flex: 1,
headerAlign: 'center',
align: 'center'
},
{
field: 'webId',
headerName: 'Web ID',
minWidth: 150,
flex: 1,
headerAlign: 'center',
align: 'center'
},
{
field: 'Profile',
renderCell: (contactData) => <ContactProfileIcon contact={contactData} />,
sortable: false,
filterable: false,
width: 80,
headerAlign: 'center',
align: 'center'
},
{
field: 'Message',
renderCell: (contactId) => (
<SendIcon
sx={{ color: '#808080', cursor: 'pointer' }}
onClick={() => handleSendMessage(contactId)}
/>
),
sortable: false,
filterable: false,
width: 80,
headerAlign: 'center',
align: 'center'
},
{
field: 'Edit',
renderCell: (contact) => (
<EditOutlined
sx={{ color: 'gray', cursor: 'pointer' }}
onClick={() => editContact(contact.row.Profile)}
/>
),
sortable: false,
filterable: false,
width: 80,
headerAlign: 'center',
align: 'center'
},
{
field: 'actions',
type: 'actions',
headerName: 'Delete',
width: 80,
getActions: (contactData) => [
<GridActionsCellItem
icon={<DeleteOutlineOutlinedIcon />}
onClick={() => deleteContact(contactData.row.Delete)}
label="Delete"
/>
]
}
];
return (
<DataGrid
data-testid={dataTestId}
columns={columnTitlesArray}
rows={contacts?.map((contact) => ({
id: contact.webId,
'First Name': contact.givenName || '',
'Last Name': contact.familyName || '',
webId: contact.webId,
Profile: contact,
Message: contact,
Delete: contact
}))}
slots={{
toolbar: CustomToolbar
}}
sx={{
'.MuiDataGrid-columnHeader': {
background: theme.palette.primary.light,
color: '#fff'
},
'.MuiDataGrid-columnSeparator': {
display: 'none'
}
}}
pageSizeOptions={[10]}
initialState={{
pagination: {
paginationModel: { pageSize: 10, page: 0 }
},
sorting: {
sortModel: [{ field: 'webId', sort: 'asc' }]
}
}}
disableColumnMenu
disableRowSelectionOnClick
/>
);
};
export default ContactListTableDesktop;