Skip to content

CMS Sorting: Add in ability to sort CMS list pages#76

Merged
ricocynthia merged 9 commits intoordercloud-api:masterfrom
kwahn20:sort-cms-docs
Apr 13, 2021
Merged

CMS Sorting: Add in ability to sort CMS list pages#76
ricocynthia merged 9 commits intoordercloud-api:masterfrom
kwahn20:sort-cms-docs

Conversation

@kwahn20
Copy link
Contributor

@kwahn20 kwahn20 commented Apr 9, 2021

This adds in the ability for users on a page-list to sort the docs by the following: Title, Date Created and Date Updated

@kwahn20 kwahn20 requested a review from ricocynthia April 9, 2021 17:23
Copy link
Contributor

@ricocynthia ricocynthia left a comment

Choose a reason for hiding this comment

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

Instead of doing a drop down for sorting, we should handle the sorting in the CMS like we are doing for non-ecommerce products, ecommerce products, and goldbook. You'll see that when you click on Name in the list of ecomm products, it will sort by Name ascending and then the top arrow on the icon will be highlighted (vice versa for descending). Could you do that here as well please?

Copy link
Contributor

@ricocynthia ricocynthia left a comment

Choose a reason for hiding this comment

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

also is there a reason you excluded "Created By" from being sorted?

@kwahn20
Copy link
Contributor Author

kwahn20 commented Apr 12, 2021

No reason in particular, it seems that we auto generate most pages to begin with (making it limited with that field) but I guess adding it in is the better option

ASSET_TYPES,
} from '../../constants/asset-types.constants';
import { PageContentDoc } from '../../models/page-content-doc.interface';
import { FormBuilder, FormGroup } from '@angular/forms';
Copy link
Contributor

Choose a reason for hiding this comment

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

it look these are no longer being used in this component, can you remove this line please?

faSortDown = faSortDown;

constructor(private spinner: NgxSpinnerService) { }
constructor(private spinner: NgxSpinnerService, private formBuilder: FormBuilder) { }
Copy link
Contributor

Choose a reason for hiding this comment

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

it looks like formBuilder is no longer being used in this component, can you remove it please?

sortBy = "!" + this.sortBy;
this.sortBy = sortBy;
}
else {this.sortBy = sortBy}
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't need this else statement here. if you move this.sortBy = sortBy; out of the if and remove the else it will work the same way

this.sortBy = sortBy;
}
else {this.sortBy = sortBy}
switch (sortBy){
Copy link
Contributor

@ricocynthia ricocynthia Apr 12, 2021

Choose a reason for hiding this comment

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

this can be simplified by removing the switch statement and doing something like this return this.list.sort((a, b) => (a.Doc[sortBy] > b.Doc[sortBy] ? 1 : -1)) since it looks like the sortBy value is the name of the property you need to get from the doc. you'll just need to add some logic to remove the ! if it exists in sortBy. let me know if you have any question about this, i'd be happy to walk you through a solution!

></fa-icon>
</fa-layers>
</th>
<th (click)="changeSortStrategy('DateUpdated')">Last Updated
Copy link
Contributor

Choose a reason for hiding this comment

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

in order to simplify the logic in changeSortStrategy(), we'll need to update the parameter to 'DateLastUpdated'

<fa-layers class="fa-fw">
<fa-icon
[icon]="faSortUp"
[ngClass]="{ inactive: sortBy != 'DateUpdated' }"
Copy link
Contributor

Choose a reason for hiding this comment

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

this will also need to be updated

></fa-icon>
<fa-icon
[icon]="faSortDown"
[ngClass]="{ inactive: sortBy != '!DateUpdated' }"
Copy link
Contributor

Choose a reason for hiding this comment

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

this will also need to be updated

></fa-icon>
</fa-layers>
</th>
<th (click)="changeSortStrategy('CreatedBy')">Created By
Copy link
Contributor

Choose a reason for hiding this comment

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

in order to simplify the logic in changeSortStrategy(), we'll need to update the parameter to 'Author'

<fa-layers class="fa-fw">
<fa-icon
[icon]="faSortUp"
[ngClass]="{ inactive: sortBy != 'CreatedBy' }"
Copy link
Contributor

Choose a reason for hiding this comment

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

this will also need to be updated

></fa-icon>
<fa-icon
[icon]="faSortDown"
[ngClass]="{ inactive: sortBy != '!CreatedBy' }"
Copy link
Contributor

Choose a reason for hiding this comment

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

this will also need to be updated

changes[propertyName].previousValue !== changes[propertyName].currentValue;
}

changeSortStrategy(sortBy: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add what this method is expected to return as well please?

@ricocynthia ricocynthia merged commit c5b1cdf into ordercloud-api:master Apr 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants