Skip to content

Commit 93e2e82

Browse files
Copilotmartinemde
andcommitted
Format all JavaScript files with Prettier
Co-authored-by: martinemde <[email protected]>
1 parent e5fb141 commit 93e2e82

24 files changed

Lines changed: 463 additions & 399 deletions

app/javascript/application.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Configure your import map in config/importmap.rb. Read more: https://github.com/rails/importmap-rails
2-
import "@hotwired/turbo-rails"
3-
Turbo.session.drive = false
2+
import "@hotwired/turbo-rails";
3+
Turbo.session.drive = false;
44

55
import Rails from "@rails/ujs";
66
Rails.start();
77

8-
import LocalTime from "local-time"
9-
LocalTime.start()
8+
import LocalTime from "local-time";
9+
LocalTime.start();
1010

11-
import "controllers"
11+
import "controllers";
1212

1313
import "src/oidc_api_key_role_form";
1414
import "src/pages";

app/javascript/avo.custom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { application } from "controllers/application"
1+
import { application } from "controllers/application";
22

33
import NestedForm from "stimulus-rails-nested-form";
44
application.register("nested-form", NestedForm);
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { Application } from "@hotwired/stimulus"
2-
import Clipboard from '@stimulus-components/clipboard'
3-
import CheckboxSelectAll from '@stimulus-components/checkbox-select-all'
1+
import { Application } from "@hotwired/stimulus";
2+
import Clipboard from "@stimulus-components/clipboard";
3+
import CheckboxSelectAll from "@stimulus-components/checkbox-select-all";
44

5-
const application = Application.start()
5+
const application = Application.start();
66

77
// Add vendored controllers
8-
application.register('clipboard', Clipboard)
9-
application.register('checkbox-select-all', CheckboxSelectAll)
8+
application.register("clipboard", Clipboard);
9+
application.register("checkbox-select-all", CheckboxSelectAll);
1010

1111
// Configure Stimulus development experience
12-
application.debug = false
13-
window.Stimulus = application
12+
application.debug = false;
13+
window.Stimulus = application;
1414

15-
export { application }
15+
export { application };

app/javascript/controllers/autocomplete_controller.js

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,30 @@
1-
import { Controller } from "@hotwired/stimulus"
1+
import { Controller } from "@hotwired/stimulus";
22

33
// TODO: Add suggest help text and aria-live
44
// https://accessibility.huit.harvard.edu/technique-aria-autocomplete
55
export default class extends Controller {
6-
static targets = ["query", "suggestions", "template", "item"]
7-
static classes = ["selected"]
6+
static targets = ["query", "suggestions", "template", "item"];
7+
static classes = ["selected"];
88

99
connect() {
1010
this.indexNumber = -1;
1111
this.suggestLength = 0;
1212
}
1313

14-
disconnect() { this.clear() }
14+
disconnect() {
15+
this.clear();
16+
}
1517

1618
clear() {
17-
this.suggestionsTarget.classList.add('hidden');
18-
this.suggestionsTarget.innerHTML = ""
19-
this.suggestionsTarget.removeAttribute('tabindex');
20-
this.suggestionsTarget.removeAttribute('aria-activedescendant');
19+
this.suggestionsTarget.classList.add("hidden");
20+
this.suggestionsTarget.innerHTML = "";
21+
this.suggestionsTarget.removeAttribute("tabindex");
22+
this.suggestionsTarget.removeAttribute("aria-activedescendant");
2123
}
2224

2325
hide(e) {
2426
// Allows adjusting the cursor in the input without hiding the suggestions.
25-
if (!this.queryTarget.contains(e.target)) this.clear()
27+
if (!this.queryTarget.contains(e.target)) this.clear();
2628
}
2729

2830
next() {
@@ -42,8 +44,8 @@ export default class extends Controller {
4244
// On mouseover, highlight the item, shifting the index,
4345
// but don't change the input because it causes an undesireable feedback loop.
4446
highlight(e) {
45-
this.indexNumber = this.itemTargets.indexOf(e.currentTarget)
46-
this.focusItem(e.currentTarget, false)
47+
this.indexNumber = this.itemTargets.indexOf(e.currentTarget);
48+
this.focusItem(e.currentTarget, false);
4749
}
4850

4951
choose(e) {
@@ -57,19 +59,21 @@ export default class extends Controller {
5759
const term = el.value.trim();
5860

5961
if (term.length >= 2) {
60-
el.classList.remove('autocomplete-done');
61-
el.classList.add('autocomplete-loading');
62-
const query = new URLSearchParams({ query: term })
62+
el.classList.remove("autocomplete-done");
63+
el.classList.add("autocomplete-loading");
64+
const query = new URLSearchParams({ query: term });
6365

6466
try {
65-
const response = await fetch('/api/v1/search/autocomplete?' + query, { method: 'GET' })
66-
const data = await response.json()
67-
this.showSuggestions(data.slice(0, 10))
68-
} catch (error) { }
69-
el.classList.remove('autocomplete-loading');
70-
el.classList.add('autocomplete-done');
67+
const response = await fetch("/api/v1/search/autocomplete?" + query, {
68+
method: "GET",
69+
});
70+
const data = await response.json();
71+
this.showSuggestions(data.slice(0, 10));
72+
} catch (error) {}
73+
el.classList.remove("autocomplete-loading");
74+
el.classList.add("autocomplete-done");
7175
} else {
72-
this.clear()
76+
this.clear();
7377
}
7478
}
7579

@@ -79,27 +83,31 @@ export default class extends Controller {
7983
return;
8084
}
8185
items.forEach((item, idx) => this.appendItem(item, idx));
82-
this.suggestionsTarget.setAttribute('tabindex', 0);
83-
this.suggestionsTarget.setAttribute('role', 'listbox');
84-
this.suggestionsTarget.classList.remove('hidden');
86+
this.suggestionsTarget.setAttribute("tabindex", 0);
87+
this.suggestionsTarget.setAttribute("role", "listbox");
88+
this.suggestionsTarget.classList.remove("hidden");
8589

8690
this.suggestLength = items.length;
8791
this.indexNumber = -1;
88-
};
92+
}
8993

9094
appendItem(text, idx) {
9195
const clone = this.templateTarget.content.cloneNode(true);
92-
const li = clone.querySelector('li')
96+
const li = clone.querySelector("li");
9397
li.textContent = text;
9498
li.id = `suggest-${idx}`;
95-
this.suggestionsTarget.appendChild(clone)
99+
this.suggestionsTarget.appendChild(clone);
96100
}
97101

98102
focusItem(el, change = true) {
99-
if (!el) { return; }
100-
this.itemTargets.forEach(el => el.classList.remove(...this.selectedClasses))
103+
if (!el) {
104+
return;
105+
}
106+
this.itemTargets.forEach((el) =>
107+
el.classList.remove(...this.selectedClasses)
108+
);
101109
el.classList.add(...this.selectedClasses);
102-
this.suggestionsTarget.setAttribute('aria-activedescendant', el.id);
110+
this.suggestionsTarget.setAttribute("aria-activedescendant", el.id);
103111
if (change) {
104112
this.queryTarget.value = el.textContent;
105113
this.queryTarget.focus();
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
import { Controller } from "@hotwired/stimulus"
1+
import { Controller } from "@hotwired/stimulus";
22

33
export default class extends Controller {
4-
static targets = ["counter", "checked"]
4+
static targets = ["counter", "checked"];
55

66
connect() {
7-
this.update()
7+
this.update();
88
}
99

1010
checkedTargetConnected(el) {
11-
el.addEventListener("change", this.update.bind(this))
12-
el.addEventListener("input", this.update.bind(this)) // input emitted by checkbox-select-all controller
11+
el.addEventListener("change", this.update.bind(this));
12+
el.addEventListener("input", this.update.bind(this)); // input emitted by checkbox-select-all controller
1313
}
1414

1515
checkedTargetdisconnected(el) {
16-
el.removeEventListener("change", this.update.bind(this))
17-
el.removeEventListener("input", this.update.bind(this))
16+
el.removeEventListener("change", this.update.bind(this));
17+
el.removeEventListener("input", this.update.bind(this));
1818
}
1919

2020
update() {
21-
const count = this.checkedTargets.filter(el => el.checked).length
22-
this.counterTarget.textContent = count
21+
const count = this.checkedTargets.filter((el) => el.checked).length;
22+
this.counterTarget.textContent = count;
2323
}
2424
}
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
import Dialog from '@stimulus-components/dialog'
1+
import Dialog from "@stimulus-components/dialog";
22

33
export default class extends Dialog {
4-
static targets = ["dialog", "button"]
4+
static targets = ["dialog", "button"];
55

66
connect() {
7-
super.connect()
8-
this.setAriaExpanded('false')
7+
super.connect();
8+
this.setAriaExpanded("false");
99
}
1010

1111
open(e) {
12-
super.open()
13-
e.preventDefault()
14-
this.setAriaExpanded('true')
12+
super.open();
13+
e.preventDefault();
14+
this.setAriaExpanded("true");
1515
}
1616

1717
close(e) {
18-
super.close()
19-
e.preventDefault()
20-
this.setAriaExpanded('false')
18+
super.close();
19+
e.preventDefault();
20+
this.setAriaExpanded("false");
2121
}
2222

2323
setAriaExpanded(expanded) {
2424
if (this.hasButtonTarget) {
25-
this.buttonTarget.setAttribute('aria-expanded', expanded)
25+
this.buttonTarget.setAttribute("aria-expanded", expanded);
2626
}
2727
}
2828
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import { Controller } from "@hotwired/stimulus"
1+
import { Controller } from "@hotwired/stimulus";
22

33
// I tested the stimulus-dropdown component but it has too many deps.
44
// This mimics the basic stimulus-dropdown api, so we could swap it in later.
55
export default class extends Controller {
6-
static targets = ["menu"]
6+
static targets = ["menu"];
77

88
hide(e) {
99
!this.element.contains(e.target) &&
1010
!this.menuTarget.classList.contains("hidden") &&
11-
this.menuTarget.classList.add('hidden');
11+
this.menuTarget.classList.add("hidden");
1212
}
1313

1414
toggle(e) {
1515
e.preventDefault();
16-
this.menuTarget.classList.toggle('hidden');
16+
this.menuTarget.classList.toggle("hidden");
1717
}
1818
}

app/javascript/controllers/dump_controller.js

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,46 @@
1-
import { Controller } from "@hotwired/stimulus"
1+
import { Controller } from "@hotwired/stimulus";
22

33
export default class extends Controller {
4-
static targets = ["list", "template"]
4+
static targets = ["list", "template"];
55

66
connect() {
77
this.getDumpData();
88
}
99

1010
getDumpData() {
11-
fetch('https://s3-us-west-2.amazonaws.com/rubygems-dumps/?prefix=production/public_postgresql')
12-
.then(response => response.text())
13-
.then(data => {
11+
fetch(
12+
"https://s3-us-west-2.amazonaws.com/rubygems-dumps/?prefix=production/public_postgresql"
13+
)
14+
.then((response) => response.text())
15+
.then((data) => {
1416
const parser = new DOMParser();
1517
const xml = parser.parseFromString(data, "application/xml");
1618
const files = this.parseS3Listing(xml);
1719
this.render(files);
1820
})
19-
.catch(error => {
21+
.catch((error) => {
2022
console.error(error);
2123
});
2224
}
2325

2426
parseS3Listing(xml) {
25-
const contents = Array.from(xml.getElementsByTagName('Contents'));
26-
return contents.map(item => {
27+
const contents = Array.from(xml.getElementsByTagName("Contents"));
28+
return contents.map((item) => {
2729
return {
28-
Key: item.getElementsByTagName('Key')[0].textContent,
29-
LastModified: item.getElementsByTagName('LastModified')[0].textContent,
30-
Size: item.getElementsByTagName('Size')[0].textContent,
31-
StorageClass: item.getElementsByTagName('StorageClass')[0].textContent
30+
Key: item.getElementsByTagName("Key")[0].textContent,
31+
LastModified: item.getElementsByTagName("LastModified")[0].textContent,
32+
Size: item.getElementsByTagName("Size")[0].textContent,
33+
StorageClass: item.getElementsByTagName("StorageClass")[0].textContent,
3234
};
3335
});
3436
}
3537

3638
render(files) {
3739
files
38-
.filter(item => 'STANDARD' === item.StorageClass)
40+
.filter((item) => "STANDARD" === item.StorageClass)
3941
.sort((a, b) => Date.parse(b.LastModified) - Date.parse(a.LastModified))
40-
.forEach(item => {
41-
let text = `${item.LastModified.replace('.000Z', '')} (${this.bytesToSize(item.Size)})`;
42+
.forEach((item) => {
43+
let text = `${item.LastModified.replace(".000Z", "")} (${this.bytesToSize(item.Size)})`;
4244
let uri = `https://s3-us-west-2.amazonaws.com/rubygems-dumps/${item.Key}`;
4345
this.appendItem(text, uri);
4446
});
@@ -50,13 +52,15 @@ export default class extends Controller {
5052
const a = clone.querySelector("a");
5153
span.textContent = text;
5254
a.href = uri;
53-
this.element.appendChild(clone)
55+
this.element.appendChild(clone);
5456
}
5557

5658
bytesToSize(bytes) {
57-
if (bytes === 0) { return '0 Bytes' }
59+
if (bytes === 0) {
60+
return "0 Bytes";
61+
}
5862
const k = 1024;
59-
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
63+
const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
6064
const i = Math.floor(Math.log(bytes) / Math.log(k));
6165
return (bytes / Math.pow(k, i)).toPrecision(3) + " " + sizes[i];
6266
}

0 commit comments

Comments
 (0)