From 6ed1b1512966733f77a50ed5fffb70b28a4ece1a Mon Sep 17 00:00:00 2001 From: bcgov-brwang Date: Mon, 22 Aug 2022 12:26:26 -0700 Subject: [PATCH 1/2] Fix HETS-1344 --- .../DistrictEquipmentTypeController.cs | 13 +-- client/src/js/views/AitReport.jsx | 79 ++++++++++++++++--- 2 files changed, 77 insertions(+), 15 deletions(-) diff --git a/Server/HetsApi/Controllers/DistrictEquipmentTypeController.cs b/Server/HetsApi/Controllers/DistrictEquipmentTypeController.cs index 632180947..60e85425e 100644 --- a/Server/HetsApi/Controllers/DistrictEquipmentTypeController.cs +++ b/Server/HetsApi/Controllers/DistrictEquipmentTypeController.cs @@ -104,18 +104,19 @@ public virtual ActionResult DistrictEquip { // get user's district int? districtId = UserAccountHelper.GetUsersDistrictId(_context); - var summary = _context.HetRentalAgreements.AsNoTracking() - .Include(x => x.Equipment.DistrictEquipmentType) - .Where(x => x.DistrictId == districtId && - !x.Number.StartsWith("BCBid")) - .ToList() - .GroupBy(x => x.Equipment.DistrictEquipmentType, (t, agreements) => new DistrictEquipmentTypeAgreementSummary + .Include(x => x.Equipment.DistrictEquipmentType) + .Where(x => x.DistrictId == districtId && + !x.Number.StartsWith("BCBid")) + .ToList() + .OrderByDescending(x => x.DatedOn).GroupBy(x => x.Equipment.DistrictEquipmentTypeId).Select(x => x.FirstOrDefault()).ToList() + .GroupBy(x => x.Equipment.DistrictEquipmentType, (t, agreements) => new DistrictEquipmentTypeAgreementSummary { Id = t.DistrictEquipmentTypeId, Name = t.DistrictEquipmentName, AgreementIds = agreements.Select(y => y.RentalAgreementId).Distinct().ToList(), ProjectIds = agreements.Select(y => y.ProjectId).Distinct().ToList(), + }) .ToList(); diff --git a/client/src/js/views/AitReport.jsx b/client/src/js/views/AitReport.jsx index 533141283..fb87864c7 100644 --- a/client/src/js/views/AitReport.jsx +++ b/client/src/js/views/AitReport.jsx @@ -36,6 +36,11 @@ const THIS_FISCAL = 'This Fiscal'; const LAST_FISCAL = 'Last Fiscal'; const CUSTOM = 'Custom'; +var projectsRetrieved = []; +var districtEquipmentTypesRetrieved = []; +var equipmentRetrieved = []; +var shouldReRender = true; + class AitReport extends React.Component { static propTypes = { currentUser: PropTypes.object, @@ -53,6 +58,7 @@ class AitReport extends React.Component { constructor(props) { super(props); + var today = Moment(); this.state = { @@ -69,6 +75,7 @@ class AitReport extends React.Component { sortField: props.ui.sortField || 'rentalAgreementNumber', sortDesc: props.ui.sortDesc === true, }, + }; } @@ -108,6 +115,8 @@ class AitReport extends React.Component { Api.getDistrictEquipmentTypesAgreementSummary(); Api.getEquipmentAgreementSummary(); + + // If this is the first load, then look for a default favourite if (_.isEmpty(this.props.search)) { var defaultFavourite = _.find(this.props.favourites, (f) => f.isDefault); @@ -117,8 +126,13 @@ class AitReport extends React.Component { } } + shouldComponentUpdate = (nextProps, nextState) => { + return shouldReRender; + } + fetch = () => { Api.searchAitReport(this.buildSearchParams()); + shouldReRender = true; }; search = (e) => { @@ -149,6 +163,7 @@ class AitReport extends React.Component { }; updateSearchState = (state, callback) => { + shouldReRender = false; this.setState({ search: { ...this.state.search, ...state, ...{ loaded: true } } }, () => { store.dispatch({ type: Action.UPDATE_AIT_SEARCH, @@ -338,10 +353,12 @@ class AitReport extends React.Component { }; getFilteredDistrictEquipmentType = () => { - return _.chain(this.props.districtEquipmentTypes.data) - .filter((x) => this.matchesDateFilter(x.agreementIds) && this.matchesProjectFilter(x.projectIds)) - .sortBy('name') - .value(); + var result = _.chain(this.props.districtEquipmentTypes.data) + .filter((x) => this.matchesDateFilter(x.agreementIds) && this.matchesProjectFilter(x.projectIds)) + .sortBy('name') + .value(); + return result; + }; getFilteredEquipment = () => { @@ -356,15 +373,55 @@ class AitReport extends React.Component { .value(); }; + getAllData = () => { + if(projectsRetrieved.length === 0){ + projectsRetrieved = _.chain(this.props.projects.data) + .filter((x) => this.matchesDateFilter(x.agreementIds)) + .sortBy('name') + .value(); + } + + if(projectsRetrieved.length > 0){ + districtEquipmentTypesRetrieved = _.chain(this.props.districtEquipmentTypes.data) + .filter((x) => this.matchesDateFilter(x.agreementIds) && this.matchesProjectFilter(x.projectIds)) + .sortBy('name') + .value(); + + if(districtEquipmentTypesRetrieved.length > 0){ + equipmentRetrieved = _.chain(this.props.equipment.data) + .filter( + (x) => + this.matchesDateFilter(x.agreementIds) && + this.matchesProjectFilter(x.projectIds) && + this.matchesDistrictEquipmentTypeFilter(x.districtEquipmentTypeId) + ) + .sortBy('equipmentCode') + .value(); + } + + } + + if(shouldReRender || (projectsRetrieved.length > 0 && districtEquipmentTypesRetrieved.length > 0 && equipmentRetrieved.length > 0)){ + shouldReRender = true; + }else{ + shouldReRender = false; + } + }; + render() { var resultCount = ''; if (this.props.aitResponses.loaded) { resultCount = '(' + Object.keys(this.props.aitResponses.data).length + ')'; } - var projects = this.getFilteredProjects(); - var districtEquipmentTypes = this.getFilteredDistrictEquipmentType(); - var equipment = this.getFilteredEquipment(); + // var projects = this.getFilteredProjects(); + // var districtEquipmentTypes = this.getFilteredDistrictEquipmentType(); + // var equipment = this.getFilteredEquipment(); + + this.getAllData(); + var projects = projectsRetrieved; + var districtEquipmentTypes = districtEquipmentTypesRetrieved; + var equipment = equipmentRetrieved; return (
@@ -489,7 +546,9 @@ class AitReport extends React.Component { } function mapStateToProps(state) { - return { + + + var result = { currentUser: state.user, agreementSummaryLite: state.lookups.agreementSummaryLite, projects: state.lookups.projectsAgreementSummary, @@ -500,6 +559,8 @@ function mapStateToProps(state) { search: state.search.aitResponses, ui: state.ui.aitResponses, }; + + return result; } -export default connect(mapStateToProps)(AitReport); +export default connect(mapStateToProps)(AitReport); \ No newline at end of file From 337dd4448dfa8a0f7c525bf6b7530735ac1bd4c5 Mon Sep 17 00:00:00 2001 From: bcgov-brwang Date: Mon, 22 Aug 2022 12:45:19 -0700 Subject: [PATCH 2/2] Update apiVersion for OpenShift configuration --- openshift/api-build-config.yaml | 2 +- openshift/api-deploy-config.yaml | 2 +- openshift/backup-deploy-config.yaml | 2 +- openshift/client-build-config.yaml | 2 +- openshift/client-deploy-config.yaml | 2 +- openshift/postgresql-deploy-config.yaml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/openshift/api-build-config.yaml b/openshift/api-build-config.yaml index 27cde0ef7..f78867b25 100644 --- a/openshift/api-build-config.yaml +++ b/openshift/api-build-config.yaml @@ -1,5 +1,5 @@ kind: Template -apiVersion: v1 +apiVersion: template.openshift.io/v1 metadata: name: ${PROJECT_NAME} creationTimestamp: diff --git a/openshift/api-deploy-config.yaml b/openshift/api-deploy-config.yaml index 4eaaa63ad..89b2a21b8 100644 --- a/openshift/api-deploy-config.yaml +++ b/openshift/api-deploy-config.yaml @@ -1,5 +1,5 @@ kind: Template -apiVersion: v1 +apiVersion: template.openshift.io/v1 metadata: name: ${PROJECT_NAME} creationTimestamp: diff --git a/openshift/backup-deploy-config.yaml b/openshift/backup-deploy-config.yaml index 70d790111..c938a73a2 100644 --- a/openshift/backup-deploy-config.yaml +++ b/openshift/backup-deploy-config.yaml @@ -1,5 +1,5 @@ kind: Template -apiVersion: v1 +apiVersion: template.openshift.io/v1 metadata: name: "${NAME}-deployment-template" objects: diff --git a/openshift/client-build-config.yaml b/openshift/client-build-config.yaml index 3218554fa..937ee36f5 100644 --- a/openshift/client-build-config.yaml +++ b/openshift/client-build-config.yaml @@ -1,4 +1,4 @@ -apiVersion: v1 +apiVersion: template.openshift.io/v1 kind: Template metadata: creationTimestamp: null diff --git a/openshift/client-deploy-config.yaml b/openshift/client-deploy-config.yaml index 367b59cac..9217b72af 100644 --- a/openshift/client-deploy-config.yaml +++ b/openshift/client-deploy-config.yaml @@ -1,5 +1,5 @@ kind: Template -apiVersion: v1 +apiVersion: template.openshift.io/v1 metadata: name: ${PROJECT_NAME} creationTimestamp: diff --git a/openshift/postgresql-deploy-config.yaml b/openshift/postgresql-deploy-config.yaml index 23fcb8029..59be5eb53 100644 --- a/openshift/postgresql-deploy-config.yaml +++ b/openshift/postgresql-deploy-config.yaml @@ -1,5 +1,5 @@ kind: Template -apiVersion: v1 +apiVersion: template.openshift.io/v1 metadata: name: ${PROJECT_NAME} objects: