-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1050 from bcgov/feature/ns-to-gw-selector
Feature/ns to gw selector
- Loading branch information
Showing
27 changed files
with
846 additions
and
226 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
2 changes: 2 additions & 0 deletions
2
src/authz/graphql-whitelist/httplocalhost4180managernamespaces-339568.gql
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 |
---|---|---|
@@ -1,7 +1,9 @@ | ||
|
||
query GetCurrentNamespace { | ||
currentNamespace { | ||
id | ||
name | ||
displayName | ||
org | ||
orgUnit | ||
orgUpdatedAt | ||
|
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 |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
allNamespaces { | ||
id | ||
name | ||
displayName | ||
orgEnabled | ||
orgUpdatedAt | ||
} | ||
|
4 changes: 4 additions & 0 deletions
4
src/authz/graphql-whitelist/httpoauth2proxylocaltestme4180managernamespaces-a5ae8c.gql
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,4 @@ | ||
|
||
mutation UpdateNamespaceDisplayName($displayName: String!) { | ||
updateCurrentNamespaceDisplayName(displayName: $displayName) | ||
} |
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
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
164 changes: 164 additions & 0 deletions
164
src/nextapp/components/edit-display-name/edit-display-name.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,164 @@ | ||
import * as React from 'react'; | ||
import { | ||
Button, | ||
ButtonGroup, | ||
FormControl, | ||
FormHelperText, | ||
FormLabel, | ||
Icon, | ||
Input, | ||
Modal, | ||
ModalBody, | ||
ModalContent, | ||
ModalFooter, | ||
ModalHeader, | ||
ModalOverlay, | ||
Text, | ||
useDisclosure, | ||
useToast, | ||
} from '@chakra-ui/react'; | ||
import { FaPen } from 'react-icons/fa'; | ||
import { QueryKey, useQueryClient } from 'react-query'; | ||
import { useApiMutation } from '@/shared/services/api'; | ||
import { gql } from 'graphql-request'; | ||
import { NamespaceInput } from '@/shared/types/query.types'; | ||
|
||
interface EditNamespaceDisplayNameProps { | ||
data: NamespaceInput; | ||
queryKey: QueryKey; | ||
} | ||
|
||
const EditNamespaceDisplayName: React.FC<EditNamespaceDisplayNameProps> = ({ | ||
data, | ||
queryKey, | ||
}) => { | ||
const toast = useToast(); | ||
const { isOpen, onOpen, onClose } = useDisclosure(); | ||
const queryClient = useQueryClient(); | ||
const mutate = useApiMutation(mutation); | ||
const [inputValue, setInputValue] = React.useState(data.displayName || ''); | ||
const [charCount, setCharCount] = React.useState( | ||
data.displayName?.length || 0 | ||
); | ||
const charLimit = 30; | ||
const handleInputChange = (event) => { | ||
const { value } = event.target; | ||
setInputValue(value); | ||
setCharCount(value.length); | ||
}; | ||
const form = React.useRef<HTMLFormElement>(); | ||
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => { | ||
event.preventDefault(); | ||
if (charCount <= charLimit) { | ||
updateNamespaceDisplayName(); | ||
} | ||
}; | ||
const updateNamespaceDisplayName = async () => { | ||
if (form.current) { | ||
try { | ||
if (form.current.checkValidity()) { | ||
const formData = new FormData(form.current); | ||
const entries = Object.fromEntries(formData); | ||
await mutate.mutateAsync(entries); | ||
queryClient.invalidateQueries(queryKey); | ||
onClose(); | ||
toast({ | ||
title: 'Display name successfully edited', | ||
status: 'success', | ||
isClosable: true, | ||
}); | ||
} | ||
} catch (err) { | ||
toast({ | ||
title: 'Display name update failed', | ||
description: err, | ||
status: 'error', | ||
isClosable: true, | ||
}); | ||
} | ||
} | ||
}; | ||
const handleSaveClick = () => { | ||
form.current?.requestSubmit(); | ||
}; | ||
return ( | ||
<> | ||
<Button | ||
p="0" | ||
leftIcon={<Icon as={FaPen} />} | ||
variant="ghost" | ||
size="sm" | ||
onClick={onOpen} | ||
data-testid="display-name-edit-btn" | ||
> | ||
Edit | ||
</Button> | ||
<Modal isOpen={isOpen} onClose={onClose}> | ||
<ModalOverlay /> | ||
<ModalContent borderRadius="4px" px={11}> | ||
<ModalHeader pt={10}>Edit display name</ModalHeader> | ||
<ModalBody pt={0} pb={10}> | ||
<form ref={form} onSubmit={handleSubmit}> | ||
<FormControl isRequired> | ||
<FormLabel></FormLabel> | ||
<FormHelperText pb={4} fontSize={'16px'}> | ||
A meaningful display name makes it easy for anyone to identify | ||
and distinguish this Gateway from others. | ||
</FormHelperText> | ||
<Text | ||
fontSize={'12px'} | ||
color={charCount > charLimit ? 'bc-error' : 'gray.500'} | ||
mt={2} | ||
textAlign="right" | ||
> | ||
{charCount}/{charLimit} | ||
</Text> | ||
<Input | ||
value={inputValue} | ||
onChange={handleInputChange} | ||
name="displayName" | ||
variant="bc-input" | ||
isInvalid={charCount > charLimit} | ||
data-testid="edit-display-name-input" | ||
/> | ||
{charCount > charLimit && ( | ||
<Text color="bc-error" mt={2} mb={-8}> | ||
You have reached the character limit | ||
</Text> | ||
)} | ||
</FormControl> | ||
</form> | ||
</ModalBody> | ||
<ModalFooter pt={7} pb={7}> | ||
<ButtonGroup> | ||
<Button | ||
px={7} | ||
onClick={onClose} | ||
variant="secondary" | ||
data-testid="edit-display-name-cancel-btn" | ||
> | ||
Cancel | ||
</Button> | ||
<Button | ||
type="submit" | ||
onClick={handleSaveClick} | ||
data-testid="edit-display-name-submit-btn" | ||
isDisabled={charCount > charLimit} | ||
> | ||
Save | ||
</Button> | ||
</ButtonGroup> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
</> | ||
); | ||
}; | ||
|
||
export default EditNamespaceDisplayName; | ||
|
||
const mutation = gql` | ||
mutation UpdateNamespaceDisplayName($displayName: String!) { | ||
updateCurrentNamespaceDisplayName(displayName: $displayName) | ||
} | ||
`; |
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 @@ | ||
export { default } from './edit-display-name'; |
Oops, something went wrong.