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

Add refresh button to the api docs examples #3287

Closed
ST-DDT opened this issue Nov 26, 2024 · 7 comments · Fixed by #3301
Closed

Add refresh button to the api docs examples #3287

ST-DDT opened this issue Nov 26, 2024 · 7 comments · Fixed by #3301
Assignees
Labels
c: docs Improvements or additions to documentation p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Milestone

Comments

@ST-DDT
Copy link
Member

ST-DDT commented Nov 26, 2024

Clear and concise description of the problem

Currently, the documentation only provides a single example per invocation, this could result in wrong expectations of method return values.

See:

Suggested solution

Adding a refresh button to the example sections:

apidocs-refresh-button.mp4

For that to work, we have to

  • trigger downloading of the latest faker version (on first press)
  • change our apidocs json data to be js/ts, so that we can store actual code in there
  • add a function () => unknown[] to the export data from the actual examples
  • take each result JSON.stringify it and insert into the code block

Alternative

Add more examples for the no args examples.

Additional context

Original issue:

Original fix suggestion:

Alternative suggestion for a fix:

@ST-DDT ST-DDT added c: feature Request for new feature s: pending triage Pending Triage s: waiting for user interest Waiting for more users interested in this feature c: docs Improvements or additions to documentation p: 1-normal Nothing urgent and removed c: feature Request for new feature s: pending triage Pending Triage s: waiting for user interest Waiting for more users interested in this feature labels Nov 26, 2024
@faker-js faker-js deleted a comment from github-actions bot Nov 26, 2024
@ST-DDT ST-DDT added this to the vAnytime milestone Nov 26, 2024
@ST-DDT ST-DDT added the s: needs decision Needs team/maintainer decision label Nov 26, 2024
@ST-DDT
Copy link
Member Author

ST-DDT commented Nov 26, 2024

FFR: The preview in the video was created using this code:
<button style="border: none; background: none; cursor: pointer;" onclick="
var lines = this.nextElementSibling.children[0].children[2].children[0].children;
lines[0].children[3].innerText = '// '+JSON.stringify(faker.lorem.sentences());
lines[1].children[5].innerText = '// '+JSON.stringify(faker.lorem.sentences(2));
const parts = JSON.stringify(faker.lorem.sentences(2, '\n')).split('\\n');
lines[3].children[0].innerText = '// '+parts[0];
lines[4].children[0].innerText = '// '+parts[1];
lines[5].children[7].innerText = '// '+JSON.stringify(faker.lorem.sentences({ min: 1, max: 3 }));
">
    <img src="https://upload.wikimedia.org/wikipedia/commons/c/ce/Ic_refresh_48px.svg" alt="Refresh Icon" width="24" height="24" style="display: inline-block; vertical-align: middle;">
</button>

The actual code should be more dynamic, so that it works without any configuration (and use a different svg).

The x in lines[i].children[x] is always the last element in the array. If that isn't the comment, then comment is in the next line.

lines can probably be resolved more easily via this.nextElementSibling.querySelectorAll('.line'); (not tested)

No additional libraries needed.

@ST-DDT
Copy link
Member Author

ST-DDT commented Nov 26, 2024

What do you think of this idea?

@sounmind
Copy link

Speaking as the author of the original issue, I think it's great idea.

@ST-DDT
Copy link
Member Author

ST-DDT commented Nov 28, 2024

Team Decision

  • We will try this
  • There should be visual feedback while downloading the current faker version (spinner etc) for people with slow internet connections

@ST-DDT ST-DDT added s: accepted Accepted feature / Confirmed bug and removed s: needs decision Needs team/maintainer decision labels Nov 28, 2024
@matthewmayer
Copy link
Contributor

I think rather than just an icon it could be a smal button in the bottom right of the examples block like "Load more examples"

@ST-DDT
Copy link
Member Author

ST-DDT commented Nov 29, 2024

Like this?

load-more-examples button

I'm unsure how this will look like if the example is only a single line.

Do you want to append or replace the new examples?

@matthewmayer
Copy link
Contributor

Replace like in your video.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: docs Improvements or additions to documentation p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants