Skip to content

Commit

Permalink
fix: fix comment ordering and add support for edge case (#3051)
Browse files Browse the repository at this point in the history
  • Loading branch information
bistaastha committed Jun 4, 2024
1 parent e04b5e8 commit 8745d14
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/app/core/mock-data/platform-report.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const platformReportData: Report = deepFreeze({
last_paid_at: null,
last_resubmitted_at: null,
last_submitted_at: null,
next_approver_user_ids: null,
next_approver_user_ids: ['us0wOWkksndvkdv'],
num_expenses: 0,
org_id: 'orNVthTo2Zyo',
purpose: '#3: Jul 2023 - Office expense',
Expand Down Expand Up @@ -137,7 +137,7 @@ export const allReportsPaginated1: PlatformApiResponse<Report[]> = deepFreeze({
},
{
comment: 'aaac',
created_at: new Date('2024-05-22T07:32:19.199048+00:00'),
created_at: new Date('2024-05-22T07:33:20.199048+00:00'),
creator_user: {
email: '[email protected]',
full_name: 'Aastha',
Expand All @@ -148,7 +148,7 @@ export const allReportsPaginated1: PlatformApiResponse<Report[]> = deepFreeze({
},
{
comment: 'aaa',
created_at: new Date('2024-05-23T07:32:19.199048+00:00'),
created_at: new Date('2024-05-23T07:34:21.199048+00:00'),
creator_user: {
email: '[email protected]',
full_name: 'Aastha',
Expand Down Expand Up @@ -204,7 +204,7 @@ export const allReportsPaginated1: PlatformApiResponse<Report[]> = deepFreeze({
last_paid_at: null,
last_resubmitted_at: null,
last_submitted_at: new Date('2023-02-01T13:02:35.097839+00:00'),
next_approver_user_ids: null,
next_approver_user_ids: ['us0wOWkksndvkdv'],
num_expenses: 0,
org_id: 'orNVthTo2Zyo',
purpose: '#8: Jan 2023',
Expand Down Expand Up @@ -682,7 +682,7 @@ export const submittedReportData: Report = deepFreeze({
},
{
comment: 'aaac',
created_at: new Date('2024-05-22T07:32:19.199048+00:00'),
created_at: new Date('2024-05-22T07:33:20.199048+00:00'),
creator_user: {
email: '[email protected]',
full_name: 'Aastha',
Expand All @@ -693,7 +693,7 @@ export const submittedReportData: Report = deepFreeze({
},
{
comment: 'aaa',
created_at: new Date('2024-05-23T07:32:19.199048+00:00'),
created_at: new Date('2024-05-23T07:34:21.199048+00:00'),
creator_user: {
email: '[email protected]',
full_name: 'Aastha',
Expand Down
4 changes: 2 additions & 2 deletions src/app/core/test-data/status.service.spec.data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2020,7 +2020,7 @@ export const userComments: ExtendedComment[] = deepFreeze([
},
{
comment: 'aaac',
created_at: new Date('2024-05-22T07:32:19.199048+00:00'),
created_at: new Date('2024-05-22T07:33:20.199048+00:00'),
creator_user: {
email: '[email protected]',
full_name: 'Aastha',
Expand All @@ -2035,7 +2035,7 @@ export const userComments: ExtendedComment[] = deepFreeze([
},
{
comment: 'aaa',
created_at: new Date('2024-05-23T07:32:19.199048+00:00'),
created_at: new Date('2024-05-23T07:34:21.199048+00:00'),
creator_user: {
email: '[email protected]',
full_name: 'Aastha',
Expand Down
4 changes: 2 additions & 2 deletions src/app/fyle/my-view-report/my-view-report.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@
<ion-grid class="view-comment--card view-comment--self-comment text-right">
<ion-row>
<ion-col size="12">
<div class="view-comment--name-container">{{ estatus.creator_user.full_name }}</div>
<div class="view-comment--name-container">{{ estatus.creator_user?.full_name }}</div>
</ion-col>
</ion-row>
<ion-row>
Expand Down Expand Up @@ -248,7 +248,7 @@
<ion-grid class="view-comment--card view-comment--others-comment text-left">
<ion-row>
<ion-col size="12">
<div class="view-comment--name-container">{{ estatus.creator_user.full_name }}</div>
<div class="view-comment--name-container">{{ estatus.creator_user?.full_name }}</div>
</ion-col>
</ion-row>
<ion-row>
Expand Down
11 changes: 9 additions & 2 deletions src/app/fyle/my-view-report/my-view-report.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ export class MyViewReportPage {
(status) => !!status.creator_user_id && !['SYSTEM', 'POLICY'].includes(status.creator_user_id)
);

this.userComments.sort((a, b) => (a.created_at > b.created_at ? 1 : -1));

for (let i = 0; i < this.userComments.length; i++) {
const prevCommentDt = dayjs(this.userComments[i - 1] && this.userComments[i - 1].created_at);
const currentCommentDt = dayjs(this.userComments[i] && this.userComments[i].created_at);
Expand Down Expand Up @@ -288,7 +290,9 @@ export class MyViewReportPage {
.pipe(
map(
(orgSetting) =>
orgSetting?.corporate_credit_card_settings?.enabled && orgSetting.pending_cct_expense_restriction?.enabled
orgSetting &&
orgSetting.corporate_credit_card_settings?.enabled &&
orgSetting.pending_cct_expense_restriction?.enabled
),
switchMap((filterPendingTxn: boolean) => {
if (filterPendingTxn) {
Expand Down Expand Up @@ -374,7 +378,10 @@ export class MyViewReportPage {
)
)
.subscribe((editReportNamePopoverDetails) => {
const newReportName = editReportNamePopoverDetails?.data?.reportName;
const newReportName =
editReportNamePopoverDetails &&
editReportNamePopoverDetails.data &&
editReportNamePopoverDetails.data.reportName;
if (newReportName) {
this.updateReportName(newReportName);
}
Expand Down
6 changes: 3 additions & 3 deletions src/app/fyle/view-team-report/view-team-report.page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ describe('ViewTeamReportPageV2', () => {

expect(component.reportExpensesIds).toEqual(['txcSFe6efB6R', 'txcSFe6efB6R']);
expect(component.isSequentialApprovalEnabled).toBeTrue();
expect(component.canApprove).toBeNull();
expect(component.canApprove).toBeFalse();
expect(component.canShowTooltip).toBeTrue();
}));

Expand Down Expand Up @@ -500,7 +500,7 @@ describe('ViewTeamReportPageV2', () => {

expect(component.systemEstatuses).toEqual(systemCommentsWithSt);

// expect(component.userComments).toEqual([expectedNewStatusData[2], expectedNewStatusData[3]]);
expect(component.userComments).toEqual(userComments);

expect(reportService.getExports).toHaveBeenCalledOnceWith(activatedRoute.snapshot.params.id);

Expand Down Expand Up @@ -998,7 +998,7 @@ describe('ViewTeamReportPageV2', () => {
component.trackReportNameChange();
expect(trackingService.reportNameChange).toHaveBeenCalledOnceWith({
Time_spent: component.timeSpentOnEditingReportName,
Roles: undefined,
Roles: null,
});
});

Expand Down
4 changes: 3 additions & 1 deletion src/app/fyle/view-team-report/view-team-report.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ export class ViewTeamReportPage {
(status) => !!status.creator_user_id && !['SYSTEM', 'POLICY'].includes(status.creator_user_id)
);

this.userComments.sort((a, b) => (a.created_at > b.created_at ? 1 : -1));

for (let i = 0; i < this.userComments.length; i++) {
const prevCommentDt = dayjs(this.userComments[i - 1] && this.userComments[i - 1].created_at);
const currentCommentDt = dayjs(this.userComments[i] && this.userComments[i].created_at);
Expand Down Expand Up @@ -579,7 +581,7 @@ export class ViewTeamReportPage {
this.timeSpentOnEditingReportName = (this.reportNameChangeEndTime - this.reportNameChangeStartTime) / 1000;
this.trackingService.reportNameChange({
Time_spent: this.timeSpentOnEditingReportName,
Roles: this.eou?.ou.roles,
Roles: this.eou && this.eou.ou.roles,
});
}

Expand Down

0 comments on commit 8745d14

Please sign in to comment.