-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk): add screen to manage service account and API keys (#815)
* chore: update style in sdk demo * feat: add APIKeys placeholder page * feat: add showAPIKeys props to IAM dialog * feat: add route for api keys page * feat: add sidebar link to api keys page * fix: pass showAPIKeys to helper function * chore: pass showAPIKeys from sdk-demo app * feat: update apsara version to v0.23.0 * feat: add empty state to API Keys screen * chore: update frontier in sdk demo * revert: sdk demo changes * refactor: create seperate component for NoServiceAccounts * feat: check permission in API keys screen * chore: update page heading
- Loading branch information
Showing
16 changed files
with
6,606 additions
and
8,033 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
109 changes: 109 additions & 0 deletions
109
sdks/js/packages/core/react/components/organization/api-keys/index.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,109 @@ | ||
import { Flex, Text, EmptyState, Button } from '@raystack/apsara/v1'; | ||
import styles from './styles.module.css'; | ||
import keyIcon from '~/react/assets/key.svg'; | ||
import { Image } from '@raystack/apsara'; | ||
import { useFrontier } from '~/react/contexts/FrontierContext'; | ||
import { DEFAULT_API_PLATFORM_APP_NAME } from '~/react/utils/constants'; | ||
import { FrontierClientAPIPlatformOptions } from '~/shared/types'; | ||
import { useMemo } from 'react'; | ||
import { PERMISSIONS, shouldShowComponent } from '~/utils'; | ||
import { usePermissions } from '~/react/hooks/usePermissions'; | ||
import { ExclamationTriangleIcon } from '@radix-ui/react-icons'; | ||
|
||
const NoServiceAccounts = ({ | ||
config | ||
}: { | ||
config?: FrontierClientAPIPlatformOptions; | ||
}) => { | ||
const appName = config?.appName || DEFAULT_API_PLATFORM_APP_NAME; | ||
return ( | ||
<EmptyState | ||
icon={ | ||
<Image | ||
// @ts-ignore | ||
src={keyIcon} | ||
alt="keyIcon" | ||
/> | ||
} | ||
heading="No service account" | ||
subHeading={`Create a new account to use the APIs of ${appName}`} | ||
primaryAction={ | ||
<Button | ||
data-test-id="frontier-sdk-new-service-account-btn" | ||
variant="secondary" | ||
> | ||
Create new service account | ||
</Button> | ||
} | ||
/> | ||
); | ||
}; | ||
|
||
const NoAccess = () => { | ||
return ( | ||
<EmptyState | ||
icon={<ExclamationTriangleIcon />} | ||
heading="Restricted Access" | ||
subHeading={`Admin access required, please reach out to your admin incase you want to generate a key.`} | ||
/> | ||
); | ||
}; | ||
|
||
const useAccess = (orgId?: string) => { | ||
const resource = `app/organization:${orgId}`; | ||
const listOfPermissionsToCheck = useMemo(() => { | ||
return [ | ||
{ | ||
permission: PERMISSIONS.UpdatePermission, | ||
resource: resource | ||
} | ||
]; | ||
}, [resource]); | ||
|
||
const { permissions, isFetching: isPermissionsFetching } = usePermissions( | ||
listOfPermissionsToCheck, | ||
!!orgId | ||
); | ||
|
||
const canUpdateWorkspace = useMemo(() => { | ||
return shouldShowComponent( | ||
permissions, | ||
`${PERMISSIONS.UpdatePermission}::${resource}` | ||
); | ||
}, [permissions, resource]); | ||
|
||
return { | ||
isPermissionsFetching, | ||
canUpdateWorkspace | ||
}; | ||
}; | ||
|
||
export default function ApiKeys() { | ||
const { | ||
activeOrganization: organization, | ||
isActiveOrganizationLoading, | ||
config | ||
} = useFrontier(); | ||
|
||
const { isPermissionsFetching, canUpdateWorkspace } = useAccess( | ||
organization?.id | ||
); | ||
|
||
// TODO: show skeleton loader for Keys List | ||
const isLoading = isActiveOrganizationLoading || isPermissionsFetching; | ||
|
||
return ( | ||
<Flex direction="column" style={{ width: '100%' }}> | ||
<Flex className={styles.header}> | ||
<Text size={6}>API</Text> | ||
</Flex> | ||
<Flex justify="center" align="center" className={styles.content}> | ||
{canUpdateWorkspace ? ( | ||
<NoServiceAccounts config={config.apiPlatform} /> | ||
) : ( | ||
<NoAccess /> | ||
)} | ||
</Flex> | ||
</Flex> | ||
); | ||
} |
8 changes: 8 additions & 0 deletions
8
sdks/js/packages/core/react/components/organization/api-keys/styles.module.css
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,8 @@ | ||
.header { | ||
padding: var(--rs-space-5) var(--rs-space-11); | ||
border-bottom: 1px solid var(--rs-color-border-base-primary); | ||
} | ||
|
||
.content { | ||
padding: var(--space-15) var(--space-11); | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,4 +25,4 @@ | |
"typescript": "^5" | ||
}, | ||
"packageManager": "pnpm@8.6.10" | ||
} | ||
} |
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.