Skip to content

My Site Dashboard: Refactor drafts and scheduled posts cells - #18340

Merged
hassaanelgarem merged 10 commits into
feature/dashboard-arch-refactor/basefrom
feature/dashboard-arch-refactor/posts-card-refactor
Apr 13, 2022
Merged

My Site Dashboard: Refactor drafts and scheduled posts cells#18340
hassaanelgarem merged 10 commits into
feature/dashboard-arch-refactor/basefrom
feature/dashboard-arch-refactor/posts-card-refactor

Conversation

@hassaanelgarem

Copy link
Copy Markdown
Contributor

Part of #18308

Description

  • This PR makes use of a new cell DashboardPostsListCardCell to display drafts and schedules posts cards.
  • "Create Next" and "Creat First" cards are still using the old DashboardPostCardCell
  • DashboardPostsListCardCell is made up of logic extracted from DashboardPostCardCell and PostsCardViewController

Next PR(s) Will Include

  • Create new cell for displaying "Create Next" and "Creat First" cards
  • Handle cases where cards should be refreshed (All drafts deleted for example)
  • Remove all unnecessary code

Testing Instructions

As with previous PRs, no testing intructions as of now.

Regression Notes

  1. Potential unintended areas of impact
    N/A

  2. What I did to test those areas of impact (or what existing automated tests I relied on)
    N/A

  3. What automated tests I added (or what prevented me from doing so)
    N/A

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@wpmobilebot

wpmobilebot commented Apr 11, 2022

Copy link
Copy Markdown
Contributor
You can test the changes in WordPress from this Pull Request by:
  • Clicking here or scanning the QR code below
  • Then installing the build number pr18340-84faa36 from App Center on your iPhone

The .ipa file can also be downloaded directly here.
If you need access to App Center, please ask a maintainer to add you.

@wpmobilebot

wpmobilebot commented Apr 11, 2022

Copy link
Copy Markdown
Contributor
You can test the changes in Jetpack from this Pull Request by:
  • Clicking here or scanning the QR code below
  • Then installing the build number pr18340-84faa36 from App Center on your iPhone

The .ipa file can also be downloaded directly here.
If you need access to App Center, please ask a maintainer to add you.

@leandroalonso leandroalonso left a comment

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.

@hassaanelgarem left a few suggestions.

Also, to add to your list of requirements for the next tasks:

  1. Remove a card when all its posts are removed (scheduled or draft)
  2. 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. :)

Comment on lines +1 to +8
//
// DashboardPostsListCardCell.swift
// WordPress
//
// Created by Hassaan El-Garem on 11/04/2022.
// Copyright © 2022 WordPress. All rights reserved.
//

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.

You can remove that. :D

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 73ce726 😅


protocol BlogDashboardCardConfigurable {
func configure(blog: Blog, viewController: BlogDashboardViewController?, apiResponse: BlogDashboardRemoteEntity?)
func configure(blog: Blog, viewController: BlogDashboardViewController?, apiResponse: BlogDashboardRemoteEntity?, cardType: DashboardCard)

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.

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?

@hassaanelgarem hassaanelgarem Apr 12, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

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've changed this in 84faa36

1:1 mapping between the DashboardCard enum to a cell looks great!


// MARK: Private Variables

private var viewModel: PostsCardViewModel?

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 did a few tests with an account with 5 sites, and the PostsCardViewModel is being retained on a few occasions:

Screen Shot 2022-04-11 at 15 41 52

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. :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

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.

Ok! I'll check that again in #18351 and think if there's anything we might be able to do, thanks for the explanation!

@hassaanelgarem

Copy link
Copy Markdown
Contributor Author

Also, to add to your list of requirements for the next tasks:

These were really helpful!

@hassaanelgarem
hassaanelgarem merged commit bdcc046 into feature/dashboard-arch-refactor/base Apr 13, 2022
@hassaanelgarem
hassaanelgarem deleted the feature/dashboard-arch-refactor/posts-card-refactor branch April 13, 2022 05:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants