Expose `data-view-only` attribute to WordPress data store
- Dominant language
- JavaScript
- Stars
- 1.4k
- Forks
- 383
- Avg merge
- 4d 12h
- Merged PRs (30d)
- 80
Description
## Feature Description
In our current setup, we extract the `data-view-only` attribute from a DOM element and pass it into the React context (`ViewContext`). However, this method doesn't fully leverage the capabilities of the WordPress data store, leading to inconsistently using the `isAuthenticated` selector to check the view-only user.
The purpose of this issue is to enhance our WordPress data store by creating a new selector that exposes the `data-view-only` attribute. Additionally, it involves refactoring instances where the `isAuthenticated()` method is currently used to check the view-only user, replacing it with this new approach.
---------------
_Do not alter or remove anything below. The following sections will be managed by moderators only._
## Acceptance criteria
* A new selector, `isViewOnly,` is implemented in the `core/user` data store, accurately reflecting the state of the `data-view-only` attribute.
* A `setIsViewOnly` action is created and appropriately dispatched in the entry files to set the initial view-only value in the `core/user` data store.
* All instances in the data store where `isAuthenticated()` is currently used to check the view-only user are successfully refactored to use the `isViewOnly` selector.
## Implementation Brief
* Finish and merge this POC [branch](https://github.com/google/site-kit-wp/compare/poc/expose-view-only-to-wp-data).
* Find all instances in the data store where `isAuthenticated()` is used to check the view-only users should be refactored to use the `isViewOnly` selector.
### Test Coverage
* Add test cases for the new `isViewOnly` selector.
* Fix any broken tests for the changes to replace the `isAuthenticated` selector.
## QA Brief
*
## Changelog entry
*
Contributor guide
Assessment
This issue has not been assessed yet.