Skip to content
Open
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
51 changes: 17 additions & 34 deletions src/app/(sidebar)/network-limits/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { SdsLink } from "@/components/SdsLink";
import { LabelHeading } from "@/components/LabelHeading";
import { SwitchNetworkButtons } from "@/components/SwitchNetworkButtons";
import { Tabs } from "@/components/Tabs";
import { CopyJsonPayloadButton } from "@/components/CopyJsonPayloadButton";
import { CodeEditor } from "@/components/CodeEditor";

import {
Expand Down Expand Up @@ -48,18 +47,7 @@ export default function NetworkLimits() {

return (
<div className="NetworkLimits">
<PageCard
heading="Network limits"
rightElement={
network.id !== "custom" ? (
<Tabs
tabs={VIEW_TABS}
activeTabId={activeTab}
onChange={setActiveTab}
/>
) : undefined
}
>
<PageCard heading="Network limits">
{network.id === "custom" ? (
<Alert
placement="inline"
Expand Down Expand Up @@ -94,6 +82,13 @@ export default function NetworkLimits() {
</SdsLink>
</Text>
</Box>

<Tabs
tabs={VIEW_TABS}
activeTabId={activeTab}
onChange={setActiveTab}
/>

{activeTab === "table" ? (
<>
<Box gap="sm">
Expand All @@ -110,27 +105,15 @@ export default function NetworkLimits() {
<ResourceFeesSection limits={limits} />
</>
) : (
<Box gap="sm">
{limitsJsonString && (
<>
<div className="NetworkLimits__json-container">
<CodeEditor
heightInRem="30"
value={limitsJsonString}
selectedLanguage="json"
/>
</div>
<Box
gap="md"
direction="row"
justify="right"
align="center"
>
<CopyJsonPayloadButton jsonString={limitsJsonString} />
</Box>
</>
)}
</Box>
<div className="NetworkLimits__json-container">
<CodeEditor
title="JSON response"
heightInRem="30"
value={limitsJsonString}
selectedLanguage="json"
fileName="network-limits"
/>
</div>
)}
</>
)}
Expand Down
137 changes: 68 additions & 69 deletions src/components/CodeEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,86 +136,85 @@ export const CodeEditor = ({
>
{title ? (
<div className="CodeEditor__header" ref={headerEl}>
{/* Title */}
<div className="CodeEditor__header__title">{renderTitle()}</div>
</div>
) : null}

{/* Content / editor */}
<div
className="CodeEditor__content"
// Container must have set height
style={{ height: title ? `calc(100% - ${headerHeight}px)` : "100%" }}
>
{/* Actions floating over the editor */}
<Box
gap="xs"
direction="row"
align="center"
justify="end"
addlClassName="CodeEditor__actions"
>
{customEl ?? null}
{languages && onLanguageChange ? (
<Select
id="code-editor-languages"
fieldSize="sm"
onChange={(e) =>
onLanguageChange(e.target.value as SupportedLanguage)
}
value={selectedLanguage}
>
{languages.map((l) => (
<option value={l} key={`ce-lang-${l}`}>
{l.toUpperCase()}
</option>
))}
</Select>
) : null}

{fileName ? (
<Button
variant="tertiary"
size="sm"
icon={<Icon.Download01 />}
title="Download"
onClick={(e) => {
e.preventDefault();

{/* Actions */}
<Box
gap="xs"
direction="row"
align="center"
justify="end"
addlClassName="CodeEditor__actions"
>
{customEl ?? null}
{languages && onLanguageChange ? (
<Select
id="code-editor-languages"
fieldSize="sm"
onChange={(e) =>
onLanguageChange(e.target.value as SupportedLanguage)
}
value={selectedLanguage}
>
{languages.map((l) => (
<option value={l} key={`ce-lang-${l}`}>
{l.toUpperCase()}
</option>
))}
</Select>
) : null}

{fileName ? (
<Button
variant="tertiary"
size="sm"
icon={<Icon.Download01 />}
title="Download"
onClick={(e) => {
e.preventDefault();

downloadFile({
value,
fileType: "application/json",
fileName,
fileExtension: getFileExtension(),
});
}}
></Button>
) : null}

<CopyText textToCopy={value}>
<Button
variant="tertiary"
size="sm"
icon={<Icon.Copy01 />}
title="Copy"
onClick={(e) => {
e.preventDefault();
}}
></Button>
</CopyText>
downloadFile({
value,
fileType: "application/json",
fileName,
fileExtension: getFileExtension(),
});
}}
></Button>
) : null}

<CopyText textToCopy={value}>
<Button
variant="tertiary"
size="sm"
icon={isExpanded ? <Icon.X /> : <Icon.Expand06 />}
title={isExpanded ? "Close" : "Expand"}
icon={<Icon.Copy01 />}
title="Copy"
onClick={(e) => {
e.preventDefault();
setIsExpanded(!isExpanded);
}}
></Button>
</Box>
</div>
) : null}
</CopyText>

<Button
variant="tertiary"
size="sm"
icon={isExpanded ? <Icon.X /> : <Icon.Expand06 />}
title={isExpanded ? "Close" : "Expand"}
onClick={(e) => {
e.preventDefault();
setIsExpanded(!isExpanded);
}}
></Button>
</Box>

{/* Content / editor */}
<div
className="CodeEditor__content"
// Container must have set height
style={{ height: title ? `calc(100% - ${headerHeight}px)` : "100%" }}
>
<MonacoEditor
defaultLanguage="javascript"
defaultValue=""
Expand Down
6 changes: 6 additions & 0 deletions src/components/CodeEditor/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,15 @@
&__content {
width: 100%;
background-color: var(--sds-clr-gray-02);
position: relative;
}

&__actions {
position: absolute;
top: pxToRem(8px);
right: pxToRem(16px);
z-index: 1;

& > .Select {
width: pxToRem(120px);
}
Expand Down
Loading