From c9c5e68283269672ad0a36c59d5627a87f717757 Mon Sep 17 00:00:00 2001 From: nick-delirium Date: Mon, 26 Jun 2023 16:47:33 +0200 Subject: [PATCH] fix(ui): re-add flag read view --- .../components/FFlags/FFlagItem/FFlagItem.tsx | 3 +- .../components/FFlags/FlagView/FlagView.tsx | 2 + .../components/FFlags/NewFFlag/Conditions.tsx | 63 +++-- .../shared/Filters/FilterItem/FilterItem.tsx | 233 +++++++++++------- .../shared/Filters/FilterList/FilterList.tsx | 3 + tracker/tracker/src/main/index.ts | 8 + .../tracker/src/main/modules/featureFlags.ts | 4 + 7 files changed, 197 insertions(+), 119 deletions(-) diff --git a/frontend/app/components/FFlags/FFlagItem/FFlagItem.tsx b/frontend/app/components/FFlags/FFlagItem/FFlagItem.tsx index 5e9b1a898..ef42aaef6 100644 --- a/frontend/app/components/FFlags/FFlagItem/FFlagItem.tsx +++ b/frontend/app/components/FFlags/FFlagItem/FFlagItem.tsx @@ -5,6 +5,7 @@ import { useStore } from 'App/mstore'; import { observer } from 'mobx-react-lite'; import { resentOrDate } from 'App/date'; import { toast } from 'react-toastify'; +import { fflagRead } from "App/routes"; function FFlagItem({ flag }: { flag: FeatureFlag }) { const { featureFlagsStore, userStore } = useStore(); @@ -32,7 +33,7 @@ function FFlagItem({ flag }: { flag: FeatureFlag }) { return (
- +
diff --git a/frontend/app/components/FFlags/FlagView/FlagView.tsx b/frontend/app/components/FFlags/FlagView/FlagView.tsx index 9a31ebae2..3a4e6413e 100644 --- a/frontend/app/components/FFlags/FlagView/FlagView.tsx +++ b/frontend/app/components/FFlags/FlagView/FlagView.tsx @@ -100,10 +100,12 @@ function FlagView({ siteId, fflagId }: { siteId: string; fflagId: string }) { +
))}
diff --git a/frontend/app/components/FFlags/NewFFlag/Conditions.tsx b/frontend/app/components/FFlags/NewFFlag/Conditions.tsx index 17fe36817..34c4ad93d 100644 --- a/frontend/app/components/FFlags/NewFFlag/Conditions.tsx +++ b/frontend/app/components/FFlags/NewFFlag/Conditions.tsx @@ -12,9 +12,10 @@ interface Props { conditions: Conditions; removeCondition: (ind: number) => void; index: number + readonly?: boolean; } -function RolloutCondition({ set, conditions, removeCondition, index }: Props) { +function RolloutCondition({ set, conditions, removeCondition, index, readonly }: Props) { const [forceRender, forceRerender] = React.useState(false); const onAddFilter = (filter = {}) => { conditions.filter.addFilter(filter); @@ -47,17 +48,16 @@ function RolloutCondition({ set, conditions, removeCondition, index }: Props) {
Condition
Set {set}
-
removeCondition(index)} - > - -
+ {readonly ? null : ( +
removeCondition(index)} + > + +
+ )}
-
+
0 ? 'p-2 border-b mb-2' : ''}> + {readonly && !conditions.filter?.filters?.length ? ( +
No conditions
+ ) : null}
- - - + {readonly ? null : ( + + + + )}
Rollout to - %
} - /> + {readonly ? ( +
{conditions.rolloutPercentage}%
+ ) : ( + %
} + /> + )} + of sessions
diff --git a/frontend/app/components/shared/Filters/FilterItem/FilterItem.tsx b/frontend/app/components/shared/Filters/FilterItem/FilterItem.tsx index efaee0b84..8d69725ca 100644 --- a/frontend/app/components/shared/Filters/FilterItem/FilterItem.tsx +++ b/frontend/app/components/shared/Filters/FilterItem/FilterItem.tsx @@ -2,112 +2,159 @@ import React from 'react'; import FilterOperator from '../FilterOperator'; import FilterSelection from '../FilterSelection'; import FilterValue from '../FilterValue'; -import { Button } from 'UI'; +import {Button} from 'UI'; import FilterSource from '../FilterSource'; -import { FilterKey, FilterType } from 'App/types/filter/filterType'; +import {FilterKey, FilterType} from 'App/types/filter/filterType'; import SubFilterItem from '../SubFilterItem'; +import {toJS} from "mobx"; interface Props { - filterIndex: number; - filter: any; // event/filter - onUpdate: (filter: any) => void; - onRemoveFilter: () => void; - isFilter?: boolean; - saveRequestPayloads?: boolean; - disableDelete?: boolean; - excludeFilterKeys?: Array; + filterIndex: number; + filter: any; // event/filter + onUpdate: (filter: any) => void; + onRemoveFilter: () => void; + isFilter?: boolean; + saveRequestPayloads?: boolean; + disableDelete?: boolean; + excludeFilterKeys?: Array; + readonly?: boolean; } + function FilterItem(props: Props) { - const { isFilter = false, filterIndex, filter, saveRequestPayloads, disableDelete = false, excludeFilterKeys = [] } = props; - const canShowValues = !(filter.operator === 'isAny' || filter.operator === 'onAny' || filter.operator === 'isUndefined'); - const isSubFilter = filter.type === FilterType.SUB_FILTERS; - const replaceFilter = (filter: any) => { - props.onUpdate({ - ...filter, - value: [''], - filters: filter.filters ? filter.filters.map((i: any) => ({ ...i, value: [''] })) : [], - }); - }; + const { + isFilter = false, + filterIndex, + filter, + saveRequestPayloads, + disableDelete = false, + excludeFilterKeys = [] + } = props; + const canShowValues = !(filter.operator === 'isAny' || filter.operator === 'onAny' || filter.operator === 'isUndefined'); + const isSubFilter = filter.type === FilterType.SUB_FILTERS; + const replaceFilter = (filter: any) => { + props.onUpdate({ + ...filter, + value: [''], + filters: filter.filters ? filter.filters.map((i: any) => ({...i, value: ['']})) : [], + }); + }; - const onOperatorChange = (e: any, { value }: any) => { - props.onUpdate({ ...filter, operator: value }); - }; + const onOperatorChange = (e: any, {value}: any) => { + props.onUpdate({...filter, operator: value}); + }; - const onSourceOperatorChange = (e: any, { value }: any) => { - props.onUpdate({ ...filter, sourceOperator: value }); - }; + const onSourceOperatorChange = (e: any, {value}: any) => { + props.onUpdate({...filter, sourceOperator: value}); + }; - const onUpdateSubFilter = (subFilter: any, subFilterIndex: any) => { - props.onUpdate({ - ...filter, - filters: filter.filters.map((i: any, index: any) => { - if (index === subFilterIndex) { - return subFilter; - } - return i; - }), - }); - }; + const onUpdateSubFilter = (subFilter: any, subFilterIndex: any) => { + props.onUpdate({ + ...filter, + filters: filter.filters.map((i: any, index: any) => { + if (index === subFilterIndex) { + return subFilter; + } + return i; + }), + }); + }; - return ( -
-
- {!isFilter && ( -
- {filterIndex + 1} -
+ console.log('FilterItem', toJS(filter)) + return ( +
+
+ {!isFilter && ( +
+ {filterIndex + 1} +
+ )} + + + {/* Filter with Source */} + {filter.hasSource && ( + <> + + + + )} + + {/* Filter values */} + {!isSubFilter && filter.operatorOptions && ( + <> + + {canShowValues && ( + <> + {props.readonly ? ( +
+ {filter.value.map((val: string) => { + return filter.options && filter.options.length + ? filter.options[filter.options.findIndex((i: any) => i.value === val)]?.label + : val + })} +
+ ) : ( + )} - + + )} + + )} - {/* Filter with Source */} - {filter.hasSource && ( - <> - - - - )} - - {/* Filter values */} - {!isSubFilter && filter.operatorOptions && ( - <> - - {canShowValues && } - - )} - - {/* filters */} - {isSubFilter && ( -
- {filter.filters - .filter((i: any) => (i.key !== FilterKey.FETCH_REQUEST_BODY && i.key !== FilterKey.FETCH_RESPONSE_BODY) || saveRequestPayloads) - .map((subFilter: any, subFilterIndex: any) => ( - onUpdateSubFilter(f, subFilterIndex)} - onRemoveFilter={props.onRemoveFilter} - /> - ))} -
- )} -
-
-
+ {/* filters */} + {isSubFilter && ( +
+ {filter.filters + .filter( + (i: any) => + (i.key !== FilterKey.FETCH_REQUEST_BODY && + i.key !== FilterKey.FETCH_RESPONSE_BODY) || + saveRequestPayloads + ) + .map((subFilter: any, subFilterIndex: any) => ( + onUpdateSubFilter(f, subFilterIndex)} + onRemoveFilter={props.onRemoveFilter} + /> + ))} +
+ )} +
+ {props.readonly ? null : +
+
- ); + } +
+ ); } export default FilterItem; diff --git a/frontend/app/components/shared/Filters/FilterList/FilterList.tsx b/frontend/app/components/shared/Filters/FilterList/FilterList.tsx index b9f0ffdd6..658df7625 100644 --- a/frontend/app/components/shared/Filters/FilterList/FilterList.tsx +++ b/frontend/app/components/shared/Filters/FilterList/FilterList.tsx @@ -13,6 +13,7 @@ interface Props { observeChanges?: () => void; saveRequestPayloads?: boolean; supportsEmpty?: boolean + readonly?: boolean; excludeFilterKeys?: Array } function FilterList(props: Props) { @@ -84,6 +85,7 @@ function FilterList(props: Props) { saveRequestPayloads={saveRequestPayloads} disableDelete={cannotDeleteFilter} excludeFilterKeys={excludeFilterKeys} + readonly={props.readonly} /> ) : null )} @@ -99,6 +101,7 @@ function FilterList(props: Props) { !filter.isEvent ? ( (fn: (app: App | null, options?: Options) => T): T { return fn(this.app, this.options) } diff --git a/tracker/tracker/src/main/modules/featureFlags.ts b/tracker/tracker/src/main/modules/featureFlags.ts index 8c40a022f..380265634 100644 --- a/tracker/tracker/src/main/modules/featureFlags.ts +++ b/tracker/tracker/src/main/modules/featureFlags.ts @@ -25,6 +25,10 @@ export default class FeatureFlags { } } + getFeatureFlag(flagName: string): IFeatureFlag | undefined { + return this.flags.find((flag) => flag.key === flagName) + } + isFlagEnabled(flagName: string): boolean { return this.flags.findIndex((flag) => flag.key === flagName) !== -1 }