This repository was archived by the owner on Nov 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Add generic request sorting button #1320
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7165dea
Add generic request sort button
TheAndrewJackson 44e140e
Update changelog
TheAndrewJackson aad0699
Merge branch 'main' into 1152_sort_days_left_dashboard
TheAndrewJackson 785131c
Implement PR feedback
TheAndrewJackson be2f45a
Merge branch 'main' into 1152_sort_days_left_dashboard
TheAndrewJackson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
171 changes: 171 additions & 0 deletions
171
clients/ops/admin-ui/src/features/common/Icon/SortArrow.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| import { Icon } from "@fidesui/react"; | ||
| import React from "react"; | ||
|
|
||
| type SortArrowProps = { | ||
| up?: boolean; | ||
| }; | ||
|
|
||
| const SortArrow: React.FC<SortArrowProps> = ({ up }) => { | ||
| if (up === undefined) { | ||
| return ( | ||
| <Icon width="24px" height="26px" viewBox="0 0 24 26" fill="none"> | ||
| <svg | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| width="24" | ||
| height="26" | ||
| viewBox="0 0 24 26" | ||
| fill="none" | ||
| > | ||
| <path | ||
| d="M8.72726 15.129L10.9716 12.8145L12 13.875L7.99998 18L4 13.875L5.02837 12.8145L7.27271 15.129V6H8.72726V15.129Z" | ||
| fill="#2D3748" | ||
| /> | ||
| <path | ||
| d="M16.7523 8.871V18H15.3089V8.871L13.0205 11.25L12 10.1895L16.0306 6L20 10.125L18.9795 11.1855L16.7523 8.871Z" | ||
| fill="#2D3748" | ||
| /> | ||
| </svg> | ||
| </Icon> | ||
| ); | ||
| } | ||
|
|
||
| if (up) { | ||
| return ( | ||
| <Icon | ||
| width="24px" | ||
| height="26px" | ||
| viewBox="0 0 24 26" | ||
| fill="none" | ||
| style={{ | ||
| transform: "rotate(180deg)", | ||
| }} | ||
| > | ||
| <svg | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| width="24" | ||
| height="26" | ||
| viewBox="0 0 24 26" | ||
| fill="none" | ||
| > | ||
| <g filter="url(#filter0_d_3399_48680)"> | ||
| <path | ||
| d="M8.72726 15.129L10.9716 12.8145L12 13.875L7.99998 18L4 13.875L5.02837 12.8145L7.27271 15.129V6H8.72726V15.129Z" | ||
| fill="#2D3748" | ||
| /> | ||
| <path | ||
| d="M8.22726 15.129V16.3629L9.08621 15.4771L10.9716 13.5327L11.3035 13.875L7.99998 17.2818L4.69648 13.875L5.02837 13.5327L6.91375 15.4771L7.77271 16.3629V15.129V6.5H8.22726V15.129Z" | ||
| stroke="black" | ||
| /> | ||
| </g> | ||
| <path | ||
| d="M16.7523 8.871V18H15.3089V8.871L13.0205 11.25L12 10.1895L16.0306 6L20 10.125L18.9795 11.1855L16.7523 8.871Z" | ||
| fill="#2D3748" | ||
| /> | ||
| <defs> | ||
| <filter | ||
| id="filter0_d_3399_48680" | ||
| x="0" | ||
| y="6" | ||
| width="16" | ||
| height="20" | ||
| filterUnits="userSpaceOnUse" | ||
| colorInterpolationFilters="sRGB" | ||
| > | ||
| <feFlood floodOpacity="0" result="BackgroundImageFix" /> | ||
| <feColorMatrix | ||
| in="SourceAlpha" | ||
| type="matrix" | ||
| values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" | ||
| result="hardAlpha" | ||
| /> | ||
| <feOffset dy="4" /> | ||
| <feGaussianBlur stdDeviation="2" /> | ||
| <feComposite in2="hardAlpha" operator="out" /> | ||
| <feColorMatrix | ||
| type="matrix" | ||
| values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0" | ||
| /> | ||
| <feBlend | ||
| mode="normal" | ||
| in2="BackgroundImageFix" | ||
| result="effect1_dropShadow_3399_48680" | ||
| /> | ||
| <feBlend | ||
| mode="normal" | ||
| in="SourceGraphic" | ||
| in2="effect1_dropShadow_3399_48680" | ||
| result="shape" | ||
| /> | ||
| </filter> | ||
| </defs> | ||
| </svg> | ||
| </Icon> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <Icon width="24px" height="26px" viewBox="0 0 24 26" fill="none"> | ||
| <svg | ||
| xmlns="http://www.w3.org/2000/svg" | ||
| width="24" | ||
| height="26" | ||
| viewBox="0 0 24 26" | ||
| fill="none" | ||
| > | ||
| <g filter="url(#filter0_d_3399_48680)"> | ||
| <path | ||
| d="M8.72726 15.129L10.9716 12.8145L12 13.875L7.99998 18L4 13.875L5.02837 12.8145L7.27271 15.129V6H8.72726V15.129Z" | ||
| fill="#2D3748" | ||
| /> | ||
| <path | ||
| d="M8.22726 15.129V16.3629L9.08621 15.4771L10.9716 13.5327L11.3035 13.875L7.99998 17.2818L4.69648 13.875L5.02837 13.5327L6.91375 15.4771L7.77271 16.3629V15.129V6.5H8.22726V15.129Z" | ||
| stroke="black" | ||
| /> | ||
| </g> | ||
| <path | ||
| d="M16.7523 8.871V18H15.3089V8.871L13.0205 11.25L12 10.1895L16.0306 6L20 10.125L18.9795 11.1855L16.7523 8.871Z" | ||
| fill="#2D3748" | ||
| /> | ||
| <defs> | ||
| <filter | ||
| id="filter0_d_3399_48680" | ||
| x="0" | ||
| y="6" | ||
| width="16" | ||
| height="20" | ||
| filterUnits="userSpaceOnUse" | ||
| colorInterpolationFilters="sRGB" | ||
| > | ||
| <feFlood floodOpacity="0" result="BackgroundImageFix" /> | ||
| <feColorMatrix | ||
| in="SourceAlpha" | ||
| type="matrix" | ||
| values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" | ||
| result="hardAlpha" | ||
| /> | ||
| <feOffset dy="4" /> | ||
| <feGaussianBlur stdDeviation="2" /> | ||
| <feComposite in2="hardAlpha" operator="out" /> | ||
| <feColorMatrix | ||
| type="matrix" | ||
| values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0" | ||
| /> | ||
| <feBlend | ||
| mode="normal" | ||
| in2="BackgroundImageFix" | ||
| result="effect1_dropShadow_3399_48680" | ||
| /> | ||
| <feBlend | ||
| mode="normal" | ||
| in="SourceGraphic" | ||
| in2="effect1_dropShadow_3399_48680" | ||
| result="shape" | ||
| /> | ||
| </filter> | ||
| </defs> | ||
| </svg> | ||
| </Icon> | ||
| ); | ||
| }; | ||
|
|
||
| export default SortArrow; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
clients/ops/admin-ui/src/features/privacy-requests/SortRequestButton.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| import { Flex, IconButton } from "@fidesui/react"; | ||
| import { SortArrowIcon } from "common/Icon"; | ||
| import React, { useCallback, useEffect, useState } from "react"; | ||
| import { useDispatch, useSelector } from "react-redux"; | ||
|
|
||
| import { | ||
| clearSortFields, | ||
| selectPrivacyRequestFilters, | ||
| setSortDirection, | ||
| setSortField, | ||
| } from "./privacy-requests.slice"; | ||
|
|
||
| type UseSortRequestButtonParams = { | ||
| sortField: string; | ||
| isLoading: boolean; | ||
| }; | ||
|
|
||
| export enum ButtonState { | ||
| ASC = "asc", | ||
| DESC = "desc", | ||
| UNSELECTED = "unselected", | ||
| } | ||
|
|
||
| const useSortRequestButton = ({ | ||
| sortField, | ||
| isLoading, | ||
| }: UseSortRequestButtonParams) => { | ||
| const filters = useSelector(selectPrivacyRequestFilters); | ||
| const dispatch = useDispatch(); | ||
| const [buttonState, setButtonState] = useState<ButtonState>( | ||
| ButtonState.UNSELECTED | ||
| ); | ||
| const [wasButtonJustClicked, setWasButtonJustClicked] = useState(false); | ||
|
|
||
| useEffect(() => { | ||
| if (!isLoading) { | ||
| setWasButtonJustClicked(false); | ||
| } | ||
| }, [isLoading]); | ||
|
|
||
| useEffect(() => { | ||
| if (filters.sort_direction === undefined) { | ||
| setButtonState(ButtonState.UNSELECTED); | ||
| } | ||
| }, [filters]); | ||
|
|
||
| const handleButtonClick = useCallback(() => { | ||
| setWasButtonJustClicked(true); | ||
| dispatch(setSortField(sortField)); | ||
|
|
||
| switch (buttonState) { | ||
| case ButtonState.UNSELECTED: | ||
| dispatch(setSortDirection(ButtonState.ASC)); | ||
| setButtonState(ButtonState.ASC); | ||
| break; | ||
| case ButtonState.ASC: | ||
| dispatch(setSortDirection(ButtonState.DESC)); | ||
| setButtonState(ButtonState.DESC); | ||
| break; | ||
| case ButtonState.DESC: | ||
| dispatch(clearSortFields()); | ||
| setButtonState(ButtonState.UNSELECTED); | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| }, [buttonState, setButtonState, dispatch, sortField]); | ||
|
|
||
| return { | ||
| handleButtonClick, | ||
| buttonState, | ||
| wasButtonJustClicked, | ||
| }; | ||
| }; | ||
|
|
||
| type SortRequestButtonProps = { | ||
| sortField: string; | ||
| isLoading: boolean; | ||
| }; | ||
|
|
||
| const SortRequestButton: React.FC<SortRequestButtonProps> = ({ | ||
| sortField, | ||
| isLoading, | ||
| }) => { | ||
| const { buttonState, handleButtonClick, wasButtonJustClicked } = | ||
| useSortRequestButton({ sortField, isLoading }); | ||
|
|
||
| let icon = null; | ||
|
|
||
| switch (buttonState) { | ||
| case ButtonState.ASC: | ||
| icon = <SortArrowIcon up />; | ||
| break; | ||
| case ButtonState.DESC: | ||
| icon = <SortArrowIcon up={false} />; | ||
| break; | ||
| case ButtonState.UNSELECTED: | ||
| icon = <SortArrowIcon />; | ||
| break; | ||
| default: | ||
| icon = <SortArrowIcon />; | ||
| } | ||
|
|
||
| return ( | ||
| <Flex paddingLeft="3px"> | ||
| <IconButton | ||
| variant="ghost" | ||
| aria-label="Sort requests" | ||
| icon={icon} | ||
| isLoading={isLoading && wasButtonJustClicked} | ||
| onClick={handleButtonClick} | ||
| /> | ||
| </Flex> | ||
| ); | ||
| }; | ||
|
|
||
| export default SortRequestButton; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.