Skip to content

Commit

Permalink
[Enterprise Search] Expose core.chrome.setIsVisible for use in Workpl…
Browse files Browse the repository at this point in the history
…ace Search (#95984)

* Hide chrome for Workplace Search by default

The Workplace Search Personal dashboard needs the chrome hidden. We hide it globally here first to prevent a flash of chrome on the Personal dashboard and unhide it for admin routes, which will be in a future commit

* Add core.chrome.setIsVisible to KibanaLogic

* Toggle chrome visibility for Workplace Search

* Add test

* Refactor to set context and chrome when pathname changes

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
scottybollinger and kibanamachine authored Apr 5, 2021
1 parent 123f340 commit ea03eb1
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const mockKibanaValues = {
history: mockHistory,
navigateToUrl: jest.fn(),
setBreadcrumbs: jest.fn(),
setChromeIsVisible: jest.fn(),
setDocTitle: jest.fn(),
renderHeaderActions: jest.fn(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const renderApp = (
history: params.history,
navigateToUrl: core.application.navigateToUrl,
setBreadcrumbs: core.chrome.setBreadcrumbs,
setChromeIsVisible: core.chrome.setIsVisible,
setDocTitle: core.chrome.docTitle.change,
renderHeaderActions: (HeaderActions) =>
params.setHeaderActionMenu((el) => renderHeaderActions(HeaderActions, store, el)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface KibanaLogicProps {
charts: ChartsPluginStart;
navigateToUrl: ApplicationStart['navigateToUrl'];
setBreadcrumbs(crumbs: ChromeBreadcrumb[]): void;
setChromeIsVisible(isVisible: boolean): void;
setDocTitle(title: string): void;
renderHeaderActions(HeaderActions: FC): void;
}
Expand All @@ -47,6 +48,7 @@ export const KibanaLogic = kea<MakeLogicType<KibanaValues>>({
{},
],
setBreadcrumbs: [props.setBreadcrumbs, {}],
setChromeIsVisible: [props.setChromeIsVisible, {}],
setDocTitle: [props.setDocTitle, {}],
renderHeaderActions: [props.renderHeaderActions, {}],
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ describe('WorkplaceSearchConfigured', () => {
setMockActions({ initializeAppData, setContext });
});

it('renders layout and header actions', () => {
it('renders layout, chrome, and header actions', () => {
const wrapper = shallow(<WorkplaceSearchConfigured />);

expect(wrapper.find(Layout).first().prop('readOnlyMode')).toBeFalsy();
expect(wrapper.find(OverviewMVP)).toHaveLength(1);

expect(mockKibanaValues.setChromeIsVisible).toHaveBeenCalledWith(true);
expect(mockKibanaValues.renderHeaderActions).toHaveBeenCalledWith(WorkplaceSearchHeaderActions);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const WorkplaceSearch: React.FC<InitialAppData> = (props) => {
export const WorkplaceSearchConfigured: React.FC<InitialAppData> = (props) => {
const { hasInitialized } = useValues(AppLogic);
const { initializeAppData, setContext } = useActions(AppLogic);
const { renderHeaderActions } = useValues(KibanaLogic);
const { renderHeaderActions, setChromeIsVisible } = useValues(KibanaLogic);
const { errorConnecting, readOnlyMode } = useValues(HttpLogic);

const { pathname } = useLocation();
Expand All @@ -66,11 +66,13 @@ export const WorkplaceSearchConfigured: React.FC<InitialAppData> = (props) => {
* Personal dashboard urls begin with /p/
* EX: http://localhost:5601/app/enterprise_search/workplace_search/p/sources
*/
const personalSourceUrlRegex = /^\/p\//g; // matches '/p/*'
useEffect(() => {
const personalSourceUrlRegex = /^\/p\//g; // matches '/p/*'
const isOrganization = !pathname.match(personalSourceUrlRegex); // TODO: Once auth is figured out, we need to have a check for the equivilent of `isAdmin`.

// TODO: Once auth is figured out, we need to have a check for the equivilent of `isAdmin`.
const isOrganization = !pathname.match(personalSourceUrlRegex);
setContext(isOrganization);
setContext(isOrganization);
setChromeIsVisible(isOrganization);
}, [pathname]);

useEffect(() => {
if (!hasInitialized) {
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/enterprise_search/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ export class EnterpriseSearchPlugin implements Plugin {
const { chrome, http } = kibanaDeps.core;
chrome.docTitle.change(WORKPLACE_SEARCH_PLUGIN.NAME);

// The Workplace Search Personal dashboard needs the chrome hidden. We hide it globally
// here first to prevent a flash of chrome on the Personal dashboard and unhide it for admin routes.
chrome.setIsVisible(false);
await this.getInitialData(http);
const pluginData = this.getPluginData();

Expand Down

0 comments on commit ea03eb1

Please sign in to comment.