Skip to content

Enhancement: Make JSON view collapsible#1007

Merged
mohdsayed merged 13 commits into
release/v0.13.1from
enhancement/json-view-collapsible
Mar 31, 2025
Merged

Enhancement: Make JSON view collapsible#1007
mohdsayed merged 13 commits into
release/v0.13.1from
enhancement/json-view-collapsible

Conversation

@CharliePops

@CharliePops CharliePops commented Mar 19, 2025

Copy link
Copy Markdown
Contributor

Description

Making JSON view collapsible and trying to match colors to the JSON view used in default Dev tools

Relevant Technical Choices

The third party library was replace to be able to acheive functionality

Testing Instructions

  1. Pull and checkout the branch enhacement/json-view-collapsible
  2. Build and run the extension: npm run build:all && npm run dev:ext
  3. Open Privacy Sandbox tab on DevTools
  4. Go to a panel with a JSON view (example: PA:EE interests group tab)
  5. Observe: the JSON view allows to expand/collapse the object type values where needed

Additional Information:

Should be tested in light and dark theme and in all posible places where JSON is previewed

Screenshot/Screencast

  • Dark <3
dark
  • Light
light

Checklist

  • I have thoroughly tested this code to the best of my abilities.
  • I have reviewed the code myself before requesting a review.
  • NA - This code is covered by unit tests to verify that it works as intended.
  • The QA of this PR is done by a member of the QA team (to be checked by QA).

@CharliePops CharliePops self-assigned this Mar 19, 2025
@mohdsayed mohdsayed added this to the v1.0 milestone Mar 21, 2025
@CharliePops CharliePops marked this pull request as ready for review March 21, 2025 15:07

useEffect(() => {
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
setIsDarkMode(true);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If we want to make it dynamic, shouldn't we make use of an event listener? Something like this

useEffect(() => {
  const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');

  const handleChange = (event: MediaQueryListEvent) => {
    setIsDarkMode(event.matches);
  };

  setIsDarkMode(mediaQuery.matches); 
  mediaQuery.addEventListener('change', handleChange); 

  return () => {
    mediaQuery.removeEventListener('change', handleChange);
  };
}, []);

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.

The problem is that the rest of our extension doesn't work like that, so if the user changes the browser's theme while using the extension, the JSON view will be dynamic but other parts of the app won't:

Screenshot 2025-03-28 at 10 46 22 AM

IMO, I think we should create a task to make it dynamic everywhere in the app.

@mohdsayed mohdsayed Mar 31, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah, that should not be too difficult to achieve, we could do something like this

  useEffect(() => {
    const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');

    if (mediaQuery.matches) {
      mediaQuery.addEventListener('change', (event) => {
        const isDarkMode = event.matches;
        if (isDarkMode) {
          document.body.classList.add('dark');
          document.body.classList.remove('light');
        } else {
          document.body.classList.add('light');
          document.body.classList.remove('dark');
        }
      });
    }
  }, []);

Let do that in a separate PR.

Comment thread packages/design-system/src/components/jsonView/jsonView.tsx Outdated
@CharliePops CharliePops requested a review from mohdsayed March 28, 2025 10:12
@mohdsayed mohdsayed changed the base branch from develop to release/v0.13.1 March 31, 2025 14:39
@mohdsayed mohdsayed modified the milestones: v1.0, Future Releases Mar 31, 2025
@mohdsayed mohdsayed merged commit ba43d61 into release/v0.13.1 Mar 31, 2025
@mohdsayed mohdsayed deleted the enhancement/json-view-collapsible branch March 31, 2025 14:40
@mohdsayed mohdsayed modified the milestones: Future Releases, v0.13.1 Mar 31, 2025
@mohdsayed mohdsayed restored the enhancement/json-view-collapsible branch April 2, 2025 05:30
mohdsayed added a commit that referenced this pull request Apr 2, 2025
mohdsayed added a commit that referenced this pull request Apr 2, 2025
* make json view collapsible and replace third party library

* improve colors and fix dark mode

* rename json theme file

* fix import statement

* fix puppeter and worker.js

* expand only root object in json view

* improve dark light color matching

* further improve styles to match default devtools styling

* Reduce the size of three dots in collapsed state

* center loading text and center collapse/expand icons

---------

Co-authored-by: sayedtaqui <sayedwp@gmail.com>
@mohdsayed mohdsayed deleted the enhancement/json-view-collapsible branch April 2, 2025 05:39
@mohdsayed mohdsayed modified the milestones: v0.13.1, Future Releases Apr 2, 2025
mohdsayed added a commit that referenced this pull request Apr 8, 2025
* make json view collapsible and replace third party library

* improve colors and fix dark mode

* rename json theme file

* fix import statement

* fix puppeter and worker.js

* expand only root object in json view

* improve dark light color matching

* further improve styles to match default devtools styling

* Reduce the size of three dots in collapsed state

* center loading text and center collapse/expand icons

---------

Co-authored-by: sayedtaqui <sayedwp@gmail.com>
@mohdsayed mohdsayed mentioned this pull request Apr 8, 2025
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