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: Adaptive cards and toolkit heights #2734

Merged
merged 7 commits into from
Aug 15, 2023
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
10 changes: 10 additions & 0 deletions src/app/views/common/dimensions/dimensions-adjustment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,14 @@ export function getResponseHeight(height: any, responseAreaExpanded: any) {
responseHeight = '90vh';
}
return responseHeight;
}

export function getResponseEditorHeight(adjustment: number){
const queryResponseElement = document.getElementsByClassName('query-response')[0];
let responseHeight = '';
if(queryResponseElement){
const queryResponseElementHeight = queryResponseElement?.clientHeight;
responseHeight = `${queryResponseElementHeight-adjustment}px`
}
return responseHeight;
}
10 changes: 5 additions & 5 deletions src/app/views/query-response/adaptive-cards/AdaptiveCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import { classNames } from '../../classnames';
import { Monaco } from '../../common';
import { trackedGenericCopy } from '../../common/copy';
import { CopyButton } from '../../common/copy/CopyButton';
import { convertVhToPx, getResponseHeight } from '../../common/dimensions/dimensions-adjustment';
import { convertVhToPx, getResponseEditorHeight,
getResponseHeight } from '../../common/dimensions/dimensions-adjustment';
import { queryResponseStyles } from './../queryResponse.styles';

const AdaptiveCard = (props: any) => {
Expand All @@ -32,8 +33,8 @@ const AdaptiveCard = (props: any) => {
const currentTheme: ITheme = getTheme();
const textStyle = queryResponseStyles(currentTheme).queryResponseText.root as IStyle;

const responseHeight = getResponseHeight(response.height, responseAreaExpanded);
const height = convertVhToPx(responseHeight, 220);
const defaultHeight = convertVhToPx(getResponseHeight(response.height, responseAreaExpanded), 220);
const monacoHeight = getResponseEditorHeight(190);

useEffect(() => {
dispatch(getAdaptiveCard(body, sampleQuery));
Expand All @@ -53,7 +54,6 @@ const AdaptiveCard = (props: any) => {
}
}, [body])


const onPivotItemClick = (query: IQuery | undefined, item?: PivotItem) => {
if (!item) { return; }
const key = item.props.itemKey;
Expand Down Expand Up @@ -187,7 +187,7 @@ const AdaptiveCard = (props: any) => {
<Monaco
language='json'
body={data.template}
height={height}
height={responseAreaExpanded ? defaultHeight : monacoHeight}
/>
</div>
</PivotItem>
Expand Down
9 changes: 6 additions & 3 deletions src/app/views/query-response/graph-toolkit/GraphToolkit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { lookupToolkitUrl } from '../../../utils/graph-toolkit-lookup';
import { translateMessage } from '../../../utils/translate-messages';
import { queryResponseStyles } from '../queryResponse.styles';
import { useAppSelector } from '../../../../store';
import { convertVhToPx, getResponseHeight } from '../../common/dimensions/dimensions-adjustment';
import { convertVhToPx, getResponseEditorHeight,
getResponseHeight } from '../../common/dimensions/dimensions-adjustment';

const GraphToolkit = () => {
const { sampleQuery, dimensions: {response },responseAreaExpanded } = useAppSelector((state) => state);
Expand All @@ -19,7 +20,8 @@ const GraphToolkit = () => {
const textStyle = queryResponseStyles(currentTheme).queryResponseText.root as IStyle;
const linkStyle = queryResponseStyles(currentTheme).link as IStyle;

const height = convertVhToPx(getResponseHeight(response.height, responseAreaExpanded), 220);
const defaultHeight = convertVhToPx(getResponseHeight(response.height, responseAreaExpanded), 220);
const monacoHeight = getResponseEditorHeight(115);

if (toolkitUrl && exampleUrl) {
return (
Expand All @@ -38,7 +40,8 @@ const GraphToolkit = () => {
</Link>
.
</MessageBar>
<iframe width='100%' height={height} src={toolkitUrl} title={translateMessage('Graph toolkit')} />
<iframe width='100%' height={responseAreaExpanded ? defaultHeight : monacoHeight}
src={toolkitUrl} title={translateMessage('Graph toolkit')} />
</>
);
}
Expand Down
13 changes: 4 additions & 9 deletions src/app/views/query-response/headers/ResponseHeaders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { RESPONSE_HEADERS_COPY_BUTTON } from '../../../../telemetry/component-na

import { Monaco } from '../../common';
import { trackedGenericCopy } from '../../common/copy';
import { convertVhToPx, getResponseHeight } from '../../common/dimensions/dimensions-adjustment';
import { convertVhToPx, getResponseEditorHeight,
getResponseHeight } from '../../common/dimensions/dimensions-adjustment';
import { CopyButton } from '../../common/copy/CopyButton';
import { useAppSelector } from '../../../../store';

Expand All @@ -13,13 +14,7 @@ const ResponseHeaders = () => {
const { headers } = graphResponse;

const defaultHeight = convertVhToPx(getResponseHeight(response.height, responseAreaExpanded), 220);
let responseHeight = defaultHeight;

const queryResponseElement = document.getElementsByClassName('query-response')[0];
if(queryResponseElement){
const queryResponseElementHeight = queryResponseElement?.clientHeight;
responseHeight = `${queryResponseElementHeight-140}px`
}
const monacoHeight = getResponseEditorHeight(120);


const handleCopy = async () => trackedGenericCopy(JSON.stringify(headers), RESPONSE_HEADERS_COPY_BUTTON, sampleQuery)
Expand All @@ -32,7 +27,7 @@ const ResponseHeaders = () => {
isIconButton={true}
style={{ float: 'right', zIndex: 1 }}
/>
<Monaco body={headers} height={responseAreaExpanded ? defaultHeight : responseHeight} />
<Monaco body={headers} height={responseAreaExpanded ? defaultHeight : monacoHeight} />
</div>
);
}
Expand Down
13 changes: 4 additions & 9 deletions src/app/views/query-response/response/Response.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { useDispatch } from 'react-redux';

import { AppDispatch, useAppSelector } from '../../../../store';
import { getContentType } from '../../../services/actions/query-action-creator-util';
import { convertVhToPx, getResponseHeight } from '../../common/dimensions/dimensions-adjustment';
import { convertVhToPx, getResponseEditorHeight,
getResponseHeight } from '../../common/dimensions/dimensions-adjustment';
import ResponseDisplay from './ResponseDisplay';
import { ResponseMessages } from './ResponseMessages';

Expand All @@ -14,13 +15,7 @@ const Response = () => {
const dispatch: AppDispatch = useDispatch();

const defaultHeight = convertVhToPx(getResponseHeight(response.height, responseAreaExpanded), 220);
let responseHeight = defaultHeight;

const queryResponseElement = document.getElementsByClassName('query-response')[0];
if(queryResponseElement){
const queryResponseElementHeight = queryResponseElement?.clientHeight;
responseHeight = `${queryResponseElementHeight-140}px`
}
const monacoHeight = getResponseEditorHeight(150);

const contentDownloadUrl = body?.contentDownloadUrl;
const throwsCorsError = body?.throwsCorsError;
Expand All @@ -32,7 +27,7 @@ const Response = () => {
<ResponseDisplay
contentType={contentType}
body={body}
height={responseAreaExpanded ? defaultHeight : responseHeight}
height={responseAreaExpanded ? defaultHeight : monacoHeight}
/>}
</div>
);
Expand Down
9 changes: 6 additions & 3 deletions src/app/views/query-response/snippets/snippets-helper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { componentNames, telemetry } from '../../../../telemetry';
import { CODE_SNIPPETS_COPY_BUTTON } from '../../../../telemetry/component-names';
import { translateMessage } from '../../../utils/translate-messages';
import { CopyButton } from '../../common/copy/CopyButton';
import { convertVhToPx, getResponseHeight } from '../../common/dimensions/dimensions-adjustment';
import { convertVhToPx, getResponseEditorHeight,
getResponseHeight } from '../../common/dimensions/dimensions-adjustment';
import { getSnippetStyles } from './Snippets.styles';

interface ISnippetProps {
Expand Down Expand Up @@ -67,9 +68,11 @@ function Snippet(props: ISnippetProps) {
const { data, pending: loadingState, error } = snippets;
const snippet = (!loadingState && data) ? data[language] : null;
const responseHeight = getResponseHeight(response.height, responseAreaExpanded);
const height = convertVhToPx(responseHeight, 220);
const defaultHeight = convertVhToPx(responseHeight, 220);
const [snippetError, setSnippetError] = useState(error);

const monacoHeight = getResponseEditorHeight(235);

const dispatch: AppDispatch = useDispatch();

useEffect(() => {
Expand Down Expand Up @@ -168,7 +171,7 @@ function Snippet(props: ISnippetProps) {
body={snippet}
language={language}
readOnly={true}
height={height}
height={responseAreaExpanded ? defaultHeight : monacoHeight}
extraInfoElement={addExtraSnippetInformation()}
/>
</>
Expand Down