Skip to content

Commit

Permalink
copy from cloud (#1441)
Browse files Browse the repository at this point in the history
  • Loading branch information
SvetaMemphis committed Nov 26, 2023
1 parent a3bdb7b commit df51fb6
Show file tree
Hide file tree
Showing 27 changed files with 260 additions and 88 deletions.
6 changes: 4 additions & 2 deletions ui_src/src/components/Tabs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import TooltipComponent from '../tooltip/tooltip';
import CheckboxComponent from '../checkBox';
import { PriorityHighRounded } from '@material-ui/icons';

const CustomTabs = ({ tabs, onChange, value, disabled, length, tooltip, icon = false, checkbox = false, defaultActiveKey }) => {
const CustomTabs = ({ tabs, onChange, value, disabled, length, tooltip, icon = false, checkbox = false, defaultActiveKey, tabsCounter }) => {
return (
<div className={!disabled ? 'tabs-container hover' : 'tabs-container'}>
<Tabs
Expand All @@ -36,7 +36,9 @@ const CustomTabs = ({ tabs, onChange, value, disabled, length, tooltip, icon = f
label: (
<label className="tabs-name" style={{ width: length && length[index] && '135px' }}>
{checkbox && <CheckboxComponent checked={tab.checked} />}
<TooltipComponent text={tooltip && tooltip[index]}>{tab?.name || tab} </TooltipComponent>
<TooltipComponent text={tooltip && tooltip[index]}>
{`${tab?.name || tab} ${tabsCounter ? `(${tabsCounter[index]})` : ''}`}{' '}
</TooltipComponent>
{length && length[index] && icon && (
<div className="error-icon">
<div>
Expand Down
6 changes: 3 additions & 3 deletions ui_src/src/const/globalConst.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ export const githubUrls = {
MEMPHIS_GIT_SSH: 'git@github.com:memphisdev/onboarding-app.git'
},
functions: {
DOWNLOAD_URL: 'https://github.com/memphisdev/function-templates/archive/refs/heads/master.zip',
MEMPHIS_GIT_HTTPS: 'https://github.com/memphisdev/function-templates.git',
MEMPHIS_GIT_SSH: 'git@github.com:memphisdev/function-templates.git'
DOWNLOAD_URL: 'https://github.com/memphisdev/functions-templates/archive/refs/heads/master.zip',
MEMPHIS_GIT_HTTPS: 'https://github.com/memphisdev/functions-templates.git',
MEMPHIS_GIT_SSH: 'git@github.com:memphisdev/functions-templates.git'
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ const GitHubIntegration = ({ close, value }) => {
/>
</div>
)}
<div className="api-details">
<div className="api-details api-details-github">
{isIntegrated && (
<div className="input-field">
<p className="title">Repos</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ const IntegrationItem = ({ value, lockFeature, isOpen }) => {
return (
<GitHubIntegration
close={(data) => {
modalFlip(false);
setIntegrateValue(data);
data !== ref.current &&
history.push({
Expand Down Expand Up @@ -173,11 +172,20 @@ const IntegrationItem = ({ value, lockFeature, isOpen }) => {
</integ-item>
<Drawer
placement="right"
onClose={() => modalFlip(false)}
onClose={() => {
if (value?.name === 'Github') {
if (state.integrationsList?.findIndex((integration) => capitalizeFirst(integration.name) === 'Github') !== -1) {
history.push({
pathname: '/functions',
integrated: true
});
}
}
modalFlip(false);
}}
destroyOnClose={true}
className="integration-modal"
width="720px"
clickOutside={() => modalFlip(false)}
open={modalIsOpen}
closeIcon={false}
headerStyle={{ display: 'none' }}
Expand Down
3 changes: 3 additions & 0 deletions ui_src/src/domain/administration/integrations/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ dynamic-integration {
justify-content: center;
align-items: center;
}
.api-details-github {
height: 100% !important;
}

.api-details {
height: calc(100% - 55px);
Expand Down
4 changes: 2 additions & 2 deletions ui_src/src/domain/functions/components/functionBox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function FunctionBox({ funcDetails, integrated, isTagsOn = true, onClick = null,
try {
await httpRequest('POST', ApiEndpoints.INSTALL_FUNCTION, bodyRequest);
showMessages('success', `We are ${functionDetails?.updates_available ? 'updating' : 'installing'} the function for you. We will let you know once its done`);
startInstallation(funcIndex);
startInstallation(funcIndex, functionDetails?.updates_available);
} catch (e) {
return;
}
Expand Down Expand Up @@ -203,7 +203,7 @@ function FunctionBox({ funcDetails, integrated, isTagsOn = true, onClick = null,
fontSize="12px"
fontFamily="InterSemiBold"
onClick={() => setIsTestFunctionModalOpen(true)}
disabled={!functionDetails?.installed}
disabled={!functionDetails?.installed || functionDetails?.installed_in_progress}
/>
)}
{isValid && (!isCloud() || functionDetails?.installed) && (
Expand Down
23 changes: 18 additions & 5 deletions ui_src/src/domain/functions/components/functionDetails/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ function FunctionDetails({ selectedFunction, handleInstall, handleUnInstall, cli
'&scm=' +
encodeURI(selectedFunction?.scm) +
'&function_name=' +
encodeURI(selectedFunction?.function_name || selectedFunction?.name)
encodeURI(selectedFunction?.function_name || selectedFunction?.name) +
'&version=' +
encodeURI(selectedVersion === 'latest' ? '' : selectedVersion)
);
setMetaData(response?.metadata_function);
setReadme(response?.readme_content);
Expand Down Expand Up @@ -248,7 +250,9 @@ function FunctionDetails({ selectedFunction, handleInstall, handleUnInstall, cli
)}
<commits is="x3d">
<FiGitCommit />
<label>Last modified on {parsingDate(selectedFunction?.installed_updated_at, false, false)}</label>
<OverflowTip text={parsingDate(selectedFunction?.installed_updated_at || metaData?.installed_updated_at, true, true)} width={'220px'}>
Last modified on {parsingDate(selectedFunction?.installed_updated_at || metaData?.installed_updated_at, true, true)}
</OverflowTip>
</commits>
</deatils>
</div>
Expand Down Expand Up @@ -307,7 +311,14 @@ function FunctionDetails({ selectedFunction, handleInstall, handleUnInstall, cli
radiusType={'circle'}
fontSize="12px"
fontFamily="InterSemiBold"
onClick={() => (selectedFunction?.installed ? handleUnInstall() : handleInstall())}
onClick={() => {
if (selectedFunction?.installed) {
handleUnInstall();
} else {
handleInstall();
}
onBackToFunction && onBackToFunction();
}}
isLoading={metaData?.installed_in_progress}
disabled={!selectedFunction?.is_valid || selectedFunction?.installed_in_progress}
/>
Expand Down Expand Up @@ -404,7 +415,7 @@ function FunctionDetails({ selectedFunction, handleInstall, handleUnInstall, cli
<Divider />
<label className="label-title">Social</label>
<deatils is="x3d">
{selectedFunction.owner === OWNER && (
{selectedFunction?.owner === OWNER && (
<>
<downloads is="x3d">
<BiDownload className="download-icon" />
Expand All @@ -420,7 +431,9 @@ function FunctionDetails({ selectedFunction, handleInstall, handleUnInstall, cli
)}
<commits is="x3d">
<FiGitCommit />
<label>Last modified on {parsingDate(selectedFunction?.installed_updated_at, false, false)}</label>
<OverflowTip text={parsingDate(selectedFunction?.installed_updated_at || metaData?.installed_updated_at, true, true)} width={'210px'}>
Last modified on {parsingDate(selectedFunction?.installed_updated_at || metaData?.installed_updated_at, true, true)}
</OverflowTip>
</commits>
</deatils>
<Divider />
Expand Down
63 changes: 42 additions & 21 deletions ui_src/src/domain/functions/components/functionList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { Collapse, Divider, Popover, Badge } from 'antd';
import { LOCAL_STORAGE_FUNCTION_PAGE_VIEW } from '../../../../const/localStorageConsts';
import { getFunctionsTabs } from '../../../../services/valueConvertor';
const { Panel } = Collapse;
const TABS = getFunctionsTabs();

function FunctionList({ tabPrivate }) {
const [state, dispatch] = useContext(Context);
Expand All @@ -69,14 +70,19 @@ function FunctionList({ tabPrivate }) {
const [refreshIndeicator, setRefreshIndicator] = useState(false);
const [isCloudModalOpen, setIsCloudModalOpen] = useState(false);
const [githubIntegrationData, setGithubIntegrationData] = useState({});

const [tabsCounter, setTabsCounter] = useState([0, 0, 0]);
const ExpandIcon = ({ isActive }) => <img className={isActive ? 'collapse-arrow open' : 'collapse-arrow close'} src={CollapseArrow} alt="collapse-arrow" />;
const TABS = getFunctionsTabs();

useEffect(() => {
findAndUpdateGithubIntegration();
}, [state?.integrationsList]);

useEffect(() => {
const memphisCount = installedFunctionList?.filter((func) => func.owner === OWNER)?.length + otherFunctionList?.filter((func) => func.owner === OWNER)?.length;
const privateCount = installedFunctionList?.filter((func) => func.owner !== OWNER)?.length + otherFunctionList?.filter((func) => func.owner !== OWNER)?.length;
setTabsCounter([memphisCount + privateCount, memphisCount, privateCount]);
}, [filteredInstalledData, filteredOtherData]);

const findAndUpdateGithubIntegration = () => {
const integrationData = state?.integrationsList?.find((integration) => integration?.name === 'github');
setGithubIntegrationData(integrationData);
Expand Down Expand Up @@ -200,21 +206,27 @@ function FunctionList({ tabPrivate }) {
});
};

const startInstallation = (index) => {
const startInstallation = (index, isUpdate) => {
setRefreshIndicator(true);
setFilteredInstalledData((prev) => {
const data = [...prev];
let func = filteredOtherData[index];
func.installed_in_progress = true;
func.installed = true;
data.push(func);
return data;
});
setFilteredOtherData((prev) => {
const data = [...prev];
data.splice(index, 1);
return data;
});
if (isUpdate) {
let installedFunctions = [...filteredInstalledData];
installedFunctions[index].installed_in_progress = true;
setFilteredInstalledData(installedFunctions);
} else {
setFilteredInstalledData((prev) => {
const data = [...prev];
let func = filteredOtherData[index];
func.installed_in_progress = true;
func.installed = true;
data.push(func);
return data;
});
setFilteredOtherData((prev) => {
const data = [...prev];
data.splice(index, 1);
return data;
});
}
};

const content = (
Expand Down Expand Up @@ -354,9 +366,13 @@ function FunctionList({ tabPrivate }) {
<div
className="git-repo git-refresh-title"
onClick={() => {
if (!isCloud()) return; //Open cloud only banner
modalFlip(true);
setClickedRefresh(false);
if (!isCloud()) {
setIsCloudModalOpen(true);
setClickedRefresh(false);
} else {
modalFlip(true);
setClickedRefresh(false);
}
}}
>
<AddRounded className="add" fontSize="small" />
Expand Down Expand Up @@ -409,8 +425,13 @@ function FunctionList({ tabPrivate }) {
</Popover>
</div>
</div>
<CustomTabs tabs={TABS} defaultActiveKey={tabPrivate ? 'Private' : 'All'} tabValue={tabValue} onChange={(tabValue) => setTabValue(tabValue)} />

<CustomTabs
tabs={TABS}
defaultActiveKey={tabPrivate ? 'Private' : 'All'}
value={tabValue}
onChange={(tabValue) => setTabValue(tabValue)}
tabsCounter={tabsCounter}
/>
<SearchInput
placeholder="Search here"
colorType="navy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ const FunctionsGuide = ({ handleClose, handleConfirm }) => {
{
name: (
<>
<label>Clone or create a new GitHub repository </label>
<label className="link" onClick={() => handleCloneClick('functions')}>
Clone
{' '}
(templates can be found here)
</label>
<label> or create a new repository (At the moment, support is available for GitHub)</label>
</>
)
},
Expand All @@ -50,7 +51,7 @@ const FunctionsGuide = ({ handleClose, handleConfirm }) => {
<label>Code your function based on the following </label>
<label
className="link"
onClick={() => window.open(`https://github.com/memphisdev/memphis-dev-functions/blob/master/README.md#rocket-step-by-step-guide`)}
onClick={() => window.open(`https://docs.memphis.dev/memphis/memphis-functions/getting-started#how-to-develop-a-new-private-function`)}
>
guide
</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import Button from '../../../../../../components/button';
import Input from '../../../../../../components/Input';
import Editor from '@monaco-editor/react';
import TestResult from '../testResult';
import { generateJSONWithMaxLength } from '../../../../../../services/valueConvertor';
import { httpRequest } from '../../../../../../services/http';
import { ApiEndpoints } from '../../../../../../const/apiEndpoints';

Expand Down Expand Up @@ -64,17 +65,7 @@ const TestMockEvent = ({ functionDetails, open }) => {
);
setTestMock(response?.content);
} catch (e) {
setTestMock(`{
"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" }
]
}`);
setTestMock(generateJSONWithMaxLength(100));
setMissingMockIndicator(true);
}
};
Expand Down Expand Up @@ -120,7 +111,7 @@ const TestMockEvent = ({ functionDetails, open }) => {
</div>
<div className="header">
<div className="title-container">
<p className="title">Generate test event</p>
<p className="title">Test the function</p>
</div>
<Button
width="120px"
Expand All @@ -142,7 +133,7 @@ const TestMockEvent = ({ functionDetails, open }) => {
<div className="text-area-wrapper">
<span className="title-span">
<label className="title">Event data</label>{' '}
{missingMockIndicator && <span className="missing-mock">{`(The file 'test.json' is not found. Creating artificial data instead.)`}</span>}
{missingMockIndicator && <span className="missing-mock">{`(The file 'test.json' is cannot be found. Creating artificial data instead)`}</span>}
</span>

<div className="text-area">
Expand Down Expand Up @@ -171,7 +162,8 @@ const TestMockEvent = ({ functionDetails, open }) => {
</div>
{inputs && inputs?.length > 0 && (
<>
<label className="title">Inputs</label>
<label className="title-inputs">Inputs</label>
<label className="description-inputs">Not sure how to fill in the inputs? Head over the function`s README for more information</label>
<div className="inputs-section">
{inputs?.map((input, index) => (
<span className="input-row" key={`${input?.name}${index}`}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
height: calc(100% - 20px);
display: flex;
flex-direction: column;
gap: 10px;

.title-span {
display: flex;
align-items: flex-end;
gap: 5px;
align-items: center;
gap: 10px;
.title {
font-size: 14px;
font-family: 'InterSemiBold';
Expand Down Expand Up @@ -99,4 +99,15 @@
}
}
}
.title-inputs {
font-size: 14px;
font-family: 'InterSemiBold';
margin-top: 10px;
}
.description-inputs {
margin-bottom: 10px;
font-size: 12px;
font-family: 'Inter';
color: #475467;
}
}
Loading

0 comments on commit df51fb6

Please sign in to comment.