datopian / ckanext-iaea

Custom extension for IAEA CKAN
GNU Affero General Public License v3.0
0 stars 1 forks source link

Present predefined filters to end users #27

Closed sagargg-zz closed 2 years ago

sagargg-zz commented 3 years ago

As a Data Publisher, I can define suggested fields for filtering data so that when users land on the page they are prompted with those fields in the filters component.

Acceptance criteria

Tasks

Analysis

The view object would have an additional attribute for storing suggested fields for filtering:

Data Explorer view:

{
  "description": "",
  "title": "My view title",
  "resource_id": "xxx",
  "view_type": "dataexplorer_view",
  "id": "xxx",
  "package_id": "xxx"
}

Data Explorer - Table only view:

{
  "description": "",
  "title": "Table",
  "resource_id": "xxx",
  "view_type": "dataexplorer_table_view",
  "id": "xxx",
  "package_id": "xxx"
}

We can add suggested_filter_fields attribute so that:

{
  "description": "",
  "title": "My view title",
  "resource_id": "xxx",
  "view_type": "dataexplorer_view",
  "id": "xxx",
  "package_id": "xxx",
  "suggested_filter_fields": ["column a", "column b"]
}

On "create view" page, we need to add another option to add suggested filter fields which can unchecked checkboxes with column names so that admin checks the fields that should be suggested for filtering.

Make sure the suggested_filter_fields is converted to rules.

Next, is to parse it and use as initial state in the query builder app:

  1. Create a new fixture for Cosmos in Datastore Query Builder app. The resource object can be something like:
import { QueryBuilder } from '../src/App.js'

const resource = {
  name: 'test',
  id: 'some-random-id',
  path: 'https://montreal-staging-site.ca/datastore/dump/some-random-id',
  schema: {
    fields: [
      {
        name: 'a',
        type: 'string'
      },
      {
        name: 'b',
        type: 'string'
      },
      {
        name: 'c',
        type: 'string'
      }
    ]
  },
  rules: [{
      'combinator': 'AND',
      'field': 'xx',
      'operator': '=',
      'value': 'x'
    },
    {
      'combinator': 'AND',
      'field': 'xxx',
      'operator': '<',
      'value': 'x'
    }],
  date: {
     startDate: null,
     endDate: null,
     fieldName: 'xxx'
   } 
 }

const filterBuilderAction = (resource) => {
  alert(JSON.stringify(resource))
}

export default {
  component: QueryBuilder,
  props: {resource, filterBuilderAction}
};
  1. Change this line https://github.com/datopian/datastore-query-builder/blob/master/src/DatastoreSearchSql.js#L89 to:
rules: resource.rules || [],
  1. Test it in Cosmos.
sagargg-zz commented 3 years ago

@anuveyatsu I have added an example of rules on fixtures. As you see there iscombinator, operator, and value property. What we will set there on the initial state?

We also need to pass the date state cuz the query builder has a separate state for the date type field.

anuveyatsu commented 3 years ago

@sagargg let's set defaults:

combinator: "AND"
operator: "="
value: ""
sagargg commented 2 years ago

DONE