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

Filters #10

Open
1 of 2 tasks
milewski opened this issue Oct 3, 2020 · 0 comments
Open
1 of 2 tasks

Filters #10

milewski opened this issue Oct 3, 2020 · 0 comments

Comments

@milewski
Copy link
Member

milewski commented Oct 3, 2020

For the frontend:

A list of available filters can be retrieved calling the following API:

GET -> /dashboard-api/:resource/filters

The response will include the filter-uri-key and a collection of fields

When sending the response back to the server to gather a filtered list of resource the user needs to follow the following steps:

Data structure:

{
 "filter-uri-key": { 
    "field-attribute": "value"
  }
}

It needs to be base64 encode before sending to the server, so a typical workflow would be as the following:

const filters = {
    'age-filter': {
        'range': '20-30'
    }
}

const encodedFilter =  btoa(JSON.stringify(filters))

GET -> /dashboard-api/:resource?filters=encodedFilter

For the backend:

On the backend, the filters are generally defined following this structure:

class KeywordFilter extends AbstractFilter
{
    public function apply(Builder $builder, FieldsData $value): Builder
    {
        return $builder->where('keywords', 'LIKE', '%' . $value->get('keyword') . '%');
    }

    public function fields(): array
    {
        return [
            new EditableField('Keyword'),
        ];
    }

}

and applied to a resource by returning an array of filters:

class PageResource extends AbstractResource
{

    public function filters(): array
    {
        return [
            new KeywordFilter(),
        ];
    }

}

Todo:

  • Validation of the fields within the filter
  • Authorization
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

No branches or pull requests

1 participant