You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by li...@apache.org on 2023/01/18 07:09:46 UTC
[incubator-devlake] branch main updated: fix(config-ui): connection initial values not work (#4223)
This is an automated email from the ASF dual-hosted git repository.
likyh 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 2131862c4 fix(config-ui): connection initial values not work (#4223)
2131862c4 is described below
commit 2131862c46adeac2dcba0ccfa20387ae9c12d201
Author: 青湛 <0x...@gmail.com>
AuthorDate: Wed Jan 18 15:09:41 2023 +0800
fix(config-ui): connection initial values not work (#4223)
---
.../connection/form/components/gitlab-token/index.tsx | 10 ++--------
config-ui/src/pages/connection/form/index.tsx | 15 +++++++--------
config-ui/src/plugins/register/base/connection-fields.ts | 1 -
config-ui/src/plugins/register/bitbucket/config.ts | 11 ++++++-----
config-ui/src/plugins/register/github/config.ts | 12 +++++++-----
config-ui/src/plugins/register/gitlab/config.ts | 11 ++++++-----
config-ui/src/plugins/register/jenkins/config.ts | 11 ++++++-----
config-ui/src/plugins/register/jira/config.ts | 11 ++++++-----
config-ui/src/plugins/register/tapd/config.ts | 11 ++++++-----
config-ui/src/plugins/register/zentao/config.ts | 11 ++++++-----
config-ui/src/plugins/types.ts | 2 +-
11 files changed, 53 insertions(+), 53 deletions(-)
diff --git a/config-ui/src/pages/connection/form/components/gitlab-token/index.tsx b/config-ui/src/pages/connection/form/components/gitlab-token/index.tsx
index ee3f4590c..9c5579446 100644
--- a/config-ui/src/pages/connection/form/components/gitlab-token/index.tsx
+++ b/config-ui/src/pages/connection/form/components/gitlab-token/index.tsx
@@ -21,12 +21,11 @@ import { InputGroup } from '@blueprintjs/core';
interface Props {
placeholder?: string;
- initialValue?: string;
value?: string;
onChange?: (value: string) => void;
}
-export const GitLabToken = ({ placeholder, initialValue, value, onChange }: Props) => {
+export const GitLabToken = ({ placeholder, value, onChange }: Props) => {
const handleChangeValue = (e: React.ChangeEvent<HTMLInputElement>) => {
onChange?.(e.target.value);
};
@@ -42,12 +41,7 @@ export const GitLabToken = ({ placeholder, initialValue, value, onChange }: Prop
Learn about how to create a personal access token
</a>
</p>
- <InputGroup
- placeholder={placeholder}
- type="password"
- value={value ?? initialValue}
- onChange={handleChangeValue}
- />
+ <InputGroup placeholder={placeholder} type="password" value={value} onChange={handleChangeValue} />
</div>
);
};
diff --git a/config-ui/src/pages/connection/form/index.tsx b/config-ui/src/pages/connection/form/index.tsx
index 7375a7632..a5d0504ae 100644
--- a/config-ui/src/pages/connection/form/index.tsx
+++ b/config-ui/src/pages/connection/form/index.tsx
@@ -18,7 +18,7 @@
import React, { useState, useEffect, useMemo } from 'react';
import { useParams, useHistory } from 'react-router-dom';
-import { pick } from 'lodash';
+import { omit, pick } from 'lodash';
import { FormGroup, InputGroup, Switch, ButtonGroup, Button, Icon, Intent, Position } from '@blueprintjs/core';
import { Tooltip2 } from '@blueprintjs/popover2';
@@ -39,15 +39,16 @@ export const ConnectionFormPage = () => {
const {
name,
- connection: { fields },
+ connection: { initialValues, fields },
} = useMemo(() => PluginConfig.find((p) => p.plugin === plugin) as PluginConfigConnectionType, [plugin]);
useEffect(() => {
setForm({
...form,
+ ...omit(initialValues, 'rateLimitPerHour'),
...(connection ?? {}),
});
- }, [connection]);
+ }, [initialValues, connection]);
const error = useMemo(
() => !!(fields.filter((field) => field.required) ?? []).find((field) => !form[field.key]),
@@ -68,7 +69,6 @@ export const ConnectionFormPage = () => {
required,
placeholder,
tooltip,
- initialValue,
}: PluginConfigConnectionType['connection']['fields']['0']) => {
return (
<FormGroup
@@ -90,7 +90,7 @@ export const ConnectionFormPage = () => {
{type === 'text' && (
<InputGroup
placeholder={placeholder}
- value={form[key] ?? initialValue ?? ''}
+ value={form[key] ?? ''}
onChange={(e) => setForm({ ...form, [`${key}`]: e.target.value })}
/>
)}
@@ -105,7 +105,7 @@ export const ConnectionFormPage = () => {
{type === 'switch' && (
<S.SwitchWrapper>
<Switch
- checked={form[key] ?? initialValue ?? false}
+ checked={form[key] ?? false}
onChange={(e) =>
setForm({
...form,
@@ -117,7 +117,7 @@ export const ConnectionFormPage = () => {
)}
{type === 'rateLimit' && (
<RateLimit
- initialValue={initialValue}
+ initialValue={initialValues?.['rateLimitPerHour']}
value={form.rateLimitPerHour}
onChange={(value) =>
setForm({
@@ -142,7 +142,6 @@ export const ConnectionFormPage = () => {
{type === 'gitlabToken' && (
<GitLabToken
placeholder={placeholder}
- initialValue={initialValue}
value={form.token}
onChange={(value) =>
setForm({
diff --git a/config-ui/src/plugins/register/base/connection-fields.ts b/config-ui/src/plugins/register/base/connection-fields.ts
index 8b4ce6e17..56b4701b1 100644
--- a/config-ui/src/plugins/register/base/connection-fields.ts
+++ b/config-ui/src/plugins/register/base/connection-fields.ts
@@ -89,7 +89,6 @@ export const ConnectionGitHubGraphql = () => ({
type: 'switch' as const,
tooltip:
'GraphQL APIs are 10+ times faster than REST APIs, but it may not be supported in GitHub on-premise versions.',
- initialValue: true,
});
export const ConnectionGitLabToken = () => ({
diff --git a/config-ui/src/plugins/register/bitbucket/config.ts b/config-ui/src/plugins/register/bitbucket/config.ts
index 3364aeb49..77225837c 100644
--- a/config-ui/src/plugins/register/bitbucket/config.ts
+++ b/config-ui/src/plugins/register/bitbucket/config.ts
@@ -37,13 +37,16 @@ export const BitBucketConfig: PluginConfigType = {
icon: Icon,
isBeta: true,
connection: {
+ initialValues: {
+ name: 'BitBucket',
+ endpoint: 'https://api.bitbucket.org/2.0/',
+ rateLimitPerHour: 10000,
+ },
fields: [
ConnectionName({
- initialValue: 'BitBucket',
placeholder: 'eg. BitBucket',
}),
ConnectionEndpoint({
- initialValue: 'https://api.bitbucket.org/2.0/',
placeholder: 'eg. https://api.bitbucket.org/2.0/',
}),
ConnectionUsername(),
@@ -52,9 +55,7 @@ export const BitBucketConfig: PluginConfigType = {
placeholder: 'App Password',
}),
ConnectionProxy(),
- ConnectionRatelimit({
- initialValue: 10000,
- }),
+ ConnectionRatelimit(),
],
},
entities: [],
diff --git a/config-ui/src/plugins/register/github/config.ts b/config-ui/src/plugins/register/github/config.ts
index 138248abf..bad965268 100644
--- a/config-ui/src/plugins/register/github/config.ts
+++ b/config-ui/src/plugins/register/github/config.ts
@@ -36,21 +36,23 @@ export const GitHubConfig: PluginConfigType = {
name: 'GitHub',
icon: Icon,
connection: {
+ initialValues: {
+ name: 'GitHub',
+ endpoint: 'https://api.github.com/',
+ enableGraphql: true,
+ rateLimitPerHour: 4500,
+ },
fields: [
ConnectionName({
- initialValue: 'GitHub',
placeholder: 'eg. GitHub',
}),
ConnectionEndpoint({
- initialValue: 'https://api.github.com/',
placeholder: 'eg. https://api.github.com/',
}),
ConnectionGitHubToken(),
ConnectionGitHubGraphql(),
ConnectionProxy(),
- ConnectionRatelimit({
- initialValue: 4500,
- }),
+ ConnectionRatelimit(),
],
},
entities: ['CODE', 'TICKET', 'CODEREVIEW', 'CROSS', 'CICD'],
diff --git a/config-ui/src/plugins/register/gitlab/config.ts b/config-ui/src/plugins/register/gitlab/config.ts
index ec9deebf7..728679052 100644
--- a/config-ui/src/plugins/register/gitlab/config.ts
+++ b/config-ui/src/plugins/register/gitlab/config.ts
@@ -35,20 +35,21 @@ export const GitLabConfig: PluginConfigType = {
name: 'GitLab',
icon: Icon,
connection: {
+ initialValues: {
+ name: 'GitLab',
+ endpoint: 'https://gitlab.com/api/v4/',
+ rateLimitPerHour: 5000,
+ },
fields: [
ConnectionName({
- initialValue: 'GitLab',
placeholder: 'eg. GitLab',
}),
ConnectionEndpoint({
- initialValue: 'https://gitlab.com/api/v4/',
placeholder: 'eg. https://gitlab.com/api/v4/',
}),
ConnectionGitLabToken(),
ConnectionProxy(),
- ConnectionRatelimit({
- initialValue: 5000,
- }),
+ ConnectionRatelimit(),
],
},
entities: ['CODE', 'TICKET', 'CODEREVIEW', 'CROSS', 'CICD'],
diff --git a/config-ui/src/plugins/register/jenkins/config.ts b/config-ui/src/plugins/register/jenkins/config.ts
index cf34ac356..14bb3fbcc 100644
--- a/config-ui/src/plugins/register/jenkins/config.ts
+++ b/config-ui/src/plugins/register/jenkins/config.ts
@@ -36,21 +36,22 @@ export const JenkinsConfig: PluginConfigType = {
name: 'Jenkins',
icon: Icon,
connection: {
+ initialValues: {
+ name: 'Jenkins',
+ endpoint: 'https://api.jenkins.io/',
+ rateLimitPerHour: 10000,
+ },
fields: [
ConnectionName({
- initialValue: 'Jenkins',
placeholder: 'eg. Jenkins',
}),
ConnectionEndpoint({
- initialValue: 'https://api.jenkins.io/',
placeholder: 'eg. https://api.jenkins.io/',
}),
ConnectionUsername(),
ConnectionPassword(),
ConnectionProxy(),
- ConnectionRatelimit({
- initialValue: 10000,
- }),
+ ConnectionRatelimit(),
],
},
entities: ['CICD'],
diff --git a/config-ui/src/plugins/register/jira/config.ts b/config-ui/src/plugins/register/jira/config.ts
index d56c4a100..eb6289cc4 100644
--- a/config-ui/src/plugins/register/jira/config.ts
+++ b/config-ui/src/plugins/register/jira/config.ts
@@ -36,13 +36,16 @@ export const JIRAConfig: PluginConfigType = {
name: 'JIRA',
icon: Icon,
connection: {
+ initialValues: {
+ name: 'JIRA',
+ endpoint: 'https://your-domain.atlassian.net/rest/',
+ rateLimitPerHour: 3000,
+ },
fields: [
ConnectionName({
- initialValue: 'JIRA',
placeholder: 'eg. JIRA',
}),
ConnectionEndpoint({
- initialValue: 'https://your-domain.atlassian.net/rest/',
placeholder: 'eg. https://your-domain.atlassian.net/rest/',
}),
ConnectionUsername({
@@ -52,9 +55,7 @@ export const JIRAConfig: PluginConfigType = {
tooltip: 'If you are using JIRA Cloud or JIRA Server,\nyour API Token should be used as password.',
}),
ConnectionProxy(),
- ConnectionRatelimit({
- initialValue: 3000,
- }),
+ ConnectionRatelimit(),
],
},
entities: ['TICKET', 'CROSS'],
diff --git a/config-ui/src/plugins/register/tapd/config.ts b/config-ui/src/plugins/register/tapd/config.ts
index dae2ad7c3..7dd81e831 100644
--- a/config-ui/src/plugins/register/tapd/config.ts
+++ b/config-ui/src/plugins/register/tapd/config.ts
@@ -37,21 +37,22 @@ export const TAPDConfig: PluginConfigType = {
isBeta: true,
icon: Icon,
connection: {
+ initialValues: {
+ name: 'TAPD',
+ endpoint: 'https://api.tapd.cn/',
+ rateLimitPerHour: 3000,
+ },
fields: [
ConnectionName({
- initialValue: 'TAPD',
placeholder: 'eg. TAPD',
}),
ConnectionEndpoint({
- initialValue: 'https://api.tapd.cn/',
placeholder: 'eg. https://api.tapd.cn/',
}),
ConnectionUsername(),
ConnectionPassword(),
ConnectionProxy(),
- ConnectionRatelimit({
- initialValue: 3000,
- }),
+ ConnectionRatelimit(),
],
},
entities: ['TICKET'],
diff --git a/config-ui/src/plugins/register/zentao/config.ts b/config-ui/src/plugins/register/zentao/config.ts
index 8026ad79e..692141ee8 100644
--- a/config-ui/src/plugins/register/zentao/config.ts
+++ b/config-ui/src/plugins/register/zentao/config.ts
@@ -37,21 +37,22 @@ export const ZenTaoConfig: PluginConfigType = {
isBeta: true,
icon: Icon,
connection: {
+ initialValues: {
+ name: 'ZenTao',
+ endpoint: 'https://your-domain:port/api.php/v1/',
+ rateLimitPerHour: 10000,
+ },
fields: [
ConnectionName({
- initialValue: 'ZenTao',
placeholder: 'eg. ZenTao',
}),
ConnectionEndpoint({
- initialValue: 'https://your-domain:port/api.php/v1/',
placeholder: 'eg. https://your-domain:port/api.php/v1/',
}),
ConnectionUsername(),
ConnectionPassword(),
ConnectionProxy(),
- ConnectionRatelimit({
- initialValue: 10000,
- }),
+ ConnectionRatelimit(),
],
},
entities: ['TICKET'],
diff --git a/config-ui/src/plugins/types.ts b/config-ui/src/plugins/types.ts
index d4d9c40fc..94282845c 100644
--- a/config-ui/src/plugins/types.ts
+++ b/config-ui/src/plugins/types.ts
@@ -29,6 +29,7 @@ export type PluginConfigConnectionType = {
icon: string;
isBeta?: boolean;
connection: {
+ initialValues?: Record<string, any>;
fields: Array<{
key: string;
type: 'text' | 'password' | 'switch' | 'rateLimit' | 'githubToken' | 'gitlabToken';
@@ -36,7 +37,6 @@ export type PluginConfigConnectionType = {
required?: boolean;
placeholder?: string;
tooltip?: string;
- initialValue?: any;
}>;
};
entities: string[];