[Enterprise Search] Expose core.chrome.setIsVisible for use in Workplace 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>
This commit is contained in:
parent
123f3400a8
commit
ea03eb1bab
|
@ -19,6 +19,7 @@ export const mockKibanaValues = {
|
|||
history: mockHistory,
|
||||
navigateToUrl: jest.fn(),
|
||||
setBreadcrumbs: jest.fn(),
|
||||
setChromeIsVisible: jest.fn(),
|
||||
setDocTitle: jest.fn(),
|
||||
renderHeaderActions: jest.fn(),
|
||||
};
|
||||
|
|
|
@ -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)),
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
@ -47,6 +48,7 @@ export const KibanaLogic = kea<MakeLogicType<KibanaValues>>({
|
|||
{},
|
||||
],
|
||||
setBreadcrumbs: [props.setBreadcrumbs, {}],
|
||||
setChromeIsVisible: [props.setChromeIsVisible, {}],
|
||||
setDocTitle: [props.setDocTitle, {}],
|
||||
renderHeaderActions: [props.renderHeaderActions, {}],
|
||||
}),
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
@ -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
|
||||
*/
|
||||
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);
|
||||
setChromeIsVisible(isOrganization);
|
||||
}, [pathname]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!hasInitialized) {
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue