}
@@ -175,7 +153,7 @@ const FeatureToggleList = ({
disabled={
!hasAccess(
CREATE_FEATURE,
- currentProjectId
+ resolvedProjectId
)
}
>
@@ -195,7 +173,7 @@ const FeatureToggleList = ({
disabled={
!hasAccess(
CREATE_FEATURE,
- currentProjectId
+ resolvedProjectId
)
}
className={classnames({
@@ -221,16 +199,14 @@ const FeatureToggleList = ({
FeatureToggleList.propTypes = {
features: PropTypes.array.isRequired,
- featureMetrics: PropTypes.object.isRequired,
- fetcher: PropTypes.func,
revive: PropTypes.func,
- updateSetting: PropTypes.func.isRequired,
- toggleFeature: PropTypes.func,
- settings: PropTypes.object,
- history: PropTypes.object.isRequired,
loading: PropTypes.bool,
- currentProjectId: PropTypes.string.isRequired,
+ archive: PropTypes.bool,
flags: PropTypes.object,
+ filter: PropTypes.object.isRequired,
+ setFilter: PropTypes.func.isRequired,
+ sort: PropTypes.object.isRequired,
+ setSort: PropTypes.func.isRequired,
};
export default FeatureToggleList;
diff --git a/frontend/src/component/feature/FeatureToggleList/FeatureToggleListActions/FeatureToggleListActions.jsx b/frontend/src/component/feature/FeatureToggleList/FeatureToggleListActions/FeatureToggleListActions.jsx
index d242ebdd2f..fd27c1a1fd 100644
--- a/frontend/src/component/feature/FeatureToggleList/FeatureToggleListActions/FeatureToggleListActions.jsx
+++ b/frontend/src/component/feature/FeatureToggleList/FeatureToggleListActions/FeatureToggleListActions.jsx
@@ -2,31 +2,21 @@ import React from 'react';
import PropTypes from 'prop-types';
import { MenuItem, Typography } from '@material-ui/core';
-// import { HourglassEmpty, HourglassFull } from '@material-ui/icons';
-// import { MenuItemWithIcon } from '../../../common';
import DropdownMenu from '../../../common/DropdownMenu/DropdownMenu';
import ProjectSelect from '../../../common/ProjectSelect';
import { useStyles } from './styles';
import useLoading from '../../../../hooks/useLoading';
import useUiConfig from '../../../../hooks/api/getters/useUiConfig/useUiConfig';
import ConditionallyRender from '../../../common/ConditionallyRender';
+import { createFeaturesFilterSortOptions } from '../../../../hooks/useFeaturesSort';
-const sortingOptions = [
- { type: 'name', displayName: 'Name' },
- { type: 'type', displayName: 'Type' },
- { type: 'enabled', displayName: 'Enabled' },
- { type: 'stale', displayName: 'Stale' },
- { type: 'created', displayName: 'Created' },
- { type: 'Last seen', displayName: 'Last seen' },
- { type: 'project', displayName: 'Project' },
- { type: 'metrics', displayName: 'Metrics' },
-];
+const sortOptions = createFeaturesFilterSortOptions();
const FeatureToggleListActions = ({
- settings,
+ filter,
+ setFilter,
+ sort,
setSort,
- toggleMetrics,
- updateSetting,
loading,
}) => {
const styles = useStyles();
@@ -34,65 +24,33 @@ const FeatureToggleListActions = ({
const ref = useLoading(loading);
const handleSort = e => {
- const target = e.target.getAttribute('data-target');
- setSort(target);
+ const type = e.target.getAttribute('data-target')?.trim();
+ type && setSort(prev => ({ ...prev, type }));
};
- const isDisabled = type => settings.sort === type;
+ const isDisabled = s => s === sort.type;
+ const selectedOption = sortOptions.find(o => o.type === sort.type) || sortOptions[0];
const renderSortingOptions = () =>
- sortingOptions.map(option => (
+ sortOptions.map(option => (
));
- /*
- const renderMetricsOptions = () => [
-
,
-
,
- ];
- */
-
return (
Sorted by:
- {/* }
-
- {*/}
setFilter(prev => ({ ...prev, project }))}
style={{
textTransform: 'lowercase',
fontWeight: 'normal',
@@ -119,10 +77,11 @@ const FeatureToggleListActions = ({
};
FeatureToggleListActions.propTypes = {
- settings: PropTypes.object,
+ filter: PropTypes.object,
+ setFilter: PropTypes.func,
+ sort: PropTypes.object,
setSort: PropTypes.func,
toggleMetrics: PropTypes.func,
- updateSetting: PropTypes.func,
loading: PropTypes.bool,
};
diff --git a/frontend/src/component/feature/FeatureToggleList/FeatureToggleListContainer.tsx b/frontend/src/component/feature/FeatureToggleList/FeatureToggleListContainer.tsx
new file mode 100644
index 0000000000..84a7f94a3c
--- /dev/null
+++ b/frontend/src/component/feature/FeatureToggleList/FeatureToggleListContainer.tsx
@@ -0,0 +1,24 @@
+import { useFeatures } from '../../../hooks/api/getters/useFeatures/useFeatures';
+import useUiConfig from '../../../hooks/api/getters/useUiConfig/useUiConfig';
+import { useFeaturesFilter } from '../../../hooks/useFeaturesFilter';
+import FeatureToggleList from './FeatureToggleList';
+import { useFeaturesSort } from '../../../hooks/useFeaturesSort';
+
+export const FeatureToggleListContainer = () => {
+ const { uiConfig } = useUiConfig();
+ const { features, loading } = useFeatures();
+ const { filtered, filter, setFilter } = useFeaturesFilter(features);
+ const { sorted, sort, setSort } = useFeaturesSort(filtered);
+
+ return (
+
+ );
+};
diff --git a/frontend/src/component/feature/FeatureToggleList/FeatureToggleListItem/FeatureToggleListItem.jsx b/frontend/src/component/feature/FeatureToggleList/FeatureToggleListItem/FeatureToggleListItem.jsx
index e157d7b9fe..e85a05da02 100644
--- a/frontend/src/component/feature/FeatureToggleList/FeatureToggleListItem/FeatureToggleListItem.jsx
+++ b/frontend/src/component/feature/FeatureToggleList/FeatureToggleListItem/FeatureToggleListItem.jsx
@@ -22,10 +22,6 @@ import PermissionIconButton from '../../../common/PermissionIconButton/Permissio
const FeatureToggleListItem = ({
feature,
- toggleFeature,
- settings,
- metricsLastHour = { yes: 0, no: 0, isFallback: true },
- metricsLastMinute = { yes: 0, no: 0, isFallback: true },
revive,
hasAccess,
flags = {},
@@ -164,10 +160,6 @@ const FeatureToggleListItem = ({
FeatureToggleListItem.propTypes = {
feature: PropTypes.object,
- toggleFeature: PropTypes.func,
- settings: PropTypes.object,
- metricsLastHour: PropTypes.object,
- metricsLastMinute: PropTypes.object,
revive: PropTypes.func,
hasAccess: PropTypes.func.isRequired,
flags: PropTypes.object,
diff --git a/frontend/src/component/feature/FeatureToggleList/FeatureToggleListItem/FeatureToggleListItemChip/FeatureToggleListItemChip.jsx b/frontend/src/component/feature/FeatureToggleList/FeatureToggleListItem/FeatureToggleListItemChip/FeatureToggleListItemChip.jsx
deleted file mode 100644
index 819f62627c..0000000000
--- a/frontend/src/component/feature/FeatureToggleList/FeatureToggleListItem/FeatureToggleListItemChip/FeatureToggleListItemChip.jsx
+++ /dev/null
@@ -1,26 +0,0 @@
-import React, { memo } from 'react';
-import { Chip } from '@material-ui/core';
-import PropTypes from 'prop-types';
-
-import { useStyles } from './styles';
-
-const FeatureToggleListItemChip = ({ type, types, onClick }) => {
- const styles = useStyles();
-
- const typeObject = types.find(o => o.id === type) || {
- id: type,
- name: type,
- };
-
- return (
-
- );
-};
-
-FeatureToggleListItemChip.propTypes = {
- type: PropTypes.string.isRequired,
- types: PropTypes.array,
- onClick: PropTypes.func,
-};
-
-export default memo(FeatureToggleListItemChip);
diff --git a/frontend/src/component/feature/FeatureToggleList/FeatureToggleListItem/FeatureToggleListItemChip/index.jsx b/frontend/src/component/feature/FeatureToggleList/FeatureToggleListItem/FeatureToggleListItemChip/index.jsx
deleted file mode 100644
index a148ec6e07..0000000000
--- a/frontend/src/component/feature/FeatureToggleList/FeatureToggleListItem/FeatureToggleListItemChip/index.jsx
+++ /dev/null
@@ -1,10 +0,0 @@
-import { connect } from 'react-redux';
-import Component from './FeatureToggleListItemChip';
-
-const mapStateToProps = state => ({
- types: state.featureTypes.toJS(),
-});
-
-const FeatureType = connect(mapStateToProps)(Component);
-
-export default FeatureType;
diff --git a/frontend/src/component/feature/FeatureToggleList/FeatureToggleListItem/FeatureToggleListItemChip/styles.js b/frontend/src/component/feature/FeatureToggleList/FeatureToggleListItem/FeatureToggleListItemChip/styles.js
deleted file mode 100644
index 1ca8703e8e..0000000000
--- a/frontend/src/component/feature/FeatureToggleList/FeatureToggleListItem/FeatureToggleListItemChip/styles.js
+++ /dev/null
@@ -1,10 +0,0 @@
-import { makeStyles } from '@material-ui/styles';
-
-export const useStyles = makeStyles(theme => ({
- typeChip: {
- margin: '0 8px',
- background: 'transparent',
- border: `1px solid ${theme.palette.primary.main}`,
- color: theme.palette.primary.main,
- },
-}));
diff --git a/frontend/src/component/feature/FeatureToggleList/__tests__/__snapshots__/list-component-test.jsx.snap b/frontend/src/component/feature/FeatureToggleList/__tests__/__snapshots__/list-component-test.jsx.snap
index 9a504742d3..36bd2043b0 100644
--- a/frontend/src/component/feature/FeatureToggleList/__tests__/__snapshots__/list-component-test.jsx.snap
+++ b/frontend/src/component/feature/FeatureToggleList/__tests__/__snapshots__/list-component-test.jsx.snap
@@ -117,7 +117,7 @@ exports[`renders correctly with one feature 1`] = `
- By name
+ By Name
@@ -185,12 +185,6 @@ exports[`renders correctly with one feature 1`] = `
}
flags={Object {}}
hasAccess={[Function]}
- settings={
- Object {
- "sort": "name",
- }
- }
- toggleFeature={[MockFunction]}
/>
@@ -315,7 +309,7 @@ exports[`renders correctly with one feature without permissions 1`] = `
- By name
+ By Name
@@ -386,12 +380,6 @@ exports[`renders correctly with one feature without permissions 1`] = `
}
flags={Object {}}
hasAccess={[Function]}
- settings={
- Object {
- "sort": "name",
- }
- }
- toggleFeature={[MockFunction]}
/>
diff --git a/frontend/src/component/feature/FeatureToggleList/__tests__/feature-list-item-component-test.jsx b/frontend/src/component/feature/FeatureToggleList/__tests__/feature-list-item-component-test.jsx
index a9325a9d36..e3af2247ca 100644
--- a/frontend/src/component/feature/FeatureToggleList/__tests__/feature-list-item-component-test.jsx
+++ b/frontend/src/component/feature/FeatureToggleList/__tests__/feature-list-item-component-test.jsx
@@ -7,8 +7,6 @@ import renderer from 'react-test-renderer';
import theme from '../../../../themes/main-theme';
-jest.mock('../FeatureToggleListItem/FeatureToggleListItemChip');
-
test('renders correctly with one feature', () => {
const feature = {
name: 'Another',
@@ -26,18 +24,12 @@ test('renders correctly with one feature', () => {
],
createdAt: '2018-02-04T20:27:52.127Z',
};
- const featureMetrics = { lastHour: {}, lastMinute: {}, seenApps: {} };
- const settings = { sort: 'name' };
const tree = renderer.create(