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

sel-esri-custom-table

v2.0.2

Published

## Overview

Downloads

156

Readme

useWithAdvanceSearch Hook

Overview

The useWithAdvanceSearch hook is designed to manage state for dynamic fields in a React application. It uses data from a feature layer and a time query to fetch unique field values and update the state accordingly.

Installation

To use this hook in your project, ensure you have the required dependencies:

npm install sel-esri-advance-search

Usage Component

The ESRIAdvanceSearch component can be used directly in your React application as shown below:

import ESRIAdvanceSearch from 'esri-advance-search';

const MyComponent = ({ featureLayer, autocompleteFields, setFinalQuery }) => {
  return (
    <ESRIAdvanceSearch
      featureLayer={featureLayer}
      timeQuery={"Proj_Start_Year <= 2026 AND Proj_End_Year >= 2017"}
      autocompleteFields={autocompleteFields}
      setFinalQuery={setFinalQuery}
    />
  );
};

Usage Custom Hook

You can use the useWithAdvanceSearch custom hook for more control over the advanced search functionalities and get the attributes from the advance search.

import { useWithAdvanceSearch } from 'esri-advance-search';

const MyComponent = ({ featureLayer, autocompleteFields, setFinalQuery }) => {
  const { fetchFeatures } = useWithAdvanceSearch({
    featureLayer,
    timeQuery: "Proj_Start_Year <= 2026 AND Proj_End_Year >= 2017",
    autocompleteFields,
    setFinalQuery,
  });

  // Example usage of fetchFeatures
  useEffect(() => {
    const fetchData = async () => {
      // pass query to fetchFeatures()
      const features = await fetchFeatures("Proj_Status = 'Active'");
    };
    fetchData();
  }, [fetchFeatures]);

  return <div>My ESRI Advanced Search Component</div>;
};

API ESRIAdvanceSearch

Props:

  • featureLayer (Object): The ESRI Feature Layer to be queried.
  • timeQuery (string): The time-based query string.
  • autocompleteFields (Array): Array of fields for autocompletion.
  • setFinalQuery (function): Function to set the final query string.

useWithAdvanceSearch

Parameters:

  • featureLayer (Object): The ESRI Feature Layer to be queried.
  • timeQuery (string): The time-based query string.
  • autocompleteFields (Array): Array of fields for autocompletion.
  • setFinalQuery (function): Function to set the final query string.

Returns:

  • state (Object): State object with keys corresponding to the autocompleteFields array.
  • autocompleteData (Array): Array containing autocomplete data.
  • setAutocompleteData (function): Function to update the autocomplete data.
  • fetchFeatures (function): Function to fetch features based on a query string.

Example

Here's a more detailed example demonstrating the usage of useWithAdvanceSearch:

import React, { useState } from 'react';
import { useWithAdvanceSearch } from 'esri-advance-search';

const MyComponent = ({ featureLayer }) => {
  const [finalQuery, setFinalQuery] = useState('');
  const autocompleteFields = ['Project_Name', 'Project_Manager'];

  const { state, autocompleteData, setAutocompleteData, fetchFeatures } = useWithAdvanceSearch({
    featureLayer,
    timeQuery: "Proj_Start_Year <= 2026 AND Proj_End_Year >= 2017",
    autocompleteFields,
    setFinalQuery,
  });

  const handleSearch = async () => {
    const features = await fetchFeatures(finalQuery);
  };

  return (
    <div>
      <button onClick={handleSearch}>Search</button>
      {/* Render UI based on state and autocompleteData */}
    </div>
  );
};

Important Notes

Ensure the featureLayer prop is valid and not null before using the hook. The hook will fetch and update field values whenever featureLayer, autocompleteData, timeQuery, or autocompleteFields change. You can manage autocompleteData using the provided setAutocompleteData function.

Error Handling

If there is an error updating the fields, it will be logged to the console with the message: "Error updating fields:"

Development

CI/CD Pipeline Diagram

Publishing the Package

To publish the npm package, follow these steps:

  1. Update the version in package.json:
{
    "version": "1.0.3"
}
  1. Commit your changes and push to GitHub:
git add .
git commit -m "Update version to 1.0.3"
git push origin main
  1. Create a Release on GitHub
  2. Go to the Releases page of your repository.
  3. Click on Draft a new release.
  4. Fill out the form:
  5. Tag version: v1.0.3
  6. Release title: v1.0.3
  7. Description: Describe the changes in this release.
  8. Click Publish release.
  9. Check on the Actions tab to see full workflow.
  10. Confirm it was published.