Skip to content

Commit

Permalink
Only show product cards if the user has access to that product
Browse files Browse the repository at this point in the history
- adds access checks
- fixes flex/CSS to show one card at a time
  • Loading branch information
cee-chen committed Sep 9, 2020
1 parent 302035c commit 8718473
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
4 changes: 4 additions & 0 deletions x-pack/plugins/enterprise_search/common/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export interface IInitialAppData {
ilmEnabled?: boolean;
isFederatedAuth?: boolean;
configuredLimits?: IConfiguredLimits;
access?: {
hasAppSearchAccess: boolean;
hasWorkplaceSearchAccess: boolean;
};
appSearch?: IAppSearchAccount;
workplaceSearch?: IWorkplaceSearchInitialData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,8 @@
margin-top: $euiSizeS;
}
}

.enterpriseSearchOverview__card {
flex-basis: 50%;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,37 @@ import { ProductCard } from './components/product_card';

describe('EnterpriseSearch', () => {
it('renders the overview page and product cards', () => {
const wrapper = shallow(<EnterpriseSearch />);
const wrapper = shallow(
<EnterpriseSearch access={{ hasAppSearchAccess: true, hasWorkplaceSearchAccess: true }} />
);

expect(wrapper.find(EuiPage)).toHaveLength(1);
expect(wrapper.find(EuiPage).hasClass('enterpriseSearchOverview')).toBe(true);
expect(wrapper.find(ProductCard)).toHaveLength(2);
});

describe('access checks', () => {
it('does not render the App Search card if the user does not have access to AS', () => {
const wrapper = shallow(
<EnterpriseSearch access={{ hasAppSearchAccess: false, hasWorkplaceSearchAccess: true }} />
);

expect(wrapper.find(ProductCard)).toHaveLength(1);
expect(wrapper.find(ProductCard).prop('product').ID).toEqual('workplaceSearch');
});

it('does not render the Workplace Search card if the user does not have access to WS', () => {
const wrapper = shallow(
<EnterpriseSearch access={{ hasAppSearchAccess: true, hasWorkplaceSearchAccess: false }} />
);

expect(wrapper.find(ProductCard)).toHaveLength(1);
expect(wrapper.find(ProductCard).prop('product').ID).toEqual('appSearch');
});

it('does not render any cards if the user does not have access', () => {
const wrapper = shallow(<EnterpriseSearch />);

expect(wrapper.find(ProductCard)).toHaveLength(0);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { IInitialAppData } from '../../../common/types';
import { APP_SEARCH_PLUGIN, WORKPLACE_SEARCH_PLUGIN } from '../../../common/constants';

import { SetEnterpriseSearchChrome as SetPageChrome } from '../shared/kibana_chrome';
Expand All @@ -29,7 +30,9 @@ import AppSearchImage from './assets/app_search.png';
import WorkplaceSearchImage from './assets/workplace_search.png';
import './index.scss';

export const EnterpriseSearch: React.FC = () => {
export const EnterpriseSearch: React.FC<IInitialAppData> = ({ access = {} }) => {
const { hasAppSearchAccess, hasWorkplaceSearchAccess } = access;

return (
<EuiPage restrictWidth className="enterpriseSearchOverview">
<SetPageChrome isRoot />
Expand All @@ -55,13 +58,17 @@ export const EnterpriseSearch: React.FC = () => {
</EuiPageHeaderSection>
</EuiPageHeader>
<EuiPageContentBody>
<EuiFlexGroup gutterSize="xl">
<EuiFlexItem>
<ProductCard product={APP_SEARCH_PLUGIN} image={AppSearchImage} />
</EuiFlexItem>
<EuiFlexItem>
<ProductCard product={WORKPLACE_SEARCH_PLUGIN} image={WorkplaceSearchImage} />
</EuiFlexItem>
<EuiFlexGroup justifyContent="center" gutterSize="xl">
{hasAppSearchAccess && (
<EuiFlexItem grow={false} className="enterpriseSearchOverview__card">
<ProductCard product={APP_SEARCH_PLUGIN} image={AppSearchImage} />
</EuiFlexItem>
)}
{hasWorkplaceSearchAccess && (
<EuiFlexItem grow={false} className="enterpriseSearchOverview__card">
<ProductCard product={WORKPLACE_SEARCH_PLUGIN} image={WorkplaceSearchImage} />
</EuiFlexItem>
)}
</EuiFlexGroup>
<EuiSpacer />
</EuiPageContentBody>
Expand Down

0 comments on commit 8718473

Please sign in to comment.