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/03/28 05:53:09 UTC
[incubator-devlake] branch main updated: fix(config-ui): some bugs for new transformation (#4793)
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 369e409ca fix(config-ui): some bugs for new transformation (#4793)
369e409ca is described below
commit 369e409ca2d4c76f431a5b4830e4110ef72271e4
Author: 青湛 <0x...@gmail.com>
AuthorDate: Tue Mar 28 13:53:04 2023 +0800
fix(config-ui): some bugs for new transformation (#4793)
---
.../blueprint/connection-add/components/step-3.tsx | 6 +-
.../src/pages/blueprint/connection-add/context.tsx | 77 +++++++++++-----------
.../pages/blueprint/connection-detail/index.tsx | 3 +-
.../pages/blueprint/detail/blueprint-detail.tsx | 2 +-
.../src/plugins/components/data-scope/index.tsx | 2 +-
5 files changed, 47 insertions(+), 43 deletions(-)
diff --git a/config-ui/src/pages/blueprint/connection-add/components/step-3.tsx b/config-ui/src/pages/blueprint/connection-add/components/step-3.tsx
index 45afa12f8..d0c9aee5d 100644
--- a/config-ui/src/pages/blueprint/connection-add/components/step-3.tsx
+++ b/config-ui/src/pages/blueprint/connection-add/components/step-3.tsx
@@ -23,7 +23,7 @@ import { useConnectionAdd } from '../context';
import * as S from './styled';
export const Step3 = () => {
- const { connection, onPrev, operating, onSubmit } = useConnectionAdd();
+ const { connection, onPrev, saving, onSave } = useConnectionAdd();
if (!connection) {
return null;
@@ -33,9 +33,9 @@ export const Step3 = () => {
<S.Wrapper>
<Transformation
connections={[connection]}
- submitBtnProps={{ text: 'Save', loading: operating }}
+ submitBtnProps={{ text: 'Save', loading: saving }}
onCancel={onPrev}
- onNext={() => onSubmit(connection)}
+ onNext={onSave}
/>
</S.Wrapper>
);
diff --git a/config-ui/src/pages/blueprint/connection-add/context.tsx b/config-ui/src/pages/blueprint/connection-add/context.tsx
index 1f6e7874a..9c4ee3c45 100644
--- a/config-ui/src/pages/blueprint/connection-add/context.tsx
+++ b/config-ui/src/pages/blueprint/connection-add/context.tsx
@@ -20,7 +20,8 @@ import React, { useState, useContext } from 'react';
import { useHistory } from 'react-router-dom';
import { PageLoading } from '@/components';
-import { useRefreshData, useOperator } from '@/hooks';
+import { useRefreshData } from '@/hooks';
+import { operator } from '@/utils';
import * as API from './api';
@@ -33,9 +34,9 @@ type ContextType = {
onPrev: () => void;
onNext: () => void;
+ saving: boolean;
+ onSave: () => void;
onCancel: () => void;
- operating: boolean;
- onSubmit: (connection: MixConnection) => void;
};
export const Context = React.createContext<ContextType>({
@@ -46,9 +47,9 @@ export const Context = React.createContext<ContextType>({
onChangeConnection: () => {},
onPrev: () => {},
onNext: () => {},
+ saving: false,
+ onSave: () => {},
onCancel: () => {},
- operating: false,
- onSubmit: () => {},
});
interface Props {
@@ -60,41 +61,12 @@ interface Props {
export const ContextProvider = ({ pname, id, children }: Props) => {
const [step, setStep] = useState(1);
const [connection, setConnection] = useState<MixConnection>();
+ const [saving, setSaving] = useState(false);
const history = useHistory();
const { ready, data } = useRefreshData(() => API.getBlueprint(id), [id]);
- const { operating, onSubmit } = useOperator(
- async (connection: MixConnection) => {
- if (!connection) return;
- const { plugin, connectionId, scope } = connection;
-
- const payload = {
- ...data,
- settings: {
- ...data.settings,
- connections: [
- ...data.settings.connections,
- {
- plugin,
- connectionId,
- scopes: scope.map((sc) => ({
- id: `${sc.id}`,
- entities: sc.entities,
- })),
- },
- ],
- },
- };
-
- await API.updateBlueprint(data.id, payload);
- },
- {
- callback: () => history.push(pname ? `/projects/${pname}` : `/blueprints/${id}`),
- },
- );
-
const handlePrev = () => {
setStep(step - 1);
};
@@ -103,6 +75,37 @@ export const ContextProvider = ({ pname, id, children }: Props) => {
setStep(step + 1);
};
+ const handleSave = async () => {
+ if (!connection) return null;
+ const { plugin, connectionId, scope } = connection;
+ const payload = {
+ ...data,
+ settings: {
+ ...data.settings,
+ connections: [
+ ...data.settings.connections,
+ {
+ plugin,
+ connectionId,
+ scopes: scope.map((sc) => ({
+ id: `${sc.id}`,
+ entities: sc.entities,
+ })),
+ },
+ ],
+ },
+ };
+
+ const [success] = await operator(() => API.updateBlueprint(data.id, payload), {
+ setOperating: setSaving,
+ });
+
+ if (success) {
+ history.push(pname ? `/projects/${pname}` : `/blueprints/${id}`);
+ return;
+ }
+ };
+
const handleCancel = () => {
history.push(`/blueprints/${id}`);
};
@@ -121,9 +124,9 @@ export const ContextProvider = ({ pname, id, children }: Props) => {
onChangeConnection: setConnection,
onPrev: handlePrev,
onNext: handleNext,
+ saving,
+ onSave: handleSave,
onCancel: handleCancel,
- operating,
- onSubmit,
}}
>
{children}
diff --git a/config-ui/src/pages/blueprint/connection-detail/index.tsx b/config-ui/src/pages/blueprint/connection-detail/index.tsx
index 4e57deec4..75adb8c44 100644
--- a/config-ui/src/pages/blueprint/connection-detail/index.tsx
+++ b/config-ui/src/pages/blueprint/connection-detail/index.tsx
@@ -74,7 +74,8 @@ export const BlueprintConnectionDetailPage = () => {
const handleShowDataScope = () => setIsOpen(true);
const handleHideDataScope = () => setIsOpen(false);
- const handleChangeDataScope = async () => {
+ const handleChangeDataScope = async (connections: MixConnection[]) => {
+ const [connection] = connections;
await API.updateBlueprint(blueprint.id, {
...blueprint,
settings: {
diff --git a/config-ui/src/pages/blueprint/detail/blueprint-detail.tsx b/config-ui/src/pages/blueprint/detail/blueprint-detail.tsx
index c3cc981d9..fc11c8d2b 100644
--- a/config-ui/src/pages/blueprint/detail/blueprint-detail.tsx
+++ b/config-ui/src/pages/blueprint/detail/blueprint-detail.tsx
@@ -42,7 +42,7 @@ export const BlueprintDetail = ({ from = FromEnum.project, pname, id }: Props) =
() =>
from === FromEnum.project
? [`/projects/${pname}/${id}/connection-add`, `/projects/${pname}/${id}/`]
- : [`/blueprints/${id}/connection-add`, `blueprints/${id}/`],
+ : [`/blueprints/${id}/connection-add`, `/blueprints/${id}/`],
[from, pname],
);
diff --git a/config-ui/src/plugins/components/data-scope/index.tsx b/config-ui/src/plugins/components/data-scope/index.tsx
index c7a76a2ce..3722cd221 100644
--- a/config-ui/src/plugins/components/data-scope/index.tsx
+++ b/config-ui/src/plugins/components/data-scope/index.tsx
@@ -85,9 +85,9 @@ export const DataScope = ({
onSubmit={(scope: MixConnection['scope'], origin: MixConnection['origin']) => {
onSubmit?.([
{
+ ...props,
plugin,
connectionId,
- ...props,
scope,
origin,
},