This repository has been 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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Datastore Connection Filtering (#691)
* Refactor routes into enums and create connections page * Test switching back to double quotes * Convert back to double quotes * Add placeholder connection filters * Set up api scaffolding * Get basic grid going * Initial grid card styling * Fix simple eslint issues * Add development config back in * Finish draft of card * Add working test button and landing page * Add pagination and small fixes * Fix testing issues * Add auth tests for datastore connection page * run formatter * Update changelog * update the create_test_data command to add connectionconfigs * Disable create buttons & fix text overflow * Update filter dropdown values * Fix test timestamp bug * Remove development variable * Add working filter dropdowns * Add outside click hook & polish things * Fix imports * Update changelog * Update button hover color * remove commented out code * fix typo * Remove Saas Option * Fix welcome screen bug * Remove edit button * Fix lint and formatting issues * removes commented-out code Co-authored-by: Sean Preston <[email protected]> Co-authored-by: eastandwestwind <[email protected]>
- Loading branch information
1 parent
106f29d
commit 7c3bf98
Showing
11 changed files
with
584 additions
and
205 deletions.
There are no files selected for viewing
This file contains 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 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 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,2 @@ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export { useOutsideClick } from "./useOutsideClick"; |
22 changes: 22 additions & 0 deletions
22
clients/admin-ui/src/features/common/hooks/useOutsideClick.ts
This file contains 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,22 @@ | ||
import { LegacyRef, useEffect, useRef } from "react"; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const useOutsideClick = (handleClick: () => void) => { | ||
const ref = useRef<HTMLDivElement | undefined>(undefined) as | ||
| LegacyRef<HTMLDivElement> | ||
| undefined; | ||
useEffect(() => { | ||
const handleOutsideClick = (event: MouseEvent) => { | ||
// @ts-ignore | ||
if (!ref.current?.contains(event.target)) { | ||
handleClick(); | ||
} | ||
}; | ||
document.addEventListener("mousedown", handleOutsideClick); | ||
return () => { | ||
document.removeEventListener("mousedown", handleOutsideClick); | ||
}; | ||
}, [ref, handleClick]); | ||
|
||
return { ref }; | ||
}; |
117 changes: 117 additions & 0 deletions
117
clients/admin-ui/src/features/datastore-connections/ConnectionDropdown.tsx
This file contains 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 { Box, Flex, IconButton, Spacer, Text } from "@fidesui/react"; | ||
import React, { useCallback, useState } from "react"; | ||
|
||
import { useOutsideClick } from "../common/hooks"; | ||
import { ArrowDownLineIcon } from "../common/Icon"; | ||
import { capitalize } from "../common/utils"; | ||
|
||
const useConnectionStatusMenu = () => { | ||
const [isOpen, setIsOpen] = useState<boolean>(false); | ||
const handleClick = useCallback(() => { | ||
if (isOpen) { | ||
setIsOpen(false); | ||
} | ||
}, [isOpen, setIsOpen]); | ||
|
||
const { ref } = useOutsideClick(handleClick); | ||
|
||
const toggleMenu = () => { | ||
setIsOpen(!isOpen); | ||
}; | ||
|
||
return { | ||
isOpen, | ||
toggleMenu, | ||
ref, | ||
}; | ||
}; | ||
|
||
type ConnectionDropdownProps = { | ||
filterOptions: string[]; | ||
// eslint-disable-next-line react/require-default-props | ||
value?: string; | ||
setValue: (x: string) => void; | ||
title: string; | ||
}; | ||
|
||
const ConnectionDropdown: React.FC<ConnectionDropdownProps> = ({ | ||
filterOptions, | ||
value, | ||
setValue, | ||
title, | ||
}) => { | ||
const { isOpen, toggleMenu, ref } = useConnectionStatusMenu(); | ||
const options = filterOptions.map((d) => ( | ||
<Flex | ||
key={d} | ||
height="36px" | ||
_hover={{ bg: "gray.100" }} | ||
alignItems="center" | ||
padding="8px" | ||
cursor="pointer" | ||
onClick={() => { | ||
setValue(d); | ||
toggleMenu(); | ||
}} | ||
> | ||
<Text | ||
marginLeft="8px" | ||
fontSize="xs" | ||
fontWeight="500" | ||
color={d === value ? "complimentary.500" : "gray.700"} | ||
lineHeight="16px" | ||
> | ||
{capitalize(d)} | ||
</Text> | ||
</Flex> | ||
)); | ||
|
||
return ( | ||
<Box width="100%" position="relative" ref={ref}> | ||
<Flex | ||
borderRadius="6px" | ||
border="1px" | ||
borderColor={isOpen ? "primary.600" : "gray.200"} | ||
height="32px" | ||
paddingRight="14px" | ||
paddingLeft="14px" | ||
alignItems="center" | ||
> | ||
<Text | ||
fontSize="14px" | ||
fontWeight="400" | ||
lineHeight="20px" | ||
color={value ? "complimentary.500" : "gray.700"} | ||
> | ||
{value ? capitalize(value) : title} | ||
</Text> | ||
<Spacer /> | ||
<IconButton | ||
variant="ghost" | ||
size="xs" | ||
aria-label="Datastore Type Dropdown" | ||
onClick={() => toggleMenu()} | ||
icon={<ArrowDownLineIcon />} | ||
/> | ||
</Flex> | ||
{isOpen ? ( | ||
<Flex | ||
marginTop="4px" | ||
backgroundColor="white" | ||
flexDirection="column" | ||
border="1px" | ||
width="100%" | ||
borderColor="gray.200" | ||
boxShadow="0px 1px 3px rgba(0, 0, 0, 0.1), 0px 1px 2px rgba(0, 0, 0, 0.06);" | ||
borderRadius="4px" | ||
position="absolute" | ||
zIndex={1} | ||
> | ||
{options} | ||
</Flex> | ||
) : null} | ||
</Box> | ||
); | ||
}; | ||
|
||
export default ConnectionDropdown; |
This file contains 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
Oops, something went wrong.