Skip to content

[ERP-2328] Wrap CopyBox #48

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

Merged
merged 3 commits into from
Aug 16, 2024
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
57 changes: 32 additions & 25 deletions src/components/output/CopyBox.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ export default function CopyBox({
children,
editable = false,
defaultRows = 10,
wrap = true,
}) {
const [hover, setHover] = useState(false);
const [copied, setCopied] = useState(false);

const borderColor = useColorModeValue("gray.200", "gray.500");
const bg = useColorModeValue("gray.50", "gray.800");
const wrapStyle = { textWrap: wrap ? "wrap" : "nowrap" };

const Wrapper = editable ? Editable : Box;
const Content = editable ? Editable : Box;

const [text, setText] = useState(
Array.isArray(children) ? children.join("") : children,
Expand All @@ -33,32 +35,37 @@ export default function CopyBox({
}, [children]);

return (
<Wrapper
as="pre"
p="4"
rounded="md"
border="1px"
borderColor={borderColor}
bg={bg}
fontSize="sm"
whiteSpace="pre-wrap"
wordBreak="break-all"
w="full"
<Box
position="relative"
onMouseOver={() => setHover(true)}
onMouseOut={() => setHover(false)}
position="relative"
defaultValue={text}
key={text}
onSubmit={(e) => setText(e)}
>
{editable ? (
<>
<EditablePreview />
<EditableTextarea rows={defaultRows} />
</>
) : (
text
)}
<Content
as="pre"
p="4"
rounded="md"
border="1px"
borderColor={borderColor}
bg={bg}
fontSize="sm"
whiteSpace="pre-wrap"
wordBreak="break-all"
overflowX="auto"
w="full"
defaultValue={text}
key={text}
onSubmit={(e) => setText(e)}
sx={wrapStyle}
>
{editable ? (
<>
<EditablePreview />
<EditableTextarea rows={defaultRows} sx={wrapStyle} />
</>
) : (
text
)}
</Content>
{hover && (
<Tooltip
label={copied ? "Copied!" : "Copy to clipboard"}
Expand All @@ -81,6 +88,6 @@ export default function CopyBox({
</Button>
</Tooltip>
)}
</Wrapper>
</Box>
);
}
14 changes: 8 additions & 6 deletions src/components/tool/guide/Instructions/StartInstructions.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ export function LyraStartInstructions({
textAfterLink={"."}
/>
</InstructionText>
<CopyBox editable={true}>{batchJobScript.join("\n")}</CopyBox>
<CopyBox editable={true} wrap={false}>
{batchJobScript.join("\n")}
</CopyBox>
<InstructionText>
You may either:
<RadioGroup defaultValue="file" onChange={setScriptInput}>
Expand Down Expand Up @@ -175,12 +177,12 @@ export function LyraStartInstructions({
<InstructionText>
The output will look similar to the following:
</InstructionText>
<CopyBox>
<CopyBox wrap={false}>
{`pbs:
Req'd Req'd Elap
Job ID Username Queue Jobname SessID NDS TSK Memory Time S Time
-------------------- -------- -------- -------- ------ --- --- ------ ----- - -----
1234567.pbs username quick job-name -- 1 4 32gb 01:00 Q --`}
Req'd Req'd Elap
Job ID Username Queue Jobname SessID NDS TSK Memory Time S Time
----------- -------- ----- -------- ------ --- --- ------ ----- - -----
1234567.pbs username quick job-name -- 1 4 32gb 01:00 Q --`}
</CopyBox>
<InstructionText>
The job status will be shown in the <Code>S</Code> column. Possible
Expand Down
Loading