Skip to content

Commit

Permalink
Merge pull request #419 from bcgov/mals-5.3.1
Browse files Browse the repository at this point in the history
Mals 5.3.1
  • Loading branch information
barrfalk authored Oct 12, 2023
2 parents b4ff305 + 365da9c commit a935f6d
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 8 deletions.
35 changes: 33 additions & 2 deletions app/client/src/features/licences/AssociatedLicences.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,33 @@ export default function AssociatedLicences({ licence }) {
);
}

function formatResultRow(result) {
function formatResultRow(result, licenceType) {
const url = `${LICENSES_PATHNAME}/${result.id}`;
return (
<tr key={result.id}>
<td className="text-nowrap">
<Link to={url}>{result.licenceNumber}</Link>
</td>
{licenceType === "VETERINARY DRUG" ? (
<td>
{result.licenceType === "DISPENSER" &&
result.registrants &&
result.registrants[0] &&
result.registrants[0].label !== "null, null"
? result.registrants[0].label
: ""}
</td>
) : null}
{licenceType === "LIVESTOCK DEALER" ? (
<td>
{result.licenceType === "LIVESTOCK DEALER AGENT" &&
result.registrants &&
result.registrants[0] &&
result.registrants[0].label !== "null, null"
? result.registrants[0].label
: ""}
</td>
) : null}
<td className="text-nowrap">{result.licenceType}</td>
<td className="text-nowrap">
{formatDateString(result.associatedOnDate)}
Expand Down Expand Up @@ -295,19 +315,30 @@ export default function AssociatedLicences({ licence }) {
</>
);
} else if (results.status === REQUEST_STATUS.FULFILLED && results.count > 0) {
console.log(licence.data);
control = (
<>
<Table striped size="sm" responsive className="mt-3 mb-0" hover>
<thead className="thead-dark">
<tr>
<th className="text-nowrap">Licence</th>
{licence.data.licenceType === "VETERINARY DRUG" ? (
<th className="text-nowrap">Dispenser</th>
) : null}
{licence.data.licenceType === "LIVESTOCK DEALER" ? (
<th className="text-nowrap">Livestock Dealer Agent</th>
) : null}
<th className="text-nowrap">Licence Type</th>
<th className="text-nowrap">Associated On</th>
<th className="text-nowrap">Company/Registrant</th>
<th />
</tr>
</thead>
<tbody>{results.data.map((result) => formatResultRow(result))}</tbody>
<tbody>
{results.data.map((result) =>
formatResultRow(result, licence.data.licenceType)
)}
</tbody>
</Table>
<Row className="mt-3">
<Col lg={3}>{associateLicenceButton}</Col>
Expand Down
35 changes: 33 additions & 2 deletions app/client/src/features/licences/LicenceSites.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
import React, { useEffect } from "react";
import React, { useEffect, useState } from "react";
import { useSelector, useDispatch } from "react-redux";
import PropTypes from "prop-types";
import { Link } from "react-router-dom";
Expand All @@ -24,6 +24,8 @@ import {
fetchSiteResults,
selectSiteResults,
setSiteSearchPage,
setSiteFilterText,
clearSiteFilterText
} from "../search/searchSlice";

import { selectLicenceStatuses } from "../lookups/licenceStatusesSlice";
Expand Down Expand Up @@ -74,12 +76,32 @@ export default function LicenceSites({ licence }) {
const createdSite = useSelector(selectCreatedSite);
const currentUser = useSelector(selectCurrentUser);

const [debouncedActionTimeout, setDebouncedActionTimeout] = useState(null);

useEffect(() => {
dispatch(clearSiteParameters());
dispatch(clearSiteFilterText());
dispatch(setSiteParameters({ licenceNumber: licence.data.licenceNumber }));
dispatch(fetchSiteResults());
}, [dispatch]);

const handleFilterTextChange = (e) => {
const newFilterText = e.target.value;

if (debouncedActionTimeout) {
clearTimeout(debouncedActionTimeout);
}

const newTimeout = setTimeout(() => {
dispatch(setSiteSearchPage(1));
dispatch(setSiteFilterText(newFilterText));
dispatch(fetchSiteResults());

}, 700);

setDebouncedActionTimeout(newTimeout);
};

function addSiteOnClick() {
const payload = {
licenceId: licence.data.id,
Expand Down Expand Up @@ -212,7 +234,16 @@ export default function LicenceSites({ licence }) {
return (
<>
<SectionHeading>Sites</SectionHeading>
<Container className="mt-3 mb-4">{control}</Container>
<Container className="mt-3 mb-4">
<div className="mb-3">
<input
type="text"
placeholder="Filter sites"
onChange={handleFilterTextChange}
/>
</div>
{control}
</Container>
</>
);
}
Expand Down
6 changes: 3 additions & 3 deletions app/client/src/features/search/SiteResultsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {

import {
REQUEST_STATUS,
CREATE_LICENSES_PATHNAME,
SITES_PATHNAME,
LICENSES_PATHNAME,
} from "../../utilities/constants";
Expand All @@ -25,7 +24,6 @@ import {
formatListShorten,
} from "../../utilities/formatting.ts";

import LinkButton from "../../components/LinkButton";
import PageHeading from "../../components/PageHeading";

import Api from "../../utilities/api.ts";
Expand All @@ -40,6 +38,7 @@ import {
selectSiteResults,
setSiteSearchPage,
selectSiteParameters,
clearSiteFilterText,
} from "./searchSlice";

import {
Expand Down Expand Up @@ -125,6 +124,7 @@ export default function SiteResultsPage() {
useEffect(() => {
dispatch(clearCurrentLicence());
dispatch(clearCurrentSite());
dispatch(clearSiteFilterText()); // filter is only used on the LicenceSites page but can affect this page if not cleared
dispatch(fetchSiteResults());
}, [dispatch]);

Expand Down Expand Up @@ -226,4 +226,4 @@ export default function SiteResultsPage() {
<Container>{control}</Container>
</section>
);
}
}
9 changes: 9 additions & 0 deletions app/client/src/features/search/searchSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const selectLicenceResults = (state) => state.search.licences.results;
export const selectSiteSearchType = (state) => state.search.sites.searchType;
export const selectSiteParameters = (state) => state.search.sites.parameters;
export const selectSiteResults = (state) => state.search.sites.results;
export const selectSiteFilterText = (state) => state.search.sites.filter;

export const selectInventoryHistorySearchType = (state) =>
state.search.inventoryHistory.searchType;
Expand Down Expand Up @@ -286,6 +287,12 @@ export const searchSlice = createSlice({
setSiteSearchPage: (state, action) => {
state.sites.parameters.page = action.payload;
},
setSiteFilterText: (state, action) => {
state.sites.parameters.filterText = action.payload;
},
clearSiteFilterText: (state) => {
state.sites.parameters.filterText = undefined;
},

// Inventory History
clearInventoryHistoryParameters: (state) => {
Expand Down Expand Up @@ -480,6 +487,8 @@ export const {
toggleSiteSearchType,
setSiteParameters,
setSiteSearchPage,
setSiteFilterText,
clearSiteFilterText,

clearInventoryHistoryParameters,
clearInventoryHistoryResults,
Expand Down
2 changes: 1 addition & 1 deletion app/client/src/utilities/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class ApiError extends Error {
}
}

const DEFAULT_TIMEOUT = 10000;
const DEFAULT_TIMEOUT = 30000;

const axiosInstance = axios.create({
baseURL: "/api/v1",
Expand Down
23 changes: 23 additions & 0 deletions app/server/routes/v1/sites.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,29 @@ function getSearchFilter(params) {
});
}

if (params.filterText) {
if (params.filterText === 'ACT' || params.filterText === 'INA') {
andArray.push({
site_status: {
contains: params.filterText,
mode: "insensitive"
}
})
} else {
andArray.push({
OR: [
{ site_id_pk: { equals: isNaN(parseInt(params.filterText, 10)) ? 0 : parseInt(params.filterText, 10) } }, // unfortunately site id has to be an exact match
{ apiary_site_id_display: { contains: params.filterText, mode: "insensitive" } },
{ registrant_last_name: { contains: params.filterText, mode: "insensitive" } },
{ registrant_first_name: { contains: params.filterText, mode: "insensitive" } },
{ site_address_line_1: { contains: params.filterText, mode: "insensitive" } },
{ licence_region_name: { contains: params.filterText, mode: "insensitive" } },
{ licence_regional_district_name: { contains: params.filterText, mode: "insensitive" } },
],
});
}
}

filter = {
AND: andArray,
};
Expand Down
Binary file modified app/server/static/templates/certificates/Livestock-Dealer.docx
Binary file not shown.
Binary file modified app/server/static/templates/notices/Renewal_Apiary_Template.docx
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified app/server/static/templates/reports/Apiary_Sites_Template.xlsx
Binary file not shown.

0 comments on commit a935f6d

Please sign in to comment.