File

libs/ngx-pfe/pfe-actions/pfe-actions.model.ts

Index

Properties

Properties

break
break: boolean
Type : boolean
Optional

If break is "true" and the action was executed (that means, no conditions or conditions returns true) The flow will be stopped and the next actions will not be executed

conditions
conditions: Conditions
Type : Conditions
Optional

A list of conditions under which the actions are executed

globalConfigId
globalConfigId: string
Type : string
Optional

Only valid on the navigation. Will spread the actions.

type
type: string
Type : string
Optional

A custom name unique for the action, for example, "UPDATE_STATE_VALUES" or "TRIGGER_SERVICE_ACTIVATORS"

import { PfeNestedActions } from './nested-actions/nested-actions.model';
import { BivariantCallbackFunction } from '../util/typescript/strict-function-types';
import { Conditions } from '../pfe-conditions/public-api';
import { PfeReloadPageActionConfig } from './reload-page/reload-page-action.model';
import { PfeResetStateActionConfig } from './reset-state/reset-state.model';
import { RewindHistoryActionConfig } from './rewind-history/rewind-history.model';
import { PfeTriggerServiceActivatorsActionConfig } from './trigger-service-activators/trigger-service-activators.model';
import { PfeUpdateStateOnBackendActionConfig } from './update-state-on-backend/update-state-on-backend.model';
import { PfeUpdateStateValuesActionConfig } from './update-state-values/update-state-values.model';

/**
 * These are the integrated default actions. Should be used as a basis for custom extensions in apps
 */
export type PfeActionConfig =
  | PfeTriggerServiceActivatorsActionConfig
  | PfeUpdateStateValuesActionConfig
  | PfeUpdateStateOnBackendActionConfig
  | RewindHistoryActionConfig
  | PfeReloadPageActionConfig
  | PfeResetStateActionConfig
  | PfeNestedActions<PfeActionConfig>
  | PfeCustomActionConfig;

// The following PfeCustomActionConfig is a bit of a workaround to allow custom actions to be
// configured in the default json schema, while keeping the validations for the default actions.
// We might be able to replace this with the if/else approach in the future, but for now this is fine.
// Important: When a new default action is added above, it also has to be listed in the @TJS-not here:

/**
 * @additionalProperties true
 */
export interface PfeCustomActionConfig extends PfeBaseActionConfig {
  /**
   * This is a placeholder for custom actions. It allows any type and additional properties to be configured.
   * @TJS-not {
            "enum": ["TRIGGER_SERVICE_ACTIVATORS", "UPDATE_STATE_VALUES", "PFE_UPDATE_STATE_ON_BACKEND", "PFE_REWIND_HISTORY", "PFE_RELOAD_PAGE", "PFE_RESET_STATE", "PFE_NESTED_ACTIONS"]
          }
   */
  type: string;
}

/**
 * On the global actions the "type" is mandatory and we don't allow the "globalConfigId" key
 */
export interface PfeGlobalAction extends Pick<PfeBaseActionConfig, Exclude<keyof PfeBaseActionConfig, 'globalConfigId'>> {
  type: string;
}

export interface PfeBaseActionConfig {
  /**
   *  A custom name unique for the action, for example, "UPDATE_STATE_VALUES" or "TRIGGER_SERVICE_ACTIVATORS"
   */
  type?: string;

  /**
   * A list of conditions under which the actions are executed
   */
  conditions?: Conditions;

  /**
   * If break is "true" and the action was executed (that means, no conditions or conditions returns true)
   * The flow will be stopped and the next actions will not be executed
   */
  break?: boolean;

  /**
   * Only valid on the navigation.
   * Will spread the actions.
   */
  globalConfigId?: string;
}

export interface GlobalActions<ACTION = PfeActionConfig> {
  [id: string]: ACTION;
}

/**
 * Actions have to implement this function.
 *
 * An action can return a boolean result to indicate if further execution should be stopped.
 * For example, this applies to a navigation that triggers an action.
 * If no boolean is returned, a positive (true) response is assumed.
 *
 * This works in a similar fashion as the Angular route guards with the difference that actions are not executed in parallel.
 * But: The break flag in the action config has to be set to true, to prevent further actions from being executed.
 *
 * If an exception is thrown by this function, the execution of the actions is aborted.
 * The function itself is responsible to handle things like a redirection to an error page, etc...
 */
export type PfeActionFunction = BivariantCallbackFunction<(actionConfig: PfeBaseActionConfig) => Promise<void | boolean>>;

export interface ExecutionResult {
  wasExecuted: boolean;
  actionResult: boolean;
}

results matching ""

    No results matching ""