Skip to content
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

fix: add full height to FrameCodeBlock #3421

Merged
merged 3 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 21 additions & 4 deletions web/src/components/CodeBlock/CodeBlock.styled.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {Button, Typography} from 'antd';
import styled from 'styled-components';
import styled, {css} from 'styled-components';

export const CodeContainer = styled.div<{$maxHeight: string; $minHeight: string}>`
export const CodeContainer = styled.div<{$maxHeight: string; $minHeight: string; $isFullHeight?: boolean}>`
position: relative;
border: ${({theme}) => `1px solid ${theme.color.border}`};
min-height: ${({$minHeight}) => $minHeight || '370px'};

pre {
border: ${({theme}) => `1px solid ${theme.color.border}`};
margin: 0;
padding: 13px 16px !important;
min-height: inherit;
Expand All @@ -17,9 +17,26 @@ export const CodeContainer = styled.div<{$maxHeight: string; $minHeight: string}
background: ${({theme}) => theme.color.backgroundInteractive} !important;
}
}

${({$isFullHeight}) =>
$isFullHeight &&
css`
height: calc(100% - 49px);

pre {
max-height: 100%;
}
`}
`;

export const FrameContainer = styled.div<{$isFullHeight?: boolean}>`
${({$isFullHeight}) =>
$isFullHeight &&
css`
height: calc(100% - 72px);
`}
`;

export const FrameContainer = styled.div``;
export const FrameHeader = styled.div`
display: flex;
justify-content: space-between;
Expand Down
5 changes: 3 additions & 2 deletions web/src/components/CodeBlock/CodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface IProps {
mimeType?: string;
maxHeight?: string;
minHeight?: string;
isFullHeight?: boolean;
}

const getLanguage = (mimeType: string): LanguageName | undefined => {
Expand All @@ -32,7 +33,7 @@ const formatValue = (value: string, lang?: string): string => {
}
};

const CodeBlock = ({value, language, mimeType = '', maxHeight = '', minHeight = ''}: IProps) => {
const CodeBlock = ({value, language, mimeType = '', maxHeight = '', minHeight = '', isFullHeight}: IProps) => {
const lang = useMemo(() => language || getLanguage(mimeType), [language, mimeType]);

// SyntaxHighlighter has a performance problem, so we need to memoize it
Expand All @@ -47,7 +48,7 @@ const CodeBlock = ({value, language, mimeType = '', maxHeight = '', minHeight =
);

return (
<S.CodeContainer data-cy="code-block" $maxHeight={maxHeight} $minHeight={minHeight}>
<S.CodeContainer data-cy="code-block" $maxHeight={maxHeight} $minHeight={minHeight} $isFullHeight={isFullHeight}>
{memoizedHighlighter}
</S.CodeContainer>
);
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/CodeBlock/FramedCodeBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const FramedCodeBlock = ({title, actions, ...props}: IProps) => {
const copy = useCopy();

return (
<S.FrameContainer>
<S.FrameContainer $isFullHeight={props.isFullHeight}>
<S.FrameHeader>
<S.FrameTitle>{title}</S.FrameTitle>
<S.ActionsContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export const Section = styled.div`
background-color: ${({theme}) => theme.color.white};
overflow-y: scroll;
flex-basis: 50%;
max-width: 50vw;
`;

export const SectionLeft = styled(Section)`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Typography} from 'antd';
import styled from 'styled-components';

export const Container = styled.div`
height: 100%;
padding: 24px;
`;

Expand All @@ -12,12 +13,6 @@ export const Title = styled(Typography.Title)`
}
`;

export const Footer = styled.div`
display: flex;
justify-content: flex-end;
margin-top: 16px;
`;

export const FileName = styled.div`
margin-bottom: 14px;
`;
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,18 @@ const RunDetailAutomateDefinition = ({id, version, resourceType, fileName, onFil
<S.FileName>
<Overlay value={fileName} onChange={onFileNameChange} />
</S.FileName>
<FramedCodeBlock title="Preview your YAML file" value={definition} language="yaml" />
<S.Footer>
<Button data-cy="file-viewer-download" icon={<DownloadOutlined />} onClick={onDownload} type="primary">
Download File
</Button>
</S.Footer>

<FramedCodeBlock
title="Preview your YAML file"
value={definition}
language="yaml"
actions={
<Button data-cy="file-viewer-download" icon={<DownloadOutlined />} onClick={onDownload} type="primary">
Download File
</Button>
}
isFullHeight
/>
</S.Container>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const BackIcon = styled(LeftOutlined)`
`;

export const Container = styled.div`
height: 100vh;
height: 100%;

.run-tabs.ant-tabs,
.run-tabs.ant-tabs .ant-tabs-content {
Expand Down