Sha256: a5f1c6a445668dced4e4f627637fdd76ea5aa650888e0906b706a3464aa16c00

Contents?: true

Size: 1.12 KB

Versions: 36

Compression:

Stored size: 1.12 KB

Contents

import ServerRefreshController from './server-refresh-controller'
import { FetchRequest } from '@rails/request.js'

export default class extends ServerRefreshController {
  static values = {
    previousCriterionId: Number,
  }

  async criterion() {
    const isValid = await this.validateBlueprint()
    if (isValid) {
      this.state.addCriterion(this.previousCriterionIdValue)
    }
    this.refreshFromServer({includeErrors: !isValid})
  }

  async group() {
    const isValid = await this.validateBlueprint()
    if (isValid) {
      this.state.addGroup()
    }
    this.refreshFromServer({includeErrors: !isValid})
  }

  async validateBlueprint(blueprint) {
    const { state } = this

    const request = new FetchRequest(
      "GET",
      this.state.validateBlueprintUrlValue,
      {
        query: {
          "refine_filters_builder[filter_class]": this.state.filterName,
          "refine_filters_builder[blueprint_json]": JSON.stringify(this.state.blueprint),
          "refine_filters_builder[client_id]": this.state.clientIdValue
        }
      }
    )
    const response = await request.perform()
    return response.ok
  }
}

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
refine-rails-2.13.3 app/javascript/controllers/refine/add-controller.js
refine-rails-2.13.2 app/javascript/controllers/refine/add-controller.js
refine-rails-2.13.1 app/javascript/controllers/refine/add-controller.js
refine-rails-2.13.0 app/javascript/controllers/refine/add-controller.js
refine-rails-2.12.2 app/javascript/controllers/refine/add-controller.js
refine-rails-2.12.1 app/javascript/controllers/refine/add-controller.js
refine-rails-2.12.0 app/javascript/controllers/refine/add-controller.js
refine-rails-2.11.12 app/javascript/controllers/refine/add-controller.js
refine-rails-2.11.11 app/javascript/controllers/refine/add-controller.js
refine-rails-2.11.10 app/javascript/controllers/refine/add-controller.js
refine-rails-2.11.9 app/javascript/controllers/refine/add-controller.js
refine-rails-2.11.8 app/javascript/controllers/refine/add-controller.js
refine-rails-2.11.6 app/javascript/controllers/refine/add-controller.js
refine-rails-2.11.5 app/javascript/controllers/refine/add-controller.js
refine-rails-2.11.4 app/javascript/controllers/refine/add-controller.js
refine-rails-2.11.3 app/javascript/controllers/refine/add-controller.js
refine-rails-2.11.2 app/javascript/controllers/refine/add-controller.js
refine-rails-2.11.1 app/javascript/controllers/refine/add-controller.js
refine-rails-2.11.0 app/javascript/controllers/refine/add-controller.js
refine-rails-2.10.1 app/javascript/controllers/refine/add-controller.js