My Site Dashboard: Refactor drafts and scheduled posts cells - #18340
Conversation
…board-arch-refactor/posts-card-refactor
You can test the changes in WordPress from this Pull Request by:
.ipa file can also be downloaded directly here.If you need access to App Center, please ask a maintainer to add you. |
You can test the changes in Jetpack from this Pull Request by:
.ipa file can also be downloaded directly here.If you need access to App Center, please ask a maintainer to add you. |
leandroalonso
left a comment
There was a problem hiding this comment.
@hassaanelgarem left a few suggestions.
Also, to add to your list of requirements for the next tasks:
- Remove a card when all its posts are removed (scheduled or draft)
- Add a new card when needed (eg.: scheduling a post should make the scheduled cards appear. Or if the scheduled is appearing and a new draft is created the draft card should appear)
Looking forward to removing code in the next PRs. :)
| // | ||
| // DashboardPostsListCardCell.swift | ||
| // WordPress | ||
| // | ||
| // Created by Hassaan El-Garem on 11/04/2022. | ||
| // Copyright © 2022 WordPress. All rights reserved. | ||
| // | ||
|
|
There was a problem hiding this comment.
You can remove that. :D
|
|
||
| protocol BlogDashboardCardConfigurable { | ||
| func configure(blog: Blog, viewController: BlogDashboardViewController?, apiResponse: BlogDashboardRemoteEntity?) | ||
| func configure(blog: Blog, viewController: BlogDashboardViewController?, apiResponse: BlogDashboardRemoteEntity?, cardType: DashboardCard) |
There was a problem hiding this comment.
Is your plan to leave the cardType here?
I ask that because it seems a little bit odd. If I'm new to this code I would expect a 1:1 to map on DashboardCard for enum ~> cell. In this case, here we changed the protocol signature for this specific case (a specific cell needs to know which card it should represent).
Do you think we could split the different types of posts cards into different cells? We could use composition or inheritance. This way we would have DashboardDraftCardCell, DashboardScheduledCardCell, DashboardFirstPostCardCell and DashboardNextPostCardCell.
Also, by doing that you can get rid of presentedPostStatuson the cell.
While maybe this means more lines of code, I think it's clearer. Thoughts?
There was a problem hiding this comment.
That's a great point! I went with that initially cause I felt there's no need to create multiple cell classes. However, now I feel that would be much clearer.
I've changed this in 84faa36
I used inheritence and kept DashboardPostsListCardCell almost the same. The new subclasses are only responsible for passing the card type to DashboardPostsListCardCell instead of including it in the protocol. This is to avoid making variables under DashboardPostsListCardCell public.
Also, by doing that you can get rid of presentedPostStatuson the cell.
I don't think we can do that. presentedPostStatus is needed by BlogDashboardViewController not the cell. It's needed because that VC needs to conform to EditorAnalyticsProperties.
There was a problem hiding this comment.
I've changed this in 84faa36
1:1 mapping between the DashboardCard enum to a cell looks great!
|
|
||
| // MARK: Private Variables | ||
|
|
||
| private var viewModel: PostsCardViewModel? |
There was a problem hiding this comment.
I did a few tests with an account with 5 sites, and the PostsCardViewModel is being retained on a few occasions:
I think this is something we might want to address because each of those view models has an NSFetchedResultsController and its observing posts.
I believe this doesn't affect many users but it's a good improvement anyway. :)
There was a problem hiding this comment.
I took a look at this and it seems that the max instances of PostsCardViewModel retained at anytime is 5.
The collection view always keeps an extra DashboardPostsListCardCell, and each cell holds one view model. So the max here is 3 view models.
And there's always 2 instances of PostsCardViewController and each hold one view model as well. These however should be removed in the following PR.
There was a problem hiding this comment.
This should be improved in #18351 since PostsCardViewController is completely removed.
However, since we split DashboardPostsListCardCell to two classes, now the collection view retains an extra cell for each. So the max is now 4 view models.
There was a problem hiding this comment.
Ok! I'll check that again in #18351 and think if there's anything we might be able to do, thanks for the explanation!
These were really helpful! |

Part of #18308
Description
DashboardPostsListCardCellto display drafts and schedules posts cards.DashboardPostCardCellDashboardPostsListCardCellis made up of logic extracted fromDashboardPostCardCellandPostsCardViewControllerNext PR(s) Will Include
Testing Instructions
As with previous PRs, no testing intructions as of now.
Regression Notes
Potential unintended areas of impact
N/A
What I did to test those areas of impact (or what existing automated tests I relied on)
N/A
What automated tests I added (or what prevented me from doing so)
N/A
PR submission checklist:
RELEASE-NOTES.txtif necessary.