-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore: Switch from Eslint to Standard
Because: - We only need a light touch with linting in our Stimulus Controllers. - We never make use of how configurable eslint is. This commit - Removes Eslint and its config file - Removes Babel and its config file - Adds Standard and fixes all the failing lint issues
- Loading branch information
1 parent
de0b832
commit 1e2e924
Showing
31 changed files
with
753 additions
and
1,620 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import { Controller } from '@hotwired/stimulus'; | ||
import { Controller } from '@hotwired/stimulus' | ||
|
||
export default class AnnouncementController extends Controller { | ||
static values = { | ||
expiresAt: String, | ||
id: Number, | ||
}; | ||
id: Number | ||
} | ||
|
||
dismiss() { | ||
const expiresAt = new Date(this.expiresAtValue).toUTCString(); | ||
document.cookie = `announcement_${this.idValue}=disabled; expires=${expiresAt}; path=/`; | ||
this.element.remove(); | ||
dismiss () { | ||
const expiresAt = new Date(this.expiresAtValue).toUTCString() | ||
document.cookie = `announcement_${this.idValue}=disabled; expires=${expiresAt}; path=/` | ||
this.element.remove() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,61 @@ | ||
import { Controller } from '@hotwired/stimulus'; | ||
import Sortable from 'sortablejs'; | ||
import { useMutation } from 'stimulus-use'; | ||
import { Controller } from '@hotwired/stimulus' | ||
import Sortable from 'sortablejs' | ||
import { useMutation } from 'stimulus-use' | ||
|
||
export default class extends Controller { | ||
static targets = ['item']; | ||
static targets = ['item'] | ||
|
||
static values = { | ||
canSort: { type: Boolean, default: false }, | ||
}; | ||
canSort: { type: Boolean, default: false } | ||
} | ||
|
||
connect() { | ||
connect () { | ||
if (this.canSortValue) { | ||
this.sortable = Sortable.create(this.element, { | ||
animation: 300, | ||
easing: 'cubic-bezier(0.61, 1, 0.88, 1)', | ||
disabled: true, | ||
}); | ||
disabled: true | ||
}) | ||
|
||
useMutation(this, { | ||
attributes: true, childList: true, subtree: true, attributeFilter: ['data-sort-code'], | ||
}); | ||
attributes: true, childList: true, subtree: true, attributeFilter: ['data-sort-code'] | ||
}) | ||
} | ||
} | ||
|
||
mutate(entries) { | ||
mutate (entries) { | ||
entries.forEach((mutation) => { | ||
if (mutation.type === 'attributes' && mutation.attributeName === 'data-sort-code') { | ||
this.sortItems(); | ||
this.sortItems() | ||
} | ||
}); | ||
}) | ||
} | ||
|
||
sortItems() { | ||
const items = Array.from(this.itemTargets); | ||
sortItems () { | ||
const items = Array.from(this.itemTargets) | ||
|
||
if (this.itemsAreSorted(items)) return; | ||
if (this.itemsAreSorted(items)) return | ||
|
||
const sortedItems = items.sort((a, b) => this.compareItems(a, b)).map((item) => item.dataset.id); | ||
this.sortable.sort(sortedItems, true); | ||
const sortedItems = items.sort((a, b) => this.compareItems(a, b)).map((item) => item.dataset.id) | ||
this.sortable.sort(sortedItems, true) | ||
} | ||
|
||
itemsAreSorted() { | ||
itemsAreSorted () { | ||
return this.itemSortCodes().every((sortCode, index, items) => { | ||
if (index === 0) return true; | ||
return sortCode <= items[index - 1]; | ||
}); | ||
if (index === 0) return true | ||
return sortCode <= items[index - 1] | ||
}) | ||
} | ||
|
||
itemSortCodes() { | ||
return this.itemTargets.map((item) => this.getSortCode(item)); | ||
itemSortCodes () { | ||
return this.itemTargets.map((item) => this.getSortCode(item)) | ||
} | ||
|
||
/* eslint-disable class-methods-use-this */ | ||
getSortCode(item) { | ||
return parseFloat(item.getAttribute('data-sort-code')) || 0; | ||
getSortCode (item) { | ||
return parseFloat(item.getAttribute('data-sort-code')) || 0 | ||
} | ||
|
||
compareItems(left, right) { | ||
return this.getSortCode(right) - this.getSortCode(left); | ||
compareItems (left, right) { | ||
return this.getSortCode(right) - this.getSortCode(left) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import { Controller } from '@hotwired/stimulus'; | ||
import debounce from 'debounce'; | ||
import { Controller } from '@hotwired/stimulus' | ||
import debounce from 'debounce' | ||
|
||
export default class Autosubmit extends Controller { | ||
initialize() { | ||
this.debouncedSubmit = debounce(this.debouncedSubmit.bind(this), 300); | ||
initialize () { | ||
this.debouncedSubmit = debounce(this.debouncedSubmit.bind(this), 300) | ||
} | ||
|
||
submit() { | ||
this.element.requestSubmit(); | ||
submit () { | ||
this.element.requestSubmit() | ||
} | ||
|
||
debouncedSubmit() { | ||
this.submit(); | ||
debouncedSubmit () { | ||
this.submit() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 16 additions & 18 deletions
34
app/javascript/controllers/chart_with_crosshair_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,39 @@ | ||
/* eslint-disable class-methods-use-this */ | ||
|
||
import { Interaction } from 'chart.js/auto'; | ||
import { CrosshairPlugin, Interpolate } from 'chartjs-plugin-crosshair'; | ||
import ChartController from './chart_controller'; | ||
import { Interaction } from 'chart.js/auto' | ||
import { CrosshairPlugin, Interpolate } from 'chartjs-plugin-crosshair' | ||
import ChartController from './chart_controller' | ||
|
||
export default class ChartWithCrosshairController extends ChartController { | ||
connect() { | ||
Interaction.modes.interpolate = Interpolate; | ||
super.connect(); | ||
connect () { | ||
Interaction.modes.interpolate = Interpolate | ||
super.connect() | ||
} | ||
|
||
chartTypePlugins() { | ||
return [CrosshairPlugin, Interpolate]; | ||
chartTypePlugins () { | ||
return [CrosshairPlugin, Interpolate] | ||
} | ||
|
||
chartTypePluginOptions() { | ||
chartTypePluginOptions () { | ||
return { | ||
tooltip: { | ||
mode: 'index', | ||
intersect: false, | ||
intersect: false | ||
}, | ||
crosshair: { | ||
line: { | ||
dashPattern: [5, 5], | ||
color: '#9ca3af', | ||
width: 1, | ||
width: 1 | ||
}, | ||
snap: { | ||
enabled: true, | ||
enabled: true | ||
}, | ||
zoom: { | ||
enabled: true, | ||
zoomboxBackgroundColor: 'rgba(66,133,244,0.2)', | ||
zoomboxBorderColor: '#48F', | ||
zoomButtonClass: 'hidden', | ||
}, | ||
}, | ||
}; | ||
zoomButtonClass: 'hidden' | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,16 @@ | ||
import { Controller } from '@hotwired/stimulus'; | ||
import { Controller } from '@hotwired/stimulus' | ||
|
||
export default class ClipboardController extends Controller { | ||
static targets = ['source', 'message']; | ||
static targets = ['source', 'message'] | ||
|
||
copy() { | ||
navigator.clipboard.writeText(this.sourceTarget.value); | ||
copy () { | ||
navigator.clipboard.writeText(this.sourceTarget.value) | ||
|
||
if (this.hasMessageTarget) { | ||
this.messageTarget.classList.remove('hidden'); | ||
this.messageTarget.classList.remove('hidden') | ||
setTimeout(() => { | ||
this.messageTarget.classList.add('hidden'); | ||
}, 2000); | ||
this.messageTarget.classList.add('hidden') | ||
}, 2000) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
import { Controller } from '@hotwired/stimulus'; | ||
import { Controller } from '@hotwired/stimulus' | ||
|
||
export default class CssToggleController extends Controller { | ||
static targets = ['element']; | ||
static targets = ['element'] | ||
|
||
static classes = ['from', 'to']; | ||
static classes = ['from', 'to'] | ||
|
||
toggle() { | ||
toggle () { | ||
this.elementTargets.forEach((element) => { | ||
element.classList.toggle(...this.toClasses); | ||
element.classList.toggle(...this.fromClasses); | ||
}); | ||
element.classList.toggle(...this.toClasses) | ||
element.classList.toggle(...this.fromClasses) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.