Skip to content

Commit efa13e1

Browse files
Drop ?mode= URL override; add 'hybrid' as reserved mode value (W-24604411)
The ?mode= URL hack was a demo-only aid; .env + local restart cover the same demo flow without shipping an escape hatch into production. Keep the mode router but drive it off config.mode alone. Expand VALID_MODES to accept 'hybrid' so merchants can be onboarded against the final enum today. Shilpi lands the shim-side hybrid routing (PDP questions inline, discovery/comparison to main drawer) in a follow-up; 'hybrid' falls back to the inline UMD renderer until then.
1 parent 3dc80c6 commit efa13e1

3 files changed

Lines changed: 20 additions & 59 deletions

File tree

‎packages/template-retail-react-app/app/components/inline-agent-widget/index.jsx‎

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,10 @@ import useInlineAgentWidget, {
1313
} from '@salesforce/retail-react-app/app/hooks/use-inline-agent-widget'
1414
import InlineAgentRedirectShim from '@salesforce/retail-react-app/app/components/inline-agent-widget/InlineAgentRedirectShim'
1515

16-
const VALID_MODES = ['inline', 'agent-redirect']
17-
18-
// Demo override: ?mode=inline / ?mode=agent-redirect flips the behavior for
19-
// the current tab without a rebuild. Returns undefined on SSR and for any
20-
// value outside VALID_MODES so the server-rendered default always wins.
21-
const readUrlModeOverride = () => {
22-
if (typeof window === 'undefined') return undefined
23-
const override = new URLSearchParams(window.location.search).get('mode')
24-
return VALID_MODES.includes(override) ? override : undefined
25-
}
16+
const VALID_MODES = ['inline', 'agent-redirect', 'hybrid']
2617

