Skip to content

Commit

Permalink
Merge pull request #122 from polkadot-cloud/rb-reset-args-at-depth
Browse files Browse the repository at this point in the history
fix: Reset child input args from key
  • Loading branch information
rossbulat authored Jun 23, 2024
2 parents 7e44b14 + b945f76 commit 2bc58e1
Show file tree
Hide file tree
Showing 23 changed files with 87 additions and 50 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public/lottie/player.js
CHANGELOG.md
.yarn
.licenserc.json
.env.yarn
.env.yarn
test/data/**/*
2 changes: 1 addition & 1 deletion .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v4
with:
ref: gh-deploy

- uses: actions/setup-node@v4
with:
node-version: 18
Expand Down
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ public/lottie/player.js
CHANGELOG.md
.yarn
.licenserc.json
.env.yarn
.env.yarn
test/data/**/*
27 changes: 12 additions & 15 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,19 @@
<meta name="msapplication-TileColor" content="#552bbf" />
<meta name="theme-color" content="#ffffff" />

<meta
name="title"
content="Polkadot Developer Console"
/>
<meta name="title" content="Polkadot Developer Console" />

<meta name="description" content="Polkadot Developer Console is an application designed to
<meta
name="description"
content="Polkadot Developer Console is an application designed to
provide Polkadot developers tools for interacting with Substrate based blockchains, allowing
them to build, test, deploy, and manage their projects." />
them to build, test, deploy, and manage their projects."
/>

<!-- Open Graph / Facebook -->
<meta property="og:type" content="website" />
<meta property="og:url" content="https://console.polkadot.cloud" />
<meta
property="og:title"
content="Polkadot Developer Console"
/>
<meta property="og:title" content="Polkadot Developer Console" />
<meta
property="og:description"
content="Polkadot Developer Console is an application designed to
Expand All @@ -56,13 +53,13 @@
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image" />
<meta property="twitter:url" content="https://console.polkadot.cloud" />
<meta property="twitter:title" content="Polkadot Developer Console" />
<meta
property="twitter:title"
content="Polkadot Developer Console"
/>
<meta property="twitter:description" content="Polkadot Developer Console is an application
property="twitter:description"
content="Polkadot Developer Console is an application
designed to provide Polkadot developers tools for interacting with Substrate based blockchains,
allowing them to build, test, deploy, and manage their projects." />
allowing them to build, test, deploy, and manage their projects."
/>
<meta property="twitter:image" content="/img/og-image.png" />
<link
rel="manifest"
Expand Down
3 changes: 2 additions & 1 deletion src/contexts/ChainUi/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ export const defaultChainContext: ChainUiContextInterface = {
getInputArgs: (tabId, section) => null,
getInputArgAtKey: (tabId, section, inputKey) => undefined,
setInputArgAtKey: (tabId, section, keys, value) => {},
resetInputArgSection: (tabId, section) => {},
resetInputArgs: (tabId, section) => {},
resetInputArgsFromKey: (tabId, section, fromKey) => {},
};
34 changes: 31 additions & 3 deletions src/contexts/ChainUi/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ export const ChainUiProvider = ({ children }: { children: ReactNode }) => {
setInputArgs(updatedInputArgs);
};

// Reset input args at a given key for either a storage item or call.
const resetInputArgSection = (tabId: number, namespace: InputNamespace) => {
// Reset input args at a given key and namespace.
const resetInputArgs = (tabId: number, namespace: InputNamespace) => {
if (!inputArgsRef.current[tabId]) {
return;
}
Expand All @@ -225,6 +225,33 @@ export const ChainUiProvider = ({ children }: { children: ReactNode }) => {
setInputArgs(updatedInputArgs);
};

// Reset input args from an input key and namespace. Removes input args from any child input of
// the provided key. Should be used on select input changes, that allow variant selection.
const resetInputArgsFromKey = (
tabId: number,
namespace: InputNamespace,
fromKey: string
) => {
if (!inputArgsRef.current[tabId]) {
return;
}

// Duplicate arg state for manipulation.
const updatedInputArgs = { ...inputArgsRef.current };
const args = updatedInputArgs[tabId][namespace];

// Iterate through keys state and remove keys that start with `fromKey`.
for (const key in args) {
if (key.startsWith(fromKey) && key !== fromKey) {
delete args[key];
}
}

// Update state.
updatedInputArgs[tabId][namespace] = args;
setInputArgs(updatedInputArgs);
};

// Reset state for a tab.
const destroyTabChainUi = (tabId: number) => {
const updatedChainUi = { ...chainUi };
Expand Down Expand Up @@ -259,7 +286,8 @@ export const ChainUiProvider = ({ children }: { children: ReactNode }) => {
getInputArgs,
getInputArgAtKey,
setInputArgAtKey,
resetInputArgSection,
resetInputArgs,
resetInputArgsFromKey,
destroyTabChainUi,
}}
>
Expand Down
7 changes: 6 additions & 1 deletion src/contexts/ChainUi/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ export interface ChainUiContextInterface {
keys: InputArgTypeKeys,
value: AnyJson
) => void;
resetInputArgSection: (tabId: number, section: InputNamespace) => void;
resetInputArgs: (tabId: number, section: InputNamespace) => void;
resetInputArgsFromKey: (
tabId: number,
section: InputNamespace,
fromKey: string
) => void;
}

// Input arg type keys.
Expand Down
10 changes: 5 additions & 5 deletions src/library/Overlay/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

::-webkit-scrollbar-thumb {
background-color: transparent; /* color of the scroll thumb */
border-radius: .6rem; /* roundness of the scroll thumb */
border-radius: 0.6rem; /* roundness of the scroll thumb */
border: 0.1rem solid transparent; /* creates padding around scroll thumb */
}
}
Expand Down Expand Up @@ -362,7 +362,7 @@
> .section {
@include modal-scrollbar;

border-radius: .6rem;
border-radius: 0.6rem;
display: flex;
flex-direction: column;
flex-basis: 33.33%;
Expand All @@ -381,7 +381,7 @@
> .section {
@include modal-scrollbar;

border-radius: .6rem;
border-radius: 0.6rem;
display: flex;
flex-direction: column;
flex-basis: 50%;
Expand Down Expand Up @@ -435,7 +435,7 @@
.modal-scroll {
@include modal-scrollbar;

border-radius: .6rem;
border-radius: 0.6rem;
position: relative;
z-index: 99;
max-height: 100%;
Expand Down Expand Up @@ -465,7 +465,7 @@

::-webkit-scrollbar-thumb {
background-color: transparent; /* color of the scroll thumb */
border-radius: .6rem; /* roundness of the scroll thumb */
border-radius: 0.6rem; /* roundness of the scroll thumb */
border: 0.1rem solid transparent; /* creates padding around scroll thumb */
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/routes/Chain/ChainState/ChainStateList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export const ChainStateList = ({
inputNamespace,
}: ChainStateListProps) => {
const { tabId } = useActiveTab();
const { getChainUi, setChainUiNamespace, resetInputArgSection } =
useChainUi();
const { getChainUi, setChainUiNamespace, resetInputArgs } = useChainUi();

const chainUi = getChainUi(tabId, chainUiSection);

Expand All @@ -52,7 +51,7 @@ export const ChainStateList = ({

// If an input namespace is provided, reset input arg values.
if (inputNamespace) {
resetInputArgSection(tabId, inputNamespace);
resetInputArgs(tabId, inputNamespace);
}

// Close item the dropdown if requested.
Expand Down
5 changes: 2 additions & 3 deletions src/routes/Chain/ChainState/StorageItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import type { InputNamespace } from 'contexts/ChainUi/types';
export const StorageItems = () => {
const { tabId } = useActiveTab();
const { chainSpec, instanceId } = useChain();
const { getChainUi, setChainUiNamespace, resetInputArgSection } =
useChainUi();
const { getChainUi, setChainUiNamespace, resetInputArgs } = useChainUi();

const chainUiSection = 'storage';
const inputNamespace: InputNamespace = 'storage';
Expand Down Expand Up @@ -117,7 +116,7 @@ export const StorageItems = () => {
setChainUiNamespace(tabId, chainUiSection, 'pallet', value);

// Reset input args when selected pallet changes.
resetInputArgSection(tabId, inputNamespace);
resetInputArgs(tabId, inputNamespace);
}}
/>
<ChainStateList
Expand Down
5 changes: 2 additions & 3 deletions src/routes/Chain/Extrinsics/CallList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import type { InputNamespace } from 'contexts/ChainUi/types';

export const CallList = ({ items }: CallListProps) => {
const { tabId } = useActiveTab();
const { getChainUi, setChainUiNamespace, resetInputArgSection } =
useChainUi();
const { getChainUi, setChainUiNamespace, resetInputArgs } = useChainUi();

const chainUiSection = 'calls';
const inputNamespace: InputNamespace = 'call';
Expand All @@ -39,7 +38,7 @@ export const CallList = ({ items }: CallListProps) => {
// Handle call change.
const handleCallChange = (name: string) => {
setChainUiNamespace(tabId, chainUiSection, 'selected', name);
resetInputArgSection(tabId, inputNamespace);
resetInputArgs(tabId, inputNamespace);
setCallsOpen(false);
};

Expand Down
5 changes: 2 additions & 3 deletions src/routes/Chain/Extrinsics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export const Extrinsics = () => {
const { tabId, metaKey } = useActiveTab();
const { getAccounts } = useImportedAccounts();
const { getFromAddress, setFromAddress } = useChainState();
const { getChainUi, setChainUiNamespace, resetInputArgSection } =
useChainUi();
const { getChainUi, setChainUiNamespace, resetInputArgs } = useChainUi();

const chainUiSection = 'calls';
const inputNamespace: InputNamespace = 'call';
Expand Down Expand Up @@ -109,7 +108,7 @@ export const Extrinsics = () => {
setChainUiNamespace(tabId, chainUiSection, 'pallet', value);

// Reset input args when selected pallet changes.
resetInputArgSection(tabId, inputNamespace);
resetInputArgs(tabId, inputNamespace);
}}
/>
<CallList items={items} />
Expand Down
10 changes: 9 additions & 1 deletion src/routes/Chain/Inputs/useInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export const useInput = () => {
const { getAccounts } = useAccounts();
const { tabId, metaKey } = useActiveTab();
const { removeInputMetaValue } = useInputMeta();
const { setInputArgAtKey, getInputArgAtKey } = useChainUi();
const { setInputArgAtKey, getInputArgAtKey, resetInputArgsFromKey } =
useChainUi();

const accounts = getAccounts(chainSpec);

Expand Down Expand Up @@ -370,6 +371,13 @@ export const useInput = () => {
onMount={onMount}
onRender={onRender}
onChange={(val) => {
// Child inputs changed - remove args.
resetInputArgsFromKey(
tabId,
inputArgConfig.namespace,
inputArgConfig.inputKey
);
// Commit new input arg value.
setInputArgAtKey(tabId, inputArgConfig.namespace, keys, val);
}}
/>
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/metadata14/array.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import assert from 'assert';
import type { AnyJson } from '@w3ux/types';
import * as metadataJson from './data/metadataV14.json';
import * as metadataJson from '../data/metadataV14.json';

/* Metadata array tests.
Expand Down
2 changes: 1 addition & 1 deletion test/metadata14/bitSequence.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import assert from 'assert';
import type { AnyJson } from '@w3ux/types';
import * as metadataJson from './data/metadataV14.json';
import * as metadataJson from '../data/metadataV14.json';

/* Metadata bitSequence tests.
Expand Down
2 changes: 1 addition & 1 deletion test/metadata14/compact.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import assert from 'assert';
import type { AnyJson } from '@w3ux/types';
import * as metadataJson from './data/metadataV14.json';
import * as metadataJson from '../data/metadataV14.json';

/* Metadata compact tests.
Expand Down
2 changes: 1 addition & 1 deletion test/metadata14/composite.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import assert from 'assert';
import * as metadataJson from './data/metadataV14.json';
import * as metadataJson from '../data/metadataV14.json';
import type { AnyJson } from '@w3ux/types';

/* Metadata composite tests.
Expand Down
2 changes: 1 addition & 1 deletion test/metadata14/lookup.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import assert from 'assert';
import * as metadataJson from './data/metadataV14.json';
import * as metadataJson from '../data/metadataV14.json';

/* Metadata lookup tests.
Expand Down
2 changes: 1 addition & 1 deletion test/metadata14/primitive.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import assert from 'assert';
import * as metadataJson from './data/metadataV14.json';
import * as metadataJson from '../data/metadataV14.json';

/* Metadata primitive tests.
Expand Down
2 changes: 1 addition & 1 deletion test/metadata14/sequence.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import assert from 'assert';
import * as metadataJson from './data/metadataV14.json';
import * as metadataJson from '../data/metadataV14.json';
import type { AnyJson } from '@w3ux/types';

/* Metadata sequence tests.
Expand Down
2 changes: 1 addition & 1 deletion test/metadata14/tuple.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import assert from 'assert';
import type { AnyJson } from '@w3ux/types';
import * as metadataJson from './data/metadataV14.json';
import * as metadataJson from '../data/metadataV14.json';

/* Metadata tuple tests.
Expand Down
2 changes: 1 addition & 1 deletion test/metadata14/variants.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-only

import assert from 'assert';
import * as metadataJson from './data/metadataV14.json';
import * as metadataJson from '../data/metadataV14.json';
import type { AnyJson } from '@w3ux/types';

/* Metadata variants tests.
Expand Down

0 comments on commit 2bc58e1

Please sign in to comment.