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 the ability to use React components inline in Docusaurus markdown #3535

Merged
merged 7 commits into from
Jul 15, 2022

Conversation

alfarok
Copy link
Contributor

@alfarok alfarok commented Jul 15, 2022

Description

This PR addresses #3533.

Two new functional React components have been added to the repo:

  1. Http-Request-Sample.jsx
  2. Web-Socket-Sample.jsx

These are not yet used anywhere in the codebase, however they can be tested by adding the following lines to any markdown document inline:

  1. Web Request
import Http from "./../../components/Http-Request-Sample"
{{ polkadot: <Http url="https://polkadot.api.subscan.io/api/scan/block" hash="0x68a27df5a52ff2251df2cc8368f7dcefb305a13bb3d89b65c8fb070f23877f2c" color="#e6007a">Polkadot</Http> :polkadot }}
{{ kusama: <Http url="https://kusama.api.subscan.io/api/scan/block" hash="0x8019e80a0b97ee827b3bd8be1ac3d0fe4e9978d7b5594c0afb109d3ff8cf3465" color="#000000">Kusama</Http> :kusama }}
  1. Web Socket
import Socket from "./../../components/Web-Socket-Sample"
{{ polkadot: <Socket url="wss://rpc.polkadot.io" color="#e6007a">Polkadot</Socket> :polkadot }}
{{ kusama: <Socket url="wss://kusama-rpc.polkadot.io" color="#000000">Kusama</Socket> :kusama }}

This will render something similar to (ignore page context for sample):
Screenshot from 2022-07-15 12-49-11
or
Screenshot from 2022-07-15 12-48-59

The first pink or black box is the web socket connection updating the current block number in real-time. The second is a POST request made to subscan to retrieve the latest information about an existing block. The web socket will continue to update, while the POST will only execute once when the page initially loads but will re-execute upon returning to the page for updated data.

Follow-up Tasks

  • Start leveraging new React components to replace existing global constants or other dynamic values #3536 which should consider the following
    • The team should discuss how we want to introduce this functionality into the existing code and determine which global constants should be replaced with these inline components
    • The inline components should be modified to handle a variety of request types. It is good practice to avoid creating new components for every scenario. Instead, we should add parameters (or optional parameters) to extend the existing components. So for example, the Http-Request-Sample.jsx component should be able to handle a GET or POST request without creating another component.

@alfarok alfarok added the A2 - Please Review Pull request is ready for review. label Jul 15, 2022
@alfarok alfarok requested review from emresurmeli and DrW3RK July 15, 2022 18:21
@alfarok alfarok self-assigned this Jul 15, 2022
@DrW3RK
Copy link
Member

DrW3RK commented Jul 15, 2022

Here are a few I could think of

  • Min Active Nomination (very useful for users landing on our Staking page)
  • Min stake backing an active validator in an era (resourceful for new node operators eyeing our ecosystem)
  • Number of parachains on Polkadot/Kusama
  • number of active nominators and Total number of nominators
  • number of active validators/ waiting validators
  • era number
  • Staked DOT/KSM percentage

@alfarok
Copy link
Contributor Author

alfarok commented Jul 15, 2022

Here are a few I could think of

  • Min Active Nomination (very useful for users landing on our Staking page)
  • Min stake backing an active validator in an era (resourceful for new node operators eyeing our ecosystem)
  • Number of parachains on Polkadot/Kusama
  • number of active nominators and Total number of nominators
  • number of active validators/ waiting validators
  • era number
  • Staked DOT/KSM percentage

Great! These will definitely get us started using the components. If you don't mind I would like to break this out into a new task. This way we can also refer to this PR as a hello_world sample regarding how we can use React inline. Abstracting the samples to fit several different scenarios will make the components slightly more confusing for someone that may be new to the workflow or React. Ultimately, I think we can eventually convert all the constants to leverage the components and remove the previous system.

@alfarok
Copy link
Contributor Author

alfarok commented Jul 15, 2022

@DrW3RK I added #3536 to start working on this. My main concern with doing both in the same PR is that the diff would be overwhelming to review. I viewed this task as more of a research spike in agile and the follow-up as the implementation of the proposed solution.

@DrW3RK
Copy link
Member

DrW3RK commented Jul 15, 2022

Tested it locally. Works as expected

image

@alfarok alfarok merged commit c2ed035 into master Jul 15, 2022
@alfarok alfarok deleted the react-inline branch July 15, 2022 20:31
alfarok added a commit that referenced this pull request Jul 28, 2022
…#3535)

* add sample inline react components to markdown

* update kusama rpc url

* clean up and add http request sample component

* formatting

* ensure to unsubscribe from web socket events when changing pages

* remove debugging code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A2 - Please Review Pull request is ready for review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants