Skip to content

Commit

Permalink
remove change request flag (#2703)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Dec 15, 2022
1 parent 97cf3cd commit f4480d5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 91 deletions.
Expand Up @@ -5,10 +5,6 @@ import useProjectRolePermissions from 'hooks/api/getters/useProjectRolePermissio
import useProjectRolesApi from 'hooks/api/actions/useProjectRolesApi/useProjectRolesApi';
import { formatUnknownError } from 'utils/formatUnknownError';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import {
APPLY_CHANGE_REQUEST,
APPROVE_CHANGE_REQUEST,
} from 'component/providers/AccessProvider/permissions';

export interface ICheckedPermission {
[key: string]: IPermission;
Expand Down Expand Up @@ -170,35 +166,12 @@ const useProjectRoleForm = (
setErrors({});
};

// TODO: Clean up when feature is complete - changeRequests
let filteredPermissions = cloneDeep(permissions);

if (!uiConfig?.flags.changeRequests) {
filteredPermissions.environments = filteredPermissions.environments.map(
env => {
env.permissions = env.permissions.filter(permission => {
if (!uiConfig?.flags.changeRequests) {
if (
permission.name === APPLY_CHANGE_REQUEST ||
permission.name === APPROVE_CHANGE_REQUEST
) {
return false;
}
}
return true;
});

return env;
}
);
}

return {
roleName,
roleDesc,
errors,
checkedPermissions,
permissions: filteredPermissions,
permissions,
setRoleName,
setRoleDesc,
handlePermissionChange,
Expand Down
89 changes: 36 additions & 53 deletions frontend/src/component/project/Project/Project.tsx
Expand Up @@ -7,7 +7,7 @@ import { styled, Tab, Tabs } from '@mui/material';
import { Delete, Edit } from '@mui/icons-material';
import useToast from 'hooks/useToast';
import useQueryParams from 'hooks/useQueryParams';
import { useEffect, useMemo, useState } from 'react';
import { useEffect, useState } from 'react';
import ProjectEnvironment from '../ProjectEnvironment/ProjectEnvironment';
import { ProjectFeaturesArchive } from './ProjectFeaturesArchive/ProjectFeaturesArchive';
import ProjectOverview from './ProjectOverview';
Expand Down Expand Up @@ -77,51 +77,44 @@ const Project = () => {
const { isOss, uiConfig } = useUiConfig();
const basePath = `/projects/${projectId}`;
const projectName = project?.name || projectId;
const { isChangeRequestConfiguredInAnyEnv, isChangeRequestFlagEnabled } =
const { isChangeRequestConfiguredInAnyEnv } =
useChangeRequestsEnabled(projectId);
const { favorite, unfavorite } = useFavoriteProjectsApi();

const [showDelDialog, setShowDelDialog] = useState(false);

const tabs = useMemo(() => {
const tabArray = [
{
title: 'Overview',
path: basePath,
name: 'overview',
},
{
title: 'Health',
path: `${basePath}/health`,
name: 'health',
},
{
title: 'Archive',
path: `${basePath}/archive`,
name: 'archive',
},
...(isChangeRequestFlagEnabled
? [
{
title: 'Change requests',
path: `${basePath}/change-requests`,
name: 'change-request',
},
]
: []),
{
title: 'Project settings',
path: `${basePath}/settings`,
name: 'settings',
},
{
title: 'Event log',
path: `${basePath}/logs`,
name: 'logs',
},
];
return tabArray;
}, [isChangeRequestFlagEnabled]);
const tabs = [
{
title: 'Overview',
path: basePath,
name: 'overview',
},
{
title: 'Health',
path: `${basePath}/health`,
name: 'health',
},
{
title: 'Archive',
path: `${basePath}/archive`,
name: 'archive',
},
{
title: 'Change requests',
path: `${basePath}/change-requests`,
name: 'change-request',
},
{
title: 'Project settings',
path: `${basePath}/settings`,
name: 'settings',
},
{
title: 'Event log',
path: `${basePath}/logs`,
name: 'logs',
},
];

const activeTab = [...tabs]
.reverse()
Expand Down Expand Up @@ -285,21 +278,11 @@ const Project = () => {
<Route path="logs" element={<ProjectLog />} />
<Route
path="change-requests"
element={
<ConditionallyRender
condition={isChangeRequestFlagEnabled}
show={<ProjectChangeRequests />}
/>
}
element={<ProjectChangeRequests />}
/>
<Route
path="change-requests/:id"
element={
<ConditionallyRender
condition={isChangeRequestFlagEnabled}
show={<ChangeRequestOverview />}
/>
}
element={<ChangeRequestOverview />}
/>
<Route path="settings/*" element={<ProjectSettings />} />
<Route path="*" element={<ProjectOverview />} />
Expand Down
12 changes: 2 additions & 10 deletions frontend/src/hooks/useChangeRequestsEnabled.ts
@@ -1,34 +1,26 @@
import React from 'react';
import useUiConfig from './api/getters/useUiConfig/useUiConfig';
import { useChangeRequestConfig } from './api/getters/useChangeRequestConfig/useChangeRequestConfig';

export const useChangeRequestsEnabled = (projectId: string) => {
const { uiConfig } = useUiConfig();
const { data } = useChangeRequestConfig(projectId);

const isChangeRequestConfigured = React.useCallback(
(environment: string): boolean => {
const enabled = data.some(draft => {
return data.some(draft => {
return (
draft.environment === environment &&
draft.changeRequestEnabled
);
});

return Boolean(uiConfig?.flags.changeRequests) && enabled;
},
[JSON.stringify(data)]
);

const isChangeRequestConfiguredInAnyEnv = React.useCallback((): boolean => {
return (
Boolean(uiConfig?.flags.changeRequests) &&
data.some(draft => draft.changeRequestEnabled)
);
return data.some(draft => draft.changeRequestEnabled);
}, [JSON.stringify(data)]);

return {
isChangeRequestFlagEnabled: Boolean(uiConfig?.flags.changeRequests),
isChangeRequestConfigured,
isChangeRequestConfiguredInAnyEnv,
};
Expand Down

0 comments on commit f4480d5

Please sign in to comment.