Skip to content

Commit

Permalink
Add Unleash flag for tag mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
dlabrecq committed Feb 21, 2024
1 parent b9cd0cb commit 6a95877
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/components/featureFlags/featureFlags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import { featureFlagsActions } from 'store/featureFlags';

// eslint-disable-next-line no-shadow
export const enum FeatureToggle {
clusterInfo = 'cost-management.ui.cluster-info', // https://issues.redhat.com/browse/COST-4559
clusterInfo = 'cost-management.ui.cluster.info', // https://issues.redhat.com/browse/COST-4559
exports = 'cost-management.ui.exports', // Async exports https://issues.redhat.com/browse/COST-2223
finsights = 'cost-management.ui.finsights', // RHEL support for FINsights https://issues.redhat.com/browse/COST-3306
ibm = 'cost-management.ui.ibm', // IBM https://issues.redhat.com/browse/COST-935
ros = 'cost-management.ui.ros', // ROS support https://issues.redhat.com/browse/COST-3477
rosBeta = 'cost-management.ui.ros-beta', // ROS support https://issues.redhat.com/browse/COST-3477
settingsPlatform = 'cost-management.ui.settings.platform', // Platform projects https://issues.redhat.com/browse/COST-3818
tagMapping = 'cost-management.ui.tag.mapping', // https://issues.redhat.com/browse/COST-3824
}

// The FeatureFlags component saves feature flags in store for places where Unleash hooks not available
Expand Down Expand Up @@ -60,6 +61,7 @@ const useFeatureFlags = () => {
isRosFeatureEnabled:
client.isEnabled(FeatureToggle.ros) || (client.isEnabled(FeatureToggle.rosBeta) && isBeta()), // Need to check beta in prod
isSettingsPlatformFeatureEnabled: client.isEnabled(FeatureToggle.settingsPlatform),
isTagMappingFeatureEnabled: client.isEnabled(FeatureToggle.tagMapping),
})
);
});
Expand Down
8 changes: 7 additions & 1 deletion src/routes/settings/tagLabels/tagLabels.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { NotAvailable } from 'routes/components/page/notAvailable';
import * as queryUtils from 'routes/utils/query';
import type { RootState } from 'store';
import { FetchStatus } from 'store/common';
import { featureFlagsSelectors } from 'store/featureFlags';
import { settingsActions, settingsSelectors } from 'store/settings';
import { useStateCallback } from 'utils/hooks';

Expand All @@ -31,6 +32,7 @@ export interface TagLabelsMapProps {
}

export interface TagLabelsStateProps {
isTagMappingFeatureEnabled?: boolean;
settings?: Settings;
settingsError?: AxiosError;
settingsStatus?: FetchStatus;
Expand All @@ -54,7 +56,7 @@ const TagLabels: React.FC<TagLabelsProps> = ({ canWrite }) => {
const dispatch: ThunkDispatch<RootState, any, AnyAction> = useDispatch();
const intl = useIntl();

const { settings, settingsError, settingsStatus } = useMapToProps({ query });
const { isTagMappingFeatureEnabled, settings, settingsError, settingsStatus } = useMapToProps({ query });

const getTags = () => {
if (settings) {
Expand Down Expand Up @@ -239,6 +241,7 @@ const TagLabels: React.FC<TagLabelsProps> = ({ canWrite }) => {
<>
{getTable()}
<div style={styles.pagination}>{getPagination(isDisabled, true)}</div>
{isTagMappingFeatureEnabled && <span>TEST</span>}
</>
)}
</PageSection>
Expand Down Expand Up @@ -285,6 +288,9 @@ const useMapToProps = ({ query }: TagLabelsMapProps): TagLabelsStateProps => {
}, [query, settingsUpdateDisableStatus, settingsUpdateEnableStatus]);

return {
isTagMappingFeatureEnabled: useSelector((state: RootState) =>
featureFlagsSelectors.selectIsTagMappingFeatureEnabled(state)
),
settings,
settingsError,
settingsStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ exports[`default state 1`] = `
"isIbmFeatureEnabled": false,
"isRosFeatureEnabled": false,
"isSettingsPlatformFeatureEnabled": false,
"isTagMappingFeatureEnabled": false,
}
`;
1 change: 1 addition & 0 deletions src/store/featureFlags/featureFlagsActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface FeatureFlagsActionMeta {
isIbmFeatureEnabled?: boolean;
isRosFeatureEnabled?: boolean;
isSettingsPlatformFeatureEnabled?: boolean;
isTagMappingFeatureEnabled?: boolean;
}

export const setFeatureFlags = createAction('feature/init_feature_flags')<FeatureFlagsActionMeta>();
Expand Down
3 changes: 3 additions & 0 deletions src/store/featureFlags/featureFlagsReducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type FeatureFlagsState = Readonly<{
isIbmFeatureEnabled: boolean;
isRosFeatureEnabled: boolean;
isSettingsPlatformFeatureEnabled: boolean;
isTagMappingFeatureEnabled: boolean;
}>;

export const defaultState: FeatureFlagsState = {
Expand All @@ -24,6 +25,7 @@ export const defaultState: FeatureFlagsState = {
isIbmFeatureEnabled: false,
isRosFeatureEnabled: false,
isSettingsPlatformFeatureEnabled: false,
isTagMappingFeatureEnabled: false,
};

export const stateKey = 'featureFlags';
Expand All @@ -40,6 +42,7 @@ export function featureFlagsReducer(state = defaultState, action: FeatureFlagsAc
isIbmFeatureEnabled: action.payload.isIbmFeatureEnabled,
isRosFeatureEnabled: action.payload.isRosFeatureEnabled,
isSettingsPlatformFeatureEnabled: action.payload.isSettingsPlatformFeatureEnabled,
isTagMappingFeatureEnabled: action.payload.isTagMappingFeatureEnabled,
};

default:
Expand Down
2 changes: 2 additions & 0 deletions src/store/featureFlags/featureFlagsSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ export const selectIsIbmFeatureEnabled = (state: RootState) => selectFeatureFlag
export const selectIsRosFeatureEnabled = (state: RootState) => selectFeatureFlagsState(state).isRosFeatureEnabled;
export const selectIsSettingsPlatformFeatureEnabled = (state: RootState) =>
selectFeatureFlagsState(state).isSettingsPlatformFeatureEnabled;
export const selectIsTagMappingFeatureEnabled = (state: RootState) =>
selectFeatureFlagsState(state).isTagMappingFeatureEnabled;

0 comments on commit 6a95877

Please sign in to comment.