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

fix unformatted response preview safari #765

Merged
merged 8 commits into from
Jan 18, 2021

Conversation

ezkemboi
Copy link
Contributor

@ezkemboi ezkemboi commented Nov 17, 2020

Overview

Fix formatting issue of JSON when using Safari Browsers

Demo

Screenshot 2020-11-17 at 23 27 04

Screenshot 2020-11-17 at 23 27 28

Notes

Here is a function I did not use and commented it in editorDidMount prop in MonacoEditor Have not removed yet

function editorDidMount(editor: any) {
  const editorHasText = !!editor.getModel().getValue();

  if (editorHasText) {
    formatDocument(editor);
  }

  editor.onDidChangeModelContent(() => {
    formatDocument(editor);
  });
}

function formatDocument(editor: any) {
  editor.getAction('editor.action.formatDocument').run();
}

Here is the replacement that seemed to work for all browsers

 body = JSON.stringify(body).replace(/(?:\\[rnt]|[\r\n\t]+)+/g, '');
 // remove whitespace, tabs or raw string (Safari related issue)
 body = JSON.parse(body); // convert back to javascript object
 body = JSON.stringify(body, null, 4); // format the string (works for all browsers)

We can discuss more on the above code under reviews and way forward to allow all browsers to format JSON effectively.

Testing Instructions

  • Need to be tested using Safari, Chrome, Edge, and/or another browser
  • Check on the formatting of response preview [Need to be JSON format]

@ezkemboi
Copy link
Contributor Author

ezkemboi commented Nov 17, 2020

@thewahome and @ElinorW I have this PR that can offer a room for discussion.

Copy link
Contributor

@jobala jobala left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@jobala
Copy link
Contributor

jobala commented Jan 12, 2021

@ezkemboi clean up the PR and this should be good to go.

@ezkemboi
Copy link
Contributor Author

ezkemboi commented Jan 12, 2021

I will be working on cleaning this one @jobala

@ezkemboi
Copy link
Contributor Author

Ping @jobala

@jobala
Copy link
Contributor

jobala commented Jan 16, 2021

Thanks @ezkemboi. @thewahome this fails with azure_static_web_apps_api_token was not provided. how can I fix this?

@jobala jobala merged commit 2f9f0bb into microsoftgraph:dev Jan 18, 2021
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.

Response preview appears unformatted in Safari
2 participants