-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc823f6
commit 6609d07
Showing
9 changed files
with
3,443 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 45 additions & 12 deletions
57
app/jenkins-for-jira-ui/src/components/InProductHelpDrawer/InProductHelpAction.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,70 @@ | ||
import React from 'react'; | ||
import React, { useState } from 'react'; | ||
import { cx } from '@emotion/css'; | ||
import Button, { Appearance } from '@atlaskit/button'; | ||
import { KeyboardOrMouseEvent } from '@atlaskit/modal-dialog'; | ||
import { inProductHelpActionLink } from './InProductHelp.styles'; | ||
import { InProductHelpDrawer } from './InProductHelpDrawer'; | ||
import useAlgolia, { Hit } from '../../hooks/useAlgolia'; | ||
|
||
export enum InProductHelpActionType { | ||
HelpLink = 'link', | ||
HelpButton = 'button' | ||
} | ||
|
||
type InProductHelpActionProps = { | ||
onClick(e: KeyboardOrMouseEvent): void, | ||
handleOpenDrawer?(e: KeyboardOrMouseEvent): void, | ||
label: string, | ||
type: InProductHelpActionType, | ||
appearance: Appearance | ||
appearance: Appearance, | ||
indexName: string | ||
}; | ||
|
||
export const InProductHelpAction = ({ | ||
onClick, | ||
label, | ||
type, | ||
appearance | ||
appearance, | ||
indexName | ||
}: InProductHelpActionProps): JSX.Element => { | ||
const [isDrawerOpen, setIsDrawerOpen] = useState(false); | ||
const [hits, setHits] = useState<Hit[]>([]); | ||
|
||
const inProductHelpTypeClassName = | ||
type === InProductHelpActionType.HelpLink ? inProductHelpActionLink : ''; | ||
|
||
const openDrawer = () => { | ||
setIsDrawerOpen(true); | ||
}; | ||
|
||
const handleSearch = async () => { | ||
try { | ||
const { hits: searchResults } = await useAlgolia({ indexName }); | ||
setHits(searchResults); | ||
setIsDrawerOpen(true); | ||
} catch (error) { | ||
console.error('Error searching Algolia index:', error); | ||
} | ||
}; | ||
|
||
return ( | ||
<Button | ||
className={cx(inProductHelpTypeClassName)} | ||
onClick={onClick} | ||
appearance={appearance} | ||
> | ||
{label} | ||
</Button> | ||
<> | ||
<Button | ||
className={cx(inProductHelpTypeClassName)} | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
handleSearch().then(() => { | ||
openDrawer(); | ||
}); | ||
}} | ||
appearance={appearance} | ||
> | ||
{label} | ||
</Button> | ||
<InProductHelpDrawer | ||
isDrawerOpen={isDrawerOpen} | ||
setIsDrawerOpen={setIsDrawerOpen} | ||
hits={hits} | ||
indexName={indexName} | ||
/> | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.