Skip to content

Commit

Permalink
Merge pull request #180 from topmonks/46-metadata-docs
Browse files Browse the repository at this point in the history
Metadata docs
  • Loading branch information
uiii committed Dec 6, 2023
2 parents c0f084f + 9b7ca49 commit a09199b
Show file tree
Hide file tree
Showing 32 changed files with 312 additions and 124 deletions.
2 changes: 1 addition & 1 deletion src/components/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const cardHeaderStyle = css`
[data-class=copy-button] {
vertical-align: text-bottom;
margin: 6px 0;
margin: 2px 0;
margin-left: 16px;
}
`;
Expand Down
1 change: 0 additions & 1 deletion src/components/CopyToClipboardButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { IconButton, IconButtonProps, Tooltip } from "@mui/material";
import { css } from "@emotion/react";

const buttonStyle = css`
padding: 0;
`;

export type CopyToClipboardButtonProps = Omit<IconButtonProps, "value"|"size"> & {
Expand Down
26 changes: 13 additions & 13 deletions src/components/DataViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/** @jsxImportSource @emotion/react */
import { PropsWithChildren, ReactNode, useMemo, useState } from "react";
import { css, Theme } from "@emotion/react";
import { IconButton, Modal, ToggleButton, ToggleButtonGroup } from "@mui/material";
import { Close } from "@mui/icons-material";
import { IconButton, Modal, ToggleButton, ToggleButtonGroup, Tooltip } from "@mui/material";
import { AutoStories, Close } from "@mui/icons-material";

import { Network } from "../model/network";
import { RuntimeMetadataArg } from "../model/runtime-metadata/runtimeMetadataArg";
Expand Down Expand Up @@ -91,6 +91,7 @@ const simpleControlsStyle = css`
align-items: flex-start;
margin-bottom: 0;
margin-left: 12px;
padding-top: 2px;
`;

const modeButtonsStyle = css`
Expand All @@ -104,21 +105,20 @@ const modeButtonStyle = css`
line-height: 24px;
`;

const fullscreenButtonStyle = css`
padding: 2px;
margin-left: 8px;
`;
const buttonStyle = css`
margin: -4px 0;
margin-left: 4px;
const copyButtonStyle = css`
padding: 2px;
&:last-child {
margin-right: -2px;
}
`;

const closeButtonStyle = css`
position: absolute;
top: 0;
right: 0;
margin: 12px;
padding: 0;
margin: 8px;
z-index: 10;
`;
Expand Down Expand Up @@ -169,7 +169,7 @@ const DataViewerModalHandle = (props: DataViewerModalHandleProps) => {

return (
<>
<IconButton css={fullscreenButtonStyle} onClick={() => setShowModal(true)}>
<IconButton css={buttonStyle} onClick={() => setShowModal(true)}>
<svg
height="20"
viewBox="0 0 20 20"
Expand Down Expand Up @@ -254,13 +254,13 @@ export const DataViewer = (props: DataViewerProps) => {
>
<div css={[controlsStyle, simple && simpleControlsStyle]}>
{!simple && <ModeSelect modes={MODES} value={mode} onChange={setMode} />}
{copyToClipboard && <CopyToClipboardButton value={copyToClipboardValue} css={copyButtonStyle} />}
{copyToClipboard && <CopyToClipboardButton value={copyToClipboardValue} css={buttonStyle} />}
{!simple &&
<DataViewerModalHandle>
<div css={dataViewerStyle}>
<div css={[controlsStyle]}>
<ModeSelect modes={MODES} value={mode} onChange={setMode} />
{copyToClipboard && <CopyToClipboardButton value={copyToClipboardValue} css={copyButtonStyle} />}
{copyToClipboard && <CopyToClipboardButton value={copyToClipboardValue} css={buttonStyle} />}
</div>
<div css={scrollAreaStyle}>
{mode === "json" && jsonContent}
Expand Down
3 changes: 2 additions & 1 deletion src/components/InfoTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ const valueStyle = css`
`;

const copyButtonStyle = css`
margin-left: 16px;
margin: -4px 0;
margin-left: 12px;
`;

type InfoTableDataFn<T, A extends any[], R> = (data: T, ...additionalData: A) => R;
Expand Down
6 changes: 5 additions & 1 deletion src/components/blocks/BlockInfoTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ export const BlockInfoTable = (props: BlockInfoTableProps) => {
/>
<BlockInfoTableAttribute
label="Spec version"
render={(data) => data.specVersion}
render={(data) =>
<Link to={`/${data.network.name}/runtime/${data.specVersion}`}>
{data.specVersion}
</Link>
}
/>
</InfoTable>

Expand Down
7 changes: 6 additions & 1 deletion src/components/blocks/BlocksTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PaginatedResource } from "../../model/paginatedResource";
import { AccountAddress } from "../account/AccountAddress";

import { ItemsTable, ItemsTableAttribute } from "../ItemsTable";
import { Link } from "../Link";
import { Time } from "../Time";

import { BlockLink } from "./BlockLink";
Expand Down Expand Up @@ -47,7 +48,11 @@ function ExtrinsicsTable(props: BlocksTableProps) {
/>
<BlocksTableAttribute
label="Spec version"
render={(block) => block.specVersion}
render={(block) =>
<Link to={`/${block.network.name}/runtime/${block.specVersion}`}>
{block.specVersion}
</Link>
}
/>
{showValidator &&
<BlocksTableAttribute
Expand Down
21 changes: 12 additions & 9 deletions src/components/calls/CallInfoTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ import { AccountAddress } from "../account/AccountAddress";
import { BlockLink } from "../blocks/BlockLink";
import { ExtrinsicLink } from "../extrinsics/ExtrinsicLink";

import { ButtonLink } from "../ButtonLink";
import { DataViewer } from "../DataViewer";
import { InfoTable, InfoTableAttribute } from "../InfoTable";
import { Link } from "../Link";
import { NetworkBadge } from "../NetworkBadge";
import { Time } from "../Time";

import { CallLink } from "./CallLink";
import { CallNameButton } from "./CallNameButton";
import { CallRuntimeMetadataButton } from "./CallRuntimeMetadataButton";

export type CallInfoTableProps = {
network: Network;
Expand Down Expand Up @@ -105,13 +107,10 @@ export const CallInfoTable = (props: CallInfoTableProps) => {
<CallInfoTableAttribute
label="Name"
render={(data) =>
<ButtonLink
to={`/search/extrinsics?query=${data.palletName}.${data.callName}&network=${network.name}`}
size="small"
color="secondary"
>
{data.palletName}.{data.callName}
</ButtonLink>
<>
<CallNameButton call={data} />
{data.metadata.call && <CallRuntimeMetadataButton call={data} />}
</>
}
/>
<CallInfoTableAttribute
Expand All @@ -127,7 +126,11 @@ export const CallInfoTable = (props: CallInfoTableProps) => {
/>
<CallInfoTableAttribute
label="Spec version"
render={(data) => data.specVersion}
render={(data) =>
<Link to={`/${data.network.name}/runtime/${data.specVersion}`}>
{data.specVersion}
</Link>
}
/>
</InfoTable>
);
Expand Down
29 changes: 29 additions & 0 deletions src/components/calls/CallNameButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/** @jsxImportSource @emotion/react */
import { css } from "@emotion/react";

import { Call } from "../../model/call";

import { ButtonLink } from "../ButtonLink";

const buttonStyle = css`
margin: -4px 0;
`;

export interface CallNameButtonProps {
call: Call;
}

export const CallNameButton = (props: CallNameButtonProps) => {
const {call} = props;

return (
<ButtonLink
to={`/search/extrinsics?query=${call.palletName}.${call.callName}&network=${call.network.name}`}
size="small"
color="secondary"
css={buttonStyle}
>
{call.palletName}.{call.callName}
</ButtonLink>
);
};
23 changes: 23 additions & 0 deletions src/components/calls/CallRuntimeMetadataButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Call } from "../../model/call";

import { RuntimeMetadataButton } from "../runtime/RuntimeMetadataButton";

export interface CallRuntimeMetadataButtonProps {
call: Call;
}

export const CallRuntimeMetadataButton = (props: CallRuntimeMetadataButtonProps) => {
const {call} = props;

if (!call.metadata.call) {
return null;
}

return (
<RuntimeMetadataButton
title={`${call.palletName}.${call.callName}`}
description={call.metadata.call.description}
link={`/${call.network.name}/runtime/${call.specVersion}/${call.palletName}/calls/${call.callName}`}
/>
);
};
11 changes: 2 additions & 9 deletions src/components/calls/CallsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ButtonLink } from "../ButtonLink";
import { ItemsTable, ItemsTableAttribute } from "../ItemsTable";

import { CallLink } from "./CallLink";
import { CallNameButton } from "./CallNameButton";

export type CallsTableProps = {
network: Network;
Expand Down Expand Up @@ -41,15 +42,7 @@ export const CallsTable = (props: CallsTableProps) => {
/>
<CallsTableAttribute
label="Name"
render={(call) =>
<ButtonLink
to={`/search/extrinsics?query=${call.palletName}.${call.callName}&network=${network.name}`}
size="small"
color="secondary"
>
{call.palletName}.{call.callName}
</ButtonLink>
}
render={(call) => <CallNameButton call={call} />}
/>
{showAccount && (
<CallsTableAttribute
Expand Down
22 changes: 13 additions & 9 deletions src/components/events/EventInfoTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import { BlockLink } from "../blocks/BlockLink";
import { CallLink } from "../calls/CallLink";
import { ExtrinsicLink } from "../extrinsics/ExtrinsicLink";

import { ButtonLink } from "../ButtonLink";
import { DataViewer } from "../DataViewer";
import { InfoTable, InfoTableAttribute } from "../InfoTable";
import { Link } from "../Link";
import { NetworkBadge } from "../NetworkBadge";
import { Time } from "../Time";

import { EventNameButton } from "./EventNameButton";
import { EventRuntimeMetadataButton } from "./EventRuntimeMetadataButton";

export type EventInfoTableProps = {
network: Network;
event: Resource<Event>;
Expand Down Expand Up @@ -72,13 +75,10 @@ export const EventInfoTable = (props: EventInfoTableProps) => {
<EventInfoTableAttribute
label="Name"
render={(data) =>
<ButtonLink
to={`/search/events?query=${data.palletName}.${data.eventName}&network=${network.name}`}
size="small"
color="secondary"
>
{data.palletName}.{data.eventName}
</ButtonLink>
<>
<EventNameButton event={data} />
{data.metadata.event && <EventRuntimeMetadataButton event={data} />}
</>
}
/>
<EventInfoTableAttribute
Expand All @@ -95,7 +95,11 @@ export const EventInfoTable = (props: EventInfoTableProps) => {
/>
<EventInfoTableAttribute
label="Spec version"
render={(data) => data.specVersion}
render={(data) =>
<Link to={`/${data.network.name}/runtime/${data.specVersion}`}>
{data.specVersion}
</Link>
}
/>
</InfoTable>
);
Expand Down
29 changes: 29 additions & 0 deletions src/components/events/EventNameButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/** @jsxImportSource @emotion/react */
import { css } from "@emotion/react";

import { Event } from "../../model/event";

import { ButtonLink } from "../ButtonLink";

const buttonStyle = css`
margin: -4px 0;
`;

export interface EventNameButtonProps {
event: Event;
}

export const EventNameButton = (props: EventNameButtonProps) => {
const {event} = props;

return (
<ButtonLink
to={`/search/events?query=${event.palletName}.${event.eventName}&network=${event.network.name}`}
size="small"
color="secondary"
css={buttonStyle}
>
{event.palletName}.{event.eventName}
</ButtonLink>
);
};
23 changes: 23 additions & 0 deletions src/components/events/EventRuntimeMetadataButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Event } from "../../model/event";

import { RuntimeMetadataButton } from "../runtime/RuntimeMetadataButton";

export interface EventRuntimeMetadataButtonProps {
event: Event;
}

export const EventRuntimeMetadataButton = (props: EventRuntimeMetadataButtonProps) => {
const {event} = props;

if (!event.metadata.event) {
return null;
}

return (
<RuntimeMetadataButton
title={`${event.palletName}.${event.eventName}`}
description={event.metadata.event.description}
link={`/${event.network.name}/runtime/${event.specVersion}/${event.palletName}/events/${event.eventName}`}
/>
);
};
11 changes: 2 additions & 9 deletions src/components/events/EventsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { DataViewer } from "../DataViewer";
import { ItemsTable, ItemsTableAttribute } from "../ItemsTable";

import { EventLink } from "./EventLink";
import { EventNameButton } from "./EventNameButton";

const parametersColCss = (showExtrinsic?: boolean) => css`
width: ${showExtrinsic ? "40%" : "60%"};
Expand Down Expand Up @@ -48,15 +49,7 @@ function EventsTable(props: EventsTableProps) {
/>
<EventsItemsTableAttribute
label="Name"
render={(event) =>
<ButtonLink
to={`/search/events?query=${event.palletName}.${event.eventName}&network=${network.name}`}
size="small"
color="secondary"
>
{event.palletName}.{event.eventName}
</ButtonLink>
}
render={(event) => <EventNameButton event={event} />}
/>
{showExtrinsic && (
<EventsItemsTableAttribute
Expand Down
Loading

0 comments on commit a09199b

Please sign in to comment.