Skip to content

Commit

Permalink
Merge pull request #304 from atlassian/issue/ARC-3020-update-iph-serv…
Browse files Browse the repository at this point in the history
…er-change

update IPH server change
  • Loading branch information
anshengxu authored May 29, 2024
2 parents 0eea563 + 677019f commit e432e4c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@ jest.mock('algoliasearch', () => {
{
id: '12323445345',
objectID: '12323445345',
title: 'Search Results',
title: 'Search Results 1',
body: '',
bodyText: ''
},
{
id: '22323445345',
objectID: '22323445345',
title: 'Search Results 2',
body: '',
bodyText: ''
}

]
}))
}))
Expand Down Expand Up @@ -188,9 +196,9 @@ describe('InProductHelpDrawer Suite', () => {
<InProductHelpDrawer
isDrawerOpen
setIsDrawerOpen={() => {}}
searchResults={[{
id: '1', title: 'Result 1', body: 'Body 1', bodyText: 'Body Text 1'
}]}
searchResults={[
{id: '1', title: 'Result 1', body: 'Body 1', bodyText: 'Body Text 1'},
{id: '2', title: 'Result 2', body: 'Body 2', bodyText: 'Body Text 2'}]}
isLoading={false}
searchQuery=""
setIsLoading={() => {}}
Expand All @@ -202,8 +210,8 @@ describe('InProductHelpDrawer Suite', () => {
);

await waitFor(() => {
expect(screen.getByText('Result 1')).toBeInTheDocument();
expect(screen.getByText('Body 1')).toBeInTheDocument();
expect(screen.getByText('Result 2')).toBeInTheDocument();
expect(screen.getByText('Body 2')).toBeInTheDocument();
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ const ALGOLIA_APP_ID = '8K6J5OJIQW';
const { ALGOLIA_API_KEY, ENVIRONMENT } = envVars;

enum AlgoliaEnvironmentIndicies {
Development = 'product_help_dev_copsi',
Staging = 'product_help_stg_copsi',
Production = 'product_help_prod_copsi'
Development = 'product_help_dev',
Staging = 'product_help_stg',
Production = 'product_help_prod'
}

const getIndexNameForEnvironment = (): string => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,18 +150,22 @@ export const InProductHelpDrawer = ({
};

const results = Array.isArray(searchResults) ? searchResults : searchResults.hits;

const {
tempDiv: tempDivBody
} = (!isLoading && !hasError && replaceAnchorsWithSpanElement(results[0]?.body)) as {
tempDiv: HTMLDivElement;
};

const {
tempDiv: tempDivBodyText
} = (!isLoading && !hasError && replaceAnchorsWithSpanElement(results[0]?.bodyText)) as {
tempDiv: HTMLDivElement;
};
let tempDivBody: HTMLDivElement | undefined;
let tempDivBodyText: HTMLDivElement | undefined;
if (results.length !== 2) {
setHasError(true);
} else {
setHasError(false);
const { tempDiv: tempDivB } = (!isLoading && !hasError && replaceAnchorsWithSpanElement(results[1]?.body)) as {
tempDiv: HTMLDivElement;
};
tempDivBody = tempDivB;
const { tempDiv: tempDivBT } = (
!isLoading && !hasError && replaceAnchorsWithSpanElement(results[1]?.bodyText)) as {
tempDiv: HTMLDivElement;
};
tempDivBodyText = tempDivBT;
}

const search = useCallback(async (searchId: string) => {
setIsLoading(true);
Expand Down Expand Up @@ -266,10 +270,10 @@ export const InProductHelpDrawer = ({
hasError
? <InProductHelpDrawerError onClick={() => search(searchQuery || innerSearchQuery)} />
: <div className={cx(inProductHelpDrawerContainer)}>
<h3 className={cx(inProductHelpDrawerTitle)}>{results[0]?.title}</h3>
<h3 className={cx(inProductHelpDrawerTitle)}>{results[1]?.title}</h3>
<div
dangerouslySetInnerHTML={{
__html: tempDivBody.innerHTML || tempDivBodyText.innerHTML || ''
__html: tempDivBody?.innerHTML || tempDivBodyText?.innerHTML || ''
}}
/>
</div>
Expand Down

0 comments on commit e432e4c

Please sign in to comment.