Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hammerstone/refine-stimulus

Package Overview
Dependencies
Maintainers
4
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hammerstone/refine-stimulus - npm Package Compare versions

Comparing version 2.4.2 to 2.4.3-0.1

17

CHANGELOG.md

@@ -0,1 +1,16 @@

### 2.4.3 (not yet released)
* features
* added generator for creating filters
* bugfix
* `Clause doesn't equal` and `clause not between` were not implemented for Date with time conditions. PR #98
* Add in missing has_error classes as specified by Tamik
* Fix raw_attribute bug for text conditions
* Clarified the installation documentation
* Included the StoredFilter class in the gem assuming that the client would override it as
necessary
* Default stored filters to false in filter_builder_dropdown
* Add automatically stabilize to the gem because it is always required
* Add the filter pill partial view to the gem (not to docs because CSS is still an issue)
* Set default stabilizers to be URL Encoded in filter.rb
### 2.4.2

@@ -136,2 +151,2 @@ * Update the configuration of stabilizer classes

* Add locales
* Add routes
* Add routes

2

package.json
{
"name": "@hammerstone/refine-stimulus",
"version":"2.4.2",
"version":"2.4.3",
"description": "Refine is a flexible query builder for your apps. It lets your users filter down to exactly what they're looking for. Completely configured on the backend.",

@@ -5,0 +5,0 @@ "browserslist": [

## How to integrate the refine filter
1. Add the gem
```
source "https://yourKey@gem.fury.io/hammerstonedev" do
gem "refine-rails"
end
```
Refer to the [installation instructions](/docs/installation.md)
2. Add the npm package
## Troubleshooting
### Stimulus package
Depending on how you import Stimulus Controllers and define `application` it may be `Stimulus.load(refineControllers)`
To confirm the Stimulus controllers are loaded, add `window.Stimulus=application` to `controllers/index.js`
Then in the console inspect the stimulus object:
```bash
$ yarn add @hammerstone/refine-stimulus
```
3. `bundle`
4. `yarn`
5. Import the Stimulus Controllers and style sheet in your application.
Typically this is in `app/javascript/controllers/index.js`
```javascript
import { controllerDefinitions as refineControllers } from "@hammerstone/refine-stimulus"
import "@hammerstone/refine-stimulus/app/assets/stylesheets/index.css";
application.load(refineControllers)
```
Depending on how you import Stimulus Controllers and define `application` it may be `Stimulus.load(refineControllers)`
### Troubleshooting Stimulus Controllers
To make sure the Stimulus controllers are loaded properly, add `window.Stimulus=application` to `controllers/index.js`
Then in the console inspect the stimulus object:
```bash
Stimulus.router.modulesByIdentifier
```
You should see the `refine--....` controllers listed
You should see the `refine--....` controllers listed.
**Note about the style sheet:**
### StyleSheets
Instead of importing the plain `index.css`, include the raw tailwind file in your app's tailwind-parsed source css files. Tailwind v3 is required for this.
Instead of importing the plain `index.css`, you can remove that line and instead, in your app's tailwind-parsed source css files, you can include the raw tailwind file. Tailwind v3 is required for this.
```css

@@ -48,51 +25,5 @@ /* in application.css */

6. Add jquery (necessary for our custom select elements)
`yarn add jquery`
Add to `index.js` or wherever you added your stimulus controllers
### Errors
You may have to restart your server if you encounter the error:
```
import jquery from 'jquery'
window.jQuery = jquery
window.$ = jquery
```
7. Implement a Filter class in `app/filters` that inherits from `Hammerstone::Refine::Filter`. Use this class to define the conditions that can be filtered.
Example (Contacts Filter on a Contact Model)
```ruby
# app/filters/contacts_filter.rb
class ContactsFilter < Hammerstone::Refine::Filter
include Hammerstone::Refine::Conditions
@@default_stabilizer = Hammerstone::Refine::Stabilizers::UrlEncodedStabilizer
def initial_query
Contact.all
end
def automatically_stabilize?
true
end
def table
Contact.arel_table
end
def conditions
[
TextCondition.new("name"),
DateCondition.new("created_at"),
DateCondition.new("updated_at"),
]
end
end
```
8. In your application controller, `include Hammerstone::FilterApplicationController` which is a helper class to get you up and running quickly. You can remove it and use your own `apply_filter` method if you want.
## Troubleshooting:
If you see this error:
```
NameError (uninitialized constant ApplicationController::Hammerstone

@@ -103,28 +34,16 @@ web |

Please restart your server!
## Custom configuration
### Define your own apply_filter_method
If you prefer, you can remove it and define your own `apply_filter`.
This is a helper method you can inspect in `Hammerstone::FilterApplicationController`. You probably *do not* want to use this method but want to implement your own. It will return `@refine_filter` which is generated from the stable_id. The `stable_id` comes in from the params when the form is submitted or the URL is directly changed.
9. In the controller you'd like to filter on, add the `apply_filter` method. For this example we'll use Contacts model and filter.
`@refine_filter = apply_filter(ContactsFilter)`
### Notes for Pagy/Jumpstart
**SIDE NOTE for Pagy/Jumpstart**
```
apply_filter(ContactsFilter, initial_query: (Contact.sort_by_params(params[:sort], sort_direction))
@pagy, @contacts = pagy(@refine_filter.get_query)
```
This is a helper method you can inspect in `Hammerstone::FilterApplicationController`. You probably *do not* want to use this method but want to implement your own. It will return `@refine_filter` which is generated from the stable_id. The `stable_id` comes in from the params when the form is submitted or the URL is directly changed.
```
10. Set the filter stabilized ENV var or credential.
If using rails credentials: EDITOR="subl --wait" bin/rails credentials:edit --environment development and set NAMESPACE_REFINE_STABILIZERS: 1
# TODO: Everything below this header was not covered in the installation guide. Not sure if it is deprecated
If using .env, application.yml or another gem set NAMESPACE_REFINE_STABILIZERS=1
11. Add the following to your index view to render a button that activates the filter:
```
<%= render partial: 'hammerstone/filter_builder_dropdown' %>
```
12. Add the `reveal` controller to your application if using the `filter_builder_dropdown` partial

@@ -325,2 +244,14 @@

Notes if linking with `yarn link` isn't working:
1. Ran `bin/webpack-dev-server`
2. In `berry-refine-demo-clean` delete node modules and re-yarn (just for fun probably not necessary)
3. in `refine-rails` repo follow all yalc steps below -> you should see this message if successful
```
@hammerstone/refine-stimulus@2.4.2 published in store.
Pushing @hammerstone/refine-stimulus@2.4.2 in /Users/colleenschnettler/Documents/Documents/Developer/Hammerstone/berry-refine-demo-clean
Package @hammerstone/refine-stimulus@2.4.2 linked ==> /Users/colleenschnettler/Documents/Documents/Developer/Hammerstone/berry-refine-demo-clean/node_modules/@hammerstone/refine-stimulus
```
4. Restart server
From this repo's directory:

@@ -390,6 +321,2 @@ We are using `yalc` for local package development.

### TODO
- Documentation for stored filters
## Readme Installation Goals (what we're working towards - does not work yet)

@@ -396,0 +323,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc