Skip to content

Commit

Permalink
Merge branch 'master' into cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wsanchez authored Mar 27, 2024
2 parents ba2da3d + 6355cf9 commit cad95ed
Show file tree
Hide file tree
Showing 39 changed files with 2,183 additions and 1,520 deletions.
52 changes: 52 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
settings:
react:
version: detect

env:
browser: true
es2021: true

extends:
- standard
- plugin:react/recommended

parserOptions:
ecmaVersion: latest
sourceType: module

plugins:
- react

overrides:
- files:
- "**/*.test.js"
- "**/*.test.jsx"
- "src/setupTests.js"
- "src/test/wait.js"
env:
jest: true

# https://eslint.org/docs/latest/rules/
rules:
comma-dangle:
- error
- always-multiline
generator-star-spacing: off
indent: off
multiline-ternary: off
no-unused-vars:
- error
- varsIgnorePattern: "^_"
args: none
quotes:
- error
- double
- avoidEscape: true
react/display-name: off
react/prop-types: off
react/react-in-jsx-scope: off
space-before-function-paren: off
semi:
- error
- always
no-var: error
2 changes: 1 addition & 1 deletion .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
run: npm test -- --ci --watchAll=false --coverage

- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v4.0.1
uses: codecov/codecov-action@v4.1.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage/coverage-final.json
Expand Down
3,059 changes: 1,829 additions & 1,230 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
},
"scripts": {
"start": "react-scripts start",
"lint": "eslint --ext .js,.jsx,.ts,.tsx .",
"lint:fix": "eslint --fix --ext .js,.jsx,.ts,.tsx .",
"build": "react-scripts build",
"test": "react-scripts test",
"test:debug": "react-scripts --inspect-brk test --runInBand --no-cache",
Expand Down Expand Up @@ -48,6 +50,12 @@
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^14.2.1",
"@testing-library/user-event": "^14.5.2",
"eslint": "^8.57.0",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-n": "^16.6.2",
"eslint-plugin-promise": "^6.1.1",
"eslint-plugin-react": "^7.34.1",
"fake-indexeddb": "^4.0.2",
"flush-promises": "^1.0.2",
"http-proxy-middleware": "^2.0.6"
Expand Down
2 changes: 1 addition & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const App = ({ ims, routerClass }) => {
return (
<Router>
<Suspense fallback={<Loading what="page" />}>
<IMSContext.Provider value={{ ims: ims }}>
<IMSContext.Provider value={{ ims }}>
<Routes>
{/* Redirect root to IMS */}
<Route path="/" element={<Navigate to={URLs.ims} />} />
Expand Down
2 changes: 1 addition & 1 deletion src/URLs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const imsURL = `/ims/`;
const imsURL = "/ims/";
const eventsURL = `${imsURL}events/`;
const adminURL = `${imsURL}admin/`;

Expand Down
2 changes: 1 addition & 1 deletion src/components/BagTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const BagTable = () => {

const [bag, setBag] = useState(undefined);

useBag({ setBag: setBag });
useBag({ setBag });

const urls = bag ? bag.urls : null;

Expand Down
2 changes: 1 addition & 1 deletion src/components/BagTable.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("BagTable component", () => {
});
console._suppressErrors();

const spy = jest.spyOn(console, "warn");
jest.spyOn(console, "warn");

renderWithIMSContext(<BagTable />, ims);
await waitForURLBag();
Expand Down
2 changes: 1 addition & 1 deletion src/components/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const Login = ({ children }) => {
async function onLogin(event) {
event.preventDefault();
try {
await ims.login(username, { password: password });
await ims.login(username, { password });
} catch (e) {
const errorMessage = e.message;
console.warn(`Login failed: ${errorMessage}`);
Expand Down
2 changes: 1 addition & 1 deletion src/components/base/LabeledSelect.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("LabeledSelect component", () => {
"valueToName ($values.length)",
({ values }) => {
const valueToName = (value) => {
if (value === undefined || value == "----") {
if (value === undefined || value === "----") {
return "----";
} else {
return "***" + value + "***";
Expand Down
10 changes: 6 additions & 4 deletions src/components/base/Select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import invariant from "invariant";

import Form from "react-bootstrap/Form";

const controlStatusTimeout = 1000;

const controlClearStatus = (control) => {
control.classList.remove("bg-warning");
control.classList.remove("bg-success");
Expand All @@ -19,13 +21,13 @@ const controlHadSuccess = (control) => {
controlClearStatus(control);
control.classList.add("bg-success");

setTimeout(() => controlClearStatus(control), 1000);
setTimeout(() => controlClearStatus(control), controlStatusTimeout);
};

const controlHadError = (control, timeout) => {
const controlHadError = (control) => {
console.debug("Control had error", control);
control.classList.add("bg-danger");
setTimeout(() => controlClearStatus(control), 1000);
setTimeout(() => controlClearStatus(control), controlStatusTimeout);
};

const controlDidChange = async (event, callback) => {
Expand Down Expand Up @@ -63,7 +65,7 @@ const Select = ({ id, width, value, setValue, values, valueToName }) => {
<Form.Select
id={id}
size="sm"
style={{ flex: "initial", width: width }}
style={{ flex: "initial", width }}
value={value}
onChange={onChange}
>
Expand Down
4 changes: 1 addition & 3 deletions src/components/base/Select.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import Label from "./Label";
import Select from "./Select";

describe("Select component", () => {
const values = ["1", "2", "3", "4"];

test.each(selectOptionValues())(
"start value selected ($values.length, $value)",
({ values, value }) => {
Expand All @@ -36,7 +34,7 @@ describe("Select component", () => {
"valueToName ($values.length, $value)",
({ values, value }) => {
const valueToName = (value) => {
if (value === undefined || value == "----") {
if (value === undefined || value === "----") {
return "----";
} else {
return "***" + value + "***";
Expand Down
5 changes: 5 additions & 0 deletions src/components/dispatch-queue/BottomToolBar.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import invariant from "invariant";

const BottomToolBar = ({ table, incidents }) => {
invariant(table != null, "table argument is required");
invariant(incidents != null, "incidents argument is required");

return "";
// return (
// <Row>
Expand Down
6 changes: 3 additions & 3 deletions src/components/dispatch-queue/DispatchQueue.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const DispatchQueue = ({ event }) => {
const [concentricStreetsByEvent, setConcentricStreetsByEvent] = useState();

useConcentricStreetsByEvent({
setConcentricStreetsByEvent: setConcentricStreetsByEvent,
setConcentricStreetsByEvent,
});

// Fetch incident data
Expand All @@ -35,8 +35,8 @@ const DispatchQueue = ({ event }) => {

useIncidents({
eventID: event.id,
setIncidents: setIncidents,
searchInput: searchInput,
setIncidents,
searchInput,
});

const table = useDispatchQueueTable(incidents, concentricStreetsByEvent);
Expand Down
14 changes: 9 additions & 5 deletions src/components/dispatch-queue/DispatchQueueTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,31 @@ export const DispatchQueueTable = ({ table, event }) => {
<Table striped hover id="queue_table" {...table.getTableProps()}>
<thead>
{table.headerGroups.map((headerGroup) => (
<tr {...headerGroup.getHeaderGroupProps()}>
<tr /* eslint-disable-line react/jsx-key */
{...headerGroup.getHeaderGroupProps()}
>
{headerGroup.headers.map((column) => (
<th {...column.getHeaderProps()}>
<th /* eslint-disable-line react/jsx-key */
{...column.getHeaderProps()}
>
{column.render("Header")}
</th>
))}
</tr>
))}
</thead>
<tbody {...table.getTableBodyProps()}>
{table.page.map((row, i) => {
{table.page.map((row, _i) => {
table.prepareRow(row);
return (
<tr
<tr /* eslint-disable-line react/jsx-key */
className="queue_incident_row"
onClick={() => handleRowClick(row.cells[0].value)}
{...row.getRowProps()}
>
{row.cells.map((cell) => {
return (
<td
<td /* eslint-disable-line react/jsx-key */
className={`queue_incident_${cell.column.id}`}
{...cell.getCellProps()}
>
Expand Down
4 changes: 2 additions & 2 deletions src/components/dispatch-queue/format.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ describe("Table cell formatting functions", () => {
});
const location = new Location({
name: "Treetop House",
address: address,
address,
});
const text = formatLocation(location, concentricStreets);
expect(text).toEqual(
Expand All @@ -256,7 +256,7 @@ describe("Table cell formatting functions", () => {
radialHour: 8,
radialMinute: 37,
});
const location = new Location({ address: address });
const location = new Location({ address });
const text = formatLocation(location, concentricStreets);
expect(text).toEqual(`${formatAddress(address, concentricStreets)}`);
});
Expand Down
6 changes: 3 additions & 3 deletions src/components/incident/Incident.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ const Incident = ({ incident }) => {

useConcentricStreets({
eventID: incident.eventID,
setConcentricStreets: setConcentricStreets,
setConcentricStreets,
});

// Incident State

const [incidentState, setIncidentState] = useState(incident.state);
// const [incidentState, setIncidentState] = useState(incident.state);

const editIncident = (imsSetValue) => (value) =>
imsSetValue(incident.eventID, incident.number, value);
Expand All @@ -51,7 +51,7 @@ const Incident = ({ incident }) => {
<Col className="text-start" />
<Col className="text-center">
<SelectState
state={incidentState}
state={incident.state}
setState={editIncident(ims.setIncidentState)}
/>
</Col>
Expand Down
16 changes: 8 additions & 8 deletions src/components/incident/LocationCard.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ describe("LocationCard component", () => {
for (const hour of hours) {
for (const minute of minutes) {
yield new Location({
name: name,
name,
address: new RodGarettAddress({
description: description,
concentric: concentric,
description,
concentric,
radialHour: hour,
radialMinute: minute,
}),
Expand Down Expand Up @@ -118,7 +118,7 @@ describe("LocationCard component", () => {
await userEvent.type(textField, name);
}

if ((name || location.name) && name != location.name) {
if ((name || location.name) && name !== location.name) {
expect(setName).toHaveBeenCalledWith(name == null ? "" : name);
}
},
Expand Down Expand Up @@ -154,7 +154,7 @@ describe("LocationCard component", () => {

if (
(description || location.description) &&
description != location.description
description !== location.description
) {
expect(setDescription).toHaveBeenCalledWith(
description == null ? "" : description,
Expand Down Expand Up @@ -198,7 +198,7 @@ describe("LocationCard component", () => {

if (
(concentricStreetID || location.address.concentric) &&
concentricStreetID != location.address.concentric
concentricStreetID !== location.address.concentric
) {
expect(setConcentricStreet).toHaveBeenCalledWith(
concentricStreetID == null ? "" : concentricStreetID,
Expand Down Expand Up @@ -238,7 +238,7 @@ describe("LocationCard component", () => {

if (
(hour || location.address.radialHour) &&
hour != location.address.radialHour
hour !== location.address.radialHour
) {
expect(setHour).toHaveBeenCalledWith(hour == null ? "" : hour);
}
Expand Down Expand Up @@ -276,7 +276,7 @@ describe("LocationCard component", () => {

if (
(minute || location.address.radialMinute) &&
minute != location.address.radialMinute
minute !== location.address.radialMinute
) {
expect(setMinute).toHaveBeenCalledWith(minute == null ? "" : minute);
}
Expand Down
8 changes: 4 additions & 4 deletions src/components/incident/ReportEntry.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ describe("ReportEntry component: display", () => {
const author = "bucket";
const text = "lorem ipsum…\nthere once was a Khaki named Sam…\nI am";
const reportEntry = new ReportEntryModel({
created: created,
author: author,
systemEntry: systemEntry,
text: text,
created,
author,
systemEntry,
text,
});

render(<ReportEntry reportEntry={reportEntry} />);
Expand Down
2 changes: 1 addition & 1 deletion src/components/nav/EventDropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const EventDropdown = () => {

const [events, setEvents] = useState(undefined);

useEvents({ setEvents: setEvents });
useEvents({ setEvents });

// Render

Expand Down
Loading

0 comments on commit cad95ed

Please sign in to comment.