Files
1127c4ba88 Project Level Permissions (#27347)
* fix: update Permission params

* fix: upgrade check permission hook to support project level role

* fix: usePermissionsLoaded

* fix: Permission params can be undefined

* Scaffold new access management UI

* Add validation

* Update roles view

* Add tooltip

* Add button to apply role to all projects

* Update UI to select projects first instead of roles

* Merge master update UI

* Midway trying to implementation project level perms API

* First pass implementating updating project level permissions

* Add client side validation for assigning/removing roles

* Midway implementing new invites

* Integrate most of the project level permissions functionality

* fix: filter out org-level permissions before checking

* Add relevant UI guards in org level pages for project role POV

* Minor refactors

* Small refactors

* More fixes

* Moar refactors

* More fixes

* More fixes

* Refactor update role logic and smack some test cases on it

* Fixes

* Fix type issue

* Fix type

* more fixes, refactors, adding checks...

* MORE fixes

* Add perms checking for replicas

* Add ButtonTooltip component and use them to prevent repetition of pointer events auto for buttons with tooltips

* Convert all buttons with tooltips to use ButtonTooltip

* refactor

* PRettier

* Small fix

* Remove commented out code in organization-invitation-accept-mutation

* fix: switch to use the platform oauth authorizations routes

* Add perms checking for org audit logs and org oauth apps

* PRettier

* Fix incorrect URL for oauth app flow

* Fix incorrect URL for oauth app flow

* Fix

* Add perms checking for warehouse related UI

* Update roles helper icon

* remove unused lib

* Update package lock... again

* Update package lock... again

* Smalllll update

* Update some checks

* Add gate for project level permissions

* Last fix

* update codegen

* Update warehouse endpoint routes

* Fix

---------

Co-authored-by: phamhieu <phamhieu1998@gmail.com>
Co-authored-by: Alaister Young <a@alaisteryoung.com>
2024-07-01 17:59:54 +08:00

70 lines
1.9 KiB
TypeScript

import type { BranchData } from 'data/branches/branch-query'
import type { Branch } from 'data/branches/branches-query'
import { Badge } from 'ui'
import { StatusIcon } from 'ui-patterns/Icons/StatusIcons'
type Status = Branch['status'] | BranchData['status']
export interface BranchStatusBadgeProps {
status: Status
}
const UNHEALTHY_STATUES: Status[] = [
'ACTIVE_UNHEALTHY',
'INIT_FAILED',
'UNKNOWN',
'MIGRATIONS_FAILED',
'FUNCTIONS_FAILED',
]
const WAITING_STATUSES: Status[] = [
'COMING_UP',
'GOING_DOWN',
'PAUSING',
'RESTORING',
'UPGRADING',
'RUNNING_MIGRATIONS',
]
const STATUS_TO_LABEL: Record<Status, string> = {
ACTIVE_HEALTHY: 'Healthy',
ACTIVE_UNHEALTHY: 'Unhealthy',
INIT_FAILED: 'Init failed',
UNKNOWN: 'Unknown',
COMING_UP: 'Coming up',
GOING_DOWN: 'Going down',
INACTIVE: 'Inactive',
PAUSING: 'Pausing',
REMOVED: 'Removed',
RESTORING: 'Restoring',
UPGRADING: 'Upgrading',
CREATING_PROJECT: 'Creating project',
RUNNING_MIGRATIONS: 'Running migrations',
MIGRATIONS_FAILED: 'Migrations failed',
MIGRATIONS_PASSED: 'Migrations applied successfully',
FUNCTIONS_DEPLOYED: 'Functions deployed',
FUNCTIONS_FAILED: 'Functions failed to deploy',
RESTARTING: 'Restarting',
RESTORE_FAILED: 'Failed to restore',
PAUSE_FAILED: 'Failed to pause',
}
const BranchStatusBadge = ({ status }: BranchStatusBadgeProps) => {
if (status === 'ACTIVE_HEALTHY' || status === 'MIGRATIONS_PASSED') {
return null
}
const isUnhealthy = UNHEALTHY_STATUES.includes(status)
const isWaiting = WAITING_STATUSES.includes(status)
return (
<Badge variant={isUnhealthy ? 'destructive' : 'default'} className="gap-1.5">
{(isUnhealthy || isWaiting) && (
<StatusIcon variant={isUnhealthy ? 'destructive' : 'default'} hideBackground />
)}
{STATUS_TO_LABEL[status]}
</Badge>
)
}
export default BranchStatusBadge