-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: keypair info/setting modal in credential page
- Loading branch information
1 parent
6405a37
commit 9d61c02
Showing
29 changed files
with
618 additions
and
143 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { localeCompare } from '../helper'; | ||
import useControllableState from '../hooks/useControllableState'; | ||
import { KeypairResourcePolicySelectorQuery } from './__generated__/KeypairResourcePolicySelectorQuery.graphql'; | ||
import { Select, SelectProps } from 'antd'; | ||
import graphql from 'babel-plugin-relay/macro'; | ||
import _ from 'lodash'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { useLazyLoadQuery } from 'react-relay'; | ||
|
||
interface KeypairResourcePolicySelectorProps extends SelectProps {} | ||
|
||
const KeypairResourcePolicySelector: React.FC< | ||
KeypairResourcePolicySelectorProps | ||
> = ({ ...selectProps }) => { | ||
const { t } = useTranslation(); | ||
const [value, setValue] = useControllableState<string>({ | ||
value: selectProps.value, | ||
onChange: selectProps.onChange, | ||
}); | ||
|
||
const { keypair_resource_policies } = | ||
useLazyLoadQuery<KeypairResourcePolicySelectorQuery>( | ||
graphql` | ||
query KeypairResourcePolicySelectorQuery { | ||
keypair_resource_policies { | ||
name | ||
} | ||
} | ||
`, | ||
{}, | ||
{ fetchPolicy: 'store-and-network' }, | ||
); | ||
|
||
return ( | ||
<Select | ||
showSearch | ||
placeholder={t('credential.SelectPolicy')} | ||
options={_.map(keypair_resource_policies, (policy) => { | ||
return { | ||
value: policy?.name, | ||
label: policy?.name, | ||
}; | ||
}).sort((a, b) => localeCompare(a?.label, b?.label))} | ||
{...selectProps} | ||
value={value} | ||
onChange={(value, option) => { | ||
setValue(value, option); | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export default KeypairResourcePolicySelector; |
Oops, something went wrong.