Skip to content

Commit

Permalink
chore(Admin): Run prettier on js files
Browse files Browse the repository at this point in the history
Adjust the syntax of all admin js files to
prettier config.
  • Loading branch information
tvdeyen committed Dec 19, 2024
1 parent a70fcf9 commit 4f79ff7
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static values = {
cookie: String
cookie: String,
}

setCookie(event) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Controller } from '@hotwired/stimulus'
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static targets = ["addresses"]

close() {
this.addressesTarget.removeAttribute('open')
this.addressesTarget.removeAttribute("open")
}
}
4 changes: 2 additions & 2 deletions admin/app/components/solidus_admin/orders/show/component.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller } from '@hotwired/stimulus'
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
closeMenus() {
this.element.querySelectorAll('details').forEach(details => details.removeAttribute('open'))
this.element.querySelectorAll("details").forEach((details) => details.removeAttribute("open"))
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Controller } from '@hotwired/stimulus'
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static values = { customersUrl: String }

async search({ detail: { query, controller } }) {
controller.resultsValue =
(await (await fetch(`${this.customersUrlValue}?q[name_or_variants_including_master_sku_cont]=${query}`)).text())
controller.resultsValue = await (
await fetch(`${this.customersUrlValue}?q[name_or_variants_including_master_sku_cont]=${query}`)
).text()
}

submit(event) {
event.detail.resultTarget.querySelector('form').submit()
event.detail.resultTarget.querySelector("form").submit()
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { Controller } from '@hotwired/stimulus'
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static values = {
initialCountOnHand: Number,
}

static targets = ['countOnHand', 'quantityAdjustment']
static targets = ["countOnHand", "quantityAdjustment"]

connect() {
this.updateCountOnHand()
}

updateCountOnHand() {
this.countOnHandTarget.value = parseInt(this.initialCountOnHandValue) + parseInt(this.quantityAdjustmentTarget.value)
this.countOnHandTarget.value =
parseInt(this.initialCountOnHandValue) + parseInt(this.quantityAdjustmentTarget.value)
}
}
6 changes: 3 additions & 3 deletions admin/app/components/solidus_admin/ui/dropdown/component.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Controller } from '@hotwired/stimulus'
import { useClickOutside } from 'stimulus-use'
import { Controller } from "@hotwired/stimulus"
import { useClickOutside } from "stimulus-use"

