Skip to content

Commit

Permalink
Moving from '@rails/ujs' to the new '@rails/request.js'
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumebriday committed Oct 12, 2021
1 parent 23697f7 commit 053465c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.1.0] - 2021-10-12

### Chore

- Moving from `@rails/ujs` to the new `@rails/request.js`

## [3.0.0] - 2021-10-11

### Chore
Expand Down
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"@babel/preset-env": "^7.15.8",
"@babel/preset-typescript": "^7.15.0",
"@hotwired/stimulus": "^3.0.1",
"@rails/ujs": "^6.1.4-1",
"@types/rails__ujs": "^6.0.1",
"@rails/request.js": "^0.0.5",
"@types/sortablejs": "^1.10.7",
"np": "^7.5.0",
"prettier-standard": "16.4.1",
Expand All @@ -35,7 +34,7 @@
},
"peerDependencies": {
"@hotwired/stimulus": "^3.0.1",
"@rails/ujs": "^6.1.4-1",
"@rails/request.js": "^0.0.5",
"sortablejs": "^1.14.0"
}
}
12 changes: 4 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Controller } from '@hotwired/stimulus'
import Sortable from 'sortablejs'
import * as Rails from '@rails/ujs'
import { patch } from '@rails/request.js'

export default class extends Controller {
animationValue: number
Expand Down Expand Up @@ -37,19 +37,15 @@ export default class extends Controller {
this.sortable = undefined
}

end ({ item, newIndex }) {
if (!item.dataset.sortableUpdateUrl || !window._rails_loaded) return
async end ({ item, newIndex }) {
if (!item.dataset.sortableUpdateUrl) return

const param = this.resourceNameValue ? `${this.resourceNameValue}[${this.paramNameValue}]` : this.paramNameValue

const data = new FormData()
data.append(param, newIndex + 1)

Rails.ajax({
url: item.dataset.sortableUpdateUrl,
type: 'PATCH',
data
})
await patch(item.dataset.sortableUpdateUrl, { body: data })
}

get options (): Sortable.Options {
Expand Down
13 changes: 4 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1158,10 +1158,10 @@
"@nodelib/fs.scandir" "2.1.3"
fastq "^1.6.0"

"@rails/ujs@^6.1.4-1":
version "6.1.4-1"
resolved "https://registry.yarnpkg.com/@rails/ujs/-/ujs-6.1.4-1.tgz#37507fe288a1c7c3a593602aa4dea42e5cb5797f"
integrity sha512-Fewm2wHk1n6Kf4E86dzzHDJOFg4EWcSHH3FsMEGs59bTdmf7099mjkOssOQtBqju4R39iaAOQNui7r8P+Q5Dgg==
"@rails/request.js@^0.0.5":
version "0.0.5"
resolved "https://registry.yarnpkg.com/@rails/request.js/-/request.js-0.0.5.tgz#5ea896085f1c82bacca0e32aa918c8cd003a3d30"
integrity sha512-EDw3d5oCSPFn/os7C41+61urT5J5n+bMXK2NTQVhJI8VCPAIVbvFGjZIQI0a9zJ9KuaWKHM6IjXTRakKemlzoA==

"@samverschueren/stream-to-observable@^0.3.0", "@samverschueren/stream-to-observable@^0.3.1":
version "0.3.1"
Expand Down Expand Up @@ -1259,11 +1259,6 @@
resolved "https://registry.yarnpkg.com/@types/parse-json/-/parse-json-4.0.0.tgz#2f8bb441434d163b35fb8ffdccd7138927ffb8c0"
integrity sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==

"@types/rails__ujs@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/@types/rails__ujs/-/rails__ujs-6.0.1.tgz#83c5aa1dad88ca869de05a9523eff58041ab307a"
integrity sha512-CVwNOdzTQ9qn6X6HPwx6ikH1T9ueJTdfjwFlXFhGvzXsQuESUksibfSosgxs1D/Q1kVEpjxeXD2RzqJv0Ma5Gw==

"@types/responselike@*":
version "1.0.0"
resolved "https://registry.yarnpkg.com/@types/responselike/-/responselike-1.0.0.tgz#251f4fe7d154d2bad125abe1b429b23afd262e29"
Expand Down

0 comments on commit 053465c

Please sign in to comment.