Skip to content

Commit

Permalink
Improve home screen for limited-access users
Browse files Browse the repository at this point in the history
  • Loading branch information
legrego committed Sep 16, 2020
1 parent fd1aad0 commit 498709f
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 28 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,9 @@ describe('ManageData', () => {
);
expect(component).toMatchSnapshot();
});

test('render empty without any features', () => {
const component = shallowWithIntl(<ManageData addBasePath={addBasePathMock} features={[]} />);
expect(component).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,33 @@ export const ManageData: FC<Props> = ({ addBasePath, features }) => (
<>
{features.length > 1 && <EuiHorizontalRule margin="xl" aria-hidden="true" />}

<section className="homDataManage" aria-labelledby="homDataManage__title">
<EuiTitle size="s">
<h2 id="homDataManage__title">
<FormattedMessage id="home.manageData.sectionTitle" defaultMessage="Manage your data" />
</h2>
</EuiTitle>
{features.length > 1 && (
<section className="homDataManage" aria-labelledby="homDataManage__title">
<EuiTitle size="s">
<h2 id="homDataManage__title">
<FormattedMessage id="home.manageData.sectionTitle" defaultMessage="Manage your data" />
</h2>
</EuiTitle>

<EuiSpacer size="m" />
<EuiSpacer size="m" />

<EuiFlexGroup className="homDataManage__content">
{features.map((feature) => (
<EuiFlexItem key={feature.id}>
<Synopsis
id={feature.id}
onClick={createAppNavigationHandler(feature.path)}
description={feature.description}
iconType={feature.icon}
title={feature.title}
url={addBasePath(feature.path)}
wrapInPanel
/>
</EuiFlexItem>
))}
</EuiFlexGroup>
</section>
<EuiFlexGroup className="homDataManage__content">
{features.map((feature) => (
<EuiFlexItem key={feature.id}>
<Synopsis
id={feature.id}
onClick={createAppNavigationHandler(feature.path)}
description={feature.description}
iconType={feature.icon}
title={feature.title}
url={addBasePath(feature.path)}
wrapInPanel
/>
</EuiFlexItem>
))}
</EuiFlexGroup>
</section>
)}
</>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,38 @@ describe('FeatureCatalogueRegistry', () => {
expect(service.get()).toEqual([]);
});
});

describe('visibility filtering', () => {
test('retains items with no "visible" callback', () => {
const service = new FeatureCatalogueRegistry();
service.setup().register(DASHBOARD_FEATURE);
const capabilities = { catalogue: {} } as any;
service.start({ capabilities });
expect(service.get()).toEqual([DASHBOARD_FEATURE]);
});

test('retains items with a "visible" callback which returns "true"', () => {
const service = new FeatureCatalogueRegistry();
service.setup().register({
...DASHBOARD_FEATURE,
visible: () => true,
});
const capabilities = { catalogue: {} } as any;
service.start({ capabilities });
expect(service.get()).toEqual([DASHBOARD_FEATURE]);
});

test('removes items with a "visible" callback which returns "false"', () => {
const service = new FeatureCatalogueRegistry();
service.setup().register({
...DASHBOARD_FEATURE,
visible: () => false,
});
const capabilities = { catalogue: {} } as any;
service.start({ capabilities });
expect(service.get()).toEqual([]);
});
});
});

describe('title sorting', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export interface FeatureCatalogueEntry {
readonly showOnHomePage: boolean;
/** An ordinal used to sort features relative to one another for display on the home page */
readonly order?: number;
/** Optional function to control visibility of this feature. */
readonly visible?: () => boolean;
}

/** @public */
Expand Down Expand Up @@ -103,7 +105,10 @@ export class FeatureCatalogueRegistry {
}
const capabilities = this.capabilities;
return [...this.features.values()]
.filter((entry) => capabilities.catalogue[entry.id] !== false)
.filter(
(entry) =>
capabilities.catalogue[entry.id] !== false && (entry.visible ? entry.visible() : true)
)
.sort(compareByKey('title'));
}

Expand Down
7 changes: 5 additions & 2 deletions src/plugins/management/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export class ManagementPlugin implements Plugin<ManagementSetup, ManagementStart

private readonly appUpdater = new BehaviorSubject<AppUpdater>(() => ({}));

private hasAnyEnabledApps = true;

constructor(private initializerContext: PluginInitializerContext) {}

public setup(core: CoreSetup, { home }: ManagementSetupDependencies) {
Expand All @@ -65,6 +67,7 @@ export class ManagementPlugin implements Plugin<ManagementSetup, ManagementStart
path: '/app/management',
showOnHomePage: false,
category: FeatureCatalogueCategory.ADMIN,
visible: () => this.hasAnyEnabledApps,
});
}

Expand Down Expand Up @@ -96,11 +99,11 @@ export class ManagementPlugin implements Plugin<ManagementSetup, ManagementStart

public start(core: CoreStart) {
this.managementSections.start({ capabilities: core.application.capabilities });
const hasAnyEnabledApps = getSectionsServiceStartPrivate()
this.hasAnyEnabledApps = getSectionsServiceStartPrivate()
.getSectionsEnabled()
.some((section) => section.getAppsEnabled().length > 0);

if (!hasAnyEnabledApps) {
if (!this.hasAnyEnabledApps) {
this.appUpdater.next(() => {
return {
status: AppStatus.inaccessible,
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/index_lifecycle_management/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ export class IndexLifecycleManagementServerPlugin implements Plugin<void, void,
);

features.registerElasticsearchFeature({
id: 'index_lifecycle_management',
id: PLUGIN.ID,
management: {
data: ['index_lifecycle_management'],
data: [PLUGIN.ID],
},
catalogue: [PLUGIN.ID],
privileges: [
{
requiredClusterPrivileges: ['manage_ilm'],
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/snapshot_restore/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export class SnapshotRestoreServerPlugin implements Plugin<void, void, any, any>
management: {
data: [PLUGIN.id],
},
catalogue: [PLUGIN.id],
privileges: [
{
requiredClusterPrivileges: [...APP_REQUIRED_CLUSTER_PRIVILEGES],
Expand Down

0 comments on commit 498709f

Please sign in to comment.