PromucFlow_constructor/app/client/src/components/editorComponents/ApiResponseMeta.tsx
Valera Melnikov b7ec5dacd8
chore: rename old ADS package (#35517)
## Description
Rename package `design-system-old` to `@appsmith/ads-old`.

## Automation

/ok-to-test tags="@tag.All"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!CAUTION]
> 🔴 🔴 🔴 Some tests have failed.
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10286195096>
> Commit: c0d478694b12f35b88687b6dae6f252967fba540
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10286195096&attempt=1&selectiontype=test&testsstatus=failed&specsstatus=fail"
target="_blank">Cypress dashboard</a>.
> Tags: @tag.All
> Spec: 
> The following are new failures, please fix them before merging the PR:
<ol>
>
<li>cypress/e2e/Regression/ClientSide/BugTests/DatasourceSchema_spec.ts</ol>
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/identified-flaky-tests-65890b3c81d7400d08fa9ee3?branch=master"
target="_blank">List of identified flaky tests</a>.
> <hr>Wed, 07 Aug 2024 15:26:02 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No
2024-08-08 15:55:00 +03:00

127 lines
3.6 KiB
TypeScript

import type { PropsWithChildren } from "react";
import React from "react";
import { Flex } from "design-system";
import { Text, TextType } from "@appsmith/ads-old";
import { formatBytes } from "../../utils/helpers";
import { isEmpty } from "lodash";
import BindDataButton from "pages/Editor/QueryEditor/BindDataButton";
import styled from "styled-components";
import type { ActionResponse } from "api/ActionAPI";
import { Text as BlueprintText } from "@blueprintjs/core/lib/esm/components/text/text";
interface TextStyleProps {
accent: "primary" | "secondary" | "error";
}
const BaseText = styled(BlueprintText)<TextStyleProps>``;
const ResponseMetaInfo = styled.div`
display: flex;
${BaseText} {
color: var(--ads-v2-color-fg);
margin-left: ${(props) => props.theme.spaces[9]}px;
}
& [type="p3"] {
color: var(--ads-v2-color-fg-muted);
}
& [type="h5"] {
color: var(--ads-v2-color-fg);
}
`;
const ResponseMetaWrapper = styled.div`
align-items: center;
display: flex;
justify-content: space-between;
padding: var(--ads-v2-spaces-3);
border-bottom: 1px solid var(--ads-v2-color-border);
height: 40px;
`;
const FlexContainer = styled.div`
display: flex;
align-items: center;
margin-left: 20px;
span:first-child {
margin-right: ${(props) => props.theme.spaces[1] + 1}px;
}
`;
const StatusCodeText = styled(BaseText)<PropsWithChildren<{ code: string }>>`
color: ${(props) =>
props.code.startsWith("2")
? "var(--ads-v2-color-fg-success)"
: "var(--ads-v2-color-fg-error)"};
cursor: pointer;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
&:hover {
width: 100%;
}
`;
interface Props {
actionResponse?: ActionResponse;
actionName?: string;
}
const ApiResponseMeta = (props: Props) => {
const { actionName, actionResponse } = props;
if (!actionResponse || !actionResponse.statusCode) return null;
return (
<ResponseMetaWrapper>
<Flex>
{actionResponse.statusCode && (
<FlexContainer>
<Text type={TextType.P3}>Status: </Text>
<StatusCodeText
accent="secondary"
className="t--response-status-code"
code={actionResponse.statusCode.toString()}
>
{actionResponse.statusCode}
</StatusCodeText>
</FlexContainer>
)}
<ResponseMetaInfo>
{actionResponse.duration && (
<FlexContainer>
<Text type={TextType.P3}>Time: </Text>
<Text type={TextType.H5}>{actionResponse.duration} ms</Text>
</FlexContainer>
)}
{actionResponse.size && (
<FlexContainer>
<Text type={TextType.P3}>Size: </Text>
<Text type={TextType.H5}>
{formatBytes(parseInt(actionResponse.size))}
</Text>
</FlexContainer>
)}
{!isEmpty(actionResponse?.body) &&
Array.isArray(actionResponse?.body) && (
<FlexContainer>
<Text type={TextType.P3}>Result: </Text>
<Text type={TextType.H5}>
{`${actionResponse?.body.length} Record${
actionResponse?.body.length > 1 ? "s" : ""
}`}
</Text>
</FlexContainer>
)}
</ResponseMetaInfo>
</Flex>
<BindDataButton
actionName={actionName || ""}
hasResponse={!!actionResponse}
suggestedWidgets={actionResponse.suggestedWidgets}
/>
</ResponseMetaWrapper>
);
};
export default ApiResponseMeta;