Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Dosant committed Jun 5, 2020
1 parent 8935a2e commit daf89fc
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 25 deletions.
5 changes: 2 additions & 3 deletions src/plugins/ui_actions/public/service/ui_actions_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class UiActionsService {
triggerToActions = new Map(),
actionDefinitions = new Map(),
}: UiActionsServiceParams = {}) {
(window as any).__uiActionsService = this;
this.triggers = triggers;
this.actions = actions;
this.triggerToActions = triggerToActions;
Expand Down Expand Up @@ -171,9 +172,7 @@ export class UiActionsService {

const actionIds = this.triggerToActions.get(triggerId);

const actions = actionIds!
.map((actionId) => this.actions.get(actionId) as ActionInternal)
.filter(Boolean);
const actions = actionIds!.map((actionId) => this.getAction(actionId)).filter(Boolean);

return actions as Array<Action<TriggerContext<T>>>;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ export interface ActionEnhanced<Context extends {} = {}, T = ActionType>
extends Action<Context, T> {
/**
* Minimal license
* if missing, then no license req.
* if missing, then no license limitations
*/
readonly licence?: LicenseType;
readonly minimalLicense?: LicenseType;

hasCompatibleLicence(): boolean;
isCompatibleLicence(): boolean;
}

export interface ActionEnhancedDefinition<Context extends object = object>
extends ActionDefinition<Context> {
/**
* Minimal license
* if missing, then no license req.
* if missing, then no license limitations
*/
readonly licence?: LicenseType;
readonly minimalLicense?: LicenseType;
}

export type ActionEnhancedContext<A> = A extends ActionEnhancedDefinition<infer Context>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ import { ILicense } from '../../../licensing/public';
export class ActionEnhancedInternal<A extends ActionEnhancedDefinition = ActionEnhancedDefinition>
extends ActionInternal
implements ActionEnhanced<ActionEnhancedContext<A>> {
readonly licence = this.definition.licence;
readonly licence = this.definition.minimalLicense;
constructor(public readonly definition: A, protected getLicense: () => ILicense) {
super(definition);
}

hasCompatibleLicence() {
isCompatibleLicence() {
if (!this.licence) return true;
return this.getLicense().hasAtLeast(this.licence) && this.getLicense().isActive;
}

async isCompatible(context: ActionEnhancedContext<A>): Promise<boolean> {
if (!this.hasCompatibleLicence()) return false;
if (!this.isCompatibleLicence()) return false;
return super.isCompatible(context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,13 @@ const ActionFactorySelector: React.FC<ActionFactorySelectorProps> = ({
label={actionFactory.getDisplayName(context)}
data-test-subj={`${TEST_SUBJ_ACTION_FACTORY_ITEM}-${actionFactory.id}`}
onClick={() => onActionFactorySelected(actionFactory)}
disabled={!actionFactory.hasCompatibleLicence()}
betaBadgeIconType={!actionFactory.hasCompatibleLicence() ? 'lock' : undefined}
betaBadgeLabel={!actionFactory.hasCompatibleLicence() ? 'License' : undefined}
disabled={!actionFactory.isCompatibleLicence()}
betaBadgeIconType={!actionFactory.isCompatibleLicence() ? 'lock' : undefined}
betaBadgeLabel={!actionFactory.isCompatibleLicence() ? 'License' : undefined}
betaBadgeTooltipContent={
!actionFactory.hasCompatibleLicence() ? 'Insufficient license level' : undefined
!actionFactory.isCompatibleLicence()
? 'Upgrade your license to get access to this action'
: undefined
}
>
{actionFactory.getIconType(context) && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface DrilldownDefinition<
* Minimal licence level
* Empty means no restrictions
*/
licence?: LicenseType;
minimalLicense?: LicenseType;

/**
* Determines the display order of the drilldowns in the flyout picker.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const URL_DRILLDOWN = 'URL_DRILLDOWN';
export class UrlDrilldownDefinition implements DrilldownDefinition<Config, ActionContext> {
public readonly id = URL_DRILLDOWN;

public readonly licence = 'basic';
public readonly minimalLicense = 'gold';

public readonly order = 8;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ActionFactory<
) {}

public readonly id = this.def.id;
public readonly license = this.def.licence;
public readonly minimalLicense = this.def.minimalLicense;
public readonly order = this.def.order || 0;
public readonly MenuItem? = this.def.MenuItem;
public readonly ReactMenuItem? = this.MenuItem ? uiToReactComponent(this.MenuItem) : undefined;
Expand Down Expand Up @@ -52,16 +52,16 @@ export class ActionFactory<
return await this.def.isCompatible(context);
}

public hasCompatibleLicence() {
if (!this.def.licence) return true;
return this.getLicence().hasAtLeast(this.def.licence);
public isCompatibleLicence() {
if (!this.def.minimalLicense) return true;
return this.getLicence().hasAtLeast(this.def.minimalLicense) && this.getLicence().isActive;
}

public create(
serializedAction: Omit<SerializedAction<Config>, 'factoryId'>
): ActionEnhancedDefinition<ActionContext> {
return {
licence: this.license, // actions created with action factory inherit it's license requirements
minimalLicense: this.minimalLicense, // actions created with action factory inherit it's license requirements
...this.def.create(serializedAction),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface ActionFactoryDefinition<
* Minimal licence level
* Empty means no licence restrictions
*/
readonly licence?: LicenseType;
readonly minimalLicense?: LicenseType;

/**
* This method should return a definition of a new action, normally used to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ export class UiActionsServiceEnhancements {
euiIcon,
execute,
getHref,
licence,
minimalLicense,
}: DrilldownDefinition<Config, ExecutionContext>): void => {
const actionFactory: ActionFactoryDefinition<Config, object, ExecutionContext> = {
id: factoryId,
licence,
minimalLicense,
order,
CollectConfig,
createConfig,
Expand Down

0 comments on commit daf89fc

Please sign in to comment.