API Documentation

source

An object containing information to source data. This should include the necessary properties for querying the data source. Data can be sourced from a static file (typically a CSV file stored locally or available on the web), a Directus API, or a custom API.

  • Object
  • Required
  • Default: null

If a static file is used, the source object should implement the path2data property, structued as a key: value object with a single path key poniting to the static file path, eg.:

{
  path2data: {
    path: "path/to/data.csv"
  }
}

If a Directus API is used, the source object should implement the directus property, structured as a key: value object with the following keys:

  • endpoint: Optional Directus endpoint. It can be omitted if env variable GATSBY_DIRECTUS_ENDPOINT is set.
  • table: Required Directus table name.
  • queryString: Optional Directus filters and other, provided as querystring compatible to Directus API.
  • token: Optional Directus access token. It can be omitted if env variable GATSBY_DIRECTUS_TOKEN is set.
  • id: Optional Id of a specific record to retrieve. Required for record data displaying.
  • geoField: Field that contains geographical data to display on map.

Example:

{
  directus: {
    endPoint: "https://example.com/directus",
    table: "my_table",
    queryString: "filter[my_field][_eq]=something&limit=-1",
    token: "my-random-string-access-token",
    id: "id-oth-the-record-to-display",
    geoField:"coordinates",
  }
}

Finally, if a custom API is used, the source object should implement the customApi property, structured as an object with the following keys:

  • formatUrl: Required function to format the URL. It accepts a string as a parameter and should return a string rappresenting the URL to get data from
  • parseResponse: Required function to parse the response. it accepts the response object and should return the data to display on the map.

Example:

{
  customApi: {
    formatUrl: (searchString) => {
      return `https://api.example.com/search?q=${searchString}`;
    },    
    parseResponse: (response) => {
      return response.data;
    }
  }
}

resultItemTemplate

A template function to render each result item. This function receives an item from the search results and should return a React element.

  • Function
  • Required
  • Default: null

resultsHeaderTemplate

Template function to render the header of the results. Default is a simple header in English with the number of results.

  • Function
  • Optional
  • Default:
    tot => ( <> <h1 className="mt-5">Results</h1> <p className="text-secondary">{tot} records found</p> </> )

fieldList

An object defining the fields available for querying. It can be a plain key-value object, where the key is the field name and the value is the label to display in the UI. But it can also be a key-object object where the key is the field name and the value is an object with the following properties:

{
  "field_name": {
    label: "Field label",
    values: ["Value 1", "Value 2", "Value 3"],
  }
}

The label key will be used to display the field name in the UI, while the values key will be used to display a dropdown with predefined values for the field.

  • Object
  • Required
  • Default: null

operators

An object containing the identifiers of the operators (keys) and the labels to use for the UI. This can be used to overwrite the default options, for example, to have the UI translated in a different language, or to provided a their limited list.

  • Object
  • Optional
  • Default:
{
  "_eq": "Equals",
  "_neq": "Doesn't equal",
  "_lt": "Less  than",
  "_lte": "Less than or equal to",
  "_gt": "Greater than",
  "_gte": "Greater than or equal to",
  "_null": "Is null",
  "_nnull": "Isn't null",
  "_contains": "Contains",
  "_icontains": "Contains (case-insensitive)",
  "_ncontains": "Doesn't contain",
  "_starts_with": "Starts with",
  "_istarts_with": "Starts with (case-insensitive)",
  "_nstarts_with": "Doesn't start with",
  "_nistarts_with": "Doesn't start with (case-insensitive)",
  "_ends_with": "Ends with",
  "_iends_with": "Ends with (case-insensitive)",
  "_nends_with": "Doesn't end with",
  "_niends_with": "Doesn't end with (case-insensitive)",
  "_empty": "Is empty",
  "_nempty": "Isn't empty"
}

connector

An object containing the logical connectors (keys) and the labels to use for the UI. This can be used to overwrite the default value, for example, to have the UI translated in a different language.

  • Object
  • Optional
  • Default:
{
  "_and": "AND",
  "_or": "OR"
}

onSearchRun

A hook function that will be called when the search is run. It receives the search parameters as an object.

  • Function
  • Optional
  • Default: null

limitTo

Limit the search UI to a simple or advanced version. Default is "simple".

  • String: "simple" | "advanced"
  • Optional
  • Default: "simple"
LAD: Laboratorio di Archeologia Digitale alla Sapienza

Built with ♥ with s:CMS v5.0.1 by LAD @Sapienza

s:CMS è un progetto ideato e sviluppato dal
LAD: Laboratorio di Archeologia Digitale alla Sapienza
Code | Issues