Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "[Spaces] Filtering out features that do not have space scope" #194329

Merged
merged 2 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { act } from 'react-dom/test-utils';

import { DEFAULT_APP_CATEGORIES } from '@kbn/core/public';
import { notificationServiceMock, scopedHistoryMock } from '@kbn/core/public/mocks';
import { KibanaFeatureScope } from '@kbn/features-plugin/common';
import { KibanaFeature } from '@kbn/features-plugin/public';
import { featuresPluginMock } from '@kbn/features-plugin/public/mocks';
import { findTestSubject, mountWithIntl } from '@kbn/test-jest-helpers';
Expand Down Expand Up @@ -49,15 +48,6 @@ featuresStart.getFeatures.mockResolvedValue([
app: [],
category: DEFAULT_APP_CATEGORIES.kibana,
privileges: null,
scope: [KibanaFeatureScope.Spaces, KibanaFeatureScope.Security],
}),
new KibanaFeature({
id: 'feature-2',
name: 'feature 2',
app: [],
category: DEFAULT_APP_CATEGORIES.kibana,
privileges: null,
scope: [KibanaFeatureScope.Security],
}),
]);

Expand Down Expand Up @@ -651,54 +641,6 @@ describe('ManageSpacePage', () => {

expect(spacesManager.updateSpace).toHaveBeenCalledTimes(1);
});

it('shows only features with space scope', async () => {
const spacesManager = spacesManagerMock.create();
spacesManager.getSpace = jest.fn().mockResolvedValue({
id: 'my-space',
name: 'Existing Space',
description: 'hey an existing space',
color: '#aabbcc',
initials: 'AB',
disabledFeatures: [],
});
spacesManager.getActiveSpace = jest.fn().mockResolvedValue(space);

const wrapper = mountWithIntl(
<CreateSpacePage
spaceId={'my-space'}
spacesManager={spacesManager as unknown as SpacesManager}
getFeatures={featuresStart.getFeatures}
notifications={notificationServiceMock.createStartContract()}
history={history}
capabilities={{
navLinks: {},
management: {},
catalogue: {},
spaces: { manage: true },
}}
eventTracker={eventTracker}
allowFeatureVisibility
allowSolutionVisibility
/>
);

await waitFor(() => {
wrapper.update();
expect(spacesManager.getSpace).toHaveBeenCalledWith('my-space');
});

expect(wrapper.state('features')).toEqual([
new KibanaFeature({
id: 'feature-1',
name: 'feature 1',
app: [],
category: DEFAULT_APP_CATEGORIES.kibana,
privileges: null,
scope: [KibanaFeatureScope.Spaces, KibanaFeatureScope.Security],
}),
]);
});
});

function updateSpace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import React, { Component } from 'react';

import type { Capabilities, NotificationsStart, ScopedHistory } from '@kbn/core/public';
import { SectionLoading } from '@kbn/es-ui-shared-plugin/public';
import { KibanaFeatureScope } from '@kbn/features-plugin/common';
import type { FeaturesPluginStart, KibanaFeature } from '@kbn/features-plugin/public';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
Expand Down Expand Up @@ -92,10 +91,6 @@ export class CreateSpacePage extends Component<Props, State> {
};
}

private filterSpaceFeatures = (features: KibanaFeature[]) => {
return features.filter((feature) => feature.scope?.includes(KibanaFeatureScope.Spaces));
};

public async componentDidMount() {
if (!this.props.capabilities.spaces.manage) {
return;
Expand All @@ -108,8 +103,7 @@ export class CreateSpacePage extends Component<Props, State> {
await this.loadSpace(spaceId, getFeatures());
} else {
const features = await getFeatures();

this.setState({ isLoading: false, features: this.filterSpaceFeatures(features) });
this.setState({ isLoading: false, features });
}
} catch (e) {
notifications.toasts.addError(e, {
Expand Down Expand Up @@ -416,7 +410,6 @@ export class CreateSpacePage extends Component<Props, State> {
spacesManager.getSpace(spaceId),
featuresPromise,
]);

if (space) {
if (onLoadSpace) {
onLoadSpace(space);
Expand All @@ -433,7 +426,7 @@ export class CreateSpacePage extends Component<Props, State> {
!!space.initials && getSpaceInitials({ name: space.name }) !== space.initials,
customAvatarColor: !!space.color && getSpaceColor({ name: space.name }) !== space.color,
},
features: this.filterSpaceFeatures(features),
features,
originalSpace: space,
isLoading: false,
});
Expand Down