Skip to content

Commit

Permalink
Merge pull request #3683 from dlabrecq/unleash
Browse files Browse the repository at this point in the history
Unleash's UserIDs strategy should use an account IDs
  • Loading branch information
dlabrecq authored Mar 5, 2024
2 parents 87b4bcf + d1c66ea commit ee125c5
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 59 deletions.
63 changes: 13 additions & 50 deletions src/components/featureFlags/featureFlags.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useChrome } from '@redhat-cloud-services/frontend-components/useChrome';
import { useUnleashClient, useUnleashContext } from '@unleash/proxy-client-react';
import { useLayoutEffect, useRef } from 'react';
import { useUnleashClient } from '@unleash/proxy-client-react';
import { useLayoutEffect } from 'react';
import { useDispatch } from 'react-redux';
import { featureFlagsActions } from 'store/featureFlags';

Expand All @@ -18,59 +18,22 @@ export const enum FeatureToggle {

// The FeatureFlags component saves feature flags in store for places where Unleash hooks not available
const useFeatureFlags = () => {
const updateContext = useUnleashContext();
const client = useUnleashClient();
const dispatch = useDispatch();
const { auth, isBeta } = useChrome();

const fetchUser = callback => {
auth.getUser().then(user => {
callback((user as any).identity.account_number);
});
};

const isMounted = useRef(false);
useLayoutEffect(() => {
isMounted.current = true;
return () => {
isMounted.current = false;
};
}, []);

// Update everytime or flags may be false
useLayoutEffect(() => {
fetchUser(userId => {
if (isMounted.current) {
updateContext({
userId,
});
}
});
});
const { isBeta } = useChrome();

useLayoutEffect(() => {
// Wait for the new flags to pull in from the different context
const fetchFlags = async userId => {
await updateContext({ userId }).then(() => {
dispatch(
featureFlagsActions.setFeatureFlags({
isClusterInfoFeatureEnabled: client.isEnabled(FeatureToggle.clusterInfo),
isExportsFeatureEnabled: client.isEnabled(FeatureToggle.exports),
isFinsightsFeatureEnabled: client.isEnabled(FeatureToggle.finsights),
isIbmFeatureEnabled: client.isEnabled(FeatureToggle.ibm),
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),
})
);
});
// Workaround for code that doesn't use hooks
const flags = {
isClusterInfoFeatureEnabled: client.isEnabled(FeatureToggle.clusterInfo),
isExportsFeatureEnabled: client.isEnabled(FeatureToggle.exports),
isFinsightsFeatureEnabled: client.isEnabled(FeatureToggle.finsights),
isIbmFeatureEnabled: client.isEnabled(FeatureToggle.ibm),
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),
};
fetchUser(userId => {
if (isMounted.current) {
fetchFlags(userId);
}
});
dispatch(featureFlagsActions.setFeatureFlags(flags));
});
};

Expand Down
2 changes: 1 addition & 1 deletion src/routes/components/charts/costChart/costChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class CostChartBase extends React.Component<CostChartProps, State> {
labelComponent: (
<ChartLegendTooltip
legendData={getLegendData(series, hiddenSeries, true)}
title={datum => intl.formatMessage(messages.chartDayOfTheMonth, { day: datum.x })}
title={(datum => intl.formatMessage(messages.chartDayOfTheMonth, { day: datum.x })) as any}
/>
),
} as any)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ class CostExplorerChartBase extends React.Component<CostExplorerChartProps, Stat
labelComponent: (
<ChartLegendTooltip
legendData={getLegendData(series, hiddenSeries, true)}
title={datum => intl.formatMessage(messages.chartDayOfTheMonth, { day: datum.x })}
title={(datum => intl.formatMessage(messages.chartDayOfTheMonth, { day: datum.x })) as any}
/>
),
} as any)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ class DailyCostChartBase extends React.Component<DailyCostChartProps, State> {
labelComponent: (
<ChartLegendTooltip
legendData={getLegendData(series, hiddenSeries, true)}
title={datum => intl.formatMessage(messages.chartDayOfTheMonth, { day: datum.x })}
title={(datum => intl.formatMessage(messages.chartDayOfTheMonth, { day: datum.x })) as any}
/>
),
} as any)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ class DailyTrendChartBase extends React.Component<DailyTrendChartProps, State> {
labelComponent: (
<ChartLegendTooltip
legendData={getLegendData(series, hiddenSeries, true)}
title={datum => intl.formatMessage(messages.chartDayOfTheMonth, { day: datum.x })}
title={(datum => intl.formatMessage(messages.chartDayOfTheMonth, { day: datum.x })) as any}
/>
),
} as any)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class HistoricalCostChartBase extends React.Component<HistoricalCostChartProps,
labelComponent: (
<ChartLegendTooltip
legendData={getLegendData(series, hiddenSeries, true)}
title={datum => intl.formatMessage(messages.chartDayOfTheMonth, { day: datum.x })}
title={(datum => intl.formatMessage(messages.chartDayOfTheMonth, { day: datum.x })) as any}
/>
),
} as any)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ class HistoricalTrendChartBase extends React.Component<HistoricalTrendChartProps
labelComponent: (
<ChartLegendTooltip
legendData={getLegendData(series, hiddenSeries, true)}
title={datum => intl.formatMessage(messages.chartDayOfTheMonth, { day: datum.x })}
title={(datum => intl.formatMessage(messages.chartDayOfTheMonth, { day: datum.x })) as any}
/>
),
} as any)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ class HistoricalUsageChartBase extends React.Component<HistoricalUsageChartProps
labelComponent: (
<ChartLegendTooltip
legendData={getLegendData(series, hiddenSeries, true)}
title={datum => intl.formatMessage(messages.chartDayOfTheMonth, { day: datum.x })}
title={(datum => intl.formatMessage(messages.chartDayOfTheMonth, { day: datum.x })) as any}
/>
),
} as any)
Expand Down
2 changes: 1 addition & 1 deletion src/routes/components/charts/trendChart/trendChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ class TrendChartBase extends React.Component<TrendChartProps, State> {
labelComponent: (
<ChartLegendTooltip
legendData={getLegendData(series, hiddenSeries, true)}
title={datum => intl.formatMessage(messages.chartDayOfTheMonth, { day: datum.x })}
title={(datum => intl.formatMessage(messages.chartDayOfTheMonth, { day: datum.x })) as any}
/>
),
} as any)
Expand Down
2 changes: 1 addition & 1 deletion src/routes/components/charts/usageChart/usageChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class UsageChartBase extends React.Component<UsageChartProps, State> {
labelComponent: (
<ChartLegendTooltip
legendData={getLegendData(series, hiddenSeries, true)}
title={datum => intl.formatMessage(messages.chartDayOfTheMonth, { day: datum.x })}
title={(datum => intl.formatMessage(messages.chartDayOfTheMonth, { day: datum.x })) as any}
/>
),
} as any)
Expand Down

0 comments on commit ee125c5

Please sign in to comment.