Skip to content

Commit

Permalink
add and remove selection wip
Browse files Browse the repository at this point in the history
  • Loading branch information
katrinan029 committed Feb 18, 2025
1 parent d080f68 commit 06549f5
Showing 1 changed file with 51 additions and 20 deletions.
71 changes: 51 additions & 20 deletions src/components/PeopleManagement/EnterpriseCustomerUserDataTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import AddMembersBulkAction from './GroupDetailPage/AddMembersBulkAction';
import RemoveMembersBulkAction from './RemoveMembersBulkAction';

Check failure on line 16 in src/components/PeopleManagement/EnterpriseCustomerUserDataTable.jsx

View workflow job for this annotation

GitHub Actions / tests

'RemoveMembersBulkAction' is defined but never used
import MemberJoinedDateCell from './MemberJoinedDateCell';
import { useEnterpriseMembersTableData } from './data/hooks';
import { useGetAllEnterpriseLearnerEmails } from './data/hooks/useEnterpriseLearnersTableData';
import { getSelectedEmailsByRow } from './utils';

export const BaseSelectWithContext = ({ row, enterpriseGroupLearners }) => {
const {
Expand Down Expand Up @@ -59,20 +61,41 @@ const deleteSelectedRowAction = (rowId) => ({
type: 'DELETE ROW', rowId,
});

const CustomSelectColumnCell = ({ row }) => {
const CustomSelectColumnCell = ({row, isEntireTableSelected, selectedFlatRows, onHandleAddMembersBulkAction, enterpriseId}) => {

Check failure on line 64 in src/components/PeopleManagement/EnterpriseCustomerUserDataTable.jsx

View workflow job for this annotation

GitHub Actions / tests

This line has a length of 128. Maximum allowed is 120

Check failure on line 64 in src/components/PeopleManagement/EnterpriseCustomerUserDataTable.jsx

View workflow job for this annotation

GitHub Actions / tests

A space is required after '{'

Check failure on line 64 in src/components/PeopleManagement/EnterpriseCustomerUserDataTable.jsx

View workflow job for this annotation

GitHub Actions / tests

Expected a line break after this opening brace

Check failure on line 64 in src/components/PeopleManagement/EnterpriseCustomerUserDataTable.jsx

View workflow job for this annotation

GitHub Actions / tests

'isEntireTableSelected' is missing in props validation

Check failure on line 64 in src/components/PeopleManagement/EnterpriseCustomerUserDataTable.jsx

View workflow job for this annotation

GitHub Actions / tests

'selectedFlatRows' is missing in props validation

Check failure on line 64 in src/components/PeopleManagement/EnterpriseCustomerUserDataTable.jsx

View workflow job for this annotation

GitHub Actions / tests

'onHandleAddMembersBulkAction' is missing in props validation

Check failure on line 64 in src/components/PeopleManagement/EnterpriseCustomerUserDataTable.jsx

View workflow job for this annotation

GitHub Actions / tests

'enterpriseId' is missing in props validation

Check failure on line 64 in src/components/PeopleManagement/EnterpriseCustomerUserDataTable.jsx

View workflow job for this annotation

GitHub Actions / tests

A space is required before '}'
const { enterpriseGroupLearners } = useContext(EnterpriseCustomerUserDataTableContext);
const [isAddedMember, setIsAddedMember] = useState(false);
const {
itemCount,
controlledTableSelections: [, dispatch],
} = useContext(DataTableContext);

const { fetchLearnerEmails, addButtonState } = useGetAllEnterpriseLearnerEmails({
enterpriseId,
isEntireTableSelected,
onHandleAddMembersBulkAction,
enterpriseGroupLearners,
});
const handleOnClick = () => {
console.log(isEntireTableSelected)

Check warning on line 79 in src/components/PeopleManagement/EnterpriseCustomerUserDataTable.jsx

View workflow job for this annotation

GitHub Actions / tests

Unexpected console statement
if (isEntireTableSelected) {
fetchLearnerEmails();
return;
}
const addedMemberEmails = enterpriseGroupLearners.map(learner => learner.memberDetails.userEmail);
console.log(selectedFlatRows)

Check warning on line 85 in src/components/PeopleManagement/EnterpriseCustomerUserDataTable.jsx

View workflow job for this annotation

GitHub Actions / tests

Unexpected console statement
const emails = getSelectedEmailsByRow(selectedFlatRows).filter(email => !addedMemberEmails.includes(email));
onHandleAddMembersBulkAction(emails);
};

const toggleSelected = useCallback(
() => {
if (row.isSelected) {
console.log('hello')

Check warning on line 93 in src/components/PeopleManagement/EnterpriseCustomerUserDataTable.jsx

View workflow job for this annotation

GitHub Actions / tests

Unexpected console statement
dispatch(deleteSelectedRowAction(row.id));
} else {
console.log('adding cell')

Check warning on line 96 in src/components/PeopleManagement/EnterpriseCustomerUserDataTable.jsx

View workflow job for this annotation

GitHub Actions / tests

Unexpected console statement
dispatch(addSelectedRowAction(row, itemCount));
handleOnClick()
}
},
[itemCount, row, dispatch],
Expand Down Expand Up @@ -123,12 +146,12 @@ const EnterpriseCustomerUserDataTable = ({
fetchEnterpriseMembersTableData,
} = useEnterpriseMembersTableData({ enterpriseId });

const selectColumn = {
id: 'selection',
Header: DataTable.ControlledSelectHeader,
Cell: CustomSelectColumnCell,
disableSortBy: true,
};
// const selectColumn = {
// id: 'selection',
// Header: DataTable.ControlledSelectHeader,
// Cell: CustomSelectColumnCell,
// disableSortBy: true,
// };

const contextValue = useMemo(() => ({
enterpriseGroupLearners,
Expand All @@ -137,18 +160,18 @@ const EnterpriseCustomerUserDataTable = ({
return (
<EnterpriseCustomerUserDataTableContext.Provider value={contextValue}>
<DataTable
bulkActions={[
<AddMembersBulkAction
onHandleAddMembersBulkAction={onHandleAddMembersBulkAction}
enterpriseId={enterpriseId}
enterpriseGroupLearners={enterpriseGroupLearners}
/>,
<RemoveMembersBulkAction
enterpriseId={enterpriseId}
learnerEmails={learnerEmails}
onHandleRemoveMembersBulkAction={onHandleRemoveMembersBulkAction}
/>,
]}
// bulkActions={[
// <AddMembersBulkAction
// onHandleAddMembersBulkAction={onHandleAddMembersBulkAction}
// enterpriseId={enterpriseId}
// enterpriseGroupLearners={enterpriseGroupLearners}
// />,
// <RemoveMembersBulkAction
// enterpriseId={enterpriseId}
// learnerEmails={learnerEmails}
// onHandleRemoveMembersBulkAction={onHandleRemoveMembersBulkAction}
// />,
// ]}
columns={[
{
Header: 'Member details',
Expand Down Expand Up @@ -187,7 +210,15 @@ const EnterpriseCustomerUserDataTable = ({
getRowId: row => row.enterpriseCustomerUser.userId.toString(),
}}
pageCount={enterpriseMembersTableData.pageCount}
manualSelectColumn={selectColumn}
manualSelectColumn={
{
id: 'selection',
Header: DataTable.ControlledSelectHeader,
/* eslint-disable react/no-unstable-nested-components */
Cell: (row) => <CustomSelectColumnCell enterpriseId={enterpriseId} onHandleAddMembersBulkAction={onHandleAddMembersBulkAction} {...row} />,
disableSortBy: true,
}
}
SelectionStatusComponent={DataTable.ControlledSelectionStatus}
/>
</EnterpriseCustomerUserDataTableContext.Provider>
Expand Down

0 comments on commit 06549f5

Please sign in to comment.