export default class extends Controller {
connect() {
Expand All @@ -11,6 +11,6 @@ export default class extends Controller {
}

close() {
this.element.removeAttribute('open')
this.element.removeAttribute("open")
}
}
11 changes: 5 additions & 6 deletions admin/app/components/solidus_admin/ui/forms/address/component.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller } from '@hotwired/stimulus'
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static targets = ["country", "state", "stateName", "stateWrapper", "stateNameWrapper"]
Expand All @@ -7,8 +7,8 @@ export default class extends Controller {
const countryId = this.countryTarget.value

fetch(`/admin/countries/${countryId}/states`)
.then(response => response.json())
.then(data => {
.then((response) => response.json())
.then((data) => {
this.updateStateOptions(data)
})
}
Expand All @@ -30,13 +30,12 @@ export default class extends Controller {
const stateSelect = this.stateTarget
const stateName = this.stateNameTarget


if (showSelect) {
// Show state select dropdown.
stateSelect.disabled = false
stateName.value = ""
stateWrapper.classList.remove('hidden')
stateNameWrapper.classList.add('hidden')
stateWrapper.classList.remove("hidden")
stateNameWrapper.classList.add("hidden")
} else {
// Show state name text input if no states to choose from.
stateSelect.disabled = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { Controller } from '@hotwired/stimulus'
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static values = {
customValidity: String,
}

connect() {
if (this.customValidityValue)
this.element.setCustomValidity(this.customValidityValue)
if (this.customValidityValue) this.element.setCustomValidity(this.customValidityValue)
}

clearCustomValidity() {
this.element.setCustomValidity('')
this.element.setCustomValidity("")
}
}
4 changes: 2 additions & 2 deletions admin/app/components/solidus_admin/ui/modal/component.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Controller } from "@hotwired/stimulus";
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
connect() {
this.element.showModal();
this.element.showModal()
}
}
28 changes: 12 additions & 16 deletions admin/app/components/solidus_admin/ui/table/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export default class extends Controller {
const shouldSetSortable = this.sortableValue && this.modeValue !== "batch" && this.modeValue !== "search"

if (shouldSetSortable) {
this.tableBodyTarget.setAttribute('data-controller', 'sortable')
this.tableBodyTarget.setAttribute("data-controller", "sortable")
} else {
this.tableBodyTarget.removeAttribute('data-controller')
this.tableBodyTarget.removeAttribute("data-controller")
}
}

Expand All @@ -54,13 +54,13 @@ export default class extends Controller {
}

clearSearch() {
this.searchFieldTarget.value = ''
this.searchFieldTarget.value = ""
this.search()
}

resetSearchAndFilters() {
if (this.hasFilterToolbarTarget) {
this.filterToolbarTarget.querySelectorAll('fieldset').forEach(fieldset => fieldset.disabled = true)
this.filterToolbarTarget.querySelectorAll("fieldset").forEach((fieldset) => (fieldset.disabled = true))
}

this.searchFieldTarget.disabled = true
Expand All @@ -70,7 +70,7 @@ export default class extends Controller {
selectRow(event) {
if (this.checkboxTargets.some((checkbox) => checkbox.checked)) {
this.modeValue = "batch"
} else if (this.hasSearchFieldTarget && (this.searchFieldTarget.value !== '')) {
} else if (this.hasSearchFieldTarget && this.searchFieldTarget.value !== "") {
this.modeValue = "search"
} else if (this.hasScopesToolbarTarget) {
this.modeValue = "scopes"
Expand All @@ -84,7 +84,7 @@ export default class extends Controller {
selectAllRows(event) {
if (event.target.checked) {
this.modeValue = "batch"
} else if (this.hasSearchFieldTarget && (this.searchFieldTarget.value !== '')) {
} else if (this.hasSearchFieldTarget && this.searchFieldTarget.value !== "") {
this.modeValue = "search"
} else if (this.hasScopesToolbarTarget) {
this.modeValue = "scopes"
Expand All @@ -106,18 +106,18 @@ export default class extends Controller {
} else {
const url = new URL(event.params.url, "http://dummy.com")
const params = new URLSearchParams(url.search)
const frameId = params.get('_turbo_frame')
const frameId = params.get("_turbo_frame")
const frame = frameId ? { frame: frameId } : {}
// remove the custom _turbo_frame param from url search:
params.delete('_turbo_frame')
params.delete("_turbo_frame")
url.search = params.toString()

window.Turbo.visit(url.pathname + url.search, frame)
}
}

toggleCheckbox(row) {
const checkbox = this.checkboxTargets.find(selection => row.contains(selection))
const checkbox = this.checkboxTargets.find((selection) => row.contains(selection))

if (checkbox) {
checkbox.checked = !checkbox.checked
Expand All @@ -131,14 +131,10 @@ export default class extends Controller {

confirmAction(event) {
const message = event.params.message
.replace("${count}", this.selectedRows().length)
.replace(
"${count}",
this.selectedRows().length
).replace(
"${resource}",
this.selectedRows().length > 1 ?
event.params.resourcePlural :
event.params.resourceSingular
this.selectedRows().length > 1 ? event.params.resourcePlural : event.params.resourceSingular
)

if (!confirm(message)) {
Expand Down Expand Up @@ -167,7 +163,7 @@ export default class extends Controller {

// Update the rows background color
this.checkboxTargets.filter((checkbox) =>
checkbox.closest("tr").classList.toggle(this.selectedRowClass, checkbox.checked),
checkbox.closest("tr").classList.toggle(this.selectedRowClass, checkbox.checked)
)

// Update the selected rows count
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Controller } from '@hotwired/stimulus'
import { useClickOutside, useDebounce } from 'stimulus-use'
import { Controller } from "@hotwired/stimulus"
import { useClickOutside, useDebounce } from "stimulus-use"

const BG_GRAY = 'bg-gray-100'
const BG_GRAY = "bg-gray-100"

export default class extends Controller {
static targets = ['details', 'summary', 'option', 'checkbox', 'menu']
static debounces = ['init']
static targets = ["details", "summary", "option", "checkbox", "menu"]
static debounces = ["init"]

connect() {
useDebounce(this, { wait: 50 })
Expand Down Expand Up @@ -37,7 +37,7 @@ export default class extends Controller {
filterOptions(event) {
const query = event.currentTarget.value.toLowerCase()
this.optionTargets.forEach((option) => {
option.style.display = option.textContent.toLowerCase().includes(query) ? 'block' : 'none'
option.style.display = option.textContent.toLowerCase().includes(query) ? "block" : "none"
})
}

Expand All @@ -50,24 +50,26 @@ export default class extends Controller {
this.checkboxTargets.forEach((checkbox) => {
const hiddenElements = checkbox.parentElement.querySelectorAll("input[type='hidden']")
checkbox.checked
? hiddenElements.forEach(e => e.removeAttribute("disabled"))
: hiddenElements.forEach(e => e.setAttribute("disabled", true))
? hiddenElements.forEach((e) => e.removeAttribute("disabled"))
: hiddenElements.forEach((e) => e.setAttribute("disabled", true))
})
}

sortCheckboxes() {
const checkboxes = this.checkboxTargets

checkboxes.sort((a, b) => {
if (a.checked && !b.checked) return -1
if (!a.checked && b.checked) return 1
return 0
}).forEach(checkbox => {
this.menuTarget.appendChild(checkbox.closest('div'))
})
checkboxes
.sort((a, b) => {
if (a.checked && !b.checked) return -1
if (!a.checked && b.checked) return 1
return 0
})
.forEach((checkbox) => {
this.menuTarget.appendChild(checkbox.closest("div"))
})
}

isAnyCheckboxChecked() {
return this.checkboxTargets.some(checkbox => checkbox.checked)
return this.checkboxTargets.some((checkbox) => checkbox.checked)
}
}
6 changes: 3 additions & 3 deletions admin/app/components/solidus_admin/ui/toast/component.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Controller } from '@hotwired/stimulus'
import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static targets = ['closeButton']
static classes = ['animation']
static targets = ["closeButton"]
static classes = ["animation"]
static values = { transition: Number }

connect() {
Expand Down
26 changes: 14 additions & 12 deletions admin/app/components/solidus_admin/ui/toggletip/component.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import { Controller } from '@hotwired/stimulus'
import { useClickOutside } from 'stimulus-use'
import { Controller } from "@hotwired/stimulus"
import { useClickOutside } from "stimulus-use"

export default class extends Controller {
static targets = ['bubble']
static targets = ["bubble"]

connect () {
connect() {
useClickOutside(this)
this.open = false
}

clickOutside () {
clickOutside() {
this.close()
}

toggle (e) {
toggle(e) {
e.preventDefault()
this.open = !this.open
this.render()
}

open () {
open() {
this.open = true
this.render()
}

close () {
close() {
this.open = false
this.render()
}
Expand All @@ -35,10 +35,12 @@ export default class extends Controller {

if (needsPositioning) {
const bubbleRect = this.bubbleTarget.getBoundingClientRect()
if (bubbleRect.right > window.innerWidth) this.bubbleTarget.style.left = `${window.innerWidth - bubbleRect.width}px`
if (bubbleRect.bottom > window.innerHeight) this.bubbleTarget.style.top = `${window.innerHeight - bubbleRect.height}px`
if (bubbleRect.left < 0) this.bubbleTarget.style.left = '0px'
if (bubbleRect.top < 0) this.bubbleTarget.style.top = '0px'
if (bubbleRect.right > window.innerWidth)
this.bubbleTarget.style.left = `${window.innerWidth - bubbleRect.width}px`
if (bubbleRect.bottom > window.innerHeight)
this.bubbleTarget.style.top = `${window.innerHeight - bubbleRect.height}px`
if (bubbleRect.left < 0) this.bubbleTarget.style.left = "0px"
if (bubbleRect.top < 0) this.bubbleTarget.style.top = "0px"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ export default class extends Controller {
actionButtonClicked(event) {
const url = new URL(event.params.url, "http://dummy.com")
const params = new URLSearchParams(url.search)
const frameId = params.get('_turbo_frame')
const frameId = params.get("_turbo_frame")
const frame = frameId ? { frame: frameId } : {}
// remove the custom _turbo_frame param from url search:
params.delete('_turbo_frame')
params.delete("_turbo_frame")
url.search = params.toString()

window.Turbo.visit(url.pathname + url.search, frame)
Expand Down
Loading

0 comments on commit 4f79ff7

Please sign in to comment.