You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by kl...@apache.org on 2023/09/08 09:42:23 UTC
[incubator-devlake] branch main updated: feat(config-ui): add api key in webhook (#6045)
This is an automated email from the ASF dual-hosted git repository.
klesh pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/main by this push:
new f54fb0f15 feat(config-ui): add api key in webhook (#6045)
f54fb0f15 is described below
commit f54fb0f154741731b395a1a3429ef12e739732c5
Author: 青湛 <0x...@gmail.com>
AuthorDate: Fri Sep 8 21:42:18 2023 +1200
feat(config-ui): add api key in webhook (#6045)
* feat(config-ui): add new component copy-text
* fix(config-ui): some style for form-item
* feat(config-ui): add api key in webhook
---
.../action/copy-text/index.tsx} | 51 ++++----
config-ui/src/components/action/index.ts | 1 +
config-ui/src/components/form/item/index.tsx | 4 +-
config-ui/src/pages/project/detail/index.tsx | 6 +-
.../plugins/register/webook/connection/index.tsx | 2 +-
.../register/webook/create-dialog/index.tsx | 133 +++++++++++++--------
.../register/webook/create-dialog/styled.ts | 16 +--
.../register/webook/create-dialog/use-create.ts | 75 ------------
.../register/webook/delete-dialog/index.tsx | 4 +-
.../register/webook/view-or-edit-dialog/index.tsx | 53 +++-----
.../register/webook/view-or-edit-dialog/styled.ts | 20 +---
11 files changed, 139 insertions(+), 226 deletions(-)
diff --git a/config-ui/src/plugins/register/webook/view-or-edit-dialog/styled.ts b/config-ui/src/components/action/copy-text/index.tsx
similarity index 55%
copy from config-ui/src/plugins/register/webook/view-or-edit-dialog/styled.ts
copy to config-ui/src/components/action/copy-text/index.tsx
index 85b29a2cb..ceeb8451f 100644
--- a/config-ui/src/plugins/register/webook/view-or-edit-dialog/styled.ts
+++ b/config-ui/src/components/action/copy-text/index.tsx
@@ -16,35 +16,32 @@
*
*/
+import { CopyToClipboard } from 'react-copy-to-clipboard';
import styled from 'styled-components';
-import { Colors } from '@blueprintjs/core';
-export const Wrapper = styled.div`
- h2 {
- display: flex;
- align-items: center;
- justify-content: center;
- margin: 16px 0;
- padding: 0;
- font-weight: 600;
- color: ${Colors.GREEN5};
+import { TextTooltip, IconButton, toast } from '@/components';
- .bp4-icon {
- margin-right: 8px;
- }
- }
+const Wrapper = styled.div`
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ padding: 10px 16px;
+ background: #f0f4fe;
+`;
- h3 {
- margin: 0;
- padding: 0;
- }
+interface Props {
+ content: string;
+}
- .block {
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin-bottom: 8px;
- padding: 10px 16px;
- background: #f0f4fe;
- }
-`;
+export const CopyText = ({ content }: Props) => {
+ return (
+ <Wrapper>
+ <TextTooltip style={{ width: '96%' }} content={content}>
+ {content}
+ </TextTooltip>
+ <CopyToClipboard text={content} onCopy={() => toast.success('Copy successfully.')}>
+ <IconButton icon="clipboard" tooltip="Copy" />
+ </CopyToClipboard>
+ </Wrapper>
+ );
+};
diff --git a/config-ui/src/components/action/index.ts b/config-ui/src/components/action/index.ts
index 1c4b7ef13..c16968efc 100644
--- a/config-ui/src/components/action/index.ts
+++ b/config-ui/src/components/action/index.ts
@@ -16,5 +16,6 @@
*
*/
+export * from './copy-text';
export * from './external-link';
export * from './icon-button';
diff --git a/config-ui/src/components/form/item/index.tsx b/config-ui/src/components/form/item/index.tsx
index 89c64fee4..c1c5002e8 100644
--- a/config-ui/src/components/form/item/index.tsx
+++ b/config-ui/src/components/form/item/index.tsx
@@ -32,8 +32,8 @@ export const FormItem = ({ style, label, subLabel, required, children }: Props)
return (
<FormGroup
style={style}
- label={<S.Label>{label}</S.Label>}
- subLabel={<S.subLabel>{subLabel}</S.subLabel>}
+ label={label ? <S.Label>{label}</S.Label> : null}
+ subLabel={subLabel ? <S.subLabel>{subLabel}</S.subLabel> : null}
labelInfo={required ? <S.LabelInfo>*</S.LabelInfo> : null}
>
{children}
diff --git a/config-ui/src/pages/project/detail/index.tsx b/config-ui/src/pages/project/detail/index.tsx
index 58337995e..131489b8f 100644
--- a/config-ui/src/pages/project/detail/index.tsx
+++ b/config-ui/src/pages/project/detail/index.tsx
@@ -66,11 +66,7 @@ export const ProjectDetailPage = () => {
title="Blueprint"
panel={<BlueprintDetail id={project.blueprint.id} from={FromEnum.project} />}
/>
- <Tab
- id="webhook"
- title="Incoming Webhooks"
- panel={<WebhooksPanel project={project} onRefresh={handleRefresh} />}
- />
+ <Tab id="webhook" title="Webhooks" panel={<WebhooksPanel project={project} onRefresh={handleRefresh} />} />
<Tab id="settings" title="Settings" panel={<SettingsPanel project={project} onRefresh={handleRefresh} />} />
</Tabs>
</S.Wrapper>
diff --git a/config-ui/src/plugins/register/webook/connection/index.tsx b/config-ui/src/plugins/register/webook/connection/index.tsx
index 5d494a7c3..3f0802e1b 100644
--- a/config-ui/src/plugins/register/webook/connection/index.tsx
+++ b/config-ui/src/plugins/register/webook/connection/index.tsx
@@ -61,7 +61,7 @@ export const WebHookConnection = ({ filterIds, onCreateAfter, onDeleteAfter }: P
key: 'id',
},
{
- title: 'Incoming Webhook Name',
+ title: 'Webhook Name',
dataIndex: 'name',
key: 'name',
render: (name, row) => <span onClick={() => handleShowDialog('show', row)}>{name}</span>,
diff --git a/config-ui/src/plugins/register/webook/create-dialog/index.tsx b/config-ui/src/plugins/register/webook/create-dialog/index.tsx
index cfab833e1..180bb16ac 100644
--- a/config-ui/src/plugins/register/webook/create-dialog/index.tsx
+++ b/config-ui/src/plugins/register/webook/create-dialog/index.tsx
@@ -16,13 +16,14 @@
*
*/
-import { useMemo } from 'react';
+import { useState, useMemo } from 'react';
import { InputGroup, Icon } from '@blueprintjs/core';
-import { CopyToClipboard } from 'react-copy-to-clipboard';
-import { Dialog, toast } from '@/components';
+import { Dialog, FormItem, CopyText, Message } from '@/components';
+import { operator } from '@/utils';
+
+import * as API from '../api';
-import { useCreate } from './use-create';
import * as S from './styled';
interface Props {
@@ -32,16 +33,57 @@ interface Props {
}
export const WebhookCreateDialog = ({ isOpen, onCancel, onSubmitAfter }: Props) => {
- const { saving, step, name, record, onChangeName, onSubmit } = useCreate();
+ const [operating, setOperating] = useState(false);
+ const [step, setStep] = useState(1);
+ const [name, setName] = useState('');
+ const [record, setRecord] = useState({
+ id: 0,
+ postIssuesEndpoint: '',
+ closeIssuesEndpoint: '',
+ postDeploymentsCurl: '',
+ apiKey: '',
+ });
- const [okText, okDisabled] = useMemo(
- () => [step === 1 ? 'Generate POST URL' : 'Done', step === 1 && !name],
- [step, name],
- );
+ const prefix = useMemo(() => `${window.location.origin}/api`, []);
- const handleSubmit = () => {
+ const handleSubmit = async () => {
if (step === 1) {
- onSubmit();
+ const [success, res] = await operator(
+ async () => {
+ const { id, apiKey } = await API.createConnection({ name });
+ const { postIssuesEndpoint, closeIssuesEndpoint, postPipelineDeployTaskEndpoint } = await API.getConnection(
+ id,
+ );
+ return {
+ id,
+ apiKey: apiKey.apiKey,
+ postIssuesEndpoint,
+ closeIssuesEndpoint,
+ postPipelineDeployTaskEndpoint,
+ };
+ },
+ {
+ setOperating,
+ hideToast: true,
+ },
+ );
+
+ if (success) {
+ setStep(2);
+ setRecord({
+ id: res.id,
+ postIssuesEndpoint: `${prefix}${res.postIssuesEndpoint}?key={KEY}`,
+ closeIssuesEndpoint: `${prefix}${res.closeIssuesEndpoint}?key={KEY}`,
+ postDeploymentsCurl: `curl ${prefix}${res.postPipelineDeployTaskEndpoint} -X 'POST'
+ \\ -H 'Authorization: Bearer {KEY}'
+ \\ -d '{
+ \\"commit_sha\\":\\"the sha of deployment commit\\",
+ \\"repo_url\\":\\"the repo URL of the deployment commit\\",
+ \\"start_time\\":\\"eg. 2020-01-01T12:00:00+00:00\\"
+ }'`,
+ apiKey: res.apiKey,
+ });
+ }
} else {
onCancel();
onSubmitAfter?.(record.id);
@@ -51,56 +93,49 @@ export const WebhookCreateDialog = ({ isOpen, onCancel, onSubmitAfter }: Props)
return (
<Dialog
isOpen={isOpen}
- title="Add a New Incoming Webhook"
- style={{ width: 600 }}
- okText={okText}
- okDisabled={okDisabled}
- okLoading={saving}
+ title="Add a New Webhook"
+ style={{ width: 820 }}
+ okText={step === 1 ? 'Generate POST URL' : 'Done'}
+ okDisabled={step === 1 && !name}
+ okLoading={operating}
onCancel={onCancel}
onOk={handleSubmit}
>
{step === 1 && (
- <S.Wrapper>
- <h3>Incoming Webhook Name *</h3>
- <p>Give your Incoming Webhook a unique name to help you identify it in the future.</p>
- <InputGroup value={name} onChange={(e) => onChangeName(e.target.value)} />
- </S.Wrapper>
+ <S.Detail>
+ <h3>Webhook Name *</h3>
+ <p>Give your Webhook a unique name to help you identify it in the future.</p>
+ <InputGroup value={name} onChange={(e) => setName(e.target.value)} />
+ </S.Detail>
)}
{step === 2 && (
- <S.Wrapper>
+ <S.Detail>
<h2>
<Icon icon="endorsed" size={30} />
<span>POST URL Generated!</span>
</h2>
- <h3>POST URL</h3>
<p>
- Copy the following URLs to your issue tracking tool for Incidents and CI tool for Deployments by making a
- POST to DevLake.
+ Copy the following POST URLs to your issue tracking or CI tools to push `Incidents` and `Deployments` by
+ making a POST to DevLake.
</p>
- <h3>Incident</h3>
- <p>POST to register an incident</p>
- <div className="block">
- <span>{record.postIssuesEndpoint}</span>
- <CopyToClipboard text={record.postIssuesEndpoint} onCopy={() => toast.success('Copy successfully.')}>
- <Icon icon="clipboard" />
- </CopyToClipboard>
- </div>
- <p>POST to close a registered incident</p>
- <div className="block">
- <span>{record.closeIssuesEndpoint}</span>
- <CopyToClipboard text={record.closeIssuesEndpoint} onCopy={() => toast.success('Copy successfully.')}>
- <Icon icon="clipboard" />
- </CopyToClipboard>
- </div>
- <h3>Deployment</h3>
- <p>POST to register a deployment</p>
- <div className="block">
- <span>{record.postDeploymentsCurl}</span>
- <CopyToClipboard text={record.postDeploymentsCurl} onCopy={() => toast.success('Copy successfully.')}>
- <Icon icon="clipboard" />
- </CopyToClipboard>
- </div>
- </S.Wrapper>
+ <FormItem label="Incident">
+ <h5>Post to register an incident</h5>
+ <CopyText content={record.postIssuesEndpoint} />
+ <h5>Post to close a registered incident</h5>
+ <CopyText content={record.closeIssuesEndpoint} />
+ </FormItem>
+ <FormItem label="Deployments">
+ <h5>Post to register a deployment</h5>
+ <CopyText content={record.postDeploymentsCurl} />
+ </FormItem>
+ <FormItem label="API Key">
+ <Message
+ style={{ marginBottom: 8 }}
+ content="Please make sure to copy your API key now. You will not be able to see it again."
+ />
+ <CopyText content={record.apiKey} />
+ </FormItem>
+ </S.Detail>
)}
</Dialog>
);
diff --git a/config-ui/src/plugins/register/webook/create-dialog/styled.ts b/config-ui/src/plugins/register/webook/create-dialog/styled.ts
index 73aa4dae0..8d4f16106 100644
--- a/config-ui/src/plugins/register/webook/create-dialog/styled.ts
+++ b/config-ui/src/plugins/register/webook/create-dialog/styled.ts
@@ -19,7 +19,7 @@
import styled from 'styled-components';
import { Colors } from '@blueprintjs/core';
-export const Wrapper = styled.div`
+export const Detail = styled.div`
h2 {
display: flex;
align-items: center;
@@ -35,17 +35,7 @@ export const Wrapper = styled.div`
}
}
- h3 {
- margin: 0;
- padding: 0;
- }
-
- .block {
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin-bottom: 8px;
- padding: 10px 16px;
- background: #f0f4fe;
+ h5 {
+ margin: 8px 0;
}
`;
diff --git a/config-ui/src/plugins/register/webook/create-dialog/use-create.ts b/config-ui/src/plugins/register/webook/create-dialog/use-create.ts
deleted file mode 100644
index b25b8726c..000000000
--- a/config-ui/src/plugins/register/webook/create-dialog/use-create.ts
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-import { useState, useMemo } from 'react';
-
-import { operator } from '@/utils';
-
-import * as API from '../api';
-
-export const useCreate = () => {
- const [saving, setSaving] = useState(false);
- const [step, setStep] = useState(1);
- const [name, setName] = useState('');
- const [record, setRecord] = useState({
- id: 0,
- postIssuesEndpoint: '',
- closeIssuesEndpoint: '',
- postDeploymentsCurl: '',
- });
-
- const prefix = useMemo(() => `${window.location.origin}/api`, []);
-
- const handleCreate = async () => {
- const [success, res] = await operator(
- async () => {
- const res = await API.createConnection({ name });
- return API.getConnection(res.id);
- },
- {
- setOperating: setSaving,
- },
- );
-
- if (success) {
- setStep(2);
- setRecord({
- id: res.id,
- postIssuesEndpoint: `${prefix}${res.postIssuesEndpoint}`,
- closeIssuesEndpoint: `${prefix}${res.closeIssuesEndpoint}`,
- postDeploymentsCurl: `curl ${prefix}${res.postPipelineDeployTaskEndpoint}-X 'POST' -d '{
- \\"commit_sha\\":\\"the sha of deployment commit\\",
- \\"repo_url\\":\\"the repo URL of the deployment commit\\",
- \\"start_time\\":\\"eg. 2020-01-01T12:00:00+00:00\\"
- }'`,
- });
- }
- };
-
- return useMemo(
- () => ({
- saving,
- step,
- name,
- record,
- onChangeName: setName,
- onSubmit: handleCreate,
- }),
- [saving, step, name, record],
- );
-};
diff --git a/config-ui/src/plugins/register/webook/delete-dialog/index.tsx b/config-ui/src/plugins/register/webook/delete-dialog/index.tsx
index 24941fc93..4fbe0433b 100644
--- a/config-ui/src/plugins/register/webook/delete-dialog/index.tsx
+++ b/config-ui/src/plugins/register/webook/delete-dialog/index.tsx
@@ -38,7 +38,7 @@ export const WebhookDeleteDialog = ({ isOpen, onCancel, ...props }: Props) => {
return (
<Dialog
isOpen={isOpen}
- title="Delete this Incoming Webhook?"
+ title="Delete this Webhook?"
style={{ width: 600 }}
okText="Confirm"
okLoading={saving}
@@ -47,7 +47,7 @@ export const WebhookDeleteDialog = ({ isOpen, onCancel, ...props }: Props) => {
>
<S.Wrapper>
<div className="message">
- <p>This Incoming Webhook cannot be recovered once it’s deleted.</p>
+ <p>This Webhook cannot be recovered once it’s deleted.</p>
</div>
</S.Wrapper>
</Dialog>
diff --git a/config-ui/src/plugins/register/webook/view-or-edit-dialog/index.tsx b/config-ui/src/plugins/register/webook/view-or-edit-dialog/index.tsx
index f57df34ab..1b9437b4f 100644
--- a/config-ui/src/plugins/register/webook/view-or-edit-dialog/index.tsx
+++ b/config-ui/src/plugins/register/webook/view-or-edit-dialog/index.tsx
@@ -16,10 +16,9 @@
*
*/
-import { InputGroup, Icon } from '@blueprintjs/core';
-import { CopyToClipboard } from 'react-copy-to-clipboard';
+import { InputGroup } from '@blueprintjs/core';
-import { Dialog, toast } from '@/components';
+import { Dialog, FormItem, CopyText } from '@/components';
import type { UseViewOrEditProps } from './use-view-or-edit';
import { useViewOrEdit } from './use-view-or-edit';
@@ -47,8 +46,8 @@ export const WebhookViewOrEditDialog = ({ type, isOpen, onCancel, ...props }: Pr
return (
<Dialog
isOpen={isOpen}
- title="View or Edit Incoming Webhook"
- style={{ width: 600 }}
+ title="View/Edit Webhook"
+ style={{ width: 820 }}
okText={type === 'edit' ? 'Save' : 'Done'}
okDisabled={!name}
okLoading={saving}
@@ -56,40 +55,26 @@ export const WebhookViewOrEditDialog = ({ type, isOpen, onCancel, ...props }: Pr
onOk={handleSubmit}
>
<S.Wrapper>
- <h3>Incoming Webhook Name *</h3>
- <p>Give your Incoming Webhook a unique name to help you identify it in the future.</p>
+ <h3>Webhook Name *</h3>
+ <p>
+ Copy the following POST URLs to your issue tracking or CI tools to push `Incidents` and `Deployments` by
+ making a POST to DevLake.
+ </p>
<InputGroup disabled={type !== 'edit'} value={name} onChange={(e) => onChangeName(e.target.value)} />
- <h2>
- <Icon icon="endorsed" size={30} />
- <span>POST URL </span>
- </h2>
<p>
Copy the following URLs to your issue tracking tool for Incidents and CI tool for Deployments by making a POST
to DevLake.
</p>
- <h3>Incident</h3>
- <p>POST to register an incident </p>
- <div className="block">
- <span>{record.postIssuesEndpoint}</span>
- <CopyToClipboard text={record.postIssuesEndpoint} onCopy={() => toast.success('Copy successfully.')}>
- <Icon icon="clipboard" />
- </CopyToClipboard>
- </div>
- <p>POST to close a registered incident</p>
- <div className="block">
- <span>{record.closeIssuesEndpoint}</span>
- <CopyToClipboard text={record.closeIssuesEndpoint} onCopy={() => toast.success('Copy successfully.')}>
- <Icon icon="clipboard" />
- </CopyToClipboard>
- </div>
- <h3>Deployment</h3>
- <p>POST to register a deployment</p>
- <div className="block">
- <span>{record.postDeploymentsCurl}</span>
- <CopyToClipboard text={record.postDeploymentsCurl} onCopy={() => toast.success('Copy successfully.')}>
- <Icon icon="clipboard" />
- </CopyToClipboard>
- </div>
+ <FormItem label="Incidents">
+ <h5>Post to register an incident</h5>
+ <CopyText content={record.postIssuesEndpoint} />
+ <h5>Post to close a registered incident</h5>
+ <CopyText content={record.closeIssuesEndpoint} />
+ </FormItem>
+ <FormItem label="Deployment">
+ <h5>Post to register a deployment</h5>
+ <CopyText content={record.postDeploymentsCurl} />
+ </FormItem>
</S.Wrapper>
</Dialog>
);
diff --git a/config-ui/src/plugins/register/webook/view-or-edit-dialog/styled.ts b/config-ui/src/plugins/register/webook/view-or-edit-dialog/styled.ts
index 85b29a2cb..969380e28 100644
--- a/config-ui/src/plugins/register/webook/view-or-edit-dialog/styled.ts
+++ b/config-ui/src/plugins/register/webook/view-or-edit-dialog/styled.ts
@@ -17,26 +17,10 @@
*/
import styled from 'styled-components';
-import { Colors } from '@blueprintjs/core';
export const Wrapper = styled.div`
- h2 {
- display: flex;
- align-items: center;
- justify-content: center;
- margin: 16px 0;
- padding: 0;
- font-weight: 600;
- color: ${Colors.GREEN5};
-
- .bp4-icon {
- margin-right: 8px;
- }
- }
-
- h3 {
- margin: 0;
- padding: 0;
+ h5 {
+ margin: 8px 0;
}
.block {