Skip to content

Commit

Permalink
Merge pull request #1415 from memphisdev/test_event_ui
Browse files Browse the repository at this point in the history
test event + build
  • Loading branch information
SvetaMemphis committed Nov 15, 2023
2 parents a757ae5 + 7c92d45 commit 963bdcd
Show file tree
Hide file tree
Showing 18 changed files with 535 additions and 703 deletions.
1 change: 1 addition & 0 deletions ui_src/src/const/apiEndpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const ApiEndpoints = {
UNINSTALL_FUNCTION: '/functions/uninstall',
GET_FUNCTION_DETAIL: '/functions/getFunctionDetails',
GET_FUNCTION_FILE_CODE: '/functions/getFunctionFileCode',
TEST_FUNCTION: '/functions/testFunction',

//Integrations
CREATE_INTEGRATION: '/integrations/createIntegration',
Expand Down
318 changes: 117 additions & 201 deletions ui_src/src/domain/functions/components/functionBox/index.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions ui_src/src/domain/functions/components/functionBox/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@
margin-right: 5px;
}
}
.ant-skeleton-element {
display: flex;
align-items: center;
height: 22px;
}
}
.func-selected {
border: 1px solid var(--purple);
Expand Down
76 changes: 45 additions & 31 deletions ui_src/src/domain/functions/components/functionDetails/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { ReactComponent as PlaceholderFunctionsIcon } from '../../../../assets/i
import { ReactComponent as ArrowBackIcon } from '../../../../assets/images/arrowBackIcon.svg';
import CustomTabs from '../../../../components/Tabs';
import SelectComponent from '../../../../components/select';
import TestFunctionModal from '../testFunctionModal';
import TestMockEvent from '../testFunctionModal/components/testMockEvent';
import Modal from '../../../../components/modal';
import { OWNER } from '../../../../const/globalConst';
import { BsFileEarmarkCode } from 'react-icons/bs';
Expand Down Expand Up @@ -201,16 +201,20 @@ function FunctionDetails({ selectedFunction, installed, handleInstall, handleUnI
<owner is="x3d">{selectedFunction?.owner === OWNER ? 'Memphis.dev' : selectedFunction?.owner}</owner>
</div>
<Divider type="vertical" />
<downloads is="x3d">
<BiDownload className="download-icon" />
<label>{Number(180).toLocaleString()}</label>
</downloads>
<Divider type="vertical" />
<rate is="x3d">
<Rate disabled defaultValue={5} className="stars-rate" />
<label>(50)</label>
</rate>
<Divider type="vertical" />
{selectedFunction.owner === OWNER && (
<>
<downloads is="x3d">
<BiDownload className="download-icon" />
<label>{Number(180).toLocaleString()}</label>
</downloads>
<Divider type="vertical" />
<rate is="x3d">
<Rate disabled defaultValue={5} className="stars-rate" />
<label>(50)</label>
</rate>
<Divider type="vertical" />
</>
)}
<commits is="x3d">
<FiGitCommit />
<label>Last commit on {parsingDate(selectedFunction?.installed_updated_at, false, false)}</label>
Expand Down Expand Up @@ -258,7 +262,7 @@ function FunctionDetails({ selectedFunction, installed, handleInstall, handleUnI
fontFamily="InterSemiBold"
onClick={() => (installed ? handleUnInstall() : handleInstall())}
isLoading={selectedFunction?.install_in_progress}
disabled={selectedFunction?.install_in_progress}
disabled={!selectedFunction?.is_valid || selectedFunction?.install_in_progress}
/>
</div>
</div>
Expand All @@ -285,8 +289,8 @@ function FunctionDetails({ selectedFunction, installed, handleInstall, handleUnI
<div>
<CustomTabs tabs={['Details', 'Code']} value={tabValue} onChange={(tabValue) => setTabValue(tabValue)} />
</div>
<Modal width={'95vw'} height={'95vh'} clickOutside={() => setIsTestFunctionModalOpen(false)} open={isTestFunctionModalOpen} displayButtons={false}>
<TestFunctionModal onCancel={() => setIsTestFunctionModalOpen(false)} />
<Modal width={'75vw'} height={'80vh'} clickOutside={() => setIsTestFunctionModalOpen(false)} open={isTestFunctionModalOpen} displayButtons={false}>
<TestMockEvent functionDetails={selectedFunction} open={isTestFunctionModalOpen} />
</Modal>
{tabValue === 'Details' && (
<code is="x3d">
Expand All @@ -308,33 +312,43 @@ function FunctionDetails({ selectedFunction, installed, handleInstall, handleUnI
<GithubBranchIcon />
<label>{selectedFunction?.branch}</label>
</branch>
<language is="x3d">
<CodeBlackIcon />
<label>{selectedFunction?.language}</label>
</language>
{selectedFunction?.is_valid && (
<language is="x3d">
<CodeBlackIcon />
<label>{selectedFunction?.language}</label>
</language>
)}
</info>
</deatils>
<Divider />
<label className="label-title">Social</label>
<deatils is="x3d">
<downloads is="x3d">
<BiDownload className="download-icon" />
<label>{Number(180).toLocaleString()}</label>
</downloads>
<Divider type="vertical" />
<rate is="x3d">
<Rate disabled defaultValue={5} className="stars-rate" />
<label>(50)</label>
</rate>
<Divider type="vertical" />
{selectedFunction.owner === OWNER && (
<>
<downloads is="x3d">
<BiDownload className="download-icon" />
<label>{Number(180).toLocaleString()}</label>
</downloads>
<Divider type="vertical" />
<rate is="x3d">
<Rate disabled defaultValue={5} className="stars-rate" />
<label>(50)</label>
</rate>
<Divider type="vertical" />
</>
)}
<commits is="x3d">
<FiGitCommit />
<label>Last commit on {parsingDate(selectedFunction?.installed_updated_at, false, false)}</label>
</commits>
</deatils>
<Divider />
<label className="label-title">Tags</label>
<TagsList tagsToShow={3} tags={selectedFunction?.tags} entityType="function" entityName={selectedFunction?.function_name} />
{selectedFunction?.is_valid && (
<>
<Divider />
<label className="label-title">Tags</label>
<TagsList tagsToShow={3} tags={selectedFunction?.tags} entityType="function" entityName={selectedFunction?.function_name} />
</>
)}
</div>
</span>
</code>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// Copyright 2022-2023 The Memphis.dev Authors
// Licensed under the Memphis Business Source License 1.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// Changed License: [Apache License, Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0), as published by the Apache Foundation.
//
// https://github.com/memphisdev/memphis/blob/master/LICENSE
//
// Additional Use Grant: You may make use of the Licensed Work (i) only as part of your own product or service, provided it is not a message broker or a message queue product or service; and (ii) provided that you do not use, provide, distribute, or make available the Licensed Work as a Service.
// A "Service" is a commercial offering, product, hosted, or managed service, that allows third parties (other than your own employees and contractors acting on your behalf) to access and/or use the Licensed Work or a substantial set of the features or functionality of the Licensed Work to third parties as a software-as-a-service, platform-as-a-service, infrastructure-as-a-service or other similar services that compete with Licensor products or services.

import './style.scss';

import { useState, useEffect } from 'react';
import { ReactComponent as TestEventModalIcon } from '../../../../../../assets/images/testEventModalcon.svg';
import Button from '../../../../../../components/button';
import Editor from '@monaco-editor/react';
import TestResult from '../testResult';
import { httpRequest } from '../../../../../../services/http';
import { ApiEndpoints } from '../../../../../../const/apiEndpoints';

const TestMockEvent = ({ functionDetails, open }) => {
const [testMock, setTestMock] = useState(`{
"type": "record",
"namespace": "com.example",
"name": "test-schema",
"fields": [
{ "name": "Master message", "type": "string", "default": "NONE" },
{ "name": "age", "type": "int", "default": "-1" },
{ "name": "phone", "type": "string", "default": "NONE" },
{ "name": "country", "type": "string", "default": "NONE" }
]
}`);
const [testResultData, setTestResult] = useState(null);
const [isLoading, setIsLoading] = useState(false);
useEffect(() => {
setTestResult(null);
}, [open]);

const testEvent = async () => {
setIsLoading(true);
const body = {
function_name: functionDetails?.function_name,
function_version: functionDetails?.installed_version,
scm_type: functionDetails?.scm,
branch: functionDetails?.branch,
repo: functionDetails?.repo,
owner: functionDetails?.owner,
test_event: {
headers: {},
content: testMock
}
};
try {
const res = await httpRequest('POST', ApiEndpoints.TEST_FUNCTION, body);
setTestResult(res);
} catch (e) {
} finally {
setIsLoading(false);
}
};

return (
<div className="test-modal">
<div className="titleIcon">
<TestEventModalIcon />
</div>
<div className="header">
<div className="title-container">
<p className="title">Generate test event</p>
</div>
<Button
width="120px"
height="40px"
placeholder={'Test'}
colorType="white"
radiusType="circle"
backgroundColorType={'purple'}
border={'gray'}
fontSize="12px"
fontWeight="bold"
onClick={() => {
setTestResult(null);
testEvent();
}}
isLoading={isLoading}
/>
</div>
<div className="test-area">
<div className="text-area-wrapper">
<label className="title">Event data</label>
<div className="text-area">
<Editor
options={{
minimap: { enabled: false },
scrollbar: { verticalScrollbarSize: 0, horizontalScrollbarSize: 0 },
scrollBeyondLastLine: false,
roundedSelection: false,
formatOnPaste: true,
formatOnType: true,
readOnly: false,
fontSize: '12px',
fontFamily: 'Inter',
lineNumbers: 'off',
automaticLayout: true
}}
language={'json'}
height="calc(100%)"
defaultValue={testMock}
value={testMock}
key={'tested'}
onChange={(value) => setTestMock(value)}
/>
</div>
</div>
<TestResult testResultData={testResultData} loading={isLoading} />
</div>
</div>
);
};

export default TestMockEvent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
.test-modal {
padding: 30px 20px 0px 20px;
height: 100%;

.result-wrapper {
width: 100%;
}
.titleIcon {
display: flex;
align-items: center;
justify-content: center;
width: 48px;
height: 48px;
background-color: #f0eeff;
border-radius: 100%;
}
.header {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
.title-container {
.title {
color: #101828;
font-family: 'Inter';
font-size: 18px;
font-style: normal;
font-weight: 600;
line-height: 28px;
margin-bottom: 0;
}
.sub-title {
color: #475467;
font-family: 'Inter';
font-size: 14px;
font-style: normal;
font-weight: 400;
line-height: 20px;
}
}
}

.test-area {
margin-top: 20px;
height: calc(100% - 120px);
overflow-y: auto;
display: grid;
grid-template-columns: 49% 49%;
gap: 10px;
position: relative;
.text-area-wrapper {
height: 100%;
display: flex;
flex-direction: column;
gap: 10px;
.title {
font-size: 14px;
font-family: 'InterSemiBold';
}
.text-area {
border-radius: 8px;
border: 1px solid #e2e2e2;
height: calc(100% - 30px);
padding: 3px;
overflow-y: auto;
}
}
}
}
Loading

0 comments on commit 963bdcd

Please sign in to comment.