Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix pro project role descriptions (#2612)
https://linear.app/unleash/issue/2-485/bug-pro-access-page-the-tooltip-on-the-roles-is-not-working Fixes an issue where we would not show anything for project role permissions since we're not serving that specific endpoint below Enterprise level. This way we fallback to the access role descriptions, which are also nice and informative: ![image](https://user-images.githubusercontent.com/14320932/205987327-def46ef2-4010-47dd-ba7d-5a264f0b547d.png) PR also adds support for SWR options in ConditionalSWR and EnterpriseSWR.
- Loading branch information
Showing
12 changed files
with
162 additions
and
82 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
19 changes: 19 additions & 0 deletions
19
...ectRoleDescriptionEnvironmentPermissions/ProjectRoleDescriptionEnvironmentPermissions.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,19 @@ | ||
interface IProjectRoleDescriptionEnvironmentPermissionsProps { | ||
environment: string; | ||
permissions: any[]; | ||
} | ||
|
||
export const ProjectRoleDescriptionEnvironmentPermissions = ({ | ||
environment, | ||
permissions, | ||
}: IProjectRoleDescriptionEnvironmentPermissionsProps) => ( | ||
<> | ||
{permissions | ||
.filter((permission: any) => permission.environment === environment) | ||
.map((permission: any) => permission.displayName) | ||
.sort() | ||
.map((permission: any) => ( | ||
<p key={permission}>{permission}</p> | ||
))} | ||
</> | ||
); |
17 changes: 17 additions & 0 deletions
17
...ion/ProjectRoleDescriptionProjectPermissions/ProjectRoleDescriptionProjectPermissions.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,17 @@ | ||
interface IProjectRoleDescriptionProjectPermissionsProps { | ||
permissions: any[]; | ||
} | ||
|
||
export const ProjectRoleDescriptionProjectPermissions = ({ | ||
permissions, | ||
}: IProjectRoleDescriptionProjectPermissionsProps) => ( | ||
<> | ||
{permissions | ||
?.filter((permission: any) => !permission.environment) | ||
.map((permission: any) => permission.displayName) | ||
.sort() | ||
.map((permission: any) => ( | ||
<p key={permission}>{permission}</p> | ||
))} | ||
</> | ||
); |
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
23 changes: 23 additions & 0 deletions
23
frontend/src/hooks/api/getters/useConditionalSWR/useConditionalSWR.ts
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,23 @@ | ||
import useSWR, { BareFetcher, Key, SWRConfiguration, SWRResponse } from 'swr'; | ||
import { useEffect } from 'react'; | ||
|
||
export const useConditionalSWR = <Data = any, Error = any, T = boolean>( | ||
condition: T, | ||
fallback: Data, | ||
key: Key, | ||
fetcher: BareFetcher<Data>, | ||
options: SWRConfiguration = {} | ||
): SWRResponse<Data, Error> => { | ||
const result = useSWR( | ||
key, | ||
(path: string) => | ||
condition ? fetcher(path) : Promise.resolve(fallback), | ||
options | ||
); | ||
|
||
useEffect(() => { | ||
result.mutate(); | ||
}, [condition]); | ||
|
||
return result; | ||
}; |
28 changes: 8 additions & 20 deletions
28
frontend/src/hooks/api/getters/useEnterpriseSWR/useEnterpriseSWR.ts
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
9accbcf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
unleash-monorepo-frontend – ./frontend
unleash-monorepo-frontend.vercel.app
unleash-monorepo-frontend-git-main-unleash-team.vercel.app
unleash-monorepo-frontend-unleash-team.vercel.app