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

[WIP] Improving Initial Load for Participant Selector in BSDT #646

Open
wants to merge 8 commits into
base: feature/242
Choose a base branch
from
9 changes: 5 additions & 4 deletions force-app/main/default/classes/ProgramEngagementSelector.cls
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public with sharing class ProgramEngagementSelector {
public List<ProgramEngagement__c> getProgramEngagementsByProgramId(
Id programId,
Set<String> fields,
Set<String> stages
Set<String> stages,
Integer engagementLimit
) {
if (
!(Schema.SObjectType.ProgramEngagement__c.isAccessible() &&
Expand All @@ -84,8 +85,8 @@ public with sharing class ProgramEngagementSelector {
return new List<ProgramEngagement__c>();
}

Integer limitTo =
System.Limits.getLimitQueryRows() - System.Limits.getQueryRows();
// Integer limitTo =
// System.Limits.getLimitQueryRows() - System.Limits.getQueryRows();

queryBuilder
.reset()
Expand All @@ -95,7 +96,7 @@ public with sharing class ProgramEngagementSelector {
String.valueOf(ProgramEngagement__c.Program__c) + ' = :programId'
)
.addCondition(String.valueOf(ProgramEngagement__c.Stage__c) + ' IN :stages')
.withLimit(limitTo);
.withLimit(engagementLimit);

List<ProgramEngagement__c> programEngagements = Database.query(
queryBuilder.buildSoqlQuery()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public with sharing class ServiceScheduleCreatorController {
}

@AuraEnabled(cacheable=true)
public static SelectParticipantModel getSelectParticipantModel(Id serviceId) {
public static SelectParticipantModel getSelectParticipantModel(Id serviceId, Integer engagementLimit) {
try {
return service.getSelectParticipantModel(serviceId);
return service.getSelectParticipantModel(serviceId, engagementLimit);
} catch (Exception ex) {
throw Util.getAuraHandledException(ex);
}
Expand Down
10 changes: 6 additions & 4 deletions force-app/main/default/classes/ServiceScheduleService.cls
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ public with sharing class ServiceScheduleService {
domain.insertParticipants(engagements, schedule);
}

public SelectParticipantModel getSelectParticipantModel(Id serviceId) {
public SelectParticipantModel getSelectParticipantModel(Id serviceId, Integer engagementLimit) {
SelectParticipantModel model = new SelectParticipantModel();
loadAndPopulateParticipantRecords(serviceId, model);
loadAndPopulateParticipantRecords(serviceId, model, engagementLimit);
return model;
}

Expand Down Expand Up @@ -248,7 +248,8 @@ public with sharing class ServiceScheduleService {

private void loadAndPopulateParticipantRecords(
Id serviceId,
SelectParticipantModel model
SelectParticipantModel model,
Integer engagementLimit
) {
model.program = programEngagementSelector.getProgramByServiceId(serviceId);
if (model.program == null) {
Expand All @@ -262,7 +263,8 @@ public with sharing class ServiceScheduleService {
model.programEngagements = programEngagementSelector.getProgramEngagementsByProgramId(
model.program.Id,
getSelectFieldsWithToLabel(model),
progEngagementService.getActiveStages()
progEngagementService.getActiveStages(),
engagementLimit
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@
onclick={handleSelectAll}
></lightning-button>
</lightning-layout-item>
<lightning-layout-item
size="12"
class="slds-var-p-bottom_small"
if:true={showLimitInfo}
>
<c-scoped-notification
theme="info"
title={none}
></c-scoped-notification>
</lightning-layout-item>
<lightning-layout-item
size="12"
if:false={noRecordsFound}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import removeLabel from "@salesforce/label/c.Remove";

const TIME = "TIME";
const SEARCH_DELAY = 1000;
const ENGAGEMENT_LIMIT = 1000;

export default class ParticipantSelector extends LightningElement {
@api serviceId;
Expand Down Expand Up @@ -69,6 +70,7 @@ export default class ParticipantSelector extends LightningElement {
offsetRows = 50;
offset = this.offsetRows;
showSpinner = false;
showLimitInfo = false;

_searchTimeout;

Expand Down Expand Up @@ -161,14 +163,15 @@ export default class ParticipantSelector extends LightningElement {
return `${name} (${this.participantCount}/${this.capacity})`;
}

@wire(getSelectParticipantModel, { serviceId: "$serviceId" })
@wire(getSelectParticipantModel, { serviceId: "$serviceId", engagementLimit: (ENGAGEMENT_LIMIT + 1)})
dataSetup(result) {
this.wiredData = result;
if (!(result.data || result.error)) {
return;
}

if (result.data) {
this.showLimitInfo = (result.data.programEngagements.length > ENGAGEMENT_LIMIT);
this.loadTable(result.data);
this.loadTableRows(result.data);
this.loadPreviousSelections();
Expand Down Expand Up @@ -207,7 +210,7 @@ export default class ParticipantSelector extends LightningElement {

loadTableRows(data) {
let selectedIds = this.selectedEngagements.map(engagement => engagement.Id);
this.allEngagements = data.programEngagements.slice(0);
this.allEngagements = data.programEngagements.slice(0, ENGAGEMENT_LIMIT);

this.availableEngagementRows = this.allEngagements
.filter(engagement => !selectedIds.includes(engagement.Id))
Expand Down