Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make a few code style improvements #1608

Merged
merged 1 commit into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ ignore = [
"EM102", # Exception must not use an f-string literal, assign to variable first
"ERA001", # Found commented-out code
"FIX001", # Line contains FIXME, consider resolving the issue
"FIX002", # Line contains TODO, consider resolving the issue
"ISC001", # Implicitly concatenated strings on a single line # Disabled for formatter compatibility
"N802", # Function name should be lowercase
"N803", # Argument name should be lowercase
Expand Down
60 changes: 28 additions & 32 deletions src/ims/element/static/field_report.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ async function initFieldReportPage() {
}
});

// Updates...it's fine to ignore the returned promise here
requestEventSourceLock();
// Fire-and-forget this promise, since it tries forever to acquire a lock
let ignoredPromise = requestEventSourceLock();

const fieldReportChannel = new BroadcastChannel(fieldReportChannelName);
fieldReportChannel.onmessage = async function (e) {
Expand Down Expand Up @@ -312,40 +312,36 @@ async function editSummary() {

async function makeIncident() {
// Create the new incident
{
const incidentsURL = urlReplace(url_incidents);
const incidentsURL = urlReplace(url_incidents);

const authors = [];
if (fieldReport.report_entries?.length > 0) {
authors.push(fieldReport.report_entries[0].author);
}
let {resp, err} = await fetchJsonNoThrow(incidentsURL, {
body:{
"summary": fieldReport.summary,
"ranger_handles": authors,
},
})
if (err != null) {
disableEditing();
setErrorMessage(`Failed to create incident: ${err}`);
return;
}
fieldReport.incident = parseInt(resp.headers.get("X-IMS-Incident-Number"));
const authors = [];
if (fieldReport.report_entries?.length > 0) {
authors.push(fieldReport.report_entries[0].author);
}
let {resp, err} = await fetchJsonNoThrow(incidentsURL, {
body:{
"summary": fieldReport.summary,
"ranger_handles": authors,
},
})
if (err != null) {
disableEditing();
setErrorMessage(`Failed to create incident: ${err}`);
return;
}
fieldReport.incident = parseInt(resp.headers.get("X-IMS-Incident-Number"));

// Attach this FR to that new incident
{
const attachToIncidentUrl =
`${urlReplace(url_fieldReports)}${fieldReport.number}` +
`?action=attach;incident=${fieldReport.incident}`;
let {err} = await fetchJsonNoThrow(attachToIncidentUrl, {
body: {},
});
if (err != null) {
disableEditing();
setErrorMessage(`Failed to attach field report: ${err}`);
return;
}
const attachToIncidentUrl =
`${urlReplace(url_fieldReports)}${fieldReport.number}` +
`?action=attach;incident=${fieldReport.incident}`;
let {attachErr} = await fetchJsonNoThrow(attachToIncidentUrl, {
body: {},
});
if (attachErr != null) {
disableEditing();
setErrorMessage(`Failed to attach field report: ${attachErr}`);
return;
}
console.log("Created and attached to new incident " + fieldReport.incident);
await loadAndDisplayFieldReport();
Expand Down
4 changes: 2 additions & 2 deletions src/ims/element/static/field_reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ function initFieldReportsTable() {
enableEditing();
}

// it's ok to ignore the returned promise
requestEventSourceLock();
// Fire-and-forget this promise, since it tries forever to acquire a lock
let ignoredPromise = requestEventSourceLock();
const fieldReportChannel = new BroadcastChannel(fieldReportChannelName);
fieldReportChannel.onmessage = function (e) {
if (e.data["update_all"]) {
Expand Down
18 changes: 8 additions & 10 deletions src/ims/element/static/incident.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ async function initIncidentPage() {
}
});

// Updates...it's good to ignore the returned promise here
requestEventSourceLock();
// Fire-and-forget this promise, since it tries forever to acquire a lock
let ignoredPromise = requestEventSourceLock();

const incidentChannel = new BroadcastChannel(incidentChannelName);
incidentChannel.onmessage = async function (e) {
Expand Down Expand Up @@ -291,12 +291,13 @@ async function loadAllFieldReports() {
return {err: null};
}

async function loadFieldReport(fieldReportNumber, success) {
async function loadFieldReport(fieldReportNumber) {
if (allFieldReports === undefined) {
return;
}

const {resp, json, err} = await fetchJsonNoThrow(urlReplace(url_fieldReport).replace("<field_report_number>", fieldReportNumber))
const {resp, json, err} = await fetchJsonNoThrow(
urlReplace(url_fieldReport).replace("<field_report_number>", fieldReportNumber));
if (err != null) {
if (resp.status !== 403) {
const message = `Failed to load field report ${fieldReportNumber} ${err}`;
Expand Down Expand Up @@ -781,11 +782,10 @@ async function sendEdits(edits) {
});

if (err != null) {
const message = "Failed to apply edit";
console.log(message + ": " + err);
const message = `Failed to apply edit: ${err}`;
await loadAndDisplayIncident();
setErrorMessage(message);
return {err: err}
return {err: message}
}

if (number == null) {
Expand Down Expand Up @@ -1035,13 +1035,11 @@ async function detachFieldReport(sender) {

async function attachFieldReport() {
if (incidentNumber == null) {
// Incident doesn't exist yet. Create it and then retry.
// Incident doesn't exist yet. Create it first.
const {err} = await sendEdits({});
if (err != null) {
return;
}
await attachFieldReport();
return;
}

const select = $("#attached_field_report_add");
Expand Down
4 changes: 2 additions & 2 deletions src/ims/element/static/incidents.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ function initIncidentsTable() {
enableEditing();
}

// ok to ignore returned Promise...have the tab wait for the lock
requestEventSourceLock();
// Fire-and-forget this promise, since it tries forever to acquire a lock
let ignoredPromise = requestEventSourceLock();
const incidentChannel = new BroadcastChannel(incidentChannelName);
incidentChannel.onmessage = async function (e) {
if (e.data["update_all"]) {
Expand Down
Loading