forked from openshift/console
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request openshift#12686 from Lucifergene/ODC-7274-prepare-…
…a-page-and-modal-to-invoke-a-serverless-function ODC-7274: Prepare a page and modal to invoke a Serverless function
- Loading branch information
Showing
25 changed files
with
923 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
frontend/packages/knative-plugin/src/components/test-function/TestFunction.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import * as React from 'react'; | ||
import { Formik, FormikValues, FormikHelpers } from 'formik'; | ||
import { ServiceKind } from '../../types'; | ||
import TestFunctionModal from './TestFunctionModal'; | ||
import { InvokeFormat } from './types'; | ||
|
||
export interface TestFunctionProps { | ||
service: ServiceKind; | ||
cancel?: () => void; | ||
close?: () => void; | ||
} | ||
|
||
export type TestFunctionFormikValues = { | ||
request: { | ||
format: InvokeFormat; | ||
contentType: string; | ||
type: string; | ||
source: string; | ||
customHeaders: string[][]; | ||
body: { | ||
data: string; | ||
}; | ||
}; | ||
response: { | ||
url: string; | ||
status: string; | ||
statusCode: number; | ||
headers: Record<string, string[]>; | ||
body: string; | ||
}; | ||
endpoint: { | ||
url: URL | string; | ||
}; | ||
}; | ||
|
||
const TestFunction: React.FC<TestFunctionProps> = ({ service, cancel, close }) => { | ||
const initialValues: TestFunctionFormikValues = { | ||
request: { | ||
format: InvokeFormat.CloudEvent, | ||
contentType: 'application/json', | ||
type: '', | ||
source: '', | ||
customHeaders: [[]], | ||
body: { | ||
data: '{"message": "Hello World!"}', | ||
}, | ||
}, | ||
response: { | ||
url: '', | ||
status: '', | ||
statusCode: 0, | ||
headers: { | ||
'content-type': ['application/json'], | ||
'ce-type': ['boson.fn'], | ||
'ce-source': ['/boson/fn'], | ||
'ce-hello': ['World', 'sds'], | ||
'ce-lorem': ['Ipsum'], | ||
}, | ||
body: '{"message": "Response Data!"}', | ||
}, | ||
endpoint: { | ||
url: '', | ||
}, | ||
}; | ||
|
||
const handleSubmit = (values: FormikValues, action: FormikHelpers<FormikValues>) => { | ||
// eslint-disable-next-line no-console | ||
console.log('!!!Invoking Function!!!'); | ||
action.setStatus({ error: '' }); | ||
}; | ||
return ( | ||
<Formik | ||
initialValues={initialValues} | ||
onSubmit={handleSubmit} | ||
onReset={cancel} | ||
initialStatus={{ error: '' }} | ||
> | ||
{(formikProps) => ( | ||
<TestFunctionModal {...formikProps} cancel={cancel} service={service} close={close} /> | ||
)} | ||
</Formik> | ||
); | ||
}; | ||
export default TestFunction; |
46 changes: 46 additions & 0 deletions
46
frontend/packages/knative-plugin/src/components/test-function/TestFunctionController.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as React from 'react'; | ||
import { createModalLauncher, ModalComponentProps } from '@console/internal/components/factory'; | ||
import { Firehose } from '@console/internal/components/utils'; | ||
import { ServiceModel } from '../../models'; | ||
import { ServiceKind } from '../../types'; | ||
import TestFunction from './TestFunction'; | ||
|
||
type ControllerProps = { | ||
loaded?: boolean; | ||
obj: ServiceKind; | ||
}; | ||
|
||
const Controller: React.FC<ControllerProps> = (props) => { | ||
const { loaded, obj } = props; | ||
return loaded ? <TestFunction {...props} service={obj} /> : null; | ||
}; | ||
|
||
type TestFunctionControllerProps = { | ||
obj: ServiceKind; | ||
}; | ||
|
||
const TestFunctionController: React.FC<TestFunctionControllerProps> = (props) => { | ||
const { obj } = props; | ||
|
||
const serverlessResources = [ | ||
{ | ||
kind: ServiceModel.kind, | ||
isList: false, | ||
prop: `obj`, | ||
namespace: obj.metadata.namespace, | ||
name: obj.metadata.name, | ||
}, | ||
]; | ||
|
||
return ( | ||
<Firehose resources={serverlessResources}> | ||
<Controller {...props} /> | ||
</Firehose> | ||
); | ||
}; | ||
|
||
type Props = TestFunctionControllerProps & ModalComponentProps; | ||
|
||
export const testFunctionModalLauncher = createModalLauncher<Props>(TestFunctionController); | ||
|
||
export default TestFunctionController; |
87 changes: 87 additions & 0 deletions
87
frontend/packages/knative-plugin/src/components/test-function/TestFunctionModal.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
@import '../../../../../public/style/vars'; | ||
|
||
.kn-test-sf-modal__size { | ||
height: 90vh; | ||
width: 80vw; | ||
} | ||
|
||
.kn-test-sf-modal { | ||
@media (max-width: $pf-global--breakpoint--md) { | ||
&__split { | ||
display: none; | ||
} | ||
} | ||
@media (min-width: $pf-global--breakpoint--md) { | ||
&__tabbed { | ||
display: none; | ||
} | ||
} | ||
} | ||
|
||
.kn-test-sf-modal__title { | ||
padding: 0.5rem 0.5rem 1.5rem 0.5rem; | ||
|
||
&__icon { | ||
margin-right: 8px; | ||
color: #0468ce; | ||
} | ||
|
||
&__badge { | ||
vertical-align: 2px; | ||
} | ||
} | ||
|
||
.kn-test-sf-modal__body { | ||
padding: 0 0.5rem 0 0.5rem; | ||
|
||
&__description { | ||
margin-bottom: 1.25rem; | ||
} | ||
} | ||
|
||
.kn-test-sf-modal__footer { | ||
margin-right: 1rem; | ||
margin-left: 0.5rem; | ||
margin-bottom: 0.5rem; | ||
} | ||
|
||
.kn-test-sf-modal__splitItem { | ||
max-width: 49%; | ||
} | ||
|
||
@media (max-width: $pf-global--breakpoint--md) { | ||
.kn-test-sf-modal__editor { | ||
margin-top: 1.5rem; | ||
margin-left: 2rem; | ||
margin-right: 2rem; | ||
} | ||
} | ||
|
||
.kn-test-sf-modal-request-pane--options__size { | ||
margin-top: 1rem; | ||
margin-left: 1.4rem; | ||
margin-right: 10rem; | ||
} | ||
|
||
.kn-test-sf-modal-request-pane--options__custom-headers { | ||
margin-top: 3rem; | ||
margin-right: -4rem; | ||
} | ||
|
||
.kn-test-sf-modal-response-pane--info__size { | ||
margin-left: 1rem; | ||
} | ||
|
||
.kn-test-sf-modal-response-pane--info__status { | ||
display: flex; | ||
flex-direction: row; | ||
|
||
&__label { | ||
padding-right: 0.5rem; | ||
padding-top: 0.2rem; | ||
} | ||
|
||
&__code { | ||
font-weight: bold !important; | ||
} | ||
} |
Oops, something went wrong.