Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion apps/backend/src/datasources/postgres/CallDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ export default class PostgresCallDataSource implements CallDataSource {
.where('s.short_code', filter.proposalStatusShortCode)
.distinctOn('call.call_id');
}
if (filter?.isOrdered) {
query.orderBy('sort_order');
}

return query.then((callDB: CallRecord[]) => {
return callDB.map((call) => createCallObject(call));
Expand Down Expand Up @@ -439,7 +442,7 @@ export default class PostgresCallDataSource implements CallDataSource {
}
async setNewSortOrder(data: CallOrderArray): Promise<number> {
return await database
.update({ sort_order: data.sort_order })
.update({ sort_order: data.sort_order + 1 })
.from('call')
.where({ call_id: data.callId });
}
Expand Down
3 changes: 3 additions & 0 deletions apps/backend/src/resolvers/queries/CallsQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ export class CallsFilter {

@Field(() => Boolean, { nullable: true })
public isCallUpcoming?: boolean;

Comment thread
jekabs-karklins marked this conversation as resolved.
@Field(() => Boolean, { nullable: true })
public isOrdered?: boolean;
}

@Resolver()
Expand Down
53 changes: 53 additions & 0 deletions apps/e2e/cypress/e2e/calls.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,59 @@ context('Calls tests', () => {
cy.contains(newCall.shortCode);
});

it('Order of calls persists ', () => {
cy.createCall({
...newInactiveCall,
esiTemplateId: esiTemplateId,
proposalWorkflowId: workflowId,
});
let firstTableRowTextBeforeSorting: string;
let firstTableRowTextAfterSorting: string;
cy.contains('Calls').click();
cy.get('[data-cy="call-status-filter"]').click();
cy.get('[role="listbox"]').contains('Open/Upcoming').click();

cy.finishedLoading();

cy.get('[data-cy="order-calls-button"]').first().click();
cy.contains('Drag to order calls');
cy.get('[data-cy="call-list-drag-item"]')
.first()
.then((element) => {
firstTableRowTextBeforeSorting = element.text();
});
//reorder
cy.get('[data-cy="call-list-drag-item"]')
.first()
.dragElement([
{ direction: 'left', length: 0 },
{ direction: 'down', length: 1 },
]);

cy.get('[data-cy="call-list-drag-item"]')
.last()
.then((element) => {
firstTableRowTextAfterSorting = element.text();
expect(firstTableRowTextBeforeSorting).not.equal(
firstTableRowTextAfterSorting
);
});

cy.contains('Proposals').click();
cy.contains('Calls').click();

cy.get('[data-cy="call-status-filter"]').click();
cy.get('[role="listbox"]').contains('Open/Upcoming').click();

cy.finishedLoading();

cy.get('[data-cy="order-calls-button"]').first().click();
cy.contains('Drag to order calls');
cy.get('[data-cy="call-list-drag-item"]').first();

cy.contains(newCall.shortCode);
});

it('User officer can filter calls by their status', () => {
cy.createCall({
...newInactiveCall,
Expand Down
27 changes: 19 additions & 8 deletions apps/frontend/src/components/call/CallsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,11 @@ const CallsTable = ({ confirm, isArchivedTab }: CallTableProps) => {
result.source.index,
result.destination.index
);
setCalls(callsWithUpdatedOrder);
setCalls(
callsWithUpdatedOrder.sort((a, b) =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: do you know why callsWithUpdatedOrder is already not in the right order and need to be sorted again?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean do we even need to call

const callsWithUpdatedOrder = reorder(
      calls,
      result.source.index,
      result.destination.index
    );

a.sort_order > b.sort_order ? -1 : 1
)
);
const callOrderList = callsWithUpdatedOrder.map((item, index) => ({
callId: item.id,
sort_order: index,
Expand All @@ -360,6 +364,13 @@ const CallsTable = ({ confirm, isArchivedTab }: CallTableProps) => {
});
};

const getCallOrder = (): void => {
setCallsFilter(() => ({
...getFilterStatus(callStatus as CallStatusFilters, isArchivedTab),
isOrdered: true,
}));
};

return (
<div data-cy="calls-table">
<Grid container spacing={2}>
Expand All @@ -381,7 +392,12 @@ const CallsTable = ({ confirm, isArchivedTab }: CallTableProps) => {
control={
<Switch
checked={isCallReorderMode}
onChange={(): void => setIsCallReorderMode(!isCallReorderMode)}
onChange={(): void => {
if (!isCallReorderMode) {
getCallOrder();
}
setIsCallReorderMode(!isCallReorderMode);
}}
/>
}
label="Order calls mode"
Expand All @@ -395,12 +411,7 @@ const CallsTable = ({ confirm, isArchivedTab }: CallTableProps) => {
Drag to order calls
</Typography>
<Paper>
<CallReorder
items={calls.sort((a, b) =>
a.sort_order > b.sort_order ? 1 : -1
)}
onDragEnd={onDragEnd}
/>
<CallReorder items={calls} onDragEnd={onDragEnd} />
</Paper>
</div>
)}
Expand Down
23 changes: 8 additions & 15 deletions apps/frontend/src/components/proposal/ProposalChooseCall.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,25 @@ const ProposalChooseCall = () => {
navigate(url);
};
function getDashBoardCallFilter(): CallsFilter {
return isInternalUser
? {
isActive: true,
isEnded: false,
isActiveInternal: true,
}
: {
isActive: true,
isEnded: false,
};
return {
isActive: true,
isEnded: false,
isActiveInternal: isInternalUser,
isOrdered: true,
};
}
const { calls } = useCallsData(getDashBoardCallFilter());
const callsOrdered = calls.sort((a, b) =>
a.sort_order > b.sort_order ? 1 : -1
);

return (
<StyledContainer>
<StyledPaper>
<Typography variant="h6" component="h2" gutterBottom>
{callsOrdered.length !== 0
{calls.length !== 0
? 'Select a call'
: 'There are no calls open at this time'}
</Typography>
<List data-cy="call-list">
{callsOrdered.map((call) => {
{calls.map((call) => {
const timeRemainingText = timeRemaining(new Date(call.endCall));
const InternalCalltimeRemainingText = timeRemaining(
new Date(call.endCallInternal)
Expand Down
Loading