Skip to content

Commit 9688679

Browse files
committed
fix: open to correct ai mode based on ld flag
1 parent 23040a7 commit 9688679

File tree

4 files changed

+34
-9
lines changed

4 files changed

+34
-9
lines changed

packages/frontend/src/pages/AiBuilder/AiBuilderContext.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { datadogRum } from '@datadog/browser-rum'
77
import { useIsMobile } from '@opengovsg/design-system-react'
88

99
import PrimarySpinner from '@/components/PrimarySpinner'
10+
import { LaunchDarklyContext } from '@/contexts/LaunchDarkly'
1011
import { GET_APPS } from '@/graphql/queries/get-apps'
1112
import { getStepGroupTypeAndCaption, getStepStructure } from '@/helpers/toolbox'
1213

@@ -40,6 +41,8 @@ interface AIBuilderContextValue extends AIBuilderSharedProps {
4041
stepGroupCaption: string | null
4142
// DataDog RUM Session ID so we can associate the trace with the RUM
4243
ddSessionId: string
44+
// TODO(kevinkim-ogp): remove this once A/B test is complete
45+
aiBuilderType: string
4346
}
4447

4548
const AiBuilderContext = createContext<AIBuilderContextValue | undefined>(
@@ -69,6 +72,9 @@ export const AiBuilderContextProvider = ({
6972
}: AiBuilderContextProviderProps) => {
7073
const isMobile = useIsMobile()
7174
const ddSessionId = datadogRum.getInternalContext()?.session_id ?? ''
75+
// TODO(kevinkim-ogp): remove this once A/B test is complete
76+
const { getFlagValue } = useContext(LaunchDarklyContext)
77+
const aiBuilderType = getFlagValue('ai-builder-type', 'none')
7278

7379
const { data: getAppsData, loading: isLoadingAllApps } = useQuery(GET_APPS)
7480

@@ -123,6 +129,8 @@ export const AiBuilderContextProvider = ({
123129
stepGroupType,
124130
stepGroupCaption,
125131
ddSessionId,
132+
// TODO(kevinkim-ogp): remove this once A/B test is complete
133+
aiBuilderType,
126134
}}
127135
>
128136
{children}

packages/frontend/src/pages/AiBuilder/index.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ import {
1515
} from './AiBuilderContext'
1616

1717
function AiBuilderContent() {
18-
const { flowName, isFormMode } = useAiBuilderContext()
18+
const { aiBuilderType, flowName, isFormMode } = useAiBuilderContext()
19+
20+
// TODO(kevinkim-ogp): remove this once A/B test is complete
21+
if (aiBuilderType === 'ai-form') {
22+
return <InvalidEditorPage message="You do not have access to this." />
23+
}
1924

2025
return (
2126
<>

packages/frontend/src/pages/Flows/components/CreateFlowModal/index.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ interface CreateFlowModalProps {
2222

2323
export default function CreateFlowModal(props: CreateFlowModalProps) {
2424
const { onClose } = props
25-
const { createMode } = useCreateFlowContext()
25+
const { createMode, aiBuilderType } = useCreateFlowContext()
2626

2727
const navigate = useNavigate()
2828
const [createFlow, { loading }] = useMutation(CREATE_FLOW)
@@ -69,14 +69,18 @@ export default function CreateFlowModal(props: CreateFlowModalProps) {
6969
return
7070
}
7171

72-
if (createMode === 'ai-form') {
72+
// TODO(kevinkim-ogp): remove aiBuilderType once A/B test is complete
73+
if (
74+
createMode === 'ai-form' &&
75+
(aiBuilderType === 'ai-form' || aiBuilderType === 'all')
76+
) {
7377
// Store the flow name before switching to AI modal content
7478
setFlowName(trimmedFlowName)
7579
setShowAiModalContent(true)
7680
return
7781
}
7882

79-
if (createMode === 'ai-chat') {
83+
if (createMode === 'ai-chat' && aiBuilderType === 'ai-chat') {
8084
event.preventDefault()
8185
onClose()
8286
navigate(`${URLS.EDITOR}/ai`, {

packages/frontend/src/pages/Flows/components/EmptyFlows.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ import CreatePipeTile, { TileProps } from './CreatePipeTile'
99

1010
export default function EmptyFlows({ onCreate }: { onCreate: () => void }) {
1111
const navigate = useNavigate()
12-
const { canUseAiBuilder, setCreateMode, setSkipModeSelection } =
13-
useCreateFlowContext()
12+
const {
13+
aiBuilderType,
14+
canUseAiBuilder,
15+
setCreateMode,
16+
setSkipModeSelection,
17+
} = useCreateFlowContext()
1418

1519
const TILES = [
1620
canUseAiBuilder && {
@@ -19,9 +23,13 @@ export default function EmptyFlows({ onCreate }: { onCreate: () => void }) {
1923
'Describe your workflow and we&apos;ll create the steps for you',
2024
iconName: 'BiSolidMagicWand',
2125
onClick: () => {
22-
setCreateMode('ai-form')
23-
setSkipModeSelection(true)
24-
onCreate()
26+
if (aiBuilderType === 'ai-form' || aiBuilderType === 'all') {
27+
setCreateMode('ai-form')
28+
setSkipModeSelection(true)
29+
onCreate()
30+
} else {
31+
navigate(`${URLS.EDITOR}/ai`)
32+
}
2533
},
2634
},
2735
{

0 commit comments

Comments
 (0)