Skip to content

Commit

Permalink
feat: page runtime detail info (#644)
Browse files Browse the repository at this point in the history
* runtime detail api

* fix runtime detail page path

* feat: fetch runtime detail

* init page runtime

* init to runtime detail item

* runtime, add detail item

* fill list data
  • Loading branch information
2nthony authored Mar 16, 2023
1 parent c2ee1ef commit 2e2adc2
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 4 deletions.
3 changes: 2 additions & 1 deletion site/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ function App() {
<Route path="/calls" element={<Calls />} />
<Route path="/calls/:id" element={<Call />} />
<Route path="/runtimes" element={<Runtimes />} />
<Route path="/runtimes/:version" element={<Runtime />} />
{/* /runtimes/:version_:startHeight */}
<Route path="/runtimes/:runtimeSlug" element={<Runtime />} />
</Routes>
</HashRouter>
);
Expand Down
2 changes: 1 addition & 1 deletion site/src/components/runtime/runtimesTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const SpecName = styled.span`
export default function RuntimesTable({ data = [], loading }) {
const tableData = data?.map?.((item) => {
return [
<ColoredLink to={`/runtimes/${item.specVersion}`}>
<ColoredLink to={`/runtimes/${item.specVersion}_${item.startHeight}`}>
{item.specVersion}
</ColoredLink>,
<SpecName>{item.specName}</SpecName>,
Expand Down
58 changes: 57 additions & 1 deletion site/src/pages/runtime.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,59 @@
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 {
clearHttpError,
handleApiError,
} from "../utils/viewFuncs/errorHandles";
import { toRuntimeDetailItem } from "../utils/viewFuncs/toDetailItem";

export default function Runtime() {
return <div>page runtime</div>;
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,
},
]}
/>
);

return (
<DetailLayout breadCrumb={breadCrumb}>
<Panel>
<List data={listData} />
</Panel>
</DetailLayout>
);
}
2 changes: 2 additions & 0 deletions site/src/services/urls.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export const nftInstanceApi = (classId, instanceId) =>

// runtimes
export const runtimeListApi = "/runtimes";
export const runtimeDetailApi = (version, startHeight) =>
`/runtimes/${version}_${startHeight}`;

// dotreasury
const dotreasuryApiEndPoint =
Expand Down
16 changes: 15 additions & 1 deletion site/src/store/reducers/runtimeSlice.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createSlice } from "@reduxjs/toolkit";
import api from "../../services/api";
import { runtimeListApi } from "../../services/urls";
import { runtimeDetailApi, runtimeListApi } from "../../services/urls";

const name = "runtime";

Expand Down Expand Up @@ -50,4 +50,18 @@ 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;
21 changes: 21 additions & 0 deletions site/src/utils/viewFuncs/toDetailItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { bigNumberToLocaleString } from ".";
import { time } from "./time";
import { isCid } from "../cid";
import { getNftInstanceParsedMetadata } from "../nft";
import capitalize from "lodash.capitalize";

const TextSecondaryWithCopy = withCopy(TextSecondary);
const ColoredMonoLinkWithCopy = withCopy(ColoredMonoLink);
Expand Down Expand Up @@ -237,6 +238,26 @@ export const toCallDetailItem = (indexer, section, method) => {
};
};

export const toRuntimeDetailItem = (runtime) => {
return {
Version: (
<TextSecondary>{runtime?.runtimeVersion?.specVersion}</TextSecondary>
),
ID: <TextSecondary>-</TextSecondary>,
"Start Height": (
<ColoredInterLink to={`/blocks/${runtime?.height}`}>
{runtime?.height?.toLocaleString?.()}
</ColoredInterLink>
),
"Spec Name": (
<TextSecondary>
{capitalize(runtime?.runtimeVersion?.specName)}
</TextSecondary>
),
Pallets: <TextSecondary>-</TextSecondary>,
};
};

export const toEventDetailItem = (event) => {
return {
"Event Time": <DetailedTime ts={event?.indexer?.blockTime} />,
Expand Down

0 comments on commit 2e2adc2

Please sign in to comment.