Skip to content

Commit 055a0cb

Browse files
committed
chore: 🤖 catch up with latest
2 parents 8375919 + e145241 commit 055a0cb

File tree

20 files changed

+297
-178
lines changed

20 files changed

+297
-178
lines changed

‎src/plugins/ui_actions/public/actions/action.ts‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import { UiComponent } from 'src/plugins/kibana_utils/common';
2121
import { ActionType, ActionContextMapping } from '../types';
2222
import { Presentable } from '../util/presentable';
23-
import { Configurable } from '../util/configurable';
2423

2524
export type ActionByType<T extends ActionType> = Action<ActionContextMapping[T], T>;
2625

@@ -82,7 +81,7 @@ export interface Action<Context extends {} = {}, T = ActionType>
8281
export interface ActionDefinition<
8382
Context extends object = object,
8483
Config extends object | undefined = undefined
85-
> extends Partial<Presentable<Context>>, Partial<Configurable<Config, Context>> {
84+
> extends Partial<Presentable<Context>> {
8685
/**
8786
* ID of the action that uniquely identifies this action in the actions registry.
8887
*/
@@ -116,7 +115,6 @@ export type ActionConfig<A> = A extends ActionDefinition<any, infer Config> ? Co
116115
export type DynamicActionDefinition<
117116
Context extends object = object,
118117
Config extends object | undefined = undefined
119-
> = ActionDefinition<Context, Config> &
120-
Required<Pick<ActionDefinition<Context, Config>, 'CollectConfig' | 'defaultConfig' | 'type'>>;
118+
> = ActionDefinition<Context, Config>;
121119

122120
export type AnyDynamicActionDefinition = DynamicActionDefinition<any, any>;

‎src/plugins/ui_actions/public/actions/action_internal.ts‎

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import { Action, ActionContext, AnyActionDefinition } from './action';
2121
import { Presentable } from '../util/presentable';
22-
import { createActionStateContainer, ActionState } from './action_state_container';
22+
// import { ActionState } from './action_state_container';
2323
import { uiToReactComponent } from '../../../kibana_react/public';
2424
import { ActionContract } from './action_contract';
2525
import { ActionType } from '../types';
@@ -33,20 +33,11 @@ export class ActionInternal<A extends AnyActionDefinition>
3333
public readonly order: number = this.definition.order || 0;
3434
public readonly MenuItem? = this.definition.MenuItem;
3535
public readonly ReactMenuItem? = this.MenuItem ? uiToReactComponent(this.MenuItem) : undefined;
36-
public readonly CollectConfig? = this.definition.CollectConfig;
37-
public readonly ReactCollectConfig? = this.CollectConfig
38-
? uiToReactComponent(this.CollectConfig)
39-
: undefined;
4036

4137
public get contract(): ActionContract<A> {
4238
return this;
4339
}
4440

45-
public readonly state = createActionStateContainer({
46-
name: '',
47-
config: this.definition.defaultConfig || {},
48-
});
49-
5041
public execute(context: ActionContext<A>) {
5142
return this.definition.execute(context);
5243
}
@@ -72,25 +63,21 @@ export class ActionInternal<A extends AnyActionDefinition>
7263
}
7364

7465
serialize(): SerializedAction {
75-
const state = this.state.get();
7666
const serialized: SerializedAction = {
7767
id: this.id,
7868
type: this.type || '',
79-
state,
8069
};
8170

8271
return serialized;
8372
}
8473

85-
deserialize({ state }: SerializedAction) {
86-
this.state.set(state);
87-
}
74+
deserialize() {}
8875
}
8976

9077
export type AnyActionInternal = ActionInternal<any>;
9178

9279
export interface SerializedAction<Config extends object = object> {
9380
readonly id: string;
9481
readonly type: string;
95-
readonly state: ActionState<Config>;
82+
// readonly state: ActionState<Config>;
9683
}

‎src/plugins/ui_actions/public/index.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ export {
3434
ActionInternal as UiActionsActionInternal,
3535
ActionContract as UiActionsActionContract,
3636
} from './actions';
37-
export { CollectConfigProps as UiActionsCollectConfigProps } from './util';
3837
export { buildContextMenuForActions, contextMenuSeparatorAction } from './context_menu';
38+
export { CollectConfigProps, Presentable, Configurable, ConfigurableBaseConfig } from './util';
39+
export { buildContextMenuForActions } from './context_menu';
3940
export { Trigger, TriggerContext } from './triggers';
4041
export { TriggerContextMapping, TriggerId, ActionContextMapping, ActionType } from './types';
4142
export { ActionByType } from './actions';

‎src/plugins/ui_actions/public/util/configurable.ts‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,33 @@
1919

2020
import { UiComponent } from 'src/plugins/kibana_utils/common';
2121

