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

@kong-ui-public/analytics-config-store

v0.8.21

Published

Cache analytics config information and conditionally render UI elements based on config.

Downloads

2,665

Readme

@kong-ui-public/analytics-config-store

Cache analytics config information and conditionally render UI elements based on config.

Features

This package provides a cache for analytics config information (including whether an organization has analytics, its data retention for various products, etc). It does not fetch the information itself; instead, it relies on an analytics bridge to issue the necessary API call. The cache ensures that the API call doesn't need to be repeated for every component that needs the information.

This package also provides a UI component, AnalyticsConfigCheck, which makes it easier to hide or show elements in the UI based on the analytics config stored in the cache.

Requirements

  • vue and pinia must be initialized in the host application.
  • A plugin providing an AnalyticsBridge must be installed in the root of the application.
    • This plugin must provide the necessary methods to adhere to the AnalyticsBridge interface defined in @kong-ui-public/analytics-utilities.

Usage

Install this package in the host app alongside the component that requires it, such as @kong-ui-public/dashboard-renderer or @kong-ui-public/analytics-metric-provider. The component will use this package without any further changes.

The config store uses the host app's Pinia instance, and must only be used after the host app has called createPinia. As long as the store is only accessed during component renders, this is guaranteed to be the case.

Note: Pinia and this package must be externalized (i.e., added to vite.config.ts's build.rollupOptions.external array). See notes in [1] and [2]. This ensures that the store uses the same instance of Pinia as the host app, rather than incorporating and using its own instance that never properly gets inited.

Direct use of the store

When the store is first instantiated, it makes a call to retrieve the org's analytics config (using the configFn from AnalyticsBridge). Because the AnalyticsBridge is injected using Vue's provide / inject mechanism, the store must be instantiated either from a component's setup block or by using app.runWithContext. Until the call to retrieve analytics config resolves, the store will return null for analyticsConfig and default values for the various computed properties.

The store exposes several computed properties that attempt to standardize common questions asked of an org's analytics config:

  • loading -- whether the call to retrieve config has resolved
  • longRetention -- whether the org has a long enough retention period to support features like trend queries.
  • defaultQueryTimeForOrg -- related to longRetention, this defines the length of time the app should query for contextual metrics.
  • analytics -- a boolean value for whether the org has analytics data.
  • percentiles -- a boolean value for whether the org's analytics data includes percentile metrics.

Note: to avoid unnecessary API calls, no queries should be issued until loading is false. Most analytics components support a queryReady property; it's a good idea to pass queryReady: !loading.

Using AnalyticsConfigCheck

To conditionally show or hide UI elements based on analytics config, use the included component:

<AnalyticsConfigCheck
  require-analytics
>
  This content is only shown if the current context has access to analytics.
  <template #fallback>
    This content is only shown if the current context does **not** have access to analytics.
  </template>
</AnalyticsConfigCheck>

The included component takes these properties:

  • require-analytics: only render the default slot if the config endpoint indicated support for analytics.
  • require-percentiles: only render the default slot if the config endpoint indicated support for percentiles specifically.

It's allowed, though redundant, to specify both properties. Doing so is equivalent to passing require-percentiles.

The component has two slots: default and fallback. The default slot is rendered if the check passes, and the fallback slot is rendered if the check fails. Both slots are empty by default.