2718
const InlineAgentWidget = ({config, pdpQuestions, productName, productId}) => {
28-
const effectiveMode = readUrlModeOverride() || config.mode
29-
const effectiveConfig = effectiveMode === config.mode ? config : {...config, mode: effectiveMode}
30-
const containerRef = useInlineAgentWidget(effectiveConfig, {pdpQuestions, productName})
19+
const containerRef = useInlineAgentWidget(config, {pdpQuestions, productName})
3120

3221
useEffect(() => {
3322
if (config.mode !== undefined && !VALID_MODES.includes(config.mode)) {
@@ -37,11 +26,11 @@ const InlineAgentWidget = ({config, pdpQuestions, productName, productId}) => {
3726
}
3827
}, [config.mode])
3928

40-
if (!isConfigured(effectiveConfig)) return null
29+
if (!isConfigured(config)) return null
4130

42-
// Agent-redirect mode: no local SCRT2 session. The shim hands the question
31+
// Agent-redirect: no local SCRT2 session — the shim hands the question
4332
// (pill or typed) off to the main Shopper Agent drawer.
44-
if (effectiveMode === 'agent-redirect') {
33+
if (config.mode === 'agent-redirect') {
4534
return (
4635
<InlineAgentRedirectShim
4736
pdpQuestions={pdpQuestions}
@@ -51,6 +40,8 @@ const InlineAgentWidget = ({config, pdpQuestions, productName, productId}) => {
5140
)
5241
}
5342

43+
// 'hybrid' is reserved — PDP-scoped questions stay inline, non-PDP routes
44+
// to the main drawer. Until that split lands, hybrid renders the inline UMD.
5445
return (
5546
<>
5647
<Helmet>
@@ -72,8 +63,10 @@ InlineAgentWidget.propTypes = {
7263
* `'inline'` (default) runs the UMD custom element with its own SCRT2 session.
7364
* `'agent-redirect'` renders a non-conversational shim that hands shopper
7465
* questions off to the main Shopper Agent drawer.
66+
* `'hybrid'` is reserved for future per-pill routing (PDP questions inline,
67+
* discovery/comparison to the main drawer); currently falls back to inline.
7568
*/
76-
mode: PropTypes.oneOf(['inline', 'agent-redirect'])
69+
mode: PropTypes.oneOf(['inline', 'agent-redirect', 'hybrid'])
7770
}),
7871
/**
7972
* Opener questions for the current product — rendered as tappable pills

‎packages/template-retail-react-app/app/components/inline-agent-widget/index.test.jsx‎

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {screen} from '@testing-library/react'
99
import {renderWithProviders} from '@salesforce/retail-react-app/app/utils/test-utils'
1010
import InlineAgentWidget from '@salesforce/retail-react-app/app/components/inline-agent-widget'
1111

12-
// The UMD-loading hook is irrelevant to the branch test — stub it.
1312
jest.mock('@salesforce/retail-react-app/app/hooks/use-inline-agent-widget', () => {
1413
const React = require('react')
1514
return {
@@ -30,7 +29,6 @@ const BASE_CONFIG = {
3029
describe('InlineAgentWidget', () => {
3130
test('renders nothing meaningful when config is not configured', () => {
3231
renderWithProviders(<InlineAgentWidget config={{enabled: false}} />)
33-
// isConfigured→false short-circuits to null; the shim and the UMD mount should not render.
3432
expect(screen.queryByTestId('inline-agent-redirect-shim')).not.toBeInTheDocument()
3533
})
3634

@@ -53,43 +51,11 @@ describe('InlineAgentWidget', () => {
5351
expect(screen.getByRole('button', {name: 'B?'})).toBeInTheDocument()
5452
})
5553

56-
test('?mode=agent-redirect in URL overrides inline config for the current tab', () => {
57-
const originalSearch = window.location.search
58-
window.history.replaceState({}, '', '/product/500400?mode=agent-redirect')
59-
try {
60-
renderWithProviders(
61-
<InlineAgentWidget config={{...BASE_CONFIG, mode: 'inline'}} />
62-
)
63-
expect(screen.getByTestId('inline-agent-redirect-shim')).toBeInTheDocument()
64-
} finally {
65-
window.history.replaceState({}, '', `/${originalSearch}`)
66-
}
67-
})
68-
69-
test('?mode=inline in URL overrides agent-redirect config for the current tab', () => {
70-
const originalSearch = window.location.search
71-
window.history.replaceState({}, '', '/product/500400?mode=inline')
72-
try {
73-
renderWithProviders(
74-
<InlineAgentWidget config={{...BASE_CONFIG, mode: 'agent-redirect'}} />
75-
)
76-
expect(screen.queryByTestId('inline-agent-redirect-shim')).not.toBeInTheDocument()
77-
} finally {
78-
window.history.replaceState({}, '', `/${originalSearch}`)
79-
}
80-
})
81-
82-
test('?mode=bogus is ignored and config.mode wins', () => {
83-
const originalSearch = window.location.search
84-
window.history.replaceState({}, '', '/product/500400?mode=bogus')
85-
try {
86-
renderWithProviders(
87-
<InlineAgentWidget config={{...BASE_CONFIG, mode: 'agent-redirect'}} />
88-
)
89-
expect(screen.getByTestId('inline-agent-redirect-shim')).toBeInTheDocument()
90-
} finally {
91-
window.history.replaceState({}, '', `/${originalSearch}`)
92-
}
54+
test('mode === "hybrid" falls back to the inline UMD (reserved — no shim yet)', () => {
55+
renderWithProviders(
56+
<InlineAgentWidget config={{...BASE_CONFIG, mode: 'hybrid'}} />
57+
)
58+
expect(screen.queryByTestId('inline-agent-redirect-shim')).not.toBeInTheDocument()
9359
})
9460

9561
test('warns in the console when config.mode is an unknown value', () => {

‎packages/template-retail-react-app/config/default.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,12 @@ module.exports = {
255255
placeholder: '',
256256
persistSession: true,
257257
enableLogging: false,
258-
// 'inline' renders the UMD custom element with its own SCRT2 session.
258+
// 'inline' (default) renders the UMD custom element with its own SCRT2 session.
259259
// 'agent-redirect' renders a non-conversational shim that hands shopper
260-
// questions off to the main Shopper Agent drawer. Merchants override via
261-
// EMBEDDED_AGENT_COMMERCE_SETTINGS JSON on MRT without a code change.
260+
// questions off to the main Shopper Agent drawer. 'hybrid' is reserved —
261+
// PDP-scoped questions stay inline, non-PDP routes to the main drawer;
262+
// currently falls back to inline until the per-pill routing lands.
263+
// Override via EMBEDDED_AGENT_COMMERCE_SETTINGS JSON on MRT.
262264
mode: 'inline',
263265
...(parseSettings(process.env.EMBEDDED_AGENT_COMMERCE_SETTINGS) || {})
264266
},

0 commit comments

Comments
 (0)