1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

show api access screen in projet settings (#3056)

Signed-off-by: andreas-unleash <andreas@getunleash.ai>

<!-- Thanks for creating a PR! To make it easier for reviewers and
everyone else to understand what your changes relate to, please add some
relevant content to the headings below. Feel free to ignore or delete
sections that you don't think are relevant. Thank you! ❤️ -->

## About the changes
<!-- Describe the changes introduced. What are they and why are they
being introduced? Feel free to also add screenshots or steps to view the
changes if they're visual. -->

<!-- Does it close an issue? Multiple? -->
Closes #
[1-612](https://linear.app/unleash/issue/1-612/first-iteration-of-project-token-management)

<!-- (For internal contributors): Does it relate to an issue on public
roadmap? -->
<!--
Relates to [roadmap](https://github.com/orgs/Unleash/projects/10) item:
#
-->

### Important files
<!-- PRs can contain a lot of changes, but not all changes are equally
important. Where should a reviewer start looking to get an overview of
the changes? Are any files particularly important? -->


## Discussion points
<!-- Anything about the PR you'd like to discuss before it gets merged?
Got any questions or doubts? -->

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
This commit is contained in:
andreas-unleash 2023-02-07 13:01:45 +02:00 committed by GitHub
parent 377e0e9d3e
commit d14072ff74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 88 additions and 2 deletions

View File

@ -28,12 +28,38 @@ import { useConditionallyHiddenColumns } from 'hooks/useConditionallyHiddenColum
import { TimeAgoCell } from 'component/common/Table/cells/TimeAgoCell/TimeAgoCell';
const hiddenColumnsSmall = ['Icon', 'createdAt'];
const hiddenColumnsCompact = ['Icon', 'project', 'seenAt'];
export const ApiTokenTable = () => {
interface IApiTokenTableProps {
compact?: boolean;
filterForProject?: string;
}
export const ApiTokenTable = ({
compact = false,
filterForProject,
}: IApiTokenTableProps) => {
const { tokens, loading } = useApiTokens();
const initialState = useMemo(() => ({ sortBy: [{ id: 'createdAt' }] }), []);
const isSmallScreen = useMediaQuery(theme.breakpoints.down('md'));
const filteredTokens = useMemo(() => {
if (Boolean(filterForProject)) {
return tokens.filter(token => {
if (token.projects) {
if (token.projects?.length > 1) return false;
if (
token.projects?.length === 1 &&
token.projects[0] === filterForProject
)
return true;
}
return token.project === filterForProject;
});
}
return tokens;
}, [tokens, filterForProject]);
const {
getTableProps,
getTableBodyProps,
@ -46,7 +72,7 @@ export const ApiTokenTable = () => {
} = useTable(
{
columns: COLUMNS as any,
data: tokens as any,
data: filteredTokens as any,
initialState,
sortTypes,
autoResetHiddenColumns: false,
@ -62,6 +88,10 @@ export const ApiTokenTable = () => {
condition: isSmallScreen,
columns: hiddenColumnsSmall,
},
{
condition: compact,
columns: hiddenColumnsCompact,
},
],
setHiddenColumns,
COLUMNS

View File

@ -0,0 +1,35 @@
import { useContext } from 'react';
import { PageContent } from 'component/common/PageContent/PageContent';
import { Alert } from '@mui/material';
import { PageHeader } from 'component/common/PageHeader/PageHeader';
import AccessContext from 'contexts/AccessContext';
import { UPDATE_PROJECT } from 'component/providers/AccessProvider/permissions';
import { useRequiredPathParam } from 'hooks/useRequiredPathParam';
import { usePageTitle } from 'hooks/usePageTitle';
import { useProjectNameOrId } from 'hooks/api/getters/useProject/useProject';
import { ApiTokenTable } from '../../../admin/apiToken/ApiTokenTable/ApiTokenTable';
export const ProjectApiAccess = () => {
const projectId = useRequiredPathParam('projectId');
const projectName = useProjectNameOrId(projectId);
const { hasAccess } = useContext(AccessContext);
usePageTitle(`Project api access ${projectName}`);
if (!hasAccess(UPDATE_PROJECT, projectId)) {
return (
<PageContent header={<PageHeader title="Api access" />}>
<Alert severity="error">
You need project owner or admin permissions to access this
section.
</Alert>
</PageContent>
);
}
return (
<div style={{ width: '100%', overflow: 'hidden' }}>
<ApiTokenTable compact filterForProject={projectId} />
</div>
);
};

View File

@ -9,10 +9,14 @@ import { ITab, VerticalTabs } from 'component/common/VerticalTabs/VerticalTabs';
import { ProjectAccess } from 'component/project/ProjectAccess/ProjectAccess';
import ProjectEnvironmentList from 'component/project/ProjectEnvironment/ProjectEnvironment';
import { ChangeRequestConfiguration } from './ChangeRequestConfiguration/ChangeRequestConfiguration';
import { ProjectApiAccess } from './ProjectApiAccess';
import useUiConfig from '../../../../hooks/api/getters/useUiConfig/useUiConfig';
export const ProjectSettings = () => {
const location = useLocation();
const navigate = useNavigate();
const { uiConfig } = useUiConfig();
const { showProjectApiAccess } = uiConfig.flags;
const tabs: ITab[] = [
{
@ -29,6 +33,13 @@ export const ProjectSettings = () => {
},
];
if (Boolean(showProjectApiAccess)) {
tabs.push({
id: 'api-access',
label: 'API access',
});
}
const onChange = (tab: ITab) => {
navigate(tab.id);
};
@ -53,6 +64,9 @@ export const ProjectSettings = () => {
path="change-requests/*"
element={<ChangeRequestConfiguration />}
/>
{Boolean(showProjectApiAccess) && (
<Route path="api-access/*" element={<ProjectApiAccess />} />
)}
<Route
path="*"
element={<Navigate replace to={tabs[0].id} />}

View File

@ -48,6 +48,7 @@ export interface IFlags {
newProjectOverview?: boolean;
caseInsensitiveInOperators?: boolean;
crOnVariants?: boolean;
showProjectApiAccess?: boolean;
}
export interface IVersionInfo {

View File

@ -83,6 +83,7 @@ exports[`should create default config 1`] = `
"proxyReturnAllToggles": false,
"responseTimeWithAppName": false,
"serviceAccounts": false,
"showProjectApiAccess": false,
"variantsPerEnvironment": false,
},
},
@ -104,6 +105,7 @@ exports[`should create default config 1`] = `
"proxyReturnAllToggles": false,
"responseTimeWithAppName": false,
"serviceAccounts": false,
"showProjectApiAccess": false,
"variantsPerEnvironment": false,
},
"externalResolver": {

View File

@ -66,6 +66,10 @@ const flags = {
process.env.UNLEASH_EXPERIMENTAL_CR_ON_VARIANTS,
false,
),
showProjectApiAccess: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_PROJECT_API_ACCESS,
false,
),
};
export const defaultExperimentalOptions: IExperimentalOptions = {