npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

xcelerate-ui

v0.0.6

Published

An NPM package that I can install in my Twilio plugin which will give me access to several Xcelerate 3.x features.

Downloads

8

Readme

xcelerate-ui

NPM JavaScript Style Guide

UI wrapper for Xcelerate's portal framework.

Table of Contents

  1. Requirements
  2. Installation
  3. Usage
  4. Example 1
  5. Example 2
  6. Local Development
  7. Deployment
  8. License

Requirements

  • Xcelerate 3.x. This package is only compatible with Xcelerate 3.x. Because this uses Flex UI 2.x.x.
  • NPM version 8 or later. Type npm -v in your terminal to check which version you have.
  • Node version 16. Type node -v in your terminal to check which version you have.
  • Twilio CLI 5 or later. Refer to the Twilio CLI Quick Start Guide for installation instructions. (If you're using a Mac, use NPM for the CLI installation: npm install twilio-cli -g )
  • Flex Plugins CLI. Refer to the Flex Developer Documentation for installation instructions, and the Plugins CLI Reference for available commands. Mainly plugin-flex v6.x.x.

Installation

npm install xcelerate-ui --save

Usage

The purpose of this library is to expose:

It primarily utilizes four methods:

  • registerAction - used to register your own action
  • invokeAction - used to invoke an action
  • addListener - used before or after an action is invoked
  • replaceAction - used when an action is already registed in Xcelerate, to customize an existing action with your own logic

The container-ids file exposes the following enums: ContainerIds, RegistrableActions, and InvocableActions. (From the root directory: src > enums > container-ids.)

  • ContainerIds identify the container in which the plugin will be injected. A ContainerId is a required attribute of the <Portal> wrapper.
  • RegistrableActions are Xcelerate versions of existing actions in the Twilio Actions Framework. These actions are already registered with Xcelerate and perform the original action. Functionality for any action can be replaced with the .replaceAction() method.
  • InvocableActions are custom actions within Xcelerate.

Example 1

This example uses minimal copy-and-paste code for a sample plugin. It does not exemplify use of the <Portal> wrapper. For a more involved example, see Example 2.

  1. Create a sample Twilio Flex plugin. This generates a boilerplate with generic files, some of which are unused by this example and can be ignored or removed. Please note this example uses TypeScript.
# Start with a TypeScript template plugin with the create command
twilio flex:plugins:create plugin-sample-1 --install --typescript
  1. Copy and paste the code below into SamplePlugin.tsx. (From root: plugin-sample-1 > src > SamplePlugin.tsx. )
import React from "react";
import * as Flex from "@twilio/flex-ui";
import { RegistrableActions, InvocableActions } from "@xcelerate-ui/core";
import { FlexPlugin } from "flex-plugin";

const PLUGIN_NAME = "SamplePlugin";

Flex.Actions.replaceAction(
  RegistrableActions.SELECT_TASK,
  (payload: any, original: any) => {
    return new Promise<void>((resolve, reject) => {
      console.log(">>>>>xcelerateSelectTask", { payload });
      Flex.Actions.invokeAction(
        InvocableActions.UPDATE_IFRAME_URL,
        `https://loremipsum.io?sid=${payload.sid}`
      );
      resolve();
    });
  }
);

Flex.Actions.replaceAction(
  RegistrableActions.WRAPUP_TASK,
  (payload: any, original: any) => {
    return new Promise<void>((resolve, reject) => {
      console.log(">>>>>xcelerateWrapupTask", { payload });
      Flex.Actions.invokeAction(
        InvocableActions.UPDATE_IFRAME_URL,
        `https://waterfieldtech.com`
      );
      resolve();
    });
  }
);

export default class SamplePlugin extends FlexPlugin {
  constructor() {
    super(PLUGIN_NAME);
  }
  /**
   * This code is run when your plugin is being started
   * Use this to modify any UI components or attach to the actions framework
   *
   * @param flex { typeof Flex }
   * @param manager { Flex.Manager }
   */
  async init(flex: typeof Flex, manager: Flex.Manager): Promise<void> {
    // this.registerReducers(manager);
    const options: Flex.ContentFragmentProps = { sortOrder: -1 };
  }
}

Example 2

This second example uses containers and components more intricately and exemplifies use of the <Portal> wrapper. It models a more complex, more organized folder structure, generally appropriate for Flex plugins.

  1. Create a sample Twilio Flex plugin. This generates a boilerplate with generic files, some of which are unused by this example and can be ignored or removed. Please note this example uses TypeScript.
# Start with a TypeScript template plugin with the create command
twilio flex:plugins:create plugin-sample-2 --install --typescript
  1. Copy and paste the code below into SamplePlugin.tsx. (From root: plugin-sample-2 > src > SamplePlugin.tsx. )
import React from "react";
import * as Flex from "@twilio/flex-ui";
import { FlexPlugin } from "flex-plugin";
import { SamplePluginInit } from "./init/SamplePluginInit";

const PLUGIN_NAME = "SamplePlugin";

export default class SamplePlugin extends FlexPlugin {
  constructor() {
    super(PLUGIN_NAME);
  }

  /**
   * This code is run when your plugin is being started
   * Use this to modify any UI components or attach to the actions framework
   *
   * @param flex { typeof Flex }
   * @param manager { Flex.Manager }
   */
  init(flex: typeof Flex, manager: Flex.Manager) {
    new SamplePluginInit({ flex, manager });
  }
}
  1. Within the plugin-sample-2 > src directory, create an init directory. Within init, create a SamplePluginInit.tsx file. Copy and paste the code below into SamplePluginInit.tsx.
import React from "react";
import * as Flex from "@twilio/flex-ui";
import { RegistrableActions, InvocableActions } from "@xcelerate-ui/core";
import { ExampleComponentContainer } from "../components/ExampleComponent/ExampleComponent.Container";

interface SamplePluginInitProps {
  flex: typeof Flex;
  manager: Flex.Manager;
}

class SamplePluginInit {
  props: SamplePluginInitProps;

  constructor(props: SamplePluginInitProps) {
    this.props = props;
    this.initializeExampleComponent();
    this.updateIframeUrlOnSelectTask();
  }

  initializeExampleComponent = () => {
    // inject the ExampleComponentContainer into the DOM
    this.props.flex.AgentDesktopView.Panel2.Content.add(
      <ExampleComponentContainer key="main-example-component"></ExampleComponentContainer>,
      { sortOrder: -1 }
    );
  };

  updateIframeUrlOnSelectTask = () => {
    // create custom logic for xcelerateSelectTask
    this.props.flex.Actions.replaceAction(
      RegistrableActions.SELECT_TASK,
      (payload: any, original: any) => {
        return new Promise<void>((resolve, reject) => {
          // see payload associated with the selected task on the console
          console.log(">>>>>xcelerateSelectTask", { payload });
          // update the iframe url upon selecting the task
          Flex.Actions.invokeAction(
            InvocableActions.UPDATE_IFRAME_URL,
            `https://loremipsum.io?sid=${payload.sid}`
          );
          resolve();
        });
      }
    );
  };
}

export { SamplePluginInit };
  1. Within the plugin-sample-2 > src > components directory, create an ExampleComponent directory. Within ExampleComponent, create an ExampleComponent.Container.ts file. Copy and paste the code below into ExampleComponent.Container.ts.
import { connect } from "react-redux";
import { ExampleComponent } from "./ExampleComponent";

export const ExampleComponentContainer = connect()(ExampleComponent);
//mapStateToProps,
//mapDispatchToProps
  1. Within ExampleComponent directory, create an ExampleComponent.tsx file. Copy and paste the code below into ExampleComponent.tsx.
import React from "react";
import { ContainerIds, Portal } from "@xcelerate-ui/core";

interface ConfigState {
  loaded: boolean;
  [key: string]: boolean;
}

export class ExampleComponent extends React.Component<any> {
  render(): JSX.Element {
    // Portal a 'Hello world!' div into the RIGHT_PANEL ContainerId
    return (
      <>
        <Portal
          reduxKey="enableExampleComponent"
          reduxValue={true}
          containerId={ContainerIds.RIGHT_PANEL}
          config={{ loaded: true, enableExampleComponent: true } as ConfigState}
        >
          <div>Hello world!</div>
        </Portal>
        <div id={ContainerIds.RIGHT_PANEL}></div>
      </>
    );
  }
}

Local Development and Deployment

Refer to the Flex Plugins CLI documentation to run your plugin locally and to deploy and release your plugin.

License

MIT ©

Maintainer

Waterfield Technologies