Skip to content

Commit

Permalink
feat: A/B test search feedback variants (#6085)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjaanus authored Jan 31, 2024
1 parent 79e86e1 commit bb02ffd
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useCallback, useEffect, useMemo, useState, VFC } from 'react';
import {
Box,
Button,
IconButton,
Link,
Tooltip,
Expand Down Expand Up @@ -69,7 +70,7 @@ const feedbackCategory = 'search';

export const FeatureToggleListTable: VFC = () => {
const theme = useTheme();
const { openFeedback } = useFeedback(feedbackCategory, 'automatic');
const featureSearchFeedback = useUiFlag('featureSearchFeedback');
const { trackEvent } = usePlausibleTracker();
const { environments } = useEnvironments();
const enabledEnvironments = environments
Expand All @@ -81,7 +82,17 @@ export const FeatureToggleListTable: VFC = () => {

const { setToastApiError } = useToast();
const { uiConfig } = useUiConfig();
const featureSearchFeedback = useUiFlag('featureSearchFeedback');

const variant =
featureSearchFeedback !== false
? featureSearchFeedback?.name ?? ''
: '';

const { openFeedback } = useFeedback(
feedbackCategory,
'automatic',
variant,
);

const stateConfig = {
offset: withDefault(NumberParam, 0),
Expand Down Expand Up @@ -352,19 +363,64 @@ export const FeatureToggleListTable: VFC = () => {
<FeatureToggleListActions
onExportClick={() => setShowExportDialog(true)}
/>
<ConditionallyRender
condition={featureSearchFeedback}
show={
<Tooltip title='Provide feedback' arrow>
<IconButton
onClick={createFeedbackContext}
size='large'
>
<ReviewsOutlined />
</IconButton>
</Tooltip>
}
/>
{featureSearchFeedback !== false &&
featureSearchFeedback?.enabled && (
<>
<ConditionallyRender
condition={
variant === 'withoutText'
}
show={
<Tooltip
title='Provide feedback'
arrow
>
<IconButton
onClick={
createFeedbackContext
}
size='large'
>
<ReviewsOutlined />
</IconButton>
</Tooltip>
}
/>
<ConditionallyRender
condition={variant === 'withText'}
show={
<Button
startIcon={
<ReviewsOutlined />
}
onClick={
createFeedbackContext
}
>
Provide feedback
</Button>
}
/>{' '}
<ConditionallyRender
condition={
variant === 'withTextOutlined'
}
show={
<Button
startIcon={
<ReviewsOutlined />
}
onClick={
createFeedbackContext
}
variant='outlined'
>
Provide feedback
</Button>
}
/>
</>
)}
</>
}
>
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/component/feedbackNew/FeedbackContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { IFeedbackCategory } from 'hooks/useSubmittedFeedback';
export type FeedbackMode = 'automatic' | 'manual';
export interface IFeedbackContext {
feedbackData: FeedbackData | undefined;
openFeedback: (data: FeedbackData, mode: FeedbackMode) => void;
openFeedback: (
data: FeedbackData,
mode: FeedbackMode,
variant?: string,
) => void;
closeFeedback: () => void;
showFeedback: boolean;
setShowFeedback: (visible: boolean) => void;
Expand Down
7 changes: 6 additions & 1 deletion frontend/src/component/feedbackNew/FeedbackProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export const FeedbackProvider: FC = ({ children }) => {
const [feedbackMode, setFeedbackMode] = useState<
FeedbackMode | undefined
>();
const openFeedback = (data: FeedbackData, mode: FeedbackMode) => {
const openFeedback = (
data: FeedbackData,
mode: FeedbackMode,
variant: string = '',
) => {
setFeedbackData(data);
setShowFeedback(true);
setFeedbackMode(mode);
Expand All @@ -22,6 +26,7 @@ export const FeedbackProvider: FC = ({ children }) => {
props: {
eventType: `feedback opened - ${data.category}`,
category: data.category,
variant: variant,
},
});
};
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/component/feedbackNew/useFeedback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const useFeedbackContext = (): IFeedbackContext => {
export const useFeedback = (
feedbackCategory: IFeedbackCategory,
mode: FeedbackMode,
variant: string = '',
) => {
const context = useFeedbackContext();
const { hasSubmittedFeedback } = useUserSubmittedFeedback(feedbackCategory);
Expand All @@ -44,6 +45,7 @@ export const useFeedback = (
category: feedbackCategory,
},
mode,
variant,
);
},
};
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/interfaces/uiConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export type UiFlags = {
automatedActions?: boolean;
celebrateUnleash?: boolean;
increaseUnleashWidth?: boolean;
featureSearchFeedback?: boolean;
featureSearchFeedback?: Variant;
enableLicense?: boolean;
newStrategyConfigurationFeedback?: boolean;
extendedUsageMetricsUI?: boolean;
Expand Down
9 changes: 8 additions & 1 deletion src/lib/__snapshots__/create-config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ exports[`should create default config 1`] = `
"executiveDashboard": false,
"extendedUsageMetrics": false,
"extendedUsageMetricsUI": false,
"featureSearchFeedback": false,
"featureSearchFeedback": {
"enabled": true,
"name": "withText",
"payload": {
"type": "json",
"value": "",
},
},
"featureSearchFeedbackPosting": false,
"featuresExportImport": true,
"feedbackComments": {
Expand Down
17 changes: 13 additions & 4 deletions src/lib/types/experimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,19 @@ const flags: IFlags = {
process.env.UNLEASH_EXPERIMENTAL_INCREASE_UNLEASH_WIDTH,
false,
),
featureSearchFeedback: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_FEATURE_SEARCH_FEEDBACK,
false,
),
featureSearchFeedback: {
name: 'withText',
enabled: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_FEATURE_SEARCH_FEEDBACK,
true,
),
payload: {
type: PayloadType.JSON,
value:
process.env
.UNLEASH_EXPERIMENTAL_FEATURE_SEARCH_FEEDBACK_PAYLOAD ?? '',
},
},
featureSearchFeedbackPosting: parseEnvVarBoolean(
process.env.UNLEASH_EXPERIMENTAL_FEATURE_SEARCH_FEEDBACK_POSTING,
false,
Expand Down
1 change: 0 additions & 1 deletion src/server-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ process.nextTick(async () => {
stripHeadersOnAPI: true,
celebrateUnleash: true,
increaseUnleashWidth: true,
featureSearchFeedback: true,
newStrategyConfigurationFeedback: true,
extendedUsageMetricsUI: true,
executiveDashboard: true,
Expand Down

0 comments on commit bb02ffd

Please sign in to comment.