Skip to content

Commit

Permalink
Make spaces optional on the front-end
Browse files Browse the repository at this point in the history
  • Loading branch information
thomheymann committed Jan 19, 2023
1 parent 6f26e8f commit ea3934d
Show file tree
Hide file tree
Showing 24 changed files with 916 additions and 20 deletions.
6 changes: 5 additions & 1 deletion x-pack/plugins/infra/public/hooks/use_kibana_space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ export type ActiveSpace =
export const useActiveKibanaSpace = (): ActiveSpace => {
const kibana = useKibanaContextForPlugin();

const asyncActiveSpace = useAsync(kibana.services.spaces.getActiveSpace);
const asyncActiveSpace = useAsync(
kibana.services.spaces
? kibana.services.spaces.getActiveSpace
: () => Promise.resolve(undefined)
);

if (asyncActiveSpace.loading) {
return {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/infra/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export interface InfraClientStartDeps {
unifiedSearch: UnifiedSearchPublicPluginStart;
dataViews: DataViewsPublicPluginStart;
observability: ObservabilityPublicStart;
spaces: SpacesPluginStart;
spaces?: SpacesPluginStart;
triggersActionsUi: TriggersAndActionsUIPublicPluginStart;
usageCollection: UsageCollectionStart;
ml: MlPluginStart;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/lens/public/app_plugin/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,7 @@ describe('Lens App', () => {
},
},
});
expect(services.spaces.ui.components.getLegacyUrlConflict).toHaveBeenCalledWith({
expect(services.spaces?.ui.components.getLegacyUrlConflict).toHaveBeenCalledWith({
currentObjectId: '1234',
objectNoun: 'Lens visualization',
otherObjectId: '2',
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/lens/public/app_plugin/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export interface LensAppServices {
savedObjectsTagging?: SavedObjectTaggingPluginStart;
getOriginatingAppName: () => string | undefined;
presentationUtil: PresentationUtilPluginStart;
spaces: SpacesApi;
spaces?: SpacesApi;
charts: ChartsPluginSetup;
share?: SharePluginStart;
unifiedSearch: UnifiedSearchPublicPluginStart;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/lens/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export interface LensPluginStartDependencies {
dataViewFieldEditor: IndexPatternFieldEditorStart;
dataViewEditor: DataViewEditorStart;
inspector: InspectorStartContract;
spaces: SpacesPluginStart;
spaces?: SpacesPluginStart;
usageCollection?: UsageCollectionStart;
docLinks: DocLinksStart;
share?: SharePluginStart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ describe('Initializing the store', () => {
expect(deps.lensServices.attributeService.unwrapAttributes).toHaveBeenCalledWith({
savedObjectId: defaultSavedObjectId,
});
expect(deps.lensServices.spaces.ui.redirectLegacyUrl).toHaveBeenCalledWith({
expect(deps.lensServices.spaces?.ui.redirectLegacyUrl).toHaveBeenCalledWith({
path: '#/edit/id2?search',
aliasPurpose: 'savedObjectConversion',
objectNoun: 'Lens visualization',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface StartPlugins {
usageCollection?: UsageCollectionSetup;
fieldFormats: FieldFormatsRegistry;
dashboard: DashboardSetup;
spacesApi: SpacesPluginStart;
spacesApi?: SpacesPluginStart;
charts: ChartsPluginStart;
cases?: CasesUiStart;
unifiedSearch: UnifiedSearchPublicPluginStart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type { Space } from '@kbn/spaces-plugin/common';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { ObservabilityPublicPluginsStart, useFetcher } from '..';

Expand All @@ -15,7 +14,7 @@ export const useKibanaSpace = () => {
data: space,
loading,
error,
} = useFetcher<Promise<Space>>(() => {
} = useFetcher(() => {
return services.spaces?.getActiveSpace();
}, [services.spaces]);

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/observability/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export interface ObservabilityPublicPluginsStart {
actionTypeRegistry: ActionTypeRegistryContract;
security: SecurityPluginStart;
guidedOnboarding: GuidedOnboardingPluginStart;
spaces: SpacesPluginStart;
spaces?: SpacesPluginStart;
}

export type ObservabilityPublicStart = ReturnType<Plugin['start']>;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/osquery/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface StartPlugins {
fleet: FleetStart;
lens?: LensPublicStart;
security: SecurityPluginStart;
spaces: SpacesPluginStart;
spaces?: SpacesPluginStart;
triggersActionsUi: TriggersAndActionsUIPublicPluginStart;
cases: CasesUiStart;
timelines: TimelinesUIStart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { dataViewPluginMocks } from '@kbn/data-views-plugin/public/mocks';
import { KibanaFeature } from '@kbn/features-plugin/public';
import { KibanaContextProvider } from '@kbn/kibana-react-plugin/public';
import type { Space } from '@kbn/spaces-plugin/public';
import { spacesManagerMock } from '@kbn/spaces-plugin/public/spaces_manager/mocks';
import { getUiApi } from '@kbn/spaces-plugin/public/ui_api';
import { mountWithIntl, nextTick } from '@kbn/test-jest-helpers';

import { licenseMock } from '../../../../common/licensing/index.mock';
Expand All @@ -26,6 +28,10 @@ import { EditRolePage } from './edit_role_page';
import { SpaceAwarePrivilegeSection } from './privileges/kibana/space_aware_privilege_section';
import { TransformErrorSection } from './privileges/kibana/transform_error_section';

const spacesManager = spacesManagerMock.create();
const { getStartServices } = coreMock.createSetup();
const spacesApiUi = getUiApi({ spacesManager, getStartServices });

const buildFeatures = () => {
return [
new KibanaFeature({
Expand Down Expand Up @@ -183,6 +189,7 @@ function getProps({
fatalErrors,
uiCapabilities: buildUICapabilities(canManageSpaces),
history: scopedHistoryMock.create(),
spacesApiUi,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,7 @@ export const EditRolePage: FunctionComponent<Props> = ({
<KibanaPrivilegesRegion
kibanaPrivileges={new KibanaPrivileges(kibanaPrivileges, features)}
spaces={spaces.list}
spacesEnabled={spaces.enabled}
uiCapabilities={uiCapabilities}
canCustomizeSubFeaturePrivileges={license.getFeatures().allowSubFeaturePrivileges}
editable={!isRoleReadOnly}
Expand Down

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 @@ -8,13 +8,21 @@
import { shallow } from 'enzyme';
import React from 'react';

import { coreMock } from '@kbn/core/public/mocks';
import { spacesManagerMock } from '@kbn/spaces-plugin/public/spaces_manager/mocks';
import { getUiApi } from '@kbn/spaces-plugin/public/ui_api';

import type { Role } from '../../../../../../common/model';
import { KibanaPrivileges } from '../../../model';
import { RoleValidator } from '../../validate_role';
import { KibanaPrivilegesRegion } from './kibana_privileges_region';
import { SpaceAwarePrivilegeSection } from './space_aware_privilege_section';
import { TransformErrorSection } from './transform_error_section';

const spacesManager = spacesManagerMock.create();
const { getStartServices } = coreMock.createSetup();
const spacesApiUi = getUiApi({ spacesManager, getStartServices });

const buildProps = () => {
return {
role: {
Expand Down Expand Up @@ -62,6 +70,8 @@ const buildProps = () => {
onChange: jest.fn(),
validator: new RoleValidator(),
canCustomizeSubFeaturePrivileges: true,
spacesEnabled: true,
spacesApiUi,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import type { Role } from '../../../../../../common/model';
import type { KibanaPrivileges } from '../../../model';
import { CollapsiblePanel } from '../../collapsible_panel';
import type { RoleValidator } from '../../validate_role';
import { SimplePrivilegeSection } from './simple_privilege_section';
import { SpaceAwarePrivilegeSection } from './space_aware_privilege_section';
import { TransformErrorSection } from './transform_error_section';

interface Props {
role: Role;
spacesEnabled: boolean;
canCustomizeSubFeaturePrivileges: boolean;
spaces?: Space[];
uiCapabilities: Capabilities;
Expand All @@ -42,6 +44,7 @@ export class KibanaPrivilegesRegion extends Component<Props, {}> {
const {
kibanaPrivileges,
role,
spacesEnabled,
canCustomizeSubFeaturePrivileges,
spaces = [],
uiCapabilities,
Expand All @@ -55,17 +58,29 @@ export class KibanaPrivilegesRegion extends Component<Props, {}> {
return <TransformErrorSection />;
}

if (spacesApiUi && spacesEnabled) {
return (
<SpaceAwarePrivilegeSection
kibanaPrivileges={kibanaPrivileges}
role={role}
spaces={spaces}
uiCapabilities={uiCapabilities}
onChange={onChange}
editable={editable}
canCustomizeSubFeaturePrivileges={canCustomizeSubFeaturePrivileges}
validator={validator}
spacesApiUi={spacesApiUi}
/>
);
}

return (
<SpaceAwarePrivilegeSection
<SimplePrivilegeSection
kibanaPrivileges={kibanaPrivileges}
role={role}
spaces={spaces}
uiCapabilities={uiCapabilities}
onChange={onChange}
editable={editable}
canCustomizeSubFeaturePrivileges={canCustomizeSubFeaturePrivileges}
validator={validator}
spacesApiUi={spacesApiUi!}
/>
);
};
Expand Down
Loading

0 comments on commit ea3934d

Please sign in to comment.