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

feat: page runtime detail info #644

Merged
merged 7 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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