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

@directus-labs/multilevel-autocomplete-api-interface

v1.0.1

Published

Get data from nested API queries.

Downloads

117

Readme

Multilevel Autocomplete Interface

Get data from nested API queries.

An open dialog with multiple dropdowns

Installation

Refer to the Official Guide for details on installing the extension from the Marketplace or manually.

Usage

Add the Multilevel Autocomplete via the interface selector. Select either a Web Request or a List and fill in the corresponding fields that define how to load the initial step. Add items to the Nested Steps list to define additional steps. Lastly, define your Payload template to produce the final output.

Example

In this example, a fixed list of regions will be shown, and then a filtered list of countries will be shown as an autocomplete interface powered by an external API.

1. Initial List

When using a list as the initial source, you must provide a fixed set of values, each with a text and a value. The value can be a string of JSON object.

Create two items in the list (you can paste in the following as a raw value):

[
    {
        "text": "Europe",
        "value": "europe"
    },
    {
        "text": "Americas",
        "value": "americas"
    }
]

The value chosen will be stored as the first item in the values array that can be referenced in nested steps.

2. Filtered Autocomplete

Create a nested step which will use the selected region. Make a GET request to https://restcountries.com/v3.1/region/{{values[0]}}.

  • As this API returns the array of options directly, there is no need to provide a Requests Path.
  • Set the Text Path to name.common to use this value as the visible text for options.
  • Set the Value Path to cca2 as this the raw value to be used.

3. Structured Payload

Finally, set a payload that will be included in the raw data:

{
    "region": "{{ values[0] }}",
    "country": {
        "name": "{{ steps[1].text }}",
        "code": "{{ steps[1].value }}"
    }
}

4. Outcome

In use, the interface will first show a dropdown with two options - Europe and Americas. Using the external API, the nested step will show an autocomplete interface of countries filtered by the value chosen.

The raw data includes text and value for all steps, and the defined payload structure:

{
    "steps": [{
        "text": "Europe",
        "value": "europe"
    }, {
        "text": "United Kingdom",
        "value": "GB"
    }],
    "payload": {
        "region": "europe",
        "country": {
            "name": "United Kingdom",
            "code": "GB"
        }
    }
}

Calling the Items API

You can use this extension with the REST API generated for your Directus Project.

This allows for filtered inputs based on your own project's data using the filter and search parameters.

When configuring the request, you must include your full Directus project URL.