22+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
23+
export interface ConfigurableBaseConfig {}
24+
2225
/**
2326
* Represents something that can be configured by user using UI.
2427
*/
25-
export interface Configurable<Config, Context = void> {
28+
export interface Configurable<Config extends ConfigurableBaseConfig> {
29+
/**
30+
* Create default config for this item, used when item is created for the first time.
31+
*/
32+
readonly createConfig: () => Config;
33+
2634
/**
27-
* Default config for this item, used when item is created for the first time.
35+
* Is this config valid. Used to validate user's input before saving
2836
*/
29-
readonly defaultConfig?: Config;
37+
readonly isConfigValid: (config: Config) => boolean;
3038

3139
/**
3240
* `UiComponent` to be rendered when collecting configuration for this item.
3341
*/
34-
readonly CollectConfig?: UiComponent<CollectConfigProps<Config, Context>>;
42+
readonly CollectConfig: UiComponent<CollectConfigProps<Config>>;
3543
}
3644

3745
/**
3846
* Props provided to `CollectConfig` component on every re-render.
3947
*/
40-
export interface CollectConfigProps<Config, Context = void> {
41-
/**
42-
* Context represents environment where this component is being rendered.
43-
*/
44-
context: Context;
45-
48+
export interface CollectConfigProps<Config> {
4649
/**
4750
* Current (latest) config of the item.
4851
*/

‎src/plugins/ui_actions/public/util/presentable.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ export interface Presentable<Context extends object = object> {
4343
/**
4444
* Optional EUI icon type that can be displayed along with the title.
4545
*/
46-
getIconType(context: Context): string | undefined;
46+
getIconType(context?: Context): string | undefined;
4747

4848
/**
4949
* Returns a title to be displayed to the user.
5050
*/
51-
getDisplayName(context: Context): string;
51+
getDisplayName(context?: Context): string;
5252

5353
/**
5454
* Returns a promise that resolves to true if this item is compatible given
5555
* the context and should be displayed to user, otherwise resolves to false.
5656
*/
57-
isCompatible(context: Context): Promise<boolean>;
57+
isCompatible(context?: Context): Promise<boolean>;
5858
}

‎x-pack/plugins/advanced_ui_actions/public/components/action_wizard/action_wizard.tsx‎

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,8 @@ import {
1616
} from '@elastic/eui';
1717
import { txtChangeButton } from './i18n';
1818
import './action_wizard.scss';
19-
20-
// TODO: this interface is temporary for just moving forward with the component
21-
// and it will be imported from the ../ui_actions when implemented properly
22-
// eslint-disable-next-line @typescript-eslint/consistent-type-definitions
23-
export type ActionBaseConfig = {};
24-
export interface ActionFactory<Config extends ActionBaseConfig = ActionBaseConfig> {
25-
type: string; // TODO: type should be tied to Action and ActionByType
26-
displayName: string;
27-
iconType?: string;
28-
wizard: React.FC<ActionFactoryWizardProps<Config>>;
29-
createConfig: () => Config;
30-
isValid: (config: Config) => boolean;
31-
}
32-
33-
export interface ActionFactoryWizardProps<Config extends ActionBaseConfig> {
34-
config?: Config;
35-
36-
/**
37-
* Callback called when user updates the config in UI.
38-
*/
39-
onConfig: (config: Config) => void;
40-
}
19+
import { ActionBaseConfig, ActionFactory } from '../../ui_actions_factory';
20+
import { uiToReactComponent } from '../../../../../../src/plugins/kibana_react/public';
4121

4222
export interface ActionWizardProps {
4323
/**
@@ -130,14 +110,14 @@ const SelectedActionFactory: React.FC<SelectedActionFactoryProps> = ({
130110
>
131111
<header>
132112
<EuiFlexGroup alignItems="center" gutterSize="s">
133-
{actionFactory.iconType && (
113+
{actionFactory.getIconType() && (
134114
<EuiFlexItem grow={false}>
135-
<EuiIcon type={actionFactory.iconType} size="m" />
115+
<EuiIcon type={actionFactory.getIconType()!} size="m" />
136116
</EuiFlexItem>
137117
)}
138118
<EuiFlexItem grow={true}>
139119
<EuiText>
140-
<h4>{actionFactory.displayName}</h4>
120+
<h4>{actionFactory.getDisplayName()}</h4>
141121
</EuiText>
142122
</EuiFlexItem>
143123
{showDeselect && (
@@ -151,7 +131,7 @@ const SelectedActionFactory: React.FC<SelectedActionFactoryProps> = ({
151131
</header>
152132
<EuiSpacer size="m" />
153133
<div>
154-
{actionFactory.wizard({
134+
{uiToReactComponent(actionFactory.CollectConfig)({
155135
config,
156136
onConfig: onConfigChange,
157137
})}
@@ -182,13 +162,13 @@ const ActionFactorySelector: React.FC<ActionFactorySelectorProps> = ({
182162
{actionFactories.map(actionFactory => (
183163
<EuiKeyPadMenuItemButton
184164
className="auaActionWizard__actionFactoryItem"
185-
key={actionFactory.type}
186-
label={actionFactory.displayName}
165+
key={actionFactory.id}
166+
label={actionFactory.getDisplayName()}
187167
data-testid={TEST_SUBJ_ACTION_FACTORY_ITEM}
188168
data-test-subj={TEST_SUBJ_ACTION_FACTORY_ITEM}
189169
onClick={() => onActionFactorySelected(actionFactory)}
190170
>
191-
{actionFactory.iconType && <EuiIcon type={actionFactory.iconType} size="m" />}
171+
{actionFactory.getIconType() && <EuiIcon type={actionFactory.getIconType()!} size="m" />}
192172
</EuiKeyPadMenuItemButton>
193173
))}
194174
</EuiFlexGroup>

‎x-pack/plugins/advanced_ui_actions/public/components/action_wizard/index.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
export { ActionFactory, ActionWizard, ActionBaseConfig } from './action_wizard';
7+
export { ActionWizard } from './action_wizard';

0 commit comments

Comments
 (0)