Skip to content

Commit

Permalink
feat: table actions clear selection (#640)
Browse files Browse the repository at this point in the history
  • Loading branch information
manny-m committed Nov 2, 2021
1 parent a5f1474 commit 6ba6095
Show file tree
Hide file tree
Showing 12 changed files with 451 additions and 220 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@edx/frontend-enterprise-logistration": "0.1.11",
"@edx/frontend-enterprise-utils": "1.1.0",
"@edx/frontend-platform": "1.11.0",
"@edx/paragon": "^16.14.5",
"@edx/paragon": "^16.16.0",
"@fortawesome/fontawesome-svg-core": "1.2.35",
"@fortawesome/free-brands-svg-icons": "5.15.3",
"@fortawesome/free-regular-svg-icons": "5.15.3",
Expand Down
19 changes: 11 additions & 8 deletions src/components/ErrorPage/__snapshots__/ErrorPage.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ exports[`<ErrorPage /> renders correctly 1`] = `
>
<svg
aria-hidden={true}
aria-label=""
fill="none"
focusable={false}
height={24}
Expand Down Expand Up @@ -85,14 +84,18 @@ exports[`<ErrorPage /> renders correctly for 403 errors 1`] = `
<p>
For assistance, please contact the edX Customer Success team at
<a
className="default-link standalone-link"
href="mailto:[email protected]"
onClick={null}
target="_self"
<span
className="pgn__mailtolink"
>
[email protected]
</a>
<a
className="pgn__hyperlink default-link standalone-link"
href="mailto:[email protected]"
onClick={null}
target="_self"
>
[email protected]
</a>
</span>
.
</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,18 @@ exports[`<ForbiddenPage /> renders correctly 1`] = `
<p>
For assistance, please contact the edX Customer Success team at
<a
className="default-link standalone-link"
href="mailto:[email protected]"
onClick={null}
target="_self"
<span
className="pgn__mailtolink"
>
[email protected]
</a>
<a
className="pgn__hyperlink default-link standalone-link"
href="mailto:[email protected]"
onClick={null}
target="_self"
>
[email protected]
</a>
</span>
.
</p>
</div>
Expand Down
18 changes: 11 additions & 7 deletions src/components/SupportPage/__snapshots__/SupportPage.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,18 @@ Array [
<p>
For assistance, please contact the edX Customer Success team at
<a
className="default-link standalone-link"
href="mailto:[email protected]"
onClick={null}
target="_self"
<span
className="pgn__mailtolink"
>
[email protected]
</a>
<a
className="pgn__hyperlink default-link standalone-link"
href="mailto:[email protected]"
onClick={null}
target="_self"
>
[email protected]
</a>
</span>
.
</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,25 @@ export const useRequestState = (isOpen) => {
return [requestState, setRequestState, initialRequestState];
};

export const licenseManagementModalZeroState = {
isOpen: false,
users: [],
allUsersSelected: false,
};

/**
* Handles basic modal open/close usage and can hold user data
* @param initialState shape:
* {
* isOpen: bool
* users: array
* allUsersSelected: bool
* }
* @returns [state, setState, zeroState]
*/
export const useLicenseManagementModalState = (initialState = licenseManagementModalZeroState) => {
const [modalState, setModalState] = useState(initialState);
return [modalState, setModalState, licenseManagementModalZeroState];
};

export default useRequestState;
Original file line number Diff line number Diff line change
@@ -1,30 +1,69 @@
import React from 'react';
import React, { useContext } from 'react';
import PropTypes from 'prop-types';
import {
IconButton,
Icon,
Tooltip,
OverlayTrigger,
DataTableContext,
} from '@edx/paragon';
import {
Email,
RemoveCircle,
} from '@edx/paragon/icons';

import LicenseManagementRevokeModal from '../LicenseManagementModals/LicenseManagementRevokeModal';
import LicenseManagementRemindModal from '../LicenseManagementModals/LicenseManagementRemindModal';
import { canRemindLicense, canRevokeLicense } from '../../data/utils';
import {
useLicenseManagementModalState,
licenseManagementModalZeroState as modalZeroState,
} from '../LicenseManagementModals/LicenseManagementModalHook';

const revokeText = 'Revoke license';
const remindText = 'Remind learner';

const LicenseManagementTableActionColumn = ({
user,
rowRemindOnClick,
rowRevokeOnClick,
subscription,
onRemindSuccess,
onRevokeSuccess,
disabled,
}) => {
const displayRemind = canRemindLicense(user.status);
const displayRevoked = canRevokeLicense(user.status);

const [revokeModal, setRevokeModal] = useLicenseManagementModalState();
const [remindModal, setRemindModal] = useLicenseManagementModalState();
const { clearSelection } = useContext(DataTableContext);

const revokeOnClick = (revokeUser) => {
setRevokeModal({
...revokeModal,
isOpen: true,
users: [revokeUser],
});
};

const remindOnClick = (remindUser) => {
setRemindModal({
...remindModal,
isOpen: true,
users: [remindUser],
});
};

const handleRevokeSuccess = () => {
setRevokeModal(modalZeroState);
onRevokeSuccess(clearSelection)();
};

const handleRemindSuccess = () => {
setRemindModal(modalZeroState);
onRemindSuccess(clearSelection)();
};

// console.log('letContext',letContext)
return (
<>
{displayRemind
Expand All @@ -43,7 +82,7 @@ const LicenseManagementTableActionColumn = ({
src={Email}
iconAs={Icon}
variant="secondary"
onClick={() => rowRemindOnClick(user)}
onClick={() => remindOnClick(user)}
disabled={disabled}
/>
</OverlayTrigger>
Expand All @@ -65,12 +104,27 @@ const LicenseManagementTableActionColumn = ({
style={{ marginLeft: displayRemind ? 0 : 44 }}
iconAs={Icon}
variant="danger"
onClick={() => rowRevokeOnClick(user)}
onClick={() => revokeOnClick(user)}
disabled={disabled}
/>
</OverlayTrigger>
)}

<LicenseManagementRevokeModal
isOpen={revokeModal.isOpen}
usersToRevoke={revokeModal.users}
subscription={subscription}
onClose={() => setRevokeModal(modalZeroState)}
onSuccess={handleRevokeSuccess}
revokeAllUsers={revokeModal.allUsersSelected}
/>
<LicenseManagementRemindModal
isOpen={remindModal.isOpen}
usersToRemind={remindModal.users}
subscription={subscription}
onClose={() => setRemindModal(modalZeroState)}
onSuccess={handleRemindSuccess}
remindAllUsers={remindModal.allUsersSelected}
/>
</>
);
};
Expand All @@ -80,11 +134,20 @@ LicenseManagementTableActionColumn.defaultProps = {
};

LicenseManagementTableActionColumn.propTypes = {
subscription: PropTypes.shape({
uuid: PropTypes.string.isRequired,
expirationDate: PropTypes.string.isRequired,
isRevocationCapEnabled: PropTypes.bool.isRequired,
revocations: PropTypes.shape({
applied: PropTypes.number.isRequired,
remaining: PropTypes.number.isRequired,
}),
}).isRequired,
user: PropTypes.shape({
status: PropTypes.string.isRequired,
}).isRequired,
rowRemindOnClick: PropTypes.func.isRequired,
rowRevokeOnClick: PropTypes.func.isRequired,
onRemindSuccess: PropTypes.func.isRequired,
onRevokeSuccess: PropTypes.func.isRequired,
disabled: PropTypes.bool,
};

Expand Down
Loading

0 comments on commit 6ba6095

Please sign in to comment.