-
Notifications
You must be signed in to change notification settings - Fork 39
feat: runtimes #640
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
Draft
2nthony
wants to merge
9
commits into
main
Choose a base branch
from
feat-runtimes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
feat: runtimes #640
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
80bdcb2
init
2nthony 2504ca9
Merge branch 'main' into feat-runtimes
2nthony b072665
urls
2nthony 8dbf7d4
init runtime store
2nthony 17ddd36
tailwind add text capitalize
2nthony d940940
prefer with s suffix
2nthony c2ee1ef
feat: page runtimes
2nthony 2e2adc2
feat: page runtime detail info (#644)
2nthony 1f7c798
fix: runtime route, start height copy
2nthony File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import styled from "styled-components"; | ||
| import { text_capitalize } from "../../styles/tailwindcss"; | ||
| import { runtimesHead } from "../../utils/constants"; | ||
| import { ColoredLink } from "../styled/link"; | ||
| import Table from "../table"; | ||
|
|
||
| const SpecName = styled.span` | ||
| ${text_capitalize}; | ||
| `; | ||
|
|
||
| /** | ||
| * @description page runtimes table | ||
| */ | ||
| export default function RuntimesTable({ data = [], loading }) { | ||
| const tableData = data?.map?.((item) => { | ||
| return [ | ||
| <ColoredLink to={`/runtimes/${item.specVersion}-${item.startHeight}`}> | ||
| {item.specVersion} | ||
| </ColoredLink>, | ||
| <SpecName>{item.specName}</SpecName>, | ||
| <ColoredLink to={`/blocks/${item.startHeight}`}> | ||
| {item.startHeight?.toLocaleString?.()} | ||
| </ColoredLink>, | ||
| item.count.pallets, | ||
| item.count.calls, | ||
| item.count.events, | ||
| item.count.storage, | ||
| item.count.constants, | ||
| ]; | ||
| }); | ||
|
|
||
| return <Table heads={runtimesHead} data={tableData} loading={loading} />; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import { useEffect } from "react"; | ||
| import { useDispatch, useSelector } from "react-redux"; | ||
| import { useParams } from "react-router-dom"; | ||
| import BreadCrumb from "../components/breadCrumb"; | ||
| import DetailLayout from "../components/layout/detailLayout"; | ||
| import List from "../components/list"; | ||
| import { Panel } from "../components/styled/panel"; | ||
| import { | ||
| clearRuntimeDetail, | ||
| runtimeDetailSelector, | ||
| runtimeFetchDetail, | ||
| } from "../store/reducers/runtimeSlice"; | ||
| import { bigNumberToLocaleString } from "../utils/viewFuncs"; | ||
| import { | ||
| clearHttpError, | ||
| handleApiError, | ||
| } from "../utils/viewFuncs/errorHandles"; | ||
| import { toRuntimeDetailItem } from "../utils/viewFuncs/toDetailItem"; | ||
|
|
||
| export default function Runtime() { | ||
| const { runtimeSlug } = useParams(); | ||
| const [version, startHeight] = runtimeSlug.split("-"); | ||
|
|
||
| const dispatch = useDispatch(); | ||
| const runtime = useSelector(runtimeDetailSelector); | ||
|
|
||
| const listData = runtime ? toRuntimeDetailItem(runtime) : {}; | ||
|
|
||
| useEffect(() => { | ||
| if (version && startHeight) { | ||
| clearHttpError(dispatch); | ||
| dispatch(runtimeFetchDetail(version, startHeight)).catch((e) => | ||
| handleApiError(e, dispatch), | ||
| ); | ||
| } | ||
|
|
||
| return () => { | ||
| dispatch(clearRuntimeDetail()); | ||
| }; | ||
| }, [version, dispatch, startHeight]); | ||
|
|
||
| const breadCrumb = ( | ||
| <BreadCrumb | ||
| data={[ | ||
| { name: "Runtimes", path: "/runtimes" }, | ||
| { | ||
| name: version + "-" + bigNumberToLocaleString(startHeight), | ||
| }, | ||
| ]} | ||
| /> | ||
| ); | ||
|
|
||
| return ( | ||
| <DetailLayout breadCrumb={breadCrumb}> | ||
| <Panel> | ||
| <List data={listData} /> | ||
| </Panel> | ||
| </DetailLayout> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import { useEffect } from "react"; | ||
| import { useDispatch, useSelector } from "react-redux"; | ||
| import { useLocation } from "react-router-dom"; | ||
| import BreadCrumb from "../components/breadCrumb"; | ||
| import Layout from "../components/layout"; | ||
| import Pagination from "../components/pagination"; | ||
| import RuntimesTable from "../components/runtime/runtimesTable"; | ||
| import { StyledPanelTableWrapper } from "../components/styled/panel"; | ||
| import { | ||
| clearRuntimeList, | ||
| runtimeFetchList, | ||
| runtimeListLoadingSelector, | ||
| runtimeListSelector, | ||
| } from "../store/reducers/runtimeSlice"; | ||
| import { LIST_DEFAULT_PAGE_SIZE } from "../utils/constants"; | ||
| import { getPageFromQuery } from "../utils/viewFuncs"; | ||
|
|
||
| export default function Runtimes() { | ||
| const dispatch = useDispatch(); | ||
| const location = useLocation(); | ||
| const page = getPageFromQuery(location); | ||
| const pageSize = LIST_DEFAULT_PAGE_SIZE; | ||
|
|
||
| const list = useSelector(runtimeListSelector); | ||
| const loading = useSelector(runtimeListLoadingSelector); | ||
|
|
||
| useEffect(() => { | ||
| const controller = new AbortController(); | ||
|
|
||
| dispatch( | ||
| runtimeFetchList(page - 1, pageSize, null, { signal: controller.signal }), | ||
| ); | ||
|
|
||
| return () => { | ||
| controller.abort(); | ||
| }; | ||
| }, [dispatch, page, pageSize]); | ||
|
|
||
| useEffect(() => { | ||
| return () => { | ||
| dispatch(clearRuntimeList()); | ||
| }; | ||
| }, [dispatch]); | ||
|
|
||
| return ( | ||
| <Layout> | ||
| <BreadCrumb data={[{ name: "Runtimes" }]} /> | ||
|
|
||
| <StyledPanelTableWrapper | ||
| footer={ | ||
| <Pagination | ||
| page={parseInt(page)} | ||
| pageSize={pageSize} | ||
| total={list?.total} | ||
| /> | ||
| } | ||
| > | ||
| <RuntimesTable data={list?.items} loading={loading} /> | ||
| </StyledPanelTableWrapper> | ||
| </Layout> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { createSlice } from "@reduxjs/toolkit"; | ||
| import api from "../../services/api"; | ||
| import { runtimeDetailApi, runtimeListApi } from "../../services/urls"; | ||
|
|
||
| const name = "runtime"; | ||
|
|
||
| const runtimeSlice = createSlice({ | ||
| name, | ||
| initialState: { | ||
| list: null, | ||
| listLoading: false, | ||
| detail: null, | ||
| }, | ||
| reducers: { | ||
| setList(state, { payload }) { | ||
| state.list = payload; | ||
| }, | ||
| setListLoading(state, { payload }) { | ||
| state.listLoading = payload; | ||
| }, | ||
| setDetail(state, { payload }) { | ||
| state.detail = payload; | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| export const { setList, setListLoading, setDetail } = runtimeSlice.actions; | ||
|
|
||
| export const runtimeListSelector = (state) => state[name].list; | ||
| export const runtimeListLoadingSelector = (state) => state[name].listLoading; | ||
| export const runtimeDetailSelector = (state) => state[name].detail; | ||
|
|
||
| export const runtimeFetchList = | ||
| (page, pageSize, params, fetchOptions) => async (dispatch) => { | ||
| dispatch(setListLoading(true)); | ||
|
|
||
| return api | ||
| .fetch(runtimeListApi, { page, pageSize, ...params }, fetchOptions) | ||
| .then(({ result }) => { | ||
| if (result) { | ||
| dispatch(setList(result)); | ||
| } | ||
| }) | ||
| .finally(() => { | ||
| dispatch(setListLoading(false)); | ||
| }); | ||
| }; | ||
|
|
||
| export const clearRuntimeList = () => (dispatch) => { | ||
| dispatch(setList(null)); | ||
| }; | ||
|
|
||
| export const runtimeFetchDetail = (version, startHeight) => (dispatch) => { | ||
| return api | ||
| .fetch(runtimeDetailApi(version, startHeight)) | ||
| .then(({ result }) => { | ||
| if (result) { | ||
| dispatch(setDetail(result)); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| export const clearRuntimeDetail = () => (dispatch) => { | ||
| dispatch(setDetail(null)); | ||
| }; | ||
|
|
||
| export default runtimeSlice.reducer; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I think we should have mounted check.