27.0.0 • Published 23 days ago

@splunk/dashboard-context v27.0.0

Weekly downloads
228
License
SEE LICENSE IN LI...
Repository
-
Last release
23 days ago

Splunk DashboardContext

Defines a context object to pass context consumers. This context object contains the following:

  • A pubsub event listener used for handling keyboard events (keyboardListener)
  • A static map for feature flags
  • Datasources' connection configuration (dataSourceContext),
  • Registry providers for images, icons, and geojson (imageRegistry, iconRegistry, geoRegistry)
  • Logger for error, warning and info level events (logger)
  • (userMessage) callback to execute application logic for user messaging

Icon, Image, GeoJson Registries

The Icon, Image, and Geo Registries are used to provide an interface to upload, list, retrieve, and remove artifacts from one or more providers. DashboardContext provides a localStorage-based reference provider, but applications are expected to implement their own interface to their storage mechanism of choice. More information about Registries and Providers can be found in @splunk/visualization-context.

Example:

import IconRegistry from '@splunk/dashboard-context/IconRegistry';
import LocalIconProvider from '@splunk/dashboard-context/LocalIconProvider';

const iconRegistry = IconRegistry.create();
iconRegistry.addDefaultProvider(new LocalIconProvider());

DataSource Context

This defines the common data needed by your dataSource implementation(s) in order to make queries.

Install

npm install @splunk/dashboard-context

    --or--

yarn add @splunk/dashboard-context

Usage

import DashboardContext, {
    DashboardContextProvider,
} from '@splunk/dashboard-context';
import EventListener from 'react-event-listener';

const Parent = () => <Child />;

class Child extends Component {
    static contextType = DashboardContext;

    componentDidMount() {
        // Add or overwrite keymap configurations
        this.context.keyboardListener.updateKeyMap({ showRespect: ['f'] });
        // Subscribe to events
        this.myEventUnsub = this.context.keyboardListener.subscribe(
            'myEvent',
            this.myEventHandler
        );
        this.respectUnsub = this.context.keyboardListener.subscribe(
            'showRespect',
            this.myEventHandler
        );
    }

    componentWillUnmount() {
        // Unsubscribe from events
        this.myEventUnsub();
        this.showRespectUnsub();
    }

    // Handle an event
    myEventHandler = (...data) => {
        console.log(...data);
    };

    // Publish an event on button click. This could happen in any component that is a DashboardContext consumer.
    // EventListener will fire event for key presses. This will cause keyboardListener to fire 'showRespect' when 'f' is pressed.
    render() {
        return (
            <>
                <EventListener
                    target="window"
                    onKeyDown={this.context.keyboardListener.handleKeyDown}
                />
                <span>Hello {this.context.hello}</span>
                <button
                    onClick={() =>
                        this.context.keyboardListener.publish(
                            'myEvent',
                            'click!'
                        )
                    }
                />
                {this.context.featureFlags.myFeatureFlag && (
                    <span>Feature is on</span>
                )}
            </>
        );
    }
}

const userMessageHandler = ({ level, message, sender, stackTrace }) => {
    /*
     * Example parameters supplied by Dashboard Framework:
     *  {
     *      level: 'error',
     *      message: 'Example message to deliver to user.',
     *      sender: 'GridLayout.jsx', // optional param.
     *      stackTrace: 'Example stack trace' // optional param.
     *  }
     *
     */

    /* example application defined behavior*/
    notifyUser(level, message, sender, stackTrace);
};

const GrandParent = () => {
    <DashboardContextProvider
        dataSourceContext={dsContext}
        featureFlags={{ myFeatureFlag: false }}
        geoRegistry={geoRegistry}
        iconRegistry={iconRegistry}
        imageRegistry={imageRegistry}
        userMessage={userMessageHandler}
    >
        <Parent />
    </DashboardContextProvider>;
};
25.1.5

23 days ago

26.6.3

24 days ago

26.0.3

24 days ago

26.6.2

25 days ago

26.2.5

25 days ago

27.0.0

25 days ago

26.6.1

26 days ago

26.6.0

2 months ago

26.2.4

3 months ago

26.5.0

3 months ago

26.4.0

4 months ago

26.3.0

6 months ago

25.1.4

6 months ago

25.1.3

9 months ago

26.2.3

6 months ago

26.2.2

6 months ago

26.2.1

8 months ago

26.2.0

8 months ago

26.1.1

9 months ago

26.1.0

9 months ago

25.3.1

6 months ago

26.0.2

6 months ago

26.0.1

9 months ago

26.0.0

10 months ago

25.4.0

12 months ago

25.3.0

1 year ago

25.2.0

1 year ago

25.1.2

1 year ago

25.1.1

1 year ago

25.1.0

1 year ago

24.3.2

1 year ago

24.3.1

1 year ago

25.0.0

2 years ago

24.9.2

2 years ago

24.9.1

2 years ago

24.9.0

2 years ago

24.8.0

2 years ago

24.5.0

2 years ago

24.7.0

2 years ago

24.6.0

2 years ago

24.4.0

2 years ago

24.3.0

2 years ago

24.2.0

2 years ago

24.1.1

2 years ago

24.1.0

2 years ago

23.6.0

2 years ago

23.5.0

2 years ago

24.0.0

2 years ago

23.4.0

3 years ago

23.3.0

3 years ago

23.2.0

3 years ago

23.1.0

3 years ago

23.0.0

3 years ago

22.4.0

3 years ago

22.3.0

3 years ago

22.2.0

3 years ago

22.1.0

3 years ago

22.0.0

3 years ago

21.1.2

3 years ago

21.1.1

3 years ago

21.1.0

3 years ago

21.0.0

3 years ago

20.8.2

3 years ago

20.8.1

3 years ago

20.8.0

3 years ago

20.7.0

3 years ago

20.6.0

3 years ago

20.5.2

3 years ago

20.5.1

3 years ago

20.5.0

3 years ago

20.4.0

3 years ago

20.3.1

3 years ago

20.3.0

3 years ago

20.2.0

3 years ago

20.1.0

4 years ago

20.0.0

4 years ago

19.1.0

4 years ago

19.0.0

4 years ago

18.4.0

4 years ago

18.3.1

4 years ago

18.3.0

4 years ago

18.2.0

4 years ago

18.1.1

4 years ago

18.1.0

4 years ago

18.0.0

4 years ago

17.0.0

4 years ago

16.0.0

4 years ago

15.1.0

4 years ago

15.0.1

4 years ago

15.0.0

4 years ago

14.2.0

4 years ago

14.1.0

4 years ago

14.0.0

4 years ago

13.1.0

4 years ago

13.0.0

4 years ago

12.0.0

4 years ago

11.0.0

4 years ago

10.0.0

4 years ago

9.5.0

4 years ago

9.4.0

4 years ago

9.3.0

4 years ago

9.2.0

4 years ago

9.1.0

4 years ago

9.0.0

4 years ago

8.4.0

4 years ago

8.3.0

4 years ago

8.2.0

4 years ago

8.1.0

5 years ago

8.0.4

5 years ago

8.0.3

5 years ago

8.0.2

5 years ago

8.0.1

5 years ago

8.0.0

5 years ago

7.4.1

5 years ago

3.1.0

5 years ago