forked from quay/quay
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI: Adding UI to read OIDC group value (PROJQUAY-6298)
- Loading branch information
1 parent
2ab7dc2
commit 03d3c36
Showing
9 changed files
with
277 additions
and
35 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,67 @@ | ||
import {useState} from 'react'; | ||
import { | ||
Alert, | ||
Button, | ||
Modal, | ||
Text, | ||
TextInput, | ||
TextVariants, | ||
} from '@patternfly/react-core'; | ||
import Conditional from 'src/components/empty/Conditional'; | ||
|
||
export default function OIDCTeamSyncModal(props: OIDCTeamSyncModalProps) { | ||
const [groupName, setGroupName] = useState<string>(''); | ||
|
||
const handleInputChange = (value: string) => { | ||
setGroupName(value); | ||
}; | ||
|
||
return ( | ||
<Modal | ||
width="50%" | ||
title={props.titleText} | ||
isOpen={props.isModalOpen} | ||
onClose={props.toggleModal} | ||
actions={[ | ||
<Button | ||
key="confirm" | ||
variant="primary" | ||
onClick={() => props.onConfirmSync(groupName)} | ||
> | ||
Enable Sync | ||
</Button>, | ||
<Button key="cancel" variant="link" onClick={props.toggleModal}> | ||
Cancel | ||
</Button>, | ||
]} | ||
> | ||
<Text component={TextVariants.p}>{props.primaryText}</Text> | ||
<br /> | ||
<div> | ||
<Conditional if={props.secondaryText != null}> | ||
<Text component={TextVariants.p}>{props.secondaryText}</Text> | ||
</Conditional> | ||
<TextInput | ||
value={groupName} | ||
type="text" | ||
onChange={(_event, value) => handleInputChange(value)} | ||
id="team-sync-group-name" | ||
/> | ||
</div> | ||
<br /> | ||
<Conditional if={props.alertText != null}> | ||
<Alert isInline variant="warning" title={props.alertText} /> | ||
</Conditional> | ||
</Modal> | ||
); | ||
} | ||
|
||
type OIDCTeamSyncModalProps = { | ||
isModalOpen: boolean; | ||
toggleModal: () => void; | ||
titleText: string; | ||
primaryText: string; | ||
onConfirmSync: (string) => void; | ||
secondaryText?: string; | ||
alertText?: string; | ||
}; |
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,25 @@ | ||
import {useMutation, useQueryClient} from '@tanstack/react-query'; | ||
import {enableTeamSyncForOrg} from 'src/resources/TeamSyncResource'; | ||
|
||
export function useTeamSync({orgName, teamName, onSuccess, onError}) { | ||
const queryClient = useQueryClient(); | ||
|
||
const enableTeamSyncMutator = useMutation( | ||
async ({groupName, service}: {groupName: string; service: string}) => { | ||
return enableTeamSyncForOrg(orgName, teamName, groupName, service); | ||
}, | ||
{ | ||
onSuccess: () => { | ||
onSuccess(); | ||
queryClient.invalidateQueries([orgName, teamName, 'teamSync']); | ||
}, | ||
onError: (err) => { | ||
onError(err); | ||
}, | ||
}, | ||
); | ||
return { | ||
enableTeamSync: async (groupName: string, service: string) => | ||
enableTeamSyncMutator.mutate({groupName, service}), | ||
}; | ||
} |
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,21 @@ | ||
import axios from 'src/libs/axios'; | ||
import {assertHttpCode} from './ErrorHandling'; | ||
import {AxiosResponse} from 'axios'; | ||
|
||
export async function enableTeamSyncForOrg( | ||
orgName: string, | ||
teamName: string, | ||
groupName: string, | ||
service: string, | ||
) { | ||
const enableSyncUrl = `/api/v1/organization/${orgName}/team/${teamName}/syncing`; | ||
let data = {}; | ||
if (service == 'oidc') { | ||
data = { | ||
group_config: `${orgName}:${groupName}`, | ||
}; | ||
} | ||
const response: AxiosResponse = await axios.post(enableSyncUrl, data); | ||
assertHttpCode(response.status, 200); | ||
return response.data; | ||
} |
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.