Skip to content

Commit 0ef54b8

Browse files
ellen-wrightmutambaraf
authored andcommitted
fix: call order is not persistent for user officers (#1294)
Co-authored-by: Farai Mutambara <71100224+mutambaraf@users.noreply.github.com>
1 parent d2501ce commit 0ef54b8

5 files changed

Lines changed: 87 additions & 24 deletions

File tree

apps/backend/src/datasources/postgres/CallDataSource.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ export default class PostgresCallDataSource implements CallDataSource {
175175
.where('s.short_code', filter.proposalStatusShortCode)
176176
.distinctOn('call.call_id');
177177
}
178+
if (filter?.isOrdered) {
179+
query.orderBy('sort_order');
180+
}
178181

179182
return query.then((callDB: CallRecord[]) => {
180183
return callDB.map((call) => createCallObject(call));
@@ -439,7 +442,7 @@ export default class PostgresCallDataSource implements CallDataSource {
439442
}
440443
async setNewSortOrder(data: CallOrderArray): Promise<number> {
441444
return await database
442-
.update({ sort_order: data.sort_order })
445+
.update({ sort_order: data.sort_order + 1 })
443446
.from('call')
444447
.where({ call_id: data.callId });
445448
}

apps/backend/src/resolvers/queries/CallsQuery.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ export class CallsFilter {
5858

5959
@Field(() => Boolean, { nullable: true })
6060
public isCallUpcoming?: boolean;
61+
62+
@Field(() => Boolean, { nullable: true })
63+
public isOrdered?: boolean;
6164
}
6265

6366
@Resolver()

apps/e2e/cypress/e2e/calls.cy.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,59 @@ context('Calls tests', () => {
897897
cy.contains(newCall.shortCode);
898898
});
899899

900+
it('Order of calls persists ', () => {
901+
cy.createCall({
902+
...newInactiveCall,
903+
esiTemplateId: esiTemplateId,
904+
proposalWorkflowId: workflowId,
905+
});
906+
let firstTableRowTextBeforeSorting: string;
907+
let firstTableRowTextAfterSorting: string;
908+
cy.contains('Calls').click();
909+
cy.get('[data-cy="call-status-filter"]').click();
910+
cy.get('[role="listbox"]').contains('Open/Upcoming').click();
911+
912+
cy.finishedLoading();
913+
914+
cy.get('[data-cy="order-calls-button"]').first().click();
915+
cy.contains('Drag to order calls');
916+
cy.get('[data-cy="call-list-drag-item"]')
917+
.first()
918+
.then((element) => {
919+
firstTableRowTextBeforeSorting = element.text();
920+
});
921+
//reorder
922+
cy.get('[data-cy="call-list-drag-item"]')
923+
.first()
924+
.dragElement([
925+
{ direction: 'left', length: 0 },
926+
{ direction: 'down', length: 1 },
927+
]);
928+
929+
cy.get('[data-cy="call-list-drag-item"]')
930+
.last()
931+
.then((element) => {
932+
firstTableRowTextAfterSorting = element.text();
933+
expect(firstTableRowTextBeforeSorting).not.equal(
934+
firstTableRowTextAfterSorting
935+
);
936+
});
937+
938+
cy.contains('Proposals').click();
939+
cy.contains('Calls').click();
940+
941+
cy.get('[data-cy="call-status-filter"]').click();
942+
cy.get('[role="listbox"]').contains('Open/Upcoming').click();
943+
944+
cy.finishedLoading();
945+
946+
cy.get('[data-cy="order-calls-button"]').first().click();
947+
cy.contains('Drag to order calls');
948+
cy.get('[data-cy="call-list-drag-item"]').first();
949+
950+
cy.contains(newCall.shortCode);
951+
});
952+
900953
it('User officer can filter calls by their status', () => {
901954
cy.createCall({
902955
...newInactiveCall,

apps/frontend/src/components/call/CallsTable.tsx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,11 @@ const CallsTable = ({ confirm, isArchivedTab }: CallTableProps) => {
349349
result.source.index,
350350
result.destination.index
351351
);
352-
setCalls(callsWithUpdatedOrder);
352+
setCalls(
353+
callsWithUpdatedOrder.sort((a, b) =>
354+
a.sort_order > b.sort_order ? -1 : 1
355+
)
356+
);
353357
const callOrderList = callsWithUpdatedOrder.map((item, index) => ({
354358
callId: item.id,
355359
sort_order: index,
@@ -360,6 +364,13 @@ const CallsTable = ({ confirm, isArchivedTab }: CallTableProps) => {
360364
});
361365
};
362366

367+
const getCallOrder = (): void => {
368+
setCallsFilter(() => ({
369+
...getFilterStatus(callStatus as CallStatusFilters, isArchivedTab),
370+
isOrdered: true,
371+
}));
372+
};
373+
363374
return (
364375
<div data-cy="calls-table">
365376
<Grid container spacing={2}>
@@ -381,7 +392,12 @@ const CallsTable = ({ confirm, isArchivedTab }: CallTableProps) => {
381392
control={
382393
<Switch
383394
checked={isCallReorderMode}
384-
onChange={(): void => setIsCallReorderMode(!isCallReorderMode)}
395+
onChange={(): void => {
396+
if (!isCallReorderMode) {
397+
getCallOrder();
398+
}
399+
setIsCallReorderMode(!isCallReorderMode);
400+
}}
385401
/>
386402
}
387403
label="Order calls mode"
@@ -395,12 +411,7 @@ const CallsTable = ({ confirm, isArchivedTab }: CallTableProps) => {
395411
Drag to order calls
396412
</Typography>
397413
<Paper>
398-
<CallReorder
399-
items={calls.sort((a, b) =>
400-
a.sort_order > b.sort_order ? 1 : -1
401-
)}
402-
onDragEnd={onDragEnd}
403-
/>
414+
<CallReorder items={calls} onDragEnd={onDragEnd} />
404415
</Paper>
405416
</div>
406417
)}

apps/frontend/src/components/proposal/ProposalChooseCall.tsx

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,25 @@ const ProposalChooseCall = () => {
2525
navigate(url);
2626
};
2727
function getDashBoardCallFilter(): CallsFilter {
28-
return isInternalUser
29-
? {
30-
isActive: true,
31-
isEnded: false,
32-
isActiveInternal: true,
33-
}
34-
: {
35-
isActive: true,
36-
isEnded: false,
37-
};
28+
return {
29+
isActive: true,
30+
isEnded: false,
31+
isActiveInternal: isInternalUser,
32+
isOrdered: true,
33+
};
3834
}
3935
const { calls } = useCallsData(getDashBoardCallFilter());
40-
const callsOrdered = calls.sort((a, b) =>
41-
a.sort_order > b.sort_order ? 1 : -1
42-
);
4336

4437
return (
4538
<StyledContainer>
4639
<StyledPaper>
4740
<Typography variant="h6" component="h2" gutterBottom>
48-
{callsOrdered.length !== 0
41+
{calls.length !== 0
4942
? 'Select a call'
5043
: 'There are no calls open at this time'}
5144
</Typography>
5245
<List data-cy="call-list">
53-
{callsOrdered.map((call) => {
46+
{calls.map((call) => {
5447
const timeRemainingText = timeRemaining(new Date(call.endCall));
5548
const InternalCalltimeRemainingText = timeRemaining(
5649
new Date(call.endCallInternal)

0 commit comments

Comments
 (0)