Skip to content

Commit

Permalink
Merge pull request #462 from kreneskyp/select_links
Browse files Browse the repository at this point in the history
ChainSelect link to open
  • Loading branch information
kreneskyp authored Feb 26, 2024
2 parents 4f957a3 + 311e6c3 commit 5fb764c
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
26 changes: 26 additions & 0 deletions frontend/chains/ChainSelect.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import React from "react";
import axios from "axios";
import { FormHelperText, Text } from "@chakra-ui/react";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faArrowUpRightFromSquare } from "@fortawesome/free-solid-svg-icons";

import { AsyncAPIObjectSelect } from "components/AsyncAPIObjectSelect";
import { MenuList } from "components/select/MenuList";
import { SingleValue } from "components/select/SingleValue";
import { Option } from "components/select/Option";
import { LinkText } from "components/LinkText";
import { EditorViewState } from "chains/editor/contexts";

const toOption = (chain) => ({
label: chain.name,
Expand Down Expand Up @@ -54,3 +59,24 @@ export const ChainSelect = ({ onChange, value, is_agent }) => {
/>
);
};

export const ChainSelectHelp = ({ value, field }) => {
const editor = React.useContext(EditorViewState);

return (
<FormHelperText fontSize={"xs"}>
<Text as={"span"}>{field.description}</Text>
{value && (
<LinkText
fontSize={"xs"}
pl={"3px"}
onClick={() => editor.selectOrOpenChain(value)}
>
Open <FontAwesomeIcon icon={faArrowUpRightFromSquare} />
</LinkText>
)}
</FormHelperText>
);
};

ChainSelect.help = ChainSelectHelp;
15 changes: 15 additions & 0 deletions frontend/components/LinkText.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from "react";
import { Text } from "@chakra-ui/react";

export const LinkText = ({ children, ...props }) => (
<Text
as={"span"}
color={"blue.300"}
css={{ textDecoration: "underline dotted" }}
mr={1}
cursor={"pointer"}
{...props}
>
{children}
</Text>
);
19 changes: 17 additions & 2 deletions frontend/json_form/fields/APISelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ import React from "react";
import { Box, FormLabel, FormHelperText } from "@chakra-ui/react";
import { getLabel } from "json_form/utils";

export const DefaultHelp = ({ field }) => (
<FormHelperText fontSize={"xs"}>{field.description}</FormHelperText>
);

/**
* Generic JSONSchemaForm field component that wraps a Select component. This is a
* shortcut for adding integrating a custom component with JSONSchemaForm.
*/
export const APISelect = ({
Component,
HelpComponent,
name,
field,
isRequired,
Expand All @@ -34,7 +39,7 @@ export const APISelect = ({
value={value}
width={"100%"}
/>
<FormHelperText fontSize={"xs"}>{field.description}</FormHelperText>
<HelpComponent field={field} value={value} config={config} />
</Box>
);
};
Expand All @@ -46,6 +51,16 @@ export const APISelect = ({
*/
APISelect.for_select = (component) => {
return (props) => {
return <APISelect Component={component} {...props} />;
return (
<APISelect
Component={component}
HelpComponent={component.help || DefaultHelp}
{...props}
/>
);
};
};

APISelect.defaultProps = {
HelpComponent: DefaultHelp,
};

0 comments on commit 5fb764c

Please sign in to comment.