Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-39: Allow post display options to be edited without a post being selected #43

Merged
merged 3 commits into from
Nov 14, 2023

Conversation

mogmarsh
Copy link
Collaborator

@mogmarsh mogmarsh commented Nov 11, 2023

Pull Request Title

Allow post display options to be edited without a post being selected (#39)

Description

This pull request addresses the issue "Allow post display options to be edited without a post being selected" (#39). The changes made in this PR will make the items under the Post section of the sidebar visible even if a post is not selected in the Newsletter Single Post block. Additionally, the checkboxes will now be draggable, enabling users to set the "order" attribute.

Issue Number

Closes #39

Related Issue URL

#39

Notes

  • Please test the changes made in this PR to ensure they work as expected.
  • Ensure that the post display options can be edited without a post being selected.
  • Verify that the draggable checkboxes for setting the "order" attribute work and are only enabled on the Template post type.
  • Review the code changes made in this PR to guarantee they follow best practices.

@mogmarsh mogmarsh marked this pull request as ready for review November 13, 2023 17:00
Copy link
Member

@attackant attackant left a comment

Choose a reason for hiding this comment

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

No blockers, but ideas for you 🐙

default:
break;
}
};
Copy link
Member

Choose a reason for hiding this comment

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

I went back and forth on this but something like this may be cleaner, but really not sure:

const displayPreferences = {
     'image': showImage,
     'byline': showByline,
     'excerpt': showExcerpt,
     'content': showContent,
     'cta': showCta,
     'title': true
  };

  const isShown = (item: string) => displayPreferences[item] ?? false;
  
  const toggleShown = (item: string) => {
    setAttributes((prevAttributes: EditProps["attributes"]) => ({
      ...prevAttributes,
      [`show${item.charAt(0).toUpperCase() + item.slice(1)}`]: !prevAttributes[`show${item.charAt(0).toUpperCase() + item.slice(1)}`]
    }));
  };

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I like this suggestion, but this work should be temporary (see #48) so I'm going to leave it as is for now.

break;
}
};

Copy link
Member

Choose a reason for hiding this comment

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

Also for the ternary's in this file we may consider logical nullish
let postTitle = record?.title.rendered ?? '';
in place of
let postTitle = record ? record.title.rendered : '';

@mogmarsh mogmarsh merged commit 674b115 into develop Nov 14, 2023
7 checks passed
@mogmarsh mogmarsh deleted the feature/issue-39/edit-display-options-without-post branch November 14, 2023 14:09
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.

Allow post display options to be edited without a post being selected
2 participants