-
Notifications
You must be signed in to change notification settings - Fork 8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…96458) * Revert change to wrap setContext in useEffect A recommendation was made to wrap the setContext call in a previous PR, which lets the app know if the context is org or account, in a useEffect call, for potential performance reasons. Unfortunately, this causes the lifecycle to change so that changing routes from org to personal dashboard does not register the change in time. This commit changes it back to a working state. * Add constants and routes for Account nav * Add AccountHeader component * Add header to layout and fix height The main layout stylesheet, https://github.com/elastic/kibana/blob/master/x-pack/plugins/enterprise_search/public/applications/shared/layout/layout.scss gives a static height that includes the main Kibana navigation. The height with the account nav only is added to the existing privateSourcesLayout css class * Refactor test Co-authored-by: Scotty Bollinger <scotty.bollinger@elastic.co>
- Loading branch information
1 parent
9ed462a
commit eb5eff7
Showing
10 changed files
with
235 additions
and
21 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...ic/applications/workplace_search/components/layout/account_header/account_header.test.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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { setMockValues } from '../../../../__mocks__'; | ||
|
||
import React from 'react'; | ||
|
||
import { shallow } from 'enzyme'; | ||
|
||
import { EuiHeader, EuiPopover } from '@elastic/eui'; | ||
|
||
import { AccountHeader } from './'; | ||
|
||
describe('AccountHeader', () => { | ||
const mockValues = { | ||
account: { | ||
isAdmin: true, | ||
}, | ||
}; | ||
|
||
beforeEach(() => { | ||
setMockValues({ ...mockValues }); | ||
}); | ||
|
||
it('renders', () => { | ||
const wrapper = shallow(<AccountHeader />); | ||
|
||
expect(wrapper.find(EuiHeader)).toHaveLength(1); | ||
}); | ||
|
||
describe('accountSubNav', () => { | ||
it('handles popover trigger click', () => { | ||
const wrapper = shallow(<AccountHeader />); | ||
const popover = wrapper.find(EuiPopover); | ||
const onClick = popover.dive().find('[data-test-subj="AccountButton"]').prop('onClick'); | ||
onClick!({} as any); | ||
|
||
expect(onClick).toBeDefined(); | ||
}); | ||
|
||
it('handles close popover', () => { | ||
const wrapper = shallow(<AccountHeader />); | ||
const popover = wrapper.find(EuiPopover); | ||
popover.prop('closePopover')!(); | ||
|
||
expect(popover.prop('isOpen')).toEqual(false); | ||
}); | ||
}); | ||
}); |
107 changes: 107 additions & 0 deletions
107
.../public/applications/workplace_search/components/layout/account_header/account_header.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 |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { useState } from 'react'; | ||
|
||
import { useValues } from 'kea'; | ||
|
||
import { | ||
EuiButton, | ||
EuiButtonEmpty, | ||
EuiHeader, | ||
EuiHeaderLogo, | ||
EuiHeaderLinks, | ||
EuiHeaderSection, | ||
EuiHeaderSectionItem, | ||
EuiText, | ||
EuiContextMenuPanel, | ||
EuiContextMenuItem, | ||
EuiPopover, | ||
} from '@elastic/eui'; | ||
|
||
import { getWorkplaceSearchUrl } from '../../../../shared/enterprise_search_url'; | ||
import { EuiButtonEmptyTo } from '../../../../shared/react_router_helpers'; | ||
import { AppLogic } from '../../../app_logic'; | ||
import { WORKPLACE_SEARCH_TITLE, ACCOUNT_NAV } from '../../../constants'; | ||
import { | ||
ALPHA_PATH, | ||
PERSONAL_SOURCES_PATH, | ||
LOGOUT_ROUTE, | ||
KIBANA_ACCOUNT_ROUTE, | ||
} from '../../../routes'; | ||
|
||
export const AccountHeader: React.FC = () => { | ||
const [isPopoverOpen, setPopover] = useState(false); | ||
const onButtonClick = () => { | ||
setPopover(!isPopoverOpen); | ||
}; | ||
const closePopover = () => { | ||
setPopover(false); | ||
}; | ||
|
||
const { | ||
account: { isAdmin }, | ||
} = useValues(AppLogic); | ||
|
||
const accountNavItems = [ | ||
<EuiContextMenuItem key="accountSettings"> | ||
{/* TODO: Once auth is completed, we need to have non-admins redirect to the self-hosted form */} | ||
<EuiButtonEmpty href={KIBANA_ACCOUNT_ROUTE}>{ACCOUNT_NAV.SETTINGS}</EuiButtonEmpty> | ||
</EuiContextMenuItem>, | ||
<EuiContextMenuItem key="logout"> | ||
<EuiButtonEmpty href={LOGOUT_ROUTE}>{ACCOUNT_NAV.LOGOUT}</EuiButtonEmpty> | ||
</EuiContextMenuItem>, | ||
]; | ||
|
||
const accountButton = ( | ||
<EuiButtonEmpty | ||
size="s" | ||
data-test-subj="AccountButton" | ||
iconType="arrowDown" | ||
iconSide="right" | ||
onClick={onButtonClick} | ||
> | ||
{ACCOUNT_NAV.ACCOUNT} | ||
</EuiButtonEmpty> | ||
); | ||
|
||
return ( | ||
<EuiHeader> | ||
<EuiHeaderSection grow={false}> | ||
<EuiHeaderSectionItem> | ||
<EuiHeaderLogo iconType="logoWorkplaceSearch" /> | ||
<EuiText>{WORKPLACE_SEARCH_TITLE}</EuiText> | ||
</EuiHeaderSectionItem> | ||
<EuiHeaderSectionItem> | ||
<EuiHeaderLinks> | ||
<EuiButtonEmptyTo to={PERSONAL_SOURCES_PATH}>{ACCOUNT_NAV.SOURCES}</EuiButtonEmptyTo> | ||
</EuiHeaderLinks> | ||
</EuiHeaderSectionItem> | ||
</EuiHeaderSection> | ||
<EuiHeaderSection grow={false} side="right"> | ||
<EuiHeaderLinks> | ||
{isAdmin && ( | ||
<EuiButtonEmptyTo to={ALPHA_PATH}>{ACCOUNT_NAV.ORG_DASHBOARD}</EuiButtonEmptyTo> | ||
)} | ||
<EuiPopover | ||
id="accountSubNav" | ||
button={accountButton} | ||
isOpen={isPopoverOpen} | ||
closePopover={closePopover} | ||
panelPaddingSize="none" | ||
anchorPosition="downLeft" | ||
> | ||
<EuiContextMenuPanel size="s" items={accountNavItems} /> | ||
</EuiPopover> | ||
<EuiButton href={getWorkplaceSearchUrl('/search')} iconType="search"> | ||
{ACCOUNT_NAV.SEARCH} | ||
</EuiButton> | ||
</EuiHeaderLinks> | ||
</EuiHeaderSection> | ||
</EuiHeader> | ||
); | ||
}; |
8 changes: 8 additions & 0 deletions
8
...ise_search/public/applications/workplace_search/components/layout/account_header/index.ts
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export { AccountHeader } from './account_header'; |
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
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