Skip to content

Commit

Permalink
Migrate UI capabilities to use new platform APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecote committed Jan 27, 2020
1 parent 8fe39ae commit 6f7ba8f
Show file tree
Hide file tree
Showing 15 changed files with 215 additions and 192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ToastsSetup,
HttpSetup,
IUiSettingsClient,
ApplicationStart,
} from 'kibana/public';
import { BASE_PATH, Section } from './constants';
import { TriggersActionsUIHome } from './home';
Expand All @@ -27,6 +28,7 @@ export interface AppDeps {
http: HttpSetup;
uiSettings: IUiSettingsClient;
legacy: LegacyDependencies;
capabilities: ApplicationStart['capabilities'];
actionTypeRegistry: TypeRegistry<ActionTypeModel>;
alertTypeRegistry: TypeRegistry<AlertTypeModel>;
}
Expand All @@ -46,10 +48,8 @@ export const App = (appDeps: AppDeps) => {
};

export const AppWithoutRouter = ({ sectionsRegex }: any) => {
const {
legacy: { capabilities },
} = useAppDependencies();
const canShowAlerts = hasShowAlertsCapability(capabilities.get());
const { capabilities } = useAppDependencies();
const canShowAlerts = hasShowAlertsCapability(capabilities);
const DEFAULT_SECTION: Section = canShowAlerts ? 'alerts' : 'connectors';
return (
<Switch>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ export const TriggersActionsUIHome: React.FunctionComponent<RouteComponentProps<
}) => {
const {
chrome,
legacy: { MANAGEMENT_BREADCRUMB, capabilities },
capabilities,
legacy: { MANAGEMENT_BREADCRUMB },
} = useAppDependencies();

const canShowActions = hasShowActionsCapability(capabilities.get());
const canShowAlerts = hasShowAlertsCapability(capabilities.get());
const canShowActions = hasShowActionsCapability(capabilities);
const canShowAlerts = hasShowAlertsCapability(capabilities);
const tabs: Array<{
id: Section;
name: React.ReactNode;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,29 @@ describe('action_connector_form', () => {

beforeAll(async () => {
const mockes = coreMock.createSetup();
const [{ chrome, docLinks }] = await mockes.getStartServices();
const [
{
chrome,
docLinks,
application: { capabilities },
},
] = await mockes.getStartServices();
const deps = {
chrome,
docLinks,
toastNotifications: mockes.notifications.toasts,
injectedMetadata: mockes.injectedMetadata,
http: mockes.http,
uiSettings: mockes.uiSettings,
capabilities: {
...capabilities,
actions: {
delete: true,
save: true,
show: true,
},
},
legacy: {
capabilities: {
get() {
return {
actions: {
delete: true,
save: true,
show: true,
},
};
},
} as any,
MANAGEMENT_BREADCRUMB: { set: () => {} } as any,
},
actionTypeRegistry: actionTypeRegistry as any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,10 @@ export const ActionConnectorForm = ({
actionTypeName,
setFlyoutVisibility,
}: ActionConnectorProps) => {
const {
http,
toastNotifications,
legacy: { capabilities },
actionTypeRegistry,
} = useAppDependencies();
const { http, toastNotifications, capabilities, actionTypeRegistry } = useAppDependencies();

const { reloadConnectors } = useActionsConnectorsContext();
const canSave = hasSaveActionsCapability(capabilities.get());
const canSave = hasSaveActionsCapability(capabilities);

// hooks
const [{ connector }, dispatch] = useReducer(connectorReducer, { connector: initialConnector });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,29 @@ describe('connector_add_flyout', () => {

beforeAll(async () => {
const mockes = coreMock.createSetup();
const [{ chrome, docLinks }] = await mockes.getStartServices();
const [
{
chrome,
docLinks,
application: { capabilities },
},
] = await mockes.getStartServices();
deps = {
chrome,
docLinks,
toastNotifications: mockes.notifications.toasts,
injectedMetadata: mockes.injectedMetadata,
http: mockes.http,
uiSettings: mockes.uiSettings,
capabilities: {
...capabilities,
actions: {
delete: true,
save: true,
show: true,
},
},
legacy: {
capabilities: {
get() {
return {
actions: {
delete: true,
save: true,
show: true,
},
};
},
} as any,
MANAGEMENT_BREADCRUMB: { set: () => {} } as any,
},
actionTypeRegistry: actionTypeRegistry as any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,29 @@ describe('connector_add_flyout', () => {

beforeAll(async () => {
const mockes = coreMock.createSetup();
const [{ chrome, docLinks }] = await mockes.getStartServices();
const [
{
chrome,
docLinks,
application: { capabilities },
},
] = await mockes.getStartServices();
const deps = {
chrome,
docLinks,
toastNotifications: mockes.notifications.toasts,
injectedMetadata: mockes.injectedMetadata,
http: mockes.http,
uiSettings: mockes.uiSettings,
capabilities: {
...capabilities,
actions: {
delete: true,
save: true,
show: true,
},
},
legacy: {
capabilities: {
get() {
return {
actions: {
delete: true,
save: true,
show: true,
},
};
},
} as any,
MANAGEMENT_BREADCRUMB: { set: () => {} } as any,
},
actionTypeRegistry: actionTypeRegistry as any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,29 @@ let deps: any;
describe('connector_edit_flyout', () => {
beforeAll(async () => {
const mockes = coreMock.createSetup();
const [{ chrome, docLinks }] = await mockes.getStartServices();
const [
{
chrome,
docLinks,
application: { capabilities },
},
] = await mockes.getStartServices();
deps = {
chrome,
docLinks,
toastNotifications: mockes.notifications.toasts,
injectedMetadata: mockes.injectedMetadata,
http: mockes.http,
uiSettings: mockes.uiSettings,
capabilities: {
...capabilities,
actions: {
delete: true,
save: true,
show: true,
},
},
legacy: {
capabilities: {
get() {
return {
actions: {
delete: true,
save: true,
show: true,
},
};
},
} as any,
MANAGEMENT_BREADCRUMB: { set: () => {} } as any,
},
actionTypeRegistry: actionTypeRegistry as any,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,29 @@ describe('actions_connectors_list component empty', () => {
},
]);
const mockes = coreMock.createSetup();
const [{ chrome, docLinks }] = await mockes.getStartServices();
const [
{
chrome,
docLinks,
application: { capabilities },
},
] = await mockes.getStartServices();
const deps = {
chrome,
docLinks,
toastNotifications: mockes.notifications.toasts,
injectedMetadata: mockes.injectedMetadata,
http: mockes.http,
uiSettings: mockes.uiSettings,
capabilities: {
...capabilities,
siem: {
'actions:show': true,
'actions:save': true,
'actions:delete': true,
},
},
legacy: {
capabilities: {
get() {
return {
siem: {
'actions:show': true,
'actions:save': true,
'actions:delete': true,
},
};
},
} as any,
MANAGEMENT_BREADCRUMB: { set: () => {} } as any,
},
actionTypeRegistry: actionTypeRegistry as any,
Expand Down Expand Up @@ -136,26 +139,29 @@ describe('actions_connectors_list component with items', () => {
]);

const mockes = coreMock.createSetup();
const [{ chrome, docLinks }] = await mockes.getStartServices();
const [
{
chrome,
docLinks,
application: { capabilities },
},
] = await mockes.getStartServices();
const deps = {
chrome,
docLinks,
toastNotifications: mockes.notifications.toasts,
injectedMetadata: mockes.injectedMetadata,
http: mockes.http,
uiSettings: mockes.uiSettings,
capabilities: {
...capabilities,
siem: {
'actions:show': true,
'actions:save': true,
'actions:delete': true,
},
},
legacy: {
capabilities: {
get() {
return {
siem: {
'actions:show': true,
'actions:save': true,
'actions:delete': true,
},
};
},
} as any,
MANAGEMENT_BREADCRUMB: { set: () => {} } as any,
},
actionTypeRegistry: {
Expand Down Expand Up @@ -217,26 +223,29 @@ describe('actions_connectors_list component empty with show only capability', ()
},
]);
const mockes = coreMock.createSetup();
const [{ chrome, docLinks }] = await mockes.getStartServices();
const [
{
chrome,
docLinks,
application: { capabilities },
},
] = await mockes.getStartServices();
const deps = {
chrome,
docLinks,
toastNotifications: mockes.notifications.toasts,
injectedMetadata: mockes.injectedMetadata,
http: mockes.http,
uiSettings: mockes.uiSettings,
capabilities: {
...capabilities,
siem: {
'actions:show': true,
'actions:save': false,
'actions:delete': false,
},
},
legacy: {
capabilities: {
get() {
return {
siem: {
'actions:show': true,
'actions:save': false,
'actions:delete': false,
},
};
},
} as any,
MANAGEMENT_BREADCRUMB: { set: () => {} } as any,
},
actionTypeRegistry: {
Expand Down Expand Up @@ -303,26 +312,29 @@ describe('actions_connectors_list with show only capability', () => {
},
]);
const mockes = coreMock.createSetup();
const [{ chrome, docLinks }] = await mockes.getStartServices();
const [
{
chrome,
docLinks,
application: { capabilities },
},
] = await mockes.getStartServices();
const deps = {
chrome,
docLinks,
toastNotifications: mockes.notifications.toasts,
injectedMetadata: mockes.injectedMetadata,
http: mockes.http,
uiSettings: mockes.uiSettings,
capabilities: {
...capabilities,
siem: {
'actions:show': true,
'actions:save': false,
'actions:delete': false,
},
},
legacy: {
capabilities: {
get() {
return {
siem: {
'actions:show': true,
'actions:save': false,
'actions:delete': false,
},
};
},
} as any,
MANAGEMENT_BREADCRUMB: { set: () => {} } as any,
},
actionTypeRegistry: {
Expand Down
Loading

0 comments on commit 6f7ba8f

Please sign in to comment.