Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

F/search package #161

Closed
wants to merge 20 commits into from
Closed

F/search package #161

wants to merge 20 commits into from

Conversation

pranavkulkarni
Copy link
Contributor

Module to search for ArcGIS items and format them for display in ArcGIS Hub

Structure --

src
  ago
    helpers
      aggs
      filters
      format
      page
      sort
    search.ts // searches for items and returns raw ago results
    params.ts // defines ISearchParams interface to hub.js/search
    serialize.ts // serialize raw UI params into query parameters that V3 understands
    format-item-collection.ts // format raw ago results into hub v3 style datasets
    compute-items-facets.ts // compute aggs/facets based on ago results and also calculate aggs for custom facets

Sample of how this will be used in UI code --

const authentication = new arcgisRest.UserSession({
      portal: 'https://qaext.arcgis.com/sharing/rest',
      username: 'dcadminqa',
      password: 'dcadminqa1'
    })
    const portal = 'https://qaext.arcgis.com/sharing/rest'
    const params = {
      q: 'crime',
      sort: 'name',
      agg: { fields: 'tags,collection,owner,source,hasApi,downloadable' },
      start: 1,
      num: 10
    }
    authentication.getToken(portal)
    .then(token => {
      const headers = { authorization: token, portal }
      const serializedParams = arcgisHub.serialize(params)
      console.log(serializedParams)
      return fetch(`hub.arcgis.com/api/v3/search?${serializedParams}`, { headers })
    })
    .then(unifiedResultsPromise => {
      return unifiedResultsPromise.json()
    })
    .then(unifiedResults => {
      console.log(unifiedResults)
      // UPDATE UI model with unified results
    })

Sample of how hub indexer api v3 new search route will use hub.js --

   const search = require('@esri/hub-search')

  // 1. perform ago search with facets and formatting
  const agoResults = await search.agoSearch(req.query, req.headers.authorization, req.headers.portal)

  // 2. compute items facets
  const facets = await search.computeItemsFacets(agoResults.aggregations, req.query, req.headers.authorization, req.headers.portal)

  // 3. format item collection based on actual search results and computed facets
  const model = search.agoFormatItemCollection(agoResults, facets, req.query)

  return model

Copy link
Contributor

@jgravois jgravois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hero's work @pranavkulkarni. this PR is really coming along.

besides my new comments, most everything in my first review still applies too.

@@ -0,0 +1,61 @@
{
"name": "@esri/hub-search",
"version": "1.10.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.11.1 (just so lerna will know to help us bump to v2.0.0)

{
"name": "@esri/hub-search",
"version": "1.10.0",
"description": "Module to search for ArcGIS items and format them for display in ArcGIS Hub.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might be helpful to state explicitly that we're using this as a server-side module.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, we will be using this on front end too.

test.html Outdated
@@ -0,0 +1,78 @@
<!DOCTYPE html>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't want to check this one in.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is there in .gitignore. Not sure why it has appeared 😕

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you overrode the .gitignore at some point with an explicit git add test.html.

luckily you can git rm test.html too.

@@ -0,0 +1,9 @@
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2019.

@@ -0,0 +1,29 @@
import { IRequestOptions } from "@esri/arcgis-rest-request";

/* Copyright (c) 2017 Environmental Systems Research Institute, Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2017 > 2019 (and move to the top of the file).

/* Copyright (c) 2017 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

export interface ISearchParams extends IRequestOptions {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ISearchOptions (see #152 (comment))


const downloadableTypeKeywords = ["Data"];
// eligible types are listed here: http://doc.arcgis.com/en/arcgis-online/reference/supported-items.htm
const downloadableTypes = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whether you keep this type in common or search, lets keep it DRY.

}

// eligible types are listed here: http://doc.arcgis.com/en/arcgis-online/reference/supported-items.htm
const downloadableTypes = [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given what we already started in @esri/hub-common, would it make more sense to export this type from there?

* require more complex and customized logic. Those go in the `customFacets` hash,
* where the name of the key is the name of the facet being computed and the custom function
* is implemented below.
*/
Copy link
Contributor

@jgravois jgravois May 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code comment isn't being picked up by TSDoc.

Screen Shot 2019-05-01 at 9 20 25 AM

for an example of method documentation that's formatted for display in our documentation, see:

/**
* ```js
* import { addAnnotations } from "@esri/hub-annotations";
* //
* addAnnotations({
* url: annotationsUrl + "/0",
* features: [{
* attributes: {
* target: "http://...", // required, explains what is being commented on
* description: "A grand idea!" // also required. this is the actual comment
* }
* }]
* })
* .then(response);
* ```
* Add an annotation to ArcGIS Hub. Uses authentication to derive authorship, appends a timestamp and sets a default status of "pending" to new comments by default.
* @param requestOptions - request options that may include authentication
* @returns A Promise that will resolve with the response from the service after attempting to add one or more new annotations.
*/
export function addAnnotations(
requestOptions: IAddAnnotationsRequestOptions
): Promise<IAddFeaturesResult> {

you can run npm run docs:serve to build the documentation locally and see it update live as you make changes to the raw source.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! I will fix that

* Construct a query object with filters, and queryParams sent by hub indexer
* @param queryObject any
*/
export function encodeAgoQuery(queryParams: any = {}) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all exported functions show up in the documentation unless they are added to the explicit blacklist below.

i think it'd be appropriate to hide a lot of your shared utility functions, but i'll leave it up to you to decide exactly which.

const blacklist = [];

const blacklist = [ "encodeAgoQuery", "etc" ];

@jgravois jgravois requested a review from tomwayson May 1, 2019 16:34
@jgravois
Copy link
Contributor

jgravois commented May 8, 2019

now that v2.0.0 has shipped, we'll land this from #152

@jgravois jgravois closed this May 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants