From fea7707551830fcb9a9fbfada19160e76657a9bc Mon Sep 17 00:00:00 2001
From: Fredrik Strand Oseberg
Date: Thu, 21 Oct 2021 09:50:58 +0200
Subject: [PATCH] fix: use path parameter for old ft view (#450)
* fix: use path parameter for old ft view
* fix: update snapshots
* fix: change text
* fix: add permission button to initial strategies view
* fix: remove unused imports
---
.../FeatureStrategiesEnvironments.tsx | 11 ++++--
.../FeatureStrategiesList.tsx | 38 +++++++++----------
.../FeatureStrategyExecution.tsx | 4 +-
.../create/CreateFeature/CreateFeature.jsx | 12 +++---
.../strategy/strategies-list-component.jsx | 5 +++
.../__snapshots__/routes-test.jsx.snap | 2 +-
frontend/src/component/menu/routes.js | 2 +-
7 files changed, 40 insertions(+), 34 deletions(-)
diff --git a/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategiesEnvironments/FeatureStrategiesEnvironments.tsx b/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategiesEnvironments/FeatureStrategiesEnvironments.tsx
index af91da5c34..89edcad032 100644
--- a/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategiesEnvironments/FeatureStrategiesEnvironments.tsx
+++ b/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategiesEnvironments/FeatureStrategiesEnvironments.tsx
@@ -1,7 +1,7 @@
import { useHistory, useParams } from 'react-router-dom';
import useFeature from '../../../../../hooks/api/getters/useFeature/useFeature';
import { useStyles } from './FeatureStrategiesEnvironments.styles';
-import { Tabs, Tab, Button, useMediaQuery } from '@material-ui/core';
+import { Tabs, Tab, useMediaQuery } from '@material-ui/core';
import TabPanel from '../../../../common/TabNav/TabPanel';
import useTabs from '../../../../../hooks/useTabs';
import FeatureStrategiesEnvironmentList from './FeatureStrategiesEnvironmentList/FeatureStrategiesEnvironmentList';
@@ -22,6 +22,7 @@ import { Add } from '@material-ui/icons';
import AccessContext from '../../../../../contexts/AccessContext';
import { UPDATE_FEATURE } from '../../../../providers/AccessProvider/permissions';
import useQueryParams from '../../../../../hooks/useQueryParams';
+import PermissionButton from '../../../../common/PermissionButton/PermissionButton';
const FeatureStrategiesEnvironments = () => {
const smallScreen = useMediaQuery('(max-width:700px)');
@@ -316,8 +317,12 @@ const FeatureStrategiesEnvironments = () => {
UPDATE_FEATURE
)}
show={
-
+
}
/>
diff --git a/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategiesList/FeatureStrategiesList.tsx b/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategiesList/FeatureStrategiesList.tsx
index 0c3ff62597..ed75590aab 100644
--- a/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategiesList/FeatureStrategiesList.tsx
+++ b/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategiesList/FeatureStrategiesList.tsx
@@ -5,18 +5,20 @@ import { useStyles } from './FeatureStrategiesList.styles';
import { useContext } from 'react';
import FeatureStrategiesUIContext from '../../../../../contexts/FeatureStrategiesUIContext';
import classnames from 'classnames';
-import { Button, IconButton, Tooltip, useMediaQuery } from '@material-ui/core';
+import { Button, useMediaQuery } from '@material-ui/core';
import { DoubleArrow } from '@material-ui/icons';
import ConditionallyRender from '../../../../common/ConditionallyRender';
import { UPDATE_FEATURE } from '../../../../providers/AccessProvider/permissions';
-import AccessContext from '../../../../../contexts/AccessContext';
+import PermissionIconButton from '../../../../common/PermissionIconButton/PermissionIconButton';
+import { useParams } from 'react-router';
+import { IFeatureViewParams } from '../../../../../interfaces/params';
const FeatureStrategiesList = () => {
const smallScreen = useMediaQuery('(max-width:700px)');
const { expandedSidebar, setExpandedSidebar } = useContext(
FeatureStrategiesUIContext
);
- const { hasAccess } = useContext(AccessContext);
+ const { projectId } = useParams();
const styles = useStyles();
@@ -64,24 +66,18 @@ const FeatureStrategiesList = () => {
}
/>
-
-
-
-
-
-
-
+
+
+
+
+
+
+
{renderStrategies()}
);
diff --git a/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategyExecution/FeatureStrategyExecution.tsx b/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategyExecution/FeatureStrategyExecution.tsx
index 3ca59f3bb9..d6053f83aa 100644
--- a/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategyExecution/FeatureStrategyExecution.tsx
+++ b/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategyExecution/FeatureStrategyExecution.tsx
@@ -67,7 +67,7 @@ const FeatureStrategyExecution = ({
{constraints.length > 0
? 'who match constraints'
: ''}{' '}
- are included.
+ is included.
0
? 'who match constraints'
: ''}{' '}
- are included.
+ is included.
{
- const params = useQueryParams();
- const project = params.get('project');
+ const { projectId } = useParams();
+
const history = useHistory();
useEffect(() => {
- if (project) {
- setValue('project', project);
+ if (projectId) {
+ setValue('project', projectId);
}
/* eslint-disable-next-line */
}, []);
@@ -88,7 +88,7 @@ const CreateFeature = ({
setValue('project', v.target.value)}
filter={projectFilterGenerator(user, CREATE_FEATURE)}
/>
diff --git a/frontend/src/component/feature/strategy/strategies-list-component.jsx b/frontend/src/component/feature/strategy/strategies-list-component.jsx
index ce72e7f568..fe45ad9d4f 100644
--- a/frontend/src/component/feature/strategy/strategies-list-component.jsx
+++ b/frontend/src/component/feature/strategy/strategies-list-component.jsx
@@ -15,6 +15,8 @@ import CreateStrategy from './AddStrategy/AddStrategy';
import Dialogue from '../../common/Dialogue/Dialogue';
import ResponsiveButton from '../../common/ResponsiveButton/ResponsiveButton';
import { Add } from '@material-ui/icons';
+import { CREATE_FEATURE } from '../../providers/AccessProvider/permissions';
+import { useParams } from 'react-router';
const cleanStrategy = strategy => ({
name: strategy.name,
@@ -23,6 +25,7 @@ const cleanStrategy = strategy => ({
});
const StrategiesList = props => {
+ const { projectId } = useParams();
const [showDelDialog, setShowDelDialog] = useState(false);
const [delStrategy, setDelStrategy] = useState(null);
const [showCreateStrategy, setShowCreateStrategy] = useState(false);
@@ -172,6 +175,8 @@ const StrategiesList = props => {
maxWidth="700px"
tooltip="Add strategy"
Icon={Add}
+ permission={CREATE_FEATURE}
+ projectId={projectId}
>
Add strategy
diff --git a/frontend/src/component/menu/__tests__/__snapshots__/routes-test.jsx.snap b/frontend/src/component/menu/__tests__/__snapshots__/routes-test.jsx.snap
index 7a41bc7ef1..5872d21257 100644
--- a/frontend/src/component/menu/__tests__/__snapshots__/routes-test.jsx.snap
+++ b/frontend/src/component/menu/__tests__/__snapshots__/routes-test.jsx.snap
@@ -71,7 +71,7 @@ Array [
"layout": "main",
"menu": Object {},
"parent": "/projects",
- "path": "/projects/:id/create-toggle",
+ "path": "/projects/:projectId/create-toggle",
"title": "Create",
"type": "protected",
},
diff --git a/frontend/src/component/menu/routes.js b/frontend/src/component/menu/routes.js
index a162b07727..48c9714224 100644
--- a/frontend/src/component/menu/routes.js
+++ b/frontend/src/component/menu/routes.js
@@ -109,7 +109,7 @@ export const routes = [
menu: {},
},
{
- path: '/projects/:id/create-toggle',
+ path: '/projects/:projectId/create-toggle',
parent: '/projects',
title: 'Create',
component: CreateFeatureToggle,