Skip to content

Commit 644449e

Browse files
authored
Merge pull request RedHatInsights#265 from aferd/RHCLOUD-45776
feat(helppanel): release search in stage preview and set as default sub-tab
2 parents 5c40ca6 + 6d68be3 commit 644449e

3 files changed

Lines changed: 46 additions & 19 deletions

File tree

cypress/component/HelpPanel.cy.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ describe('HelpPanel', () => {
9494

9595
cy.contains('Help').should('be.visible');
9696
cy.contains('Find help').should('be.visible');
97-
// Should default to Learn tab
98-
cy.contains(getMessageText('learnPanelDescription'), { timeout: 10000 }).should('be.visible');
97+
// Should default to Search tab when search flag is enabled
98+
cy.contains(getMessageText('searchPanelRecentSearch'), { timeout: 10000 }).should('be.visible');
9999
})
100100

101101
it('should not display sub tabs hidden by FF', () => {
@@ -279,8 +279,8 @@ describe('HelpPanel', () => {
279279
cy.get('.pf-v6-c-tabs__item').should('have.length', 2) // Back to VA + Find help tabs
280280
});
281281

282-
// Should show Learn panel content after closing the extra tab
283-
cy.contains(getMessageText('learnPanelDescription')).should('be.visible');
282+
// Find help defaults to Search when search flag is enabled; expect Search panel content
283+
cy.contains(getMessageText('searchPanelRecentSearch')).should('be.visible');
284284
})
285285

286286
it('should change tab title when switching sub-tabs', () => {

src/components/HelpPanel/HelpPanelCustomTabs.tsx

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,12 @@ const useTabs = (apiStoreMock: ReturnType<typeof createTabsStore>) => {
184184

185185
useEffect(() => {
186186
const unsubscribe = subscribe(dispatch);
187+
// Sync state from current store (needed when store instance changed, e.g. flags)
188+
dispatch();
187189
return () => {
188190
unsubscribe();
189191
};
190-
}, []);
192+
}, [apiStoreMock]);
191193

192194
return {
193195
tabs,
@@ -253,17 +255,30 @@ const HelpPanelCustomTabs = React.forwardRef<HelpPanelCustomTabsRef>(
253255
const intl = useIntl();
254256
const chrome = useChrome();
255257
const vaFlag = useFlag('platform.chrome.help-panel_chatbot');
258+
const searchFlag = useFlag('platform.chrome.help-panel_search');
256259

257260
const baseTabs = useMemo(() => createBaseTabs(vaFlag), [vaFlag]);
258-
const apiStoreMock = useMemo(() => createTabsStore(baseTabs), [baseTabs]);
259-
260-
// Find the Learn tab index (it might be 0 or 1 depending on VA flag)
261-
const learnTabIndex = baseTabs.findIndex(
262-
(tab) => tab.tabType === TabType.learn
261+
// Initialize store with find-help tab already having the correct sub-tab (Search when flag on, else Learn)
262+
// so content is correct on first paint and tests don't depend on a follow-up effect.
263+
const initialTabs = useMemo(
264+
() =>
265+
baseTabs.map((tab) =>
266+
tab.id === 'find-help' && searchFlag
267+
? { ...tab, tabType: TabType.search }
268+
: tab
269+
),
270+
[baseTabs, searchFlag]
271+
);
272+
const apiStoreMock = useMemo(
273+
() => createTabsStore(initialTabs),
274+
[initialTabs]
263275
);
264-
const [activeTab, setActiveTab] = useState<TabDefinition>(
265-
baseTabs[learnTabIndex]
266-
); // Default to 'Find help' tab (Learn)
276+
277+
// Default to 'Find help' tab; default sub-tab is Search when search flag is enabled, otherwise Learn
278+
const defaultFindHelpTab =
279+
initialTabs.find((t) => t.id === 'find-help') ?? initialTabs[0];
280+
const [activeTab, setActiveTab] =
281+
useState<TabDefinition>(defaultFindHelpTab);
267282

268283
const [newActionTitle, setNewActionTitle] = useState<string | undefined>(
269284
undefined
@@ -524,13 +539,20 @@ const HelpPanelCustomTabs = React.forwardRef<HelpPanelCustomTabsRef>(
524539
!activeTab.closeable &&
525540
!baseTabs.find((tab) => tab.id === activeTab.id)
526541
) {
527-
// Current active tab is no longer available, default to Learn tab
528-
const learnTab = baseTabs.find((tab) => tab.tabType === TabType.learn);
529-
if (learnTab) {
530-
setActiveTab(learnTab);
542+
// Current active tab is no longer available, default to Search tab when available, otherwise Learn tab
543+
const findHelpTabFallback = baseTabs.find(
544+
(tab) => tab.tabType === TabType.learn
545+
);
546+
if (findHelpTabFallback) {
547+
const fallbackTab = {
548+
...findHelpTabFallback,
549+
tabType: searchFlag ? TabType.search : TabType.learn,
550+
};
551+
updateTab(fallbackTab);
552+
setActiveTab(fallbackTab);
531553
}
532554
}
533-
}, [baseTabs, activeTab.id, activeTab.closeable]);
555+
}, [baseTabs, activeTab.id, activeTab.closeable, searchFlag, updateTab]);
534556

535557
useEffect(() => {
536558
// Ensure the Add tab button has a stable OUIA id

src/components/HelpPanel/HelpPanelTabs/SearchPanel/SearchPanel.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,9 +380,14 @@ const SearchPanel = ({
380380
});
381381
};
382382

383-
// Load quickstarts data once on mount
383+
// Load quickstarts data once on mount (skip when chrome auth is unavailable, e.g. in tests)
384384
useEffect(() => {
385385
let cancelled = false;
386+
if (!chrome?.auth?.getUser) {
387+
return () => {
388+
cancelled = true;
389+
};
390+
}
386391
fetchAllData(chrome.auth.getUser, {})
387392
.then(([, quickStarts]) => {
388393
if (!cancelled) {

0 commit comments

Comments
 (0)