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 2585a607c refactor(config-ui): the create blueprint page (#3925)
2585a607c is described below
commit 2585a607cbbec3ac118d8f13678f79c46297652e
Author: 青湛 <[email protected]>
AuthorDate: Wed Dec 14 13:00:20 2022 +0800
refactor(config-ui): the create blueprint page (#3925)
* refactor(config-ui): remove data-scope-selector from plugin common
* refactor(config-ui): remove rule-selector from plugin common
* refactor(config-ui): adjust the style for dialog
* refactor(config-ui): adjust the style for table
* refactor(config-ui): adjust the style for base-layout
* refactor(config-ui): the data scope in plugins
* refactor(config-ui): the transformation in plugins
* refactor(config-ui): adjust the style for github plugin
* feat(config-ui): add sync policy in plugin common
* refactor(config-ui): the create blueprint page
* fix(config-ui): missed StoreContextProvider in App
* refactor(config-ui): add global style for blueprintjs
---
config-ui/src/components/dialog/index.tsx | 40 ++--
config-ui/src/components/dialog/styled.ts | 3 -
config-ui/src/components/table/table.tsx | 64 +++---
config-ui/src/config/cron.ts | 87 +++++++
.../blueprint/create/hooks => config}/index.ts | 4 +-
config-ui/src/index.css | 4 +
config-ui/src/index.js | 13 +-
config-ui/src/layouts/base/styled.ts | 2 +-
config-ui/src/pages/blueprint/create/api.ts | 15 +-
.../src/pages/blueprint/create/bp-context.tsx | 249 +++++++++++++++++++++
.../blueprint/create/components/action/index.tsx | 4 +-
.../create/components/inspector/index.tsx | 6 +-
.../blueprint/create/components/workflow/index.tsx | 4 +-
.../blueprint/create/hooks/blueprint-context.ts | 94 --------
.../blueprint/create/hooks/use-blueprint-value.ts | 198 ----------------
config-ui/src/pages/blueprint/create/index.tsx | 50 ++---
.../src/pages/blueprint/create/step-four/index.tsx | 177 ++-------------
.../src/pages/blueprint/create/step-one/index.tsx | 73 +++---
.../src/pages/blueprint/create/step-one/styled.ts | 2 -
.../pages/blueprint/create/step-three/index.tsx | 213 ++++--------------
.../pages/blueprint/create/step-three/styled.ts | 2 -
.../create/step-three/use-transformation.ts | 64 ------
.../src/pages/blueprint/create/step-two/index.tsx | 60 +++--
.../src/pages/blueprint/create/step-two/styled.ts | 2 -
config-ui/src/pages/blueprint/create/styled.ts | 53 +----
config-ui/src/pages/blueprint/create/types.ts | 40 +++-
config-ui/src/pages/project/home/index.tsx | 10 +-
config-ui/src/pages/project/home/styled.ts | 18 +-
.../src/plugins/common/data-scope-selector/api.ts | 27 ---
.../plugins/common/data-scope-selector/index.tsx | 48 ----
.../data-scope-selector/use-data-scope-selector.ts | 81 -------
config-ui/src/plugins/common/data-scope/index.tsx | 45 ++--
.../{github => common/data-scope}/styled.ts | 28 +--
.../plugins/common/data-scope/use-data-scope.ts | 48 ++--
config-ui/src/plugins/common/index.ts | 3 +-
config-ui/src/plugins/common/rule-selector/api.ts | 32 ---
.../src/plugins/common/rule-selector/index.tsx | 43 ----
.../src/plugins/common/rule-selector/use-rule.ts | 57 -----
.../common/sync-policy}/index.tsx | 135 +++++------
.../common/sync-policy}/styled.ts | 15 +-
config-ui/src/plugins/common/transformation/api.ts | 28 +++
.../src/plugins/common/transformation/index.tsx | 238 +++++++++++++++-----
.../src/plugins/common/transformation/styled.ts | 50 +++--
.../common/transformation/types.ts} | 13 +-
.../common/transformation/use-transformation.ts | 120 ++++++++--
config-ui/src/plugins/github/data-scope.tsx | 2 +-
config-ui/src/plugins/github/transformation.tsx | 6 +-
config-ui/src/plugins/webook/connection/index.tsx | 4 +-
config-ui/src/plugins/webook/connection/styled.ts | 12 +-
49 files changed, 1120 insertions(+), 1466 deletions(-)
diff --git a/config-ui/src/components/dialog/index.tsx
b/config-ui/src/components/dialog/index.tsx
index 0ae8570eb..b0c50c348 100644
--- a/config-ui/src/components/dialog/index.tsx
+++ b/config-ui/src/components/dialog/index.tsx
@@ -26,6 +26,7 @@ interface Props {
children: React.ReactNode
style?: React.CSSProperties
title?: string
+ footer?: React.ReactNode | null
cancelText?: string
okText?: string
okDisabled?: boolean
@@ -39,6 +40,7 @@ export const Dialog = ({
children,
style,
title,
+ footer,
cancelText = 'Cancel',
okText = 'OK',
okDisabled,
@@ -55,23 +57,27 @@ export const Dialog = ({
</S.Header>
)}
<S.Body className={Classes.DIALOG_BODY}>{children}</S.Body>
- <S.Footer className={Classes.DIALOG_FOOTER}>
- <div className={Classes.DIALOG_FOOTER_ACTIONS}>
- <Button
- outlined
- intent={Intent.PRIMARY}
- onClick={onCancel}
- text={cancelText}
- />
- <Button
- disabled={okDisabled}
- loading={okLoading}
- intent={Intent.PRIMARY}
- text={okText}
- onClick={onOk}
- />
- </div>
- </S.Footer>
+ {footer ? (
+ footer
+ ) : footer !== null ? (
+ <S.Footer className={Classes.DIALOG_FOOTER}>
+ <div className={Classes.DIALOG_FOOTER_ACTIONS}>
+ <Button
+ outlined
+ intent={Intent.PRIMARY}
+ onClick={onCancel}
+ text={cancelText}
+ />
+ <Button
+ disabled={okDisabled}
+ loading={okLoading}
+ intent={Intent.PRIMARY}
+ text={okText}
+ onClick={onOk}
+ />
+ </div>
+ </S.Footer>
+ ) : null}
</S.Container>
)
}
diff --git a/config-ui/src/components/dialog/styled.ts
b/config-ui/src/components/dialog/styled.ts
index 3e731ec09..66d1fa9b0 100644
--- a/config-ui/src/components/dialog/styled.ts
+++ b/config-ui/src/components/dialog/styled.ts
@@ -21,9 +21,6 @@ import { Dialog } from '@blueprintjs/core'
export const Container = styled(Dialog)`
position: relative;
- top: -200px;
- left: 90px;
- width: 820px;
background-color: #fff;
`
diff --git a/config-ui/src/components/table/table.tsx
b/config-ui/src/components/table/table.tsx
index 22563d1f1..017a9f1d5 100644
--- a/config-ui/src/components/table/table.tsx
+++ b/config-ui/src/components/table/table.tsx
@@ -18,7 +18,7 @@
import React from 'react'
-import { Loading } from '@/components'
+import { Loading, Card } from '@/components'
import { ColumnType } from './types'
import * as S from './styled'
@@ -35,36 +35,38 @@ export const Table = <T extends Record<string, any>>({
dataSource
}: Props<T>) => {
return (
- <S.Container>
- <S.TableWrapper loading={loading ? 1 : 0}>
- <S.TableHeader>
- {columns.map(({ key, title }) => (
- <span key={key}>{title}</span>
+ <Card style={{ padding: 0 }}>
+ <S.Container>
+ <S.TableWrapper loading={loading ? 1 : 0}>
+ <S.TableHeader>
+ {columns.map(({ key, title }) => (
+ <span key={key}>{title}</span>
+ ))}
+ </S.TableHeader>
+ {dataSource.map((data, i) => (
+ <S.TableRow key={i}>
+ {columns.map(({ key, align = 'left', dataIndex, render }) => {
+ const value = Array.isArray(dataIndex)
+ ? dataIndex.reduce((acc, cur) => {
+ acc[cur] = data[cur]
+ return acc
+ }, {} as any)
+ : data[dataIndex]
+ return (
+ <span key={key} style={{ textAlign: align }}>
+ {render ? render(value, data) : value}
+ </span>
+ )
+ })}
+ </S.TableRow>
))}
- </S.TableHeader>
- {dataSource.map((data, i) => (
- <S.TableRow key={i}>
- {columns.map(({ key, align = 'left', dataIndex, render }) => {
- const value = Array.isArray(dataIndex)
- ? dataIndex.reduce((acc, cur) => {
- acc[cur] = data[cur]
- return acc
- }, {} as any)
- : data[dataIndex]
- return (
- <span key={key} style={{ textAlign: align }}>
- {render ? render(value, data) : value}
- </span>
- )
- })}
- </S.TableRow>
- ))}
- </S.TableWrapper>
- {loading && (
- <S.TableMask>
- <Loading />
- </S.TableMask>
- )}
- </S.Container>
+ </S.TableWrapper>
+ {loading && (
+ <S.TableMask>
+ <Loading />
+ </S.TableMask>
+ )}
+ </S.Container>
+ </Card>
)
}
diff --git a/config-ui/src/config/cron.ts b/config-ui/src/config/cron.ts
new file mode 100644
index 000000000..bb396ca72
--- /dev/null
+++ b/config-ui/src/config/cron.ts
@@ -0,0 +1,87 @@
+/*
+ * 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.
+ *
+ */
+
+export const cronPresets = [
+ {
+ label: 'Hourly',
+ config: '59 * * * *',
+ description: 'At minute 59 on every day-of-week from Monday through
Sunday.'
+ },
+ {
+ label: 'Daily',
+ config: '0 0 * * *',
+ description:
+ 'At 00:00 (Midnight) on every day-of-week from Monday through Sunday.'
+ },
+ {
+ label: 'Weekly',
+ config: '0 0 * * 1',
+ description: 'At 00:00 (Midnight) on Monday.'
+ },
+ {
+ label: 'Monthly',
+ config: '0 0 1 * *',
+ description: 'At 00:00 (Midnight) on day-of-month 1.'
+ }
+]
+
+export const getCron = (isManual: boolean, config: string) => {
+ if (isManual) {
+ return {
+ label: 'Manual',
+ value: 'manual',
+ description: 'Manual',
+ config: ''
+ }
+ }
+
+ const preset = cronPresets.find((preset) => preset.config === config)
+
+ return preset
+ ? {
+ ...preset,
+ value: preset.config
+ }
+ : {
+ label: 'Custom',
+ value: 'custom',
+ description: 'Custom',
+ config
+ }
+}
+
+export const getCronOptions = () => {
+ return [
+ {
+ label: 'Manual',
+ value: 'manual'
+ }
+ ]
+ .concat(
+ cronPresets.map((cp) => ({
+ label: cp.label,
+ value: cp.config
+ }))
+ )
+ .concat([
+ {
+ label: 'Custom',
+ value: 'custom'
+ }
+ ])
+}
diff --git a/config-ui/src/pages/blueprint/create/hooks/index.ts
b/config-ui/src/config/index.ts
similarity index 88%
rename from config-ui/src/pages/blueprint/create/hooks/index.ts
rename to config-ui/src/config/index.ts
index d8f1fc9e1..87a9b1d49 100644
--- a/config-ui/src/pages/blueprint/create/hooks/index.ts
+++ b/config-ui/src/config/index.ts
@@ -16,6 +16,4 @@
*
*/
-export * from './blueprint-context'
-export * from './use-blueprint-value'
-export * from './use-blueprint'
+export * from './cron'
diff --git a/config-ui/src/index.css b/config-ui/src/index.css
index fb1a71a35..aed437a07 100644
--- a/config-ui/src/index.css
+++ b/config-ui/src/index.css
@@ -22,3 +22,7 @@
@import '~@blueprintjs/select/lib/css/blueprint-select.css';
@import '~@blueprintjs/popover2/lib/css/blueprint-popover2.css';
@import '~@blueprintjs/datetime/lib/css/blueprint-datetime.css';
+
+.bp4-button + .bp4-button {
+ margin-left: 8px;
+}
diff --git a/config-ui/src/index.js b/config-ui/src/index.js
index 93b76d0be..308ec6359 100644
--- a/config-ui/src/index.js
+++ b/config-ui/src/index.js
@@ -21,6 +21,7 @@ import ReactDOM from 'react-dom'
import { BrowserRouter as Router } from 'react-router-dom'
import { ErrorBoundary } from '@/components'
+import { StoreContextProvider } from '@/store'
import App from './App'
import { UIContextProvider } from '@/store/UIContext'
@@ -31,11 +32,13 @@ import './index.css'
ReactDOM.render(
<UIContextProvider>
<IntegrationsContextProvider>
- <ErrorBoundary>
- <Router>
- <App />
- </Router>
- </ErrorBoundary>
+ <StoreContextProvider>
+ <ErrorBoundary>
+ <Router>
+ <App />
+ </Router>
+ </ErrorBoundary>
+ </StoreContextProvider>
</IntegrationsContextProvider>
</UIContextProvider>,
document.getElementById('app')
diff --git a/config-ui/src/layouts/base/styled.ts
b/config-ui/src/layouts/base/styled.ts
index 8b0a3e954..c408cae85 100644
--- a/config-ui/src/layouts/base/styled.ts
+++ b/config-ui/src/layouts/base/styled.ts
@@ -96,7 +96,7 @@ export const Header = styled(Navbar)`
export const Content = styled.div`
flex: auto;
- margin: 24px auto 0;
+ margin: 24px auto;
max-width: 900px;
width: 100%;
`
diff --git a/config-ui/src/pages/blueprint/create/api.ts
b/config-ui/src/pages/blueprint/create/api.ts
index 621e4b096..659358d15 100644
--- a/config-ui/src/pages/blueprint/create/api.ts
+++ b/config-ui/src/pages/blueprint/create/api.ts
@@ -18,18 +18,13 @@
import request from '@/components/utils/request'
-export const updateDataScope = (
- plugin: string,
- connectionId: ID,
- payload: any
-) =>
- request(`/plugins/${plugin}/connections/${connectionId}/scopes`, {
- method: 'put',
- data: payload
- })
-
export const createBlueprint = (payload: any) =>
request('/blueprints', {
method: 'post',
data: payload
})
+
+export const runBlueprint = (id: ID) =>
+ request(`/blueprints/${id}/trigger`, {
+ method: 'post'
+ })
diff --git a/config-ui/src/pages/blueprint/create/bp-context.tsx
b/config-ui/src/pages/blueprint/create/bp-context.tsx
new file mode 100644
index 000000000..92a6a646b
--- /dev/null
+++ b/config-ui/src/pages/blueprint/create/bp-context.tsx
@@ -0,0 +1,249 @@
+/*
+ * 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 React, { useState, useMemo, useContext } from 'react'
+import { useHistory } from 'react-router-dom'
+
+import type { ConnectionItemType } from '@/store'
+import { useStore, ConnectionStatusEnum } from '@/store'
+import { operator } from '@/utils'
+
+import type { BPContextType } from './types'
+import { FromEnum, ModeEnum } from './types'
+import * as API from './api'
+
+export const BPContext = React.createContext<BPContextType>({
+ step: 1,
+ error: '',
+ showInspector: false,
+ showDetail: false,
+ payload: {},
+
+ name: 'MY BLUEPRINT',
+ mode: ModeEnum.normal,
+ rawPlan: JSON.stringify([[]], null, ' '),
+ uniqueList: [],
+ scopeMap: {},
+ cronConfig: '0 0 * * *',
+ isManual: false,
+ skipOnFail: false,
+ createdDateAfter: null,
+
+ onChangeStep: () => {},
+ onChangeShowInspector: () => {},
+ onChangeShowDetail: () => {},
+
+ onChangeMode: () => {},
+ onChangeName: () => {},
+ onChangeRawPlan: () => {},
+ onChangeUniqueList: () => {},
+ onChangeScopeMap: () => {},
+ onChangeCronConfig: () => {},
+ onChangeIsManual: () => {},
+ onChangeSkipOnFail: () => {},
+ onChangeCreatedDateAfter: () => {},
+
+ onSave: () => {},
+ onSaveAndRun: () => {}
+})
+
+interface Props {
+ from: FromEnum
+ projectName: string
+ children: React.ReactNode
+}
+
+export const BPContextProvider = ({ from, projectName, children }: Props) => {
+ const [step, setStep] = useState(1)
+ const [showInspector, setShowInspector] = useState(false)
+ const [showDetail, setShowDetail] = useState(false)
+
+ const [name, setName] = useState(
+ from === FromEnum.project ? `${projectName}-BLUEPRINT` : 'MY BLUEPRINT'
+ )
+ const [mode, setMode] = useState<ModeEnum>(ModeEnum.normal)
+ const [rawPlan, setRawPlan] = useState(JSON.stringify([[]], null, ' '))
+ const [uniqueList, setUniqueList] = useState<string[]>([])
+ const [scopeMap, setScopeMap] = useState<Record<string, any>>({})
+ const [cronConfig, setCronConfig] = useState('0 0 * * *')
+ const [isManual, setIsManual] = useState(false)
+ const [skipOnFail, setSkipOnFail] = useState(false)
+ const [createdDateAfter, setCreatedDateAfter] = useState<string | null>(null)
+
+ const history = useHistory()
+
+ const { connections } = useStore()
+
+ const validRawPlan = (rp: string) => {
+ try {
+ const p = JSON.parse(rp)
+ if (p.flat().length === 0) {
+ return true
+ }
+ return false
+ } catch {
+ return true
+ }
+ }
+
+ const error = useMemo(() => {
+ switch (true) {
+ case !name:
+ return 'Blueprint Name: Enter a valid Name'
+ case name.length < 3:
+ return 'Blueprint Name: Name too short, 3 chars minimum.'
+ case mode === ModeEnum.advanced && validRawPlan(rawPlan):
+ return 'Advanced Mode: Invalid/Empty Configuration'
+ case mode === ModeEnum.normal && !uniqueList.length:
+ return 'Normal Mode: No Data Connections selected.'
+ case mode === ModeEnum.normal &&
+ !connections
+ .filter((cs) => uniqueList.includes(cs.unique))
+ .every((cs) => cs.status === ConnectionStatusEnum.ONLINE):
+ return 'Normal Mode: Has some offline connections'
+ case step === 2 && Object.keys(scopeMap).length !== uniqueList.length:
+ return 'No Data Scope is Selected'
+ default:
+ return ''
+ }
+ }, [name, mode, rawPlan, uniqueList, connections, step, scopeMap])
+
+ const payload = useMemo(() => {
+ const params: any = {
+ name,
+ projectName,
+ mode,
+ enable: true,
+ cronConfig,
+ isManual,
+ skipOnFail,
+ createdDateAfter
+ }
+
+ if (mode === ModeEnum.normal) {
+ params.settings = {
+ version: '2.0.0',
+ connections: uniqueList.map((unique) => {
+ const connection = connections.find(
+ (cs) => cs.unique === unique
+ ) as ConnectionItemType
+ const scope = scopeMap[unique] ?? []
+ return {
+ plugin: connection.plugin,
+ connectionId: connection.id,
+ scope: scope.map((sc: any) => ({
+ id: `${sc.id}`,
+ entities: sc.entities
+ }))
+ }
+ })
+ }
+ }
+
+ if (mode === ModeEnum.advanced) {
+ params.plan = validRawPlan(rawPlan) ? JSON.parse(rawPlan) : [[]]
+ }
+
+ return params
+ }, [
+ name,
+ projectName,
+ mode,
+ cronConfig,
+ isManual,
+ skipOnFail,
+ createdDateAfter,
+ rawPlan,
+ uniqueList,
+ scopeMap,
+ connections
+ ])
+
+ const handleSaveAfter = (id: ID) => {
+ const path =
+ from === FromEnum.blueprint
+ ? `/blueprints/${id}`
+ : `/projects/${projectName}`
+
+ history.push(path)
+ }
+
+ const handleSave = async () => {
+ const [success, res] = await operator(() => API.createBlueprint(payload))
+
+ if (success) {
+ handleSaveAfter(res.id)
+ }
+ }
+
+ const hanldeSaveAndRun = async () => {
+ const [success, res] = await operator(async () => {
+ const res = await API.createBlueprint(payload)
+ return await API.runBlueprint(res.id)
+ })
+
+ if (success) {
+ handleSaveAfter(res.id)
+ }
+ }
+
+ return (
+ <BPContext.Provider
+ value={{
+ step,
+ error,
+ showInspector,
+ showDetail,
+ payload,
+
+ name,
+ mode,
+ rawPlan,
+ uniqueList,
+ scopeMap,
+ cronConfig,
+ isManual,
+ skipOnFail,
+ createdDateAfter,
+
+ onChangeStep: setStep,
+ onChangeShowInspector: setShowInspector,
+ onChangeShowDetail: setShowDetail,
+
+ onChangeName: setName,
+ onChangeMode: setMode,
+ onChangeRawPlan: setRawPlan,
+ onChangeUniqueList: setUniqueList,
+ onChangeScopeMap: setScopeMap,
+ onChangeCronConfig: setCronConfig,
+ onChangeIsManual: setIsManual,
+ onChangeSkipOnFail: setSkipOnFail,
+ onChangeCreatedDateAfter: setCreatedDateAfter,
+
+ onSave: handleSave,
+ onSaveAndRun: hanldeSaveAndRun
+ }}
+ >
+ {children}
+ </BPContext.Provider>
+ )
+}
+
+export const useCreateBP = () => {
+ return useContext(BPContext)
+}
diff --git a/config-ui/src/pages/blueprint/create/components/action/index.tsx
b/config-ui/src/pages/blueprint/create/components/action/index.tsx
index 56833ccbe..390d58c90 100644
--- a/config-ui/src/pages/blueprint/create/components/action/index.tsx
+++ b/config-ui/src/pages/blueprint/create/components/action/index.tsx
@@ -28,7 +28,7 @@ import {
import { Popover2 } from '@blueprintjs/popover2'
import { ModeEnum } from '../../types'
-import { useBlueprint } from '../../hooks'
+import { useCreateBP } from '../../bp-context'
import * as S from './styled'
@@ -42,7 +42,7 @@ export const Action = () => {
onChangeShowInspector,
onSave,
onSaveAndRun
- } = useBlueprint()
+ } = useCreateBP()
const [isFirst, isLast] = useMemo(() => {
return [
diff --git
a/config-ui/src/pages/blueprint/create/components/inspector/index.tsx
b/config-ui/src/pages/blueprint/create/components/inspector/index.tsx
index 757713acd..6b16ea6ba 100644
--- a/config-ui/src/pages/blueprint/create/components/inspector/index.tsx
+++ b/config-ui/src/pages/blueprint/create/components/inspector/index.tsx
@@ -16,15 +16,15 @@
*
*/
-import React, { useMemo } from 'react'
+import React from 'react'
import { Drawer, DrawerSize, Classes, IconName } from '@blueprintjs/core'
-import { useBlueprint } from '../../hooks'
+import { useCreateBP } from '../../bp-context'
import * as S from './styled'
export const Inspector = () => {
- const { name, payload, showInspector, onChangeShowInspector } =
useBlueprint()
+ const { name, payload, showInspector, onChangeShowInspector } = useCreateBP()
const props = {
icon: 'code' as IconName,
diff --git a/config-ui/src/pages/blueprint/create/components/workflow/index.tsx
b/config-ui/src/pages/blueprint/create/components/workflow/index.tsx
index 0767cc72b..2d6eead51 100644
--- a/config-ui/src/pages/blueprint/create/components/workflow/index.tsx
+++ b/config-ui/src/pages/blueprint/create/components/workflow/index.tsx
@@ -19,12 +19,12 @@
import React, { useMemo } from 'react'
import { ModeEnum } from '../../types'
-import { useBlueprint } from '../../hooks'
+import { useCreateBP } from '../../bp-context'
import * as S from './styled'
export const WorkFlow = () => {
- const { step, mode } = useBlueprint()
+ const { step, mode } = useCreateBP()
const steps = useMemo(
() =>
diff --git a/config-ui/src/pages/blueprint/create/hooks/blueprint-context.ts
b/config-ui/src/pages/blueprint/create/hooks/blueprint-context.ts
deleted file mode 100644
index 43654cbe2..000000000
--- a/config-ui/src/pages/blueprint/create/hooks/blueprint-context.ts
+++ /dev/null
@@ -1,94 +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 React from 'react'
-
-import type { BPConnectionItemType, BPScopeItemType } from '../types'
-import { ModeEnum } from '../types'
-
-export type BlueprintContextType = {
- step: number
- error: string
- showInspector: boolean
- showDetail: boolean
- payload: any
-
- name: string
- mode: ModeEnum
- rawPlan: string
- connections: BPConnectionItemType[]
- scope: BPScopeItemType[]
- cronConfig: string
- isManual: boolean
- skipOnFail: boolean
- createdDateAfter: string | null
-
- onChangeStep: React.Dispatch<React.SetStateAction<number>>
- onChangeShowInspector: React.Dispatch<React.SetStateAction<boolean>>
- onChangeShowDetail: React.Dispatch<React.SetStateAction<boolean>>
-
- onChangeName: React.Dispatch<React.SetStateAction<string>>
- onChangeMode: (mode: ModeEnum) => void
- onChangeRawPlan: React.Dispatch<React.SetStateAction<string>>
- onChangeConnections: React.Dispatch<
- React.SetStateAction<BPConnectionItemType[]>
- >
- onChangeScope: React.Dispatch<React.SetStateAction<BPScopeItemType[]>>
- onChangeCronConfig: React.Dispatch<React.SetStateAction<string>>
- onChangeIsManual: React.Dispatch<React.SetStateAction<boolean>>
- onChangeSkipOnFail: React.Dispatch<React.SetStateAction<boolean>>
- onChangeCreatedDateAfter: React.Dispatch<React.SetStateAction<string | null>>
-
- onSave: () => void
- onSaveAndRun: () => void
-}
-
-export const BlueprintContext = React.createContext<BlueprintContextType>({
- step: 1,
- error: '',
- showInspector: false,
- showDetail: false,
- payload: {},
-
- name: 'MY BLUEPRINT',
- mode: ModeEnum.normal,
- rawPlan: JSON.stringify([[]], null, ' '),
- connections: [],
- scope: [],
- cronConfig: '0 0 * * *',
- isManual: false,
- skipOnFail: false,
- createdDateAfter: null,
-
- onChangeStep: () => {},
- onChangeShowInspector: () => {},
- onChangeShowDetail: () => {},
-
- onChangeMode: () => {},
- onChangeName: () => {},
- onChangeRawPlan: () => {},
- onChangeConnections: () => {},
- onChangeScope: () => {},
- onChangeCronConfig: () => {},
- onChangeIsManual: () => {},
- onChangeSkipOnFail: () => {},
- onChangeCreatedDateAfter: () => {},
-
- onSave: () => {},
- onSaveAndRun: () => {}
-})
diff --git a/config-ui/src/pages/blueprint/create/hooks/use-blueprint-value.ts
b/config-ui/src/pages/blueprint/create/hooks/use-blueprint-value.ts
deleted file mode 100644
index 0e4f9e9ff..000000000
--- a/config-ui/src/pages/blueprint/create/hooks/use-blueprint-value.ts
+++ /dev/null
@@ -1,198 +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 { useHistory } from 'react-router-dom'
-
-import { useStore, ConnectionStatusEnum } from '@/store'
-import { operator } from '@/utils'
-
-import type { BPConnectionItemType, BPScopeItemType } from '../types'
-import { FromEnum, ModeEnum } from '../types'
-import * as API from '../api'
-
-interface Props {
- from: FromEnum
- projectName: string
-}
-
-export const useBlueprintValue = ({ from, projectName }: Props) => {
- const [step, setStep] = useState(1)
- const [showInspector, setShowInspector] = useState(false)
- const [showDetail, setShowDetail] = useState(false)
-
- const [name, setName] = useState(
- from === FromEnum.project ? `${projectName}-BLUEPRINT` : 'MY BLUEPRINT'
- )
- const [mode, setMode] = useState<ModeEnum>(ModeEnum.normal)
- const [rawPlan, setRawPlan] = useState(JSON.stringify([[]], null, ' '))
- const [connections, setConnections] = useState<BPConnectionItemType[]>([])
- const [scope, setScope] = useState<BPScopeItemType[]>([])
- const [cronConfig, setCronConfig] = useState('0 0 * * *')
- const [isManual, setIsManual] = useState(false)
- const [skipOnFail, setSkipOnFail] = useState(false)
- const [createdDateAfter, setCreatedDateAfter] = useState<string | null>(null)
-
- const history = useHistory()
-
- const store = useStore()
-
- const validRawPlan = (rp: string) => {
- try {
- const p = JSON.parse(rp)
- if (p.flat().length === 0) {
- return true
- }
- return false
- } catch {
- return true
- }
- }
-
- const error = useMemo(() => {
- switch (true) {
- case !name:
- return 'Blueprint Name: Enter a valid Name'
- case name.length < 3:
- return 'Blueprint Name: Name too short, 3 chars minimum.'
- case mode === ModeEnum.advanced && validRawPlan(rawPlan):
- return 'Advanced Mode: Invalid/Empty Configuration'
- case mode === ModeEnum.normal && !connections.length:
- return 'Normal Mode: No Data Connections selected.'
- case mode === ModeEnum.normal &&
- !store.connections
- .filter((cs) =>
- connections.map((it) => it.unique).includes(cs.unique)
- )
- .every((cs) => cs.status === ConnectionStatusEnum.ONLINE):
- return 'Normal Mode: Has some offline connections'
- case step === 2 && !connections.every((cs) => cs.scope.length):
- return 'No Data Scope is Selected'
- default:
- return ''
- }
- }, [name, mode, rawPlan, connections, step, store])
-
- const payload = useMemo(() => {
- const params: any = {
- name,
- projectName,
- mode,
- enable: true,
- cronConfig,
- isManual,
- skipOnFail,
- createdDateAfter
- }
-
- if (mode === ModeEnum.normal) {
- params.settings = {
- version: '2.0.0',
- connections: connections.map((cs) => ({
- plugin: cs.plugin,
- connectionId: cs.id,
- scopes: cs.scope.map((sc) => ({
- ...sc,
- id: `${sc.id}`
- }))
- }))
- }
- }
-
- if (mode === ModeEnum.advanced) {
- params.plan = validRawPlan(rawPlan) ? JSON.parse(rawPlan) : [[]]
- }
-
- return params
- }, [
- name,
- projectName,
- mode,
- rawPlan,
- cronConfig,
- isManual,
- skipOnFail,
- createdDateAfter,
- connections,
- scope
- ])
-
- const handleSave = async () => {
- const [success] = await operator(() => API.createBlueprint(payload))
- const path =
- from === FromEnum.blueprint ? '/blueprints' : `/projects/${projectName}`
- if (success) {
- history.push(path)
- }
- }
-
- const hanldeSaveAndRun = () => {}
-
- return useMemo(
- () => ({
- step,
- error,
- showInspector,
- showDetail,
- payload,
-
- name,
- mode,
- rawPlan,
- connections,
- scope,
- cronConfig,
- isManual,
- skipOnFail,
- createdDateAfter,
-
- onChangeStep: setStep,
- onChangeShowInspector: setShowInspector,
- onChangeShowDetail: setShowDetail,
-
- onChangeName: setName,
- onChangeMode: setMode,
- onChangeRawPlan: setRawPlan,
- onChangeConnections: setConnections,
- onChangeScope: setScope,
- onChangeCronConfig: setCronConfig,
- onChangeIsManual: setIsManual,
- onChangeSkipOnFail: setSkipOnFail,
- onChangeCreatedDateAfter: setCreatedDateAfter,
-
- onSave: handleSave,
- onSaveAndRun: hanldeSaveAndRun
- }),
- [
- step,
- error,
- connections,
- showInspector,
- showDetail,
- name,
- mode,
- rawPlan,
- connections,
- scope,
- cronConfig,
- isManual,
- skipOnFail,
- createdDateAfter
- ]
- )
-}
diff --git a/config-ui/src/pages/blueprint/create/index.tsx
b/config-ui/src/pages/blueprint/create/index.tsx
index 5383383e9..07d7461dd 100644
--- a/config-ui/src/pages/blueprint/create/index.tsx
+++ b/config-ui/src/pages/blueprint/create/index.tsx
@@ -21,8 +21,7 @@ import { useParams } from 'react-router-dom'
import { PageHeader } from '@/components'
-import { useBlueprintValue } from './hooks/use-blueprint-value'
-import { BlueprintContext } from './hooks/blueprint-context'
+import { BPContext, BPContextProvider } from './bp-context'
import { FromEnum, ModeEnum } from './types'
import { WorkFlow, Action, Inspector } from './components'
@@ -39,11 +38,6 @@ interface Props {
export const CreateBlueprintPage = ({ from }: Props) => {
const { pname } = useParams<{ pname: string }>()
- const { step, mode, ...props } = useBlueprintValue({
- from,
- projectName: pname
- })
-
const breadcrumbs = useMemo(
() =>
from === FromEnum.project
@@ -63,27 +57,25 @@ export const CreateBlueprintPage = ({ from }: Props) => {
)
return (
- <BlueprintContext.Provider
- value={{
- step,
- mode,
- ...props
- }}
- >
- <PageHeader breadcrumbs={breadcrumbs}>
- <S.Container>
- <WorkFlow />
- <S.Content>
- {step === 1 && <StepOne />}
- {mode === ModeEnum.normal && step === 2 && <StepTwo />}
- {step === 3 && <StepThree />}
- {((mode === ModeEnum.normal && step === 4) ||
- (mode === ModeEnum.advanced && step === 2)) && <StepFour />}
- </S.Content>
- <Action />
- <Inspector />
- </S.Container>
- </PageHeader>
- </BlueprintContext.Provider>
+ <BPContextProvider from={from} projectName={pname}>
+ <BPContext.Consumer>
+ {({ step, mode }) => (
+ <PageHeader breadcrumbs={breadcrumbs}>
+ <S.Container>
+ <WorkFlow />
+ <S.Content>
+ {step === 1 && <StepOne />}
+ {mode === ModeEnum.normal && step === 2 && <StepTwo />}
+ {step === 3 && <StepThree />}
+ {((mode === ModeEnum.normal && step === 4) ||
+ (mode === ModeEnum.advanced && step === 2)) && <StepFour />}
+ </S.Content>
+ <Action />
+ <Inspector />
+ </S.Container>
+ </PageHeader>
+ )}
+ </BPContext.Consumer>
+ </BPContextProvider>
)
}
diff --git a/config-ui/src/pages/blueprint/create/step-four/index.tsx
b/config-ui/src/pages/blueprint/create/step-four/index.tsx
index cd3c42c1a..4d7a5a116 100644
--- a/config-ui/src/pages/blueprint/create/step-four/index.tsx
+++ b/config-ui/src/pages/blueprint/create/step-four/index.tsx
@@ -16,178 +16,39 @@
*
*/
-import React, { useState, useEffect, useMemo } from 'react'
-import {
- RadioGroup,
- Radio,
- Checkbox,
- InputGroup,
- Icon,
- Position
-} from '@blueprintjs/core'
-import { Popover2 } from '@blueprintjs/popover2'
+import React from 'react'
-import { Divider } from '@/components'
-import CronHelp from '@/images/cron-help.png'
+import { SyncPolicy } from '@/plugins'
+import { Card, Divider } from '@/components'
-import { useBlueprint } from '../hooks'
-
-import * as S from './styled'
-import StartFromSelector from "@/components/blueprints/StartFromSelector";
-
-const cronPresets = [
- {
- label: 'Hourly',
- config: '59 * * * *',
- desc: 'At minute 59 on every day-of-week from Monday through Sunday.'
- },
- {
- label: 'Daily',
- config: '0 0 * * *',
- desc: 'At 00:00 (Midnight) on every day-of-week from Monday through
Sunday.'
- },
- {
- label: 'Weekly',
- config: '0 0 * * 1',
- desc: 'At 00:00 (Midnight) on Monday.'
- },
- {
- label: 'Monthly',
- config: '0 0 1 * *',
- desc: 'At 00:00 (Midnight) on day-of-month 1.'
- }
-]
+import { useCreateBP } from '../bp-context'
export const StepFour = () => {
- const [frequency, setFrequency] = useState('')
-
const {
- cronConfig,
isManual,
+ cronConfig,
skipOnFail,
createdDateAfter,
- onChangeCronConfig,
onChangeIsManual,
+ onChangeCronConfig,
onChangeSkipOnFail,
onChangeCreatedDateAfter
- } = useBlueprint()
-
- const description = useMemo(() => {
- switch (frequency) {
- case 'manual':
- return 'Manual'
- case 'custom':
- return 'Custom'
- default:
- return cronPresets.find((it) => it.config === frequency)?.desc ?? ''
- }
- }, [frequency])
-
- useEffect(() => {
- if (isManual) {
- setFrequency('manual')
- } else if (frequency !== 'custom') {
- setFrequency(cronConfig)
- }
- }, [cronConfig, isManual])
-
- const handleChangeFrequency = (e: React.FormEvent<HTMLInputElement>) => {
- const value = (e.target as HTMLInputElement).value
- if (value === 'manual') {
- onChangeIsManual(true)
- } else if (value === 'custom') {
- onChangeIsManual(false)
- setFrequency('custom')
- } else {
- onChangeIsManual(false)
- onChangeCronConfig(value)
- setFrequency(value)
- }
- }
-
- const handleChangeCronConfig = (e: React.ChangeEvent<HTMLInputElement>) => {
- onChangeCronConfig(e.target.value)
- }
+ } = useCreateBP()
return (
- <S.Card>
+ <Card>
<h2>Set Sync Policy</h2>
<Divider />
- <div className='block'>
- <h4>Time Filter *</h4>
- <p>Select the data range you wish to collect. DevLake will collect
the last six months of data by default.</p>
- <StartFromSelector
- autoFillDefault={true}
- date={createdDateAfter}
- onSave={onChangeCreatedDateAfter}
- />
- </div>
- <div className='block'>
- <h3>Frequency</h3>
- <p>Blueprints will run recurringly based on the sync frequency.</p>
- <p style={{ margin: '10px 0' }}>{description}</p>
- <RadioGroup selectedValue={frequency} onChange={handleChangeFrequency}>
- <Radio label='Manual' value='manual' />
- {cronPresets.map((cron) => (
- <Radio key={cron.label} label={cron.label} value={cron.config} />
- ))}
- <Radio label='Custom' value='custom' />
- </RadioGroup>
- {frequency === 'custom' && (
- <S.Input>
- <InputGroup value={cronConfig} onChange={handleChangeCronConfig} />
- <Popover2
- position={Position.RIGHT}
- content={
- <S.Help>
- <div className='title'>
- <Icon icon='help' />
- <span>Cron Expression Format</span>
- </div>
- <p>
- Need Help? — For additional information on{' '}
- <strong>Crontab</strong>, please reference the{' '}
- <a
-
href='https://man7.org/linux/man-pages/man5/crontab.5.html'
- rel='noreferrer'
- target='_blank'
- style={{ textDecoration: 'underline' }}
- >
- Crontab Linux manual
- </a>
- .
- </p>
- <img src={CronHelp} alt='' />
- </S.Help>
- }
- >
- <Icon
- icon='help'
- size={14}
- style={{ marginLeft: '10px', transition: 'none' }}
- />
- </Popover2>
- </S.Input>
- )}
- </div>
- <div className='block'>
- <h3>Running Policy</h3>
- <Checkbox
- label='Skip failed tasks (Recommended when collecting large volume
of data, eg. 10+ GitHub repos/Jira boards)'
- checked={skipOnFail}
- onChange={(e) =>
- onChangeSkipOnFail((e.target as HTMLInputElement).checked)
- }
- />
- <p>
- A task is a unit of a pipeline. A pipeline is an execution of a
- blueprint. By default, when a task is failed, the whole pipeline will
- fail and all the data that has been collected will be discarded. By
- skipping failed tasks, the pipeline will continue to run, and the
data
- collected by other tasks will not be affected. After the pipeline is
- finished, you can rerun these failed tasks.
- </p>
- </div>
- </S.Card>
+ <SyncPolicy
+ isManual={isManual}
+ cronConfig={cronConfig}
+ skipOnFail={skipOnFail}
+ createdDateAfter={createdDateAfter}
+ onChangeIsManual={onChangeIsManual}
+ onChangeCronConfig={onChangeCronConfig}
+ onChangeSkipOnFail={onChangeSkipOnFail}
+ onChangeCreatedDateAfter={onChangeCreatedDateAfter}
+ />
+ </Card>
)
}
diff --git a/config-ui/src/pages/blueprint/create/step-one/index.tsx
b/config-ui/src/pages/blueprint/create/step-one/index.tsx
index b9c57d282..a6f5c81cf 100644
--- a/config-ui/src/pages/blueprint/create/step-one/index.tsx
+++ b/config-ui/src/pages/blueprint/create/step-one/index.tsx
@@ -16,7 +16,7 @@
*
*/
-import React, { useState, useMemo, useEffect } from 'react'
+import React, { useState } from 'react'
import {
InputGroup,
TextArea,
@@ -29,10 +29,10 @@ import {
import { Popover2 } from '@blueprintjs/popover2'
import { useStore } from '@/store/store'
-import { Divider, MultiSelector, Loading } from '@/components'
+import { Card, Divider, MultiSelector, Loading } from '@/components'
import { ModeEnum } from '../types'
-import { useBlueprint } from '../hooks'
+import { useCreateBP } from '../bp-context'
import { DEFAULT_CONFIG } from './example'
import * as S from './styled'
@@ -40,30 +40,22 @@ import * as S from './styled'
export const StepOne = () => {
const [isOpen, setIsOpen] = useState(false)
- const connectionsStore = useStore()
+ const { connections, onTestConnections } = useStore()
const {
mode,
name,
rawPlan,
- connections,
+ uniqueList,
onChangeMode,
onChangeName,
onChangeRawPlan,
- onChangeConnections
- } = useBlueprint()
-
- const selectedConnections = useMemo(
- () =>
- connectionsStore.connections.filter((cs) =>
- connections.map((cs) => cs.unique).includes(cs.unique)
- ),
- [connectionsStore, connections]
- )
+ onChangeUniqueList
+ } = useCreateBP()
return (
<>
- <S.Card>
+ <Card className='card'>
<h2>Blueprint Name</h2>
<Divider />
<p>
@@ -75,46 +67,45 @@ export const StepOne = () => {
value={name}
onChange={(e) => onChangeName(e.target.value)}
/>
- </S.Card>
+ </Card>
{mode === ModeEnum.normal && (
<>
- <S.Card>
+ <Card className='card'>
<h2>Add Data Connections</h2>
<Divider />
<h3>Select Connections</h3>
<p>Select from existing or create new connections</p>
<MultiSelector
placeholder='Select Connections...'
- items={connectionsStore.connections}
+ items={connections}
getKey={(it) => it.unique}
getName={(it) => it.name}
getIcon={(it) => it.icon}
- selectedItems={selectedConnections}
+ selectedItems={connections.filter((cs) =>
+ uniqueList.includes(cs.unique)
+ )}
onChangeItems={(selectedItems) => {
- connectionsStore.onTestConnections(selectedItems)
- onChangeConnections(
- selectedItems.map((it) => ({
- ...it,
- scope: []
- }))
- )
+ onTestConnections(selectedItems)
+ onChangeUniqueList(selectedItems.map((sc) => sc.unique))
}}
/>
<S.ConnectionList>
- {selectedConnections.map((cs) => (
- <li key={cs.unique}>
- <span className='name'>{cs.name}</span>
- <span className={`status ${cs.status}`}>
- {cs.status === 'testing' && (
- <Loading size={14} style={{ marginRight: 4 }} />
- )}
- {cs.status}
- </span>
- </li>
- ))}
+ {connections
+ .filter((cs) => uniqueList.includes(cs.unique))
+ .map((cs) => (
+ <li key={cs.unique}>
+ <span className='name'>{cs.name}</span>
+ <span className={`status ${cs.status}`}>
+ {cs.status === 'testing' && (
+ <Loading size={14} style={{ marginRight: 4 }} />
+ )}
+ {cs.status}
+ </span>
+ </li>
+ ))}
</S.ConnectionList>
- </S.Card>
+ </Card>
<S.Tips>
<span>
To customize how tasks are executed in the blueprint, please
use{' '}
@@ -128,7 +119,7 @@ export const StepOne = () => {
{mode === ModeEnum.advanced && (
<>
- <S.Card>
+ <Card className='card'>
<h2>JSON Configuration</h2>
<Divider />
<h3>Task Editor</h3>
@@ -167,7 +158,7 @@ export const StepOne = () => {
/>
</Popover2>
</ButtonGroup>
- </S.Card>
+ </Card>
<S.Tips>
<span>To visually define blueprint tasks, please use </span>
<span onClick={() => onChangeMode(ModeEnum.normal)}>
diff --git a/config-ui/src/pages/blueprint/create/step-one/styled.ts
b/config-ui/src/pages/blueprint/create/step-one/styled.ts
index 8768b4e74..613be898c 100644
--- a/config-ui/src/pages/blueprint/create/step-one/styled.ts
+++ b/config-ui/src/pages/blueprint/create/step-one/styled.ts
@@ -19,8 +19,6 @@
import styled from 'styled-components'
import { Colors } from '@blueprintjs/core'
-export * from '../styled'
-
export const ConnectionList = styled.ul`
margin: 0;
padding: 12px;
diff --git a/config-ui/src/pages/blueprint/create/step-three/index.tsx
b/config-ui/src/pages/blueprint/create/step-three/index.tsx
index cfdafbb2f..cac1017e6 100644
--- a/config-ui/src/pages/blueprint/create/step-three/index.tsx
+++ b/config-ui/src/pages/blueprint/create/step-three/index.tsx
@@ -16,193 +16,72 @@
*
*/
-import React, { useState } from 'react'
-import {
- Icon,
- RadioGroup,
- Radio,
- InputGroup,
- ButtonGroup,
- Button,
- Intent
-} from '@blueprintjs/core'
+import React, { useState, useMemo } from 'react'
+import { Icon } from '@blueprintjs/core'
-import { Table, Divider } from '@/components'
-import {
- DataScopeSelector,
- RuleSelector,
- Transformation,
- Plugins
-} from '@/plugins'
+import type { ConnectionItemType } from '@/store'
+import { Card, Table, Divider } from '@/components'
+import { useStore } from '@/store'
+import { Transformation } from '@/plugins'
-import type { BPConnectionItemType } from '../types'
-import { useBlueprint } from '../hooks'
-import * as API from '../api'
+import { useCreateBP } from '../bp-context'
import { useColumns } from './use-columns'
-import * as S from './styled'
-
-type TransformationType = 'create' | 'createByExist' | 'selectExist'
export const StepThree = () => {
- const [connection, setConnection] = useState<BPConnectionItemType>()
- const [type, setType] = useState<TransformationType>()
- const [name, setName] = useState('')
- const [selectedRule, setSelectedRule] = useState<any>()
- const [selectedScope, setSelectedScope] = useState<any>([])
+ const [connection, setConnection] = useState<
+ ConnectionItemType & { scope: any }
+ >()
- const { connections, onChangeShowDetail } = useBlueprint()
+ const { connections } = useStore()
+ const { uniqueList, scopeMap, onChangeShowDetail } = useCreateBP()
- const handleGoDetail = (c: BPConnectionItemType) => {
+ const handleGoDetail = (c: ConnectionItemType & { scope: any }) => {
setConnection(c)
onChangeShowDetail(true)
}
const handleBack = () => {
setConnection(undefined)
- setType(undefined)
- setSelectedRule(undefined)
onChangeShowDetail(false)
}
- const handleChangeType = (e: React.FormEvent<HTMLInputElement>) => {
- setType((e.target as HTMLInputElement).value as TransformationType)
- setSelectedRule(undefined)
- }
-
- const handleUpdateScopeRule = async (
- plugin: Plugins,
- connectionId: ID,
- tsId: ID
- ) => {
- const paylod = selectedScope.map((sc: any) => ({
- ...sc,
- transformationRuleId: tsId
- }))
-
- if (paylod.length) {
- await API.updateDataScope(plugin, connectionId, {
- data: paylod
- })
- }
-
- handleBack()
- }
-
const columns = useColumns({ onDetail: handleGoDetail })
+ const dataSource = useMemo(
+ () =>
+ uniqueList.map((unique) => {
+ const connection = connections.find(
+ (cs) => cs.unique === unique
+ ) as ConnectionItemType
+ const scope = scopeMap[unique] ?? []
+ return {
+ ...connection,
+ scope: scope.map((sc: any) => ({
+ id: `${sc.id}`,
+ entities: `${sc.entities}`
+ }))
+ }
+ }),
+ [uniqueList, connections, scopeMap]
+ )
return !connection ? (
- <S.Card style={{ padding: 0 }}>
- <Table columns={columns} dataSource={connections} />
- </S.Card>
+ <Table columns={columns} dataSource={dataSource} />
) : (
- <>
- <S.Card>
- <div className='back' onClick={handleBack}>
- <Icon icon='arrow-left' size={14} />
- <span>Cancel and Go Back</span>
- </div>
- <h2>Create/Select a Transformation</h2>
- <Divider />
- <h3 style={{ marginBottom: 12 }}>
- Create a New or Select an Existing Transformation *
- </h3>
- <RadioGroup selectedValue={type} onChange={handleChangeType}>
- <Radio
- label='Create a new transformation from a blank template'
- value='create'
- />
- <Radio
- label='Create a new transformation by duplicating an exisitng
transformation as the template'
- value='createByExist'
- />
- <Radio
- label='Select an existing transformation'
- value='selectExist'
- />
- </RadioGroup>
- </S.Card>
- {type && (
- <S.Card>
- {(type === 'createByExist' || type === 'selectExist') && (
- <div className='block'>
- <h3>Select a Transformation to Duplicate *</h3>
- <p>
- The selected transformation will be used as template that you
- can tweak and save as a new transformation.
- </p>
- <RuleSelector
- plugin={connection.plugin}
- selectedRule={selectedRule}
- onChangeRule={setSelectedRule}
- />
- </div>
- )}
- {type !== 'selectExist' && (
- <div className='block'>
- <h3>Transformation Name *</h3>
- <p>
- Give this set of transformation rules a unique name so that you
- can identify it in the future.
- </p>
- <InputGroup
- placeholder='Enter Transformation Name'
- value={name}
- onChange={(e) => setName(e.target.value)}
- />
- </div>
- )}
- <div className='block'>
- <h3>Applied Data Scope</h3>
- <p>
- Select the data scope for which you want to apply this
- transformation for.
- </p>
- <DataScopeSelector
- plugin={connection.plugin}
- connectionId={connection.id}
- scopeIds={connection.scope.map((sc) => sc.id)}
- selectedItems={selectedScope}
- onChangeItems={setSelectedScope}
- />
- {type === 'selectExist' && (
- <ButtonGroup>
- <Button
- outlined
- intent={Intent.PRIMARY}
- text='Cancel and Go Back'
- onClick={handleBack}
- />
- <Button
- outlined
- disabled={!selectedRule}
- intent={Intent.PRIMARY}
- text='Save'
- onClick={() =>
- handleUpdateScopeRule(
- connection.plugin,
- connection.id,
- selectedRule.id
- )
- }
- />
- </ButtonGroup>
- )}
- </div>
- </S.Card>
- )}
- {(type === 'create' || (type === 'createByExist' && selectedRule)) && (
- <Transformation
- plugin={connection.plugin}
- connectionId={connection.id}
- name={name}
- initialValues={selectedRule}
- onSaveAfter={(tsid) =>
- handleUpdateScopeRule(connection.plugin, connection.id, tsid)
- }
- onCancel={handleBack}
- />
- )}
- </>
+ <Card>
+ <div className='back' onClick={handleBack}>
+ <Icon icon='arrow-left' size={14} />
+ <span>Cancel and Go Back</span>
+ </div>
+ <h2>Create/Select a Transformation</h2>
+ <Divider />
+ <Transformation
+ plugin={connection.plugin}
+ connectionId={connection.id}
+ scopeIds={connection.scope.map((sc: any) => sc.id)}
+ onCancel={handleBack}
+ onSave={handleBack}
+ />
+ </Card>
)
}
diff --git a/config-ui/src/pages/blueprint/create/step-three/styled.ts
b/config-ui/src/pages/blueprint/create/step-three/styled.ts
index e1517f2f4..2a9c4e370 100644
--- a/config-ui/src/pages/blueprint/create/step-three/styled.ts
+++ b/config-ui/src/pages/blueprint/create/step-three/styled.ts
@@ -18,8 +18,6 @@
import styled from 'styled-components'
-export * from '../styled'
-
export const ConnectionColumn = styled.div`
display: flex;
align-items: center;
diff --git
a/config-ui/src/pages/blueprint/create/step-three/use-transformation.ts
b/config-ui/src/pages/blueprint/create/step-three/use-transformation.ts
deleted file mode 100644
index fb33c870a..000000000
--- a/config-ui/src/pages/blueprint/create/step-three/use-transformation.ts
+++ /dev/null
@@ -1,64 +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 type { Plugins } from '@/plugins'
-import { operator } from '@/utils'
-
-import * as API from '../api'
-
-interface Props {
- plugin: Plugins
- connectionId: ID
- onBack: () => void
-}
-
-export const useTransformation = ({ plugin, connectionId, onBack }: Props) => {
- const [saving, setSaving] = useState(false)
- const [selectedScope, setSelectedScope] = useState<any>([])
-
- const updateScopeRule = async (tsId: ID) => {
- setSaving(true)
- const paylod = selectedScope.map((sc: any) => ({
- ...sc,
- transformationRuleId: tsId
- }))
-
- if (paylod.length) {
- await operator(() =>
- API.updateDataScope(plugin, connectionId, {
- data: paylod
- })
- )
- }
-
- setSaving(false)
- onBack()
- }
-
- return useMemo(
- () => ({
- saving,
- selectedScope,
- onChangeSelectedScope: setSelectedScope,
- updateScopeRule
- }),
- [saving, selectedScope]
- )
-}
diff --git a/config-ui/src/pages/blueprint/create/step-two/index.tsx
b/config-ui/src/pages/blueprint/create/step-two/index.tsx
index bf7d4f796..5247f1945 100644
--- a/config-ui/src/pages/blueprint/create/step-two/index.tsx
+++ b/config-ui/src/pages/blueprint/create/step-two/index.tsx
@@ -16,25 +16,28 @@
*
*/
-import React, { useState, useEffect } from 'react'
+import React, { useState, useMemo } from 'react'
import { Icon } from '@blueprintjs/core'
-import { Table, Divider } from '@/components'
+import type { ConnectionItemType } from '@/store'
+import { Card, Table, Divider } from '@/components'
+import { useStore } from '@/store'
import { DataScope } from '@/plugins'
-import type { BPConnectionItemType, BPScopeItemType } from '../types'
-import { useBlueprint } from '../hooks'
+import { useCreateBP } from '../bp-context'
import { useColumns } from './use-columns'
-import * as S from './styled'
export const StepTwo = () => {
- const [connection, setConnection] = useState<BPConnectionItemType>()
+ const [connection, setConnection] = useState<
+ ConnectionItemType & { scope: any }
+ >()
- const { connections, onChangeConnections, onChangeShowDetail } =
- useBlueprint()
+ const { connections } = useStore()
+ const { uniqueList, scopeMap, onChangeScopeMap, onChangeShowDetail } =
+ useCreateBP()
- const handleGoDetail = (c: BPConnectionItemType) => {
+ const handleGoDetail = (c: ConnectionItemType & { scope: any }) => {
setConnection(c)
onChangeShowDetail(true)
}
@@ -44,23 +47,38 @@ export const StepTwo = () => {
onChangeShowDetail(false)
}
- const handleSave = (scope: BPScopeItemType[]) => {
+ const handleSave = (scope: any) => {
if (!connection) return
- const newConnections = connections.map((cs) =>
- cs.unique !== connection.unique ? cs : { ...cs, scope }
- )
- onChangeConnections(newConnections)
+ onChangeScopeMap({
+ ...scopeMap,
+ [`${connection.unique}`]: scope
+ })
handleBack()
}
const columns = useColumns({ onDetail: handleGoDetail })
+ const dataSource = useMemo(
+ () =>
+ uniqueList.map((unique) => {
+ const connection = connections.find(
+ (cs) => cs.unique === unique
+ ) as ConnectionItemType
+ const scope = scopeMap[unique] ?? []
+ return {
+ ...connection,
+ scope: scope.map((sc: any) => ({
+ id: `${sc.id}`,
+ entities: `${sc.entities}`
+ }))
+ }
+ }),
+ [uniqueList, connections, scopeMap]
+ )
return !connection ? (
- <S.Card style={{ padding: 0 }}>
- <Table columns={columns} dataSource={connections} />
- </S.Card>
+ <Table columns={columns} dataSource={dataSource} />
) : (
- <S.Card>
+ <Card>
<div className='back' onClick={handleBack}>
<Icon icon='arrow-left' size={14} />
<span>Cancel and Go Back to the Data Scope List</span>
@@ -74,10 +92,10 @@ export const StepTwo = () => {
<DataScope
plugin={connection.plugin}
connectionId={connection.id}
- allEntities={connection.entities}
+ entities={connection.entities}
onCancel={handleBack}
- onSaveAfter={handleSave}
+ onSave={handleSave}
/>
- </S.Card>
+ </Card>
)
}
diff --git a/config-ui/src/pages/blueprint/create/step-two/styled.ts
b/config-ui/src/pages/blueprint/create/step-two/styled.ts
index e1517f2f4..2a9c4e370 100644
--- a/config-ui/src/pages/blueprint/create/step-two/styled.ts
+++ b/config-ui/src/pages/blueprint/create/step-two/styled.ts
@@ -18,8 +18,6 @@
import styled from 'styled-components'
-export * from '../styled'
-
export const ConnectionColumn = styled.div`
display: flex;
align-items: center;
diff --git a/config-ui/src/pages/blueprint/create/styled.ts
b/config-ui/src/pages/blueprint/create/styled.ts
index 07595e0fb..4e32c2b83 100644
--- a/config-ui/src/pages/blueprint/create/styled.ts
+++ b/config-ui/src/pages/blueprint/create/styled.ts
@@ -23,18 +23,9 @@ export const Container = styled.div``
export const Content = styled.div`
margin-top: 36px;
margin-bottom: 24px;
-`
-
-export const Card = styled.div`
- padding: 24px;
font-size: 12px;
- color: #292b3f;
- background-color: #fff;
- box-shadow: 0px 2.4px 4.8px -0.8px rgba(0, 0, 0, 0.1),
- 0px 1.6px 8px rgba(0, 0, 0, 0.07);
- border-radius: 8px;
- & + & {
+ .card + .card {
margin-top: 24px;
}
@@ -46,48 +37,12 @@ export const Card = styled.div`
}
h3 {
- margin: 0 0 6px;
+ margin: 0 0 8px;
padding: 0;
font-size: 14px;
font-weight: 600;
}
- h5 {
- margin: 8px 0;
- padding: 0;
- font-size: 13px;
- font-weight: 600;
- }
-
- .bp4-input-group > input {
- font-size: 12px;
- }
-
- .bp4-tag-input-values > input {
- font-size: 12px;
- }
-
- textarea.bp4-input {
- min-height: 240px;
- font-family: 'JetBrains Mono', monospace;
- font-size: 10px;
- background-color: #f9f9f9;
- }
-
- .bp4-button-group {
- display: block;
- margin-top: 8px;
- text-align: right;
-
- .bp4-button + .bp4-button {
- margin-left: 4px;
- }
- }
-
- .bp4-button.bp4-small {
- font-size: 12px;
- }
-
.back {
display: flex;
align-items: center;
@@ -113,8 +68,4 @@ export const Card = styled.div`
font-weight: 600;
}
}
-
- .block + .block {
- margin-top: 12px;
- }
`
diff --git a/config-ui/src/pages/blueprint/create/types.ts
b/config-ui/src/pages/blueprint/create/types.ts
index 28f7ed1c8..fc99a1526 100644
--- a/config-ui/src/pages/blueprint/create/types.ts
+++ b/config-ui/src/pages/blueprint/create/types.ts
@@ -16,8 +16,6 @@
*
*/
-import type { ConnectionItemType } from '@/store'
-
export enum FromEnum {
project = 'project',
blueprint = 'blueprint'
@@ -28,11 +26,37 @@ export enum ModeEnum {
normal = 'NORMAL'
}
-export type BPScopeItemType = {
- id: ID
- entities: string[]
-}
+export type BPContextType = {
+ step: number
+ error: string
+ showInspector: boolean
+ showDetail: boolean
+ payload: any
+
+ name: string
+ mode: ModeEnum
+ rawPlan: string
+ uniqueList: string[]
+ scopeMap: Record<string, any>
+ cronConfig: string
+ isManual: boolean
+ skipOnFail: boolean
+ createdDateAfter: string | null
+
+ onChangeStep: React.Dispatch<React.SetStateAction<number>>
+ onChangeShowInspector: React.Dispatch<React.SetStateAction<boolean>>
+ onChangeShowDetail: React.Dispatch<React.SetStateAction<boolean>>
+
+ onChangeName: React.Dispatch<React.SetStateAction<string>>
+ onChangeMode: (mode: ModeEnum) => void
+ onChangeRawPlan: React.Dispatch<React.SetStateAction<string>>
+ onChangeUniqueList: React.Dispatch<React.SetStateAction<string[]>>
+ onChangeScopeMap: React.Dispatch<React.SetStateAction<Record<string, any>>>
+ onChangeCronConfig: React.Dispatch<React.SetStateAction<string>>
+ onChangeIsManual: React.Dispatch<React.SetStateAction<boolean>>
+ onChangeSkipOnFail: React.Dispatch<React.SetStateAction<boolean>>
+ onChangeCreatedDateAfter: React.Dispatch<React.SetStateAction<string | null>>
-export type BPConnectionItemType = ConnectionItemType & {
- scope: BPScopeItemType[]
+ onSave: () => void
+ onSaveAndRun: () => void
}
diff --git a/config-ui/src/pages/project/home/index.tsx
b/config-ui/src/pages/project/home/index.tsx
index ec1683bb1..81a9fe248 100644
--- a/config-ui/src/pages/project/home/index.tsx
+++ b/config-ui/src/pages/project/home/index.tsx
@@ -21,7 +21,7 @@ import { Link, useHistory } from 'react-router-dom'
import { Button, InputGroup, Checkbox, Intent } from '@blueprintjs/core'
import NoData from '@/images/no-data.svg'
-import { PageHeader, Table, ColumnType, Dialog } from '@/components'
+import { PageHeader, Card, Table, ColumnType, Dialog } from '@/components'
import { useProject } from './use-project'
import * as S from './styled'
@@ -93,7 +93,7 @@ export const ProjectHomePage = () => {
>
<S.Container>
{!projects.length ? (
- <S.Inner>
+ <Card className='card'>
<div className='logo'>
<img src={NoData} alt='' />
</div>
@@ -110,13 +110,17 @@ export const ProjectHomePage = () => {
onClick={handleShowDialog}
/>
</div>
- </S.Inner>
+ </Card>
) : (
<Table loading={loading} columns={columns} dataSource={projects} />
)}
<Dialog
isOpen={isOpen}
title='Create a New Project'
+ style={{
+ top: -100,
+ width: 820
+ }}
okText='Save'
okDisabled={!name}
okLoading={operating}
diff --git a/config-ui/src/pages/project/home/styled.ts
b/config-ui/src/pages/project/home/styled.ts
index 5931d70c4..7df745eac 100644
--- a/config-ui/src/pages/project/home/styled.ts
+++ b/config-ui/src/pages/project/home/styled.ts
@@ -19,26 +19,18 @@
import styled from '@emotion/styled'
export const Container = styled.div`
- background-color: #ffffff;
- box-shadow: 0px 2.4px 4.8px -0.8px rgba(0, 0, 0, 0.1),
- 0px 1.6px 8px rgba(0, 0, 0, 0.07);
- border-radius: 4px;
-`
-
-export const Inner = styled.div`
- padding: 24px;
- text-align: center;
+ .card {
+ text-align: center;
- .logo {
img {
display: inline-block;
width: 120px;
height: 120px;
}
- }
- .desc {
- margin: 20px 0;
+ .desc {
+ margin: 24px 0;
+ }
}
`
diff --git a/config-ui/src/plugins/common/data-scope-selector/api.ts
b/config-ui/src/plugins/common/data-scope-selector/api.ts
deleted file mode 100644
index 9f714f462..000000000
--- a/config-ui/src/plugins/common/data-scope-selector/api.ts
+++ /dev/null
@@ -1,27 +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 request from '@/components/utils/request'
-
-import { Plugins } from '@/plugins'
-
-export const getDataScopeRepo = (
- plugin: Plugins,
- connectionId: ID,
- repoId: ID
-) => request(`/plugins/${plugin}/connections/${connectionId}/scopes/${repoId}`)
diff --git a/config-ui/src/plugins/common/data-scope-selector/index.tsx
b/config-ui/src/plugins/common/data-scope-selector/index.tsx
deleted file mode 100644
index 7fb23430f..000000000
--- a/config-ui/src/plugins/common/data-scope-selector/index.tsx
+++ /dev/null
@@ -1,48 +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 React from 'react'
-
-import { MultiSelector } from '@/components'
-
-import type { UseDataScopeSelector } from './use-data-scope-selector'
-import { useDataScopeSelector } from './use-data-scope-selector'
-
-interface Props extends UseDataScopeSelector {
- selectedItems: any
- onChangeItems: (selectedItems: any) => void
-}
-
-export const DataScopeSelector = ({
- selectedItems,
- onChangeItems,
- ...props
-}: Props) => {
- const { loading, scope, getKey, getName } = useDataScopeSelector({ ...props
})
-
- return (
- <MultiSelector
- loading={loading}
- items={scope}
- getKey={getKey}
- getName={getName}
- selectedItems={selectedItems}
- onChangeItems={onChangeItems}
- />
- )
-}
diff --git
a/config-ui/src/plugins/common/data-scope-selector/use-data-scope-selector.ts
b/config-ui/src/plugins/common/data-scope-selector/use-data-scope-selector.ts
deleted file mode 100644
index 64a0680dc..000000000
---
a/config-ui/src/plugins/common/data-scope-selector/use-data-scope-selector.ts
+++ /dev/null
@@ -1,81 +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, useEffect, useMemo } from 'react'
-
-import { Plugins } from '@/plugins'
-
-import * as API from './api'
-
-type ScopeItem = {
- name: string
-} & any
-
-export interface UseDataScopeSelector {
- plugin: Plugins
- connectionId: ID
- scopeIds: ID[]
-}
-
-export const useDataScopeSelector = ({
- plugin,
- connectionId,
- scopeIds
-}: UseDataScopeSelector) => {
- const [loading, setLoading] = useState(false)
- const [scope, setScope] = useState<ScopeItem[]>([])
-
- const getScopeDetail = async () => {
- setLoading(true)
- try {
- const res = await Promise.all(
- scopeIds.map((id) => API.getDataScopeRepo(plugin, connectionId, id))
- )
- setScope(res)
- } finally {
- setLoading(false)
- }
- }
-
- useEffect(() => {
- getScopeDetail()
- }, [])
-
- return useMemo(
- () => ({
- loading,
- scope,
- getKey(sc: ScopeItem) {
- switch (true) {
- case plugin === Plugins.GitHub:
- return sc.githubId
- case plugin === Plugins.JIRA:
- return sc.boardId
- case plugin === Plugins.GitLab:
- return sc.gitlabId
- case plugin === Plugins.Jenkins:
- return sc.fullName
- }
- },
- getName(sc: ScopeItem) {
- return sc.name
- }
- }),
- [loading, scope, plugin]
- )
-}
diff --git a/config-ui/src/plugins/common/data-scope/index.tsx
b/config-ui/src/plugins/common/data-scope/index.tsx
index c76ceb370..5a4300975 100644
--- a/config-ui/src/plugins/common/data-scope/index.tsx
+++ b/config-ui/src/plugins/common/data-scope/index.tsx
@@ -28,6 +28,7 @@ import { MultiSelector } from '@/components'
import type { UseDataScope } from './use-data-scope'
import { useDataScope } from './use-data-scope'
+import * as S from './styled'
interface Props extends UseDataScope {
onCancel?: () => void
@@ -36,25 +37,31 @@ interface Props extends UseDataScope {
export const DataScope = ({
plugin,
connectionId,
- allEntities,
+ entities,
onCancel,
- onSaveAfter
+ ...props
}: Props) => {
- const { saving, scope, entities, onChangeScope, onChangeEntities, onSave } =
- useDataScope({
- plugin,
- connectionId,
- allEntities,
- onSaveAfter
- })
+ const {
+ saving,
+ selectedScope,
+ selectedEntities,
+ onChangeScope,
+ onChangeEntites,
+ onSave
+ } = useDataScope({
+ ...props,
+ plugin,
+ connectionId,
+ entities
+ })
return (
- <>
+ <S.Wrapper>
<div className='block'>
{plugin === Plugins.GitHub && (
<GitHubDataScope
connectionId={connectionId}
- selectedItems={scope}
+ selectedItems={selectedScope}
onChangeItems={onChangeScope}
/>
)}
@@ -62,7 +69,7 @@ export const DataScope = ({
{plugin === Plugins.JIRA && (
<JIRADataScope
connectionId={connectionId}
- selectedItems={scope}
+ selectedItems={selectedScope}
onChangeItems={onChangeScope}
/>
)}
@@ -70,7 +77,7 @@ export const DataScope = ({
{plugin === Plugins.GitLab && (
<GitLabDataScope
connectionId={connectionId}
- selectedItems={scope}
+ selectedItems={selectedScope}
onChangeItems={onChangeScope}
/>
)}
@@ -78,7 +85,7 @@ export const DataScope = ({
{plugin === Plugins.Jenkins && (
<JenkinsDataScope
connectionId={connectionId}
- selectedItems={scope}
+ selectedItems={selectedScope}
onChangeItems={onChangeScope}
/>
)}
@@ -98,9 +105,9 @@ export const DataScope = ({
</a>
</p>
<MultiSelector
- items={allEntities}
- selectedItems={entities}
- onChangeItems={onChangeEntities}
+ items={entities}
+ selectedItems={selectedEntities}
+ onChangeItems={onChangeEntites}
/>
</div>
@@ -110,11 +117,11 @@ export const DataScope = ({
outlined
intent={Intent.PRIMARY}
loading={saving}
- disabled={!scope.length || !entities.length}
+ disabled={!selectedScope.length || !selectedEntities.length}
text='Save'
onClick={onSave}
/>
</ButtonGroup>
- </>
+ </S.Wrapper>
)
}
diff --git a/config-ui/src/plugins/github/styled.ts
b/config-ui/src/plugins/common/data-scope/styled.ts
similarity index 79%
rename from config-ui/src/plugins/github/styled.ts
rename to config-ui/src/plugins/common/data-scope/styled.ts
index 35fc9640e..8c88d799a 100644
--- a/config-ui/src/plugins/github/styled.ts
+++ b/config-ui/src/plugins/common/data-scope/styled.ts
@@ -18,25 +18,25 @@
import styled from 'styled-components'
-export const TransformationWrapper = styled.div`
+export const Wrapper = styled.div`
+ .block {
+ margin-bottom: 16px;
+ }
+
h3 {
margin: 0 0 8px;
-
- .bp4-tag {
- margin-left: 6px;
- }
}
- .bp4-form-group {
- display: flex;
- align-items: center;
+ h4 {
+ margin: 8px 0;
+ }
- .bp4-label {
- flex: 0 0 150px;
- }
+ p {
+ margin: 0 0 8px;
+ }
- .bp4-form-content {
- flex: auto;
- }
+ .bp4-button-group {
+ display: flex;
+ justify-content: flex-end;
}
`
diff --git a/config-ui/src/plugins/common/data-scope/use-data-scope.ts
b/config-ui/src/plugins/common/data-scope/use-data-scope.ts
index 5caddd4d7..79b7ef878 100644
--- a/config-ui/src/plugins/common/data-scope/use-data-scope.ts
+++ b/config-ui/src/plugins/common/data-scope/use-data-scope.ts
@@ -27,46 +27,56 @@ import * as API from './api'
export interface UseDataScope {
plugin: string
connectionId: ID
- allEntities: string[]
- onSaveAfter?: (scope: Array<{ id: ID; entities: string[] }>) => void
+ entities: string[]
+ initialValues?: any
+ onSave?: (scope: any) => void
}
export const useDataScope = ({
plugin,
connectionId,
- allEntities,
- onSaveAfter
+ entities,
+ initialValues,
+ onSave
}: UseDataScope) => {
const [saving, setSaving] = useState(false)
- const [scope, setScope] = useState<any>([])
- const [entities, setEntities] = useState<string[]>([])
+ const [selectedScope, setSelectedScope] = useState<any>([])
+ const [selectedEntities, setSelectedEntities] = useState<string[]>([])
useEffect(() => {
- setEntities(allEntities ?? [])
- }, [allEntities])
+ setSelectedScope(initialValues ?? [])
+ }, [initialValues])
+
+ useEffect(() => {
+ setSelectedEntities(entities ?? [])
+ }, [entities])
const formatScope = (scope: any) => {
return scope.map((sc: any) => {
switch (true) {
case plugin === Plugins.GitHub:
return {
+ ...sc,
id: sc.githubId,
- entities
+ entities: selectedEntities
}
case plugin === Plugins.JIRA:
return {
+ ...sc,
id: sc.boardId,
- entities
+ entities: selectedEntities
}
case plugin === Plugins.GitLab:
return {
+ ...sc,
id: sc.gitlabId,
- entities
+ entities: selectedEntities
}
case plugin === Plugins.Jenkins:
return {
+ ...sc,
id: sc.fullName,
- entities
+ entities: selectedEntities
}
}
})
@@ -76,7 +86,7 @@ export const useDataScope = ({
const [success, res] = await operator(
() =>
API.updateDataScope(plugin, connectionId, {
- data: scope.map((sc: any) => omit(sc, 'from'))
+ data: selectedScope.map((sc: any) => omit(sc, 'from'))
}),
{
setOperating: setSaving
@@ -84,19 +94,19 @@ export const useDataScope = ({
)
if (success) {
- onSaveAfter?.(formatScope(res))
+ onSave?.(formatScope(res))
}
}
return useMemo(
() => ({
saving,
- scope,
- entities,
- onChangeScope: setScope,
- onChangeEntities: setEntities,
+ selectedScope,
+ selectedEntities,
+ onChangeScope: setSelectedScope,
+ onChangeEntites: setSelectedEntities,
onSave: handleSave
}),
- [saving, scope]
+ [saving, selectedScope, selectedEntities]
)
}
diff --git a/config-ui/src/plugins/common/index.ts
b/config-ui/src/plugins/common/index.ts
index 144e5be26..26381231f 100644
--- a/config-ui/src/plugins/common/index.ts
+++ b/config-ui/src/plugins/common/index.ts
@@ -18,7 +18,6 @@
export * from './types'
export * from './data-scope-list'
-export * from './data-scope-selector'
export * from './data-scope'
-export * from './rule-selector'
export * from './transformation'
+export * from './sync-policy'
diff --git a/config-ui/src/plugins/common/rule-selector/api.ts
b/config-ui/src/plugins/common/rule-selector/api.ts
deleted file mode 100644
index 5fcd5a243..000000000
--- a/config-ui/src/plugins/common/rule-selector/api.ts
+++ /dev/null
@@ -1,32 +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 request from '@/components/utils/request'
-
-import { Plugins } from '@/plugins'
-
-type GetRulesParams = {
- page: number
- pageSize: number
-}
-
-export const getRules = (plugin: Plugins, params?: GetRulesParams) =>
- request(`/plugins/${plugin}/transformation_rules`, {
- method: 'get',
- data: params
- })
diff --git a/config-ui/src/plugins/common/rule-selector/index.tsx
b/config-ui/src/plugins/common/rule-selector/index.tsx
deleted file mode 100644
index 5a9be4a18..000000000
--- a/config-ui/src/plugins/common/rule-selector/index.tsx
+++ /dev/null
@@ -1,43 +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 React from 'react'
-
-import { Selector } from '@/components'
-
-import type { RuleItem, UseRuleProps } from './use-rule'
-import { useRule } from './use-rule'
-
-interface Props extends UseRuleProps {
- selectedRule: RuleItem
- onChangeRule: (selectedRule: RuleItem) => void
-}
-
-export const RuleSelector = ({ plugin, selectedRule, onChangeRule }: Props) =>
{
- const { rules } = useRule({ plugin })
-
- return (
- <Selector
- items={rules}
- getKey={(it) => it.id}
- getName={(it) => it.name}
- selectedItem={selectedRule}
- onChangeItem={onChangeRule}
- />
- )
-}
diff --git a/config-ui/src/plugins/common/rule-selector/use-rule.ts
b/config-ui/src/plugins/common/rule-selector/use-rule.ts
deleted file mode 100644
index 09f982a8b..000000000
--- a/config-ui/src/plugins/common/rule-selector/use-rule.ts
+++ /dev/null
@@ -1,57 +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 { useEffect, useMemo, useState } from 'react'
-
-import { Plugins } from '@/plugins'
-
-import * as API from './api'
-
-export type RuleItem = {
- id: ID
- name: string
-}
-
-export interface UseRuleProps {
- plugin: Plugins
-}
-
-export const useRule = ({ plugin }: UseRuleProps) => {
- const [loading, setLoading] = useState(false)
- const [rules, setRules] = useState<RuleItem[]>([])
-
- useEffect(() => {
- ;(async () => {
- setLoading(true)
- try {
- const res = await API.getRules(plugin)
- setRules(res)
- } finally {
- setLoading(false)
- }
- })()
- }, [])
-
- return useMemo(
- () => ({
- loading,
- rules
- }),
- [loading, rules]
- )
-}
diff --git a/config-ui/src/pages/blueprint/create/step-four/index.tsx
b/config-ui/src/plugins/common/sync-policy/index.tsx
similarity index 59%
copy from config-ui/src/pages/blueprint/create/step-four/index.tsx
copy to config-ui/src/plugins/common/sync-policy/index.tsx
index cd3c42c1a..bb37ad642 100644
--- a/config-ui/src/pages/blueprint/create/step-four/index.tsx
+++ b/config-ui/src/plugins/common/sync-policy/index.tsx
@@ -16,80 +16,50 @@
*
*/
-import React, { useState, useEffect, useMemo } from 'react'
+import React, { useMemo } from 'react'
import {
RadioGroup,
Radio,
- Checkbox,
InputGroup,
Icon,
+ Checkbox,
Position
} from '@blueprintjs/core'
import { Popover2 } from '@blueprintjs/popover2'
-import { Divider } from '@/components'
+import StartFromSelector from '@/components/blueprints/StartFromSelector'
+import { getCron, getCronOptions } from '@/config'
import CronHelp from '@/images/cron-help.png'
-import { useBlueprint } from '../hooks'
-
import * as S from './styled'
-import StartFromSelector from "@/components/blueprints/StartFromSelector";
-
-const cronPresets = [
- {
- label: 'Hourly',
- config: '59 * * * *',
- desc: 'At minute 59 on every day-of-week from Monday through Sunday.'
- },
- {
- label: 'Daily',
- config: '0 0 * * *',
- desc: 'At 00:00 (Midnight) on every day-of-week from Monday through
Sunday.'
- },
- {
- label: 'Weekly',
- config: '0 0 * * 1',
- desc: 'At 00:00 (Midnight) on Monday.'
- },
- {
- label: 'Monthly',
- config: '0 0 1 * *',
- desc: 'At 00:00 (Midnight) on day-of-month 1.'
- }
-]
-
-export const StepFour = () => {
- const [frequency, setFrequency] = useState('')
- const {
- cronConfig,
- isManual,
- skipOnFail,
- createdDateAfter,
- onChangeCronConfig,
- onChangeIsManual,
- onChangeSkipOnFail,
- onChangeCreatedDateAfter
- } = useBlueprint()
+interface Props {
+ isManual: boolean
+ cronConfig: string
+ skipOnFail: boolean
+ createdDateAfter: string | null
+ onChangeIsManual: (val: boolean) => void
+ onChangeCronConfig: (val: string) => void
+ onChangeSkipOnFail: (val: boolean) => void
+ onChangeCreatedDateAfter: (val: string | null) => void
+}
- const description = useMemo(() => {
- switch (frequency) {
- case 'manual':
- return 'Manual'
- case 'custom':
- return 'Custom'
- default:
- return cronPresets.find((it) => it.config === frequency)?.desc ?? ''
- }
- }, [frequency])
+export const SyncPolicy = ({
+ isManual,
+ cronConfig,
+ skipOnFail,
+ createdDateAfter,
+ onChangeIsManual,
+ onChangeCronConfig,
+ onChangeSkipOnFail,
+ onChangeCreatedDateAfter
+}: Props) => {
+ const cron = useMemo(
+ () => getCron(isManual, cronConfig),
+ [isManual, cronConfig]
+ )
- useEffect(() => {
- if (isManual) {
- setFrequency('manual')
- } else if (frequency !== 'custom') {
- setFrequency(cronConfig)
- }
- }, [cronConfig, isManual])
+ const options = useMemo(() => getCronOptions(), [])
const handleChangeFrequency = (e: React.FormEvent<HTMLInputElement>) => {
const value = (e.target as HTMLInputElement).value
@@ -97,45 +67,42 @@ export const StepFour = () => {
onChangeIsManual(true)
} else if (value === 'custom') {
onChangeIsManual(false)
- setFrequency('custom')
+ onChangeCronConfig('* * * * *')
} else {
onChangeIsManual(false)
onChangeCronConfig(value)
- setFrequency(value)
}
}
- const handleChangeCronConfig = (e: React.ChangeEvent<HTMLInputElement>) => {
- onChangeCronConfig(e.target.value)
- }
-
return (
- <S.Card>
- <h2>Set Sync Policy</h2>
- <Divider />
+ <S.Wrapper>
<div className='block'>
- <h4>Time Filter *</h4>
- <p>Select the data range you wish to collect. DevLake will collect
the last six months of data by default.</p>
- <StartFromSelector
- autoFillDefault={true}
- date={createdDateAfter}
- onSave={onChangeCreatedDateAfter}
- />
+ <h3>Time Filter *</h3>
+ <p>
+ Select the data range you wish to collect. DevLake will collect the
+ last six months of data by default.
+ </p>
+ <StartFromSelector
+ autoFillDefault={true}
+ date={createdDateAfter}
+ onSave={onChangeCreatedDateAfter}
+ />
</div>
<div className='block'>
<h3>Frequency</h3>
<p>Blueprints will run recurringly based on the sync frequency.</p>
- <p style={{ margin: '10px 0' }}>{description}</p>
- <RadioGroup selectedValue={frequency} onChange={handleChangeFrequency}>
- <Radio label='Manual' value='manual' />
- {cronPresets.map((cron) => (
- <Radio key={cron.label} label={cron.label} value={cron.config} />
+ <p style={{ margin: '10px 0' }}>{cron.description}</p>
+ <RadioGroup selectedValue={cron.value}
onChange={handleChangeFrequency}>
+ {options.map(({ label, value }) => (
+ <Radio label={label} value={value} />
))}
- <Radio label='Custom' value='custom' />
</RadioGroup>
- {frequency === 'custom' && (
+ {cron.value === 'custom' && (
<S.Input>
- <InputGroup value={cronConfig} onChange={handleChangeCronConfig} />
+ <InputGroup
+ value={cronConfig}
+ onChange={(e) => onChangeCronConfig(e.target.value)}
+ />
<Popover2
position={Position.RIGHT}
content={
@@ -188,6 +155,6 @@ export const StepFour = () => {
finished, you can rerun these failed tasks.
</p>
</div>
- </S.Card>
+ </S.Wrapper>
)
}
diff --git a/config-ui/src/pages/blueprint/create/step-four/styled.ts
b/config-ui/src/plugins/common/sync-policy/styled.ts
similarity index 93%
rename from config-ui/src/pages/blueprint/create/step-four/styled.ts
rename to config-ui/src/plugins/common/sync-policy/styled.ts
index dc188a400..f5d2466c3 100644
--- a/config-ui/src/pages/blueprint/create/step-four/styled.ts
+++ b/config-ui/src/plugins/common/sync-policy/styled.ts
@@ -18,7 +18,15 @@
import styled from 'styled-components'
-export * from '../styled'
+export const Wrapper = styled.div`
+ .block + .block {
+ margin-top: 24px;
+ }
+`
+export const Input = styled.div`
+ display: flex;
+ align-items: center;
+`
export const Help = styled.div`
padding: 10px;
@@ -39,8 +47,3 @@ export const Help = styled.div`
width: 100%;
}
`
-
-export const Input = styled.div`
- display: flex;
- align-items: center;
-`
diff --git a/config-ui/src/plugins/common/transformation/api.ts
b/config-ui/src/plugins/common/transformation/api.ts
index 40b0a9737..8bf9ebe20 100644
--- a/config-ui/src/plugins/common/transformation/api.ts
+++ b/config-ui/src/plugins/common/transformation/api.ts
@@ -17,6 +17,34 @@
*/
import request from '@/components/utils/request'
+import { Plugins } from '@/plugins'
+
+type GetRulesParams = {
+ page: number
+ pageSize: number
+}
+
+export const getRules = (plugin: Plugins, params?: GetRulesParams) =>
+ request(`/plugins/${plugin}/transformation_rules`, {
+ method: 'get',
+ data: params
+ })
+
+export const getDataScopeRepo = (
+ plugin: Plugins,
+ connectionId: ID,
+ repoId: ID
+) => request(`/plugins/${plugin}/connections/${connectionId}/scopes/${repoId}`)
+
+export const updateDataScope = (
+ plugin: string,
+ connectionId: ID,
+ payload: any
+) =>
+ request(`/plugins/${plugin}/connections/${connectionId}/scopes`, {
+ method: 'put',
+ data: payload
+ })
export const createTransformation = (plugin: string, paylod: any) =>
request(`/plugins/${plugin}/transformation_rules`, {
diff --git a/config-ui/src/plugins/common/transformation/index.tsx
b/config-ui/src/plugins/common/transformation/index.tsx
index 3737e760e..d0e2f34af 100644
--- a/config-ui/src/plugins/common/transformation/index.tsx
+++ b/config-ui/src/plugins/common/transformation/index.tsx
@@ -16,8 +16,17 @@
*
*/
-import React from 'react'
-import { ButtonGroup, Button, Intent } from '@blueprintjs/core'
+import React, { useState } from 'react'
+import {
+ RadioGroup,
+ Radio,
+ InputGroup,
+ ButtonGroup,
+ Button,
+ Intent
+} from '@blueprintjs/core'
+
+import { Divider, Selector, MultiSelector } from '@/components'
import { Plugins } from '@/plugins'
import { GitHubTransformation } from '@/plugins/github'
@@ -25,77 +34,196 @@ import { JIRATransformation } from '@/plugins/jira'
import { GitLabTransformation } from '@/plugins/gitlab'
import { JenkinsTransformation } from '@/plugins/jenkins'
+import type { TransformationType, RuleItem } from './types'
import type { UseTransformationProps } from './use-transformation'
import { useTransformation } from './use-transformation'
import * as S from './styled'
-interface Props extends UseTransformationProps {
- connectionId: ID
+interface Props
+ extends Omit<
+ UseTransformationProps,
+ 'name' | 'selectedRule' | 'setSelectedScope'
+ > {
onCancel?: () => void
}
export const Transformation = ({
plugin,
connectionId,
- name,
- initialValues,
onCancel,
- onSaveAfter
+ ...props
}: Props) => {
- const { saving, transformation, setTransformation, onSave } =
- useTransformation({
- plugin,
- name,
- initialValues,
- onSaveAfter
- })
+ const [type, setType] = useState<TransformationType>()
+ const [name, setName] = useState('')
+ const [selectedRule, setSelectedRule] = useState<RuleItem>()
+ const [selectedScope, setSelectedScope] = useState<any>([])
+
+ const {
+ loading,
+ rules,
+ scope,
+ saving,
+ transformation,
+ getScopeKey,
+ onSave,
+ onUpdateScope,
+ onChangeTransformation
+ } = useTransformation({
+ ...props,
+ plugin,
+ connectionId,
+ name,
+ selectedRule,
+ selectedScope
+ })
+
+ const handleChangeType = (e: React.FormEvent<HTMLInputElement>) => {
+ setType((e.target as HTMLInputElement).value as TransformationType)
+ setSelectedRule(undefined)
+ }
return (
- <S.Container>
- {plugin === Plugins.GitHub && (
- <GitHubTransformation
- transformation={transformation}
- setTransformation={setTransformation}
- />
- )}
+ <S.Wrapper>
+ <div className='block'>
+ <h3>Create a New or Select an Existing Transformation *</h3>
+ <RadioGroup selectedValue={type} onChange={handleChangeType}>
+ <Radio
+ label='Create a new transformation from a blank template'
+ value='create'
+ />
+ <Radio
+ label='Create a new transformation by duplicating an exisitng
transformation as the template'
+ value='createByExist'
+ />
+ <Radio
+ label='Select an existing transformation'
+ value='selectExist'
+ />
+ </RadioGroup>
+ </div>
- {plugin === Plugins.JIRA && (
- <JIRATransformation
- connectionId={connectionId}
- transformation={transformation}
- setTransformation={setTransformation}
- />
+ {type && (
+ <>
+ <Divider />
+ <div className='block'>
+ {(type === 'createByExist' || type === 'selectExist') && (
+ <div className='item'>
+ <h3>Select a Transformation to Duplicate *</h3>
+ <p>
+ The selected transformation will be used as template that you
+ can tweak and save as a new transformation.
+ </p>
+ <Selector
+ items={rules}
+ getKey={(it) => it.id}
+ getName={(it) => it.name}
+ selectedItem={selectedRule}
+ onChangeItem={setSelectedRule}
+ />
+ </div>
+ )}
+ {type !== 'selectExist' && (
+ <div className='item'>
+ <h3>Transformation Name *</h3>
+ <p>
+ Give this set of transformation rules a unique name so that
+ you can identify it in the future.
+ </p>
+ <InputGroup
+ placeholder='Enter Transformation Name'
+ value={name}
+ onChange={(e) => setName(e.target.value)}
+ />
+ </div>
+ )}
+ <div className='item'>
+ <h3>Applied Data Scope</h3>
+ <p>
+ Select the data scope for which you want to apply this
+ transformation for.
+ </p>
+ <MultiSelector
+ loading={loading}
+ items={scope}
+ getKey={getScopeKey}
+ getName={(sc) => sc.name}
+ selectedItems={selectedScope}
+ onChangeItems={setSelectedScope}
+ />
+ {type === 'selectExist' && (
+ <ButtonGroup>
+ <Button
+ outlined
+ intent={Intent.PRIMARY}
+ text='Cancel and Go Back'
+ onClick={onCancel}
+ />
+ <Button
+ outlined
+ disabled={!selectedRule || !selectedScope.length}
+ intent={Intent.PRIMARY}
+ text='Save'
+ onClick={() => onUpdateScope(selectedRule?.id)}
+ />
+ </ButtonGroup>
+ )}
+ </div>
+ </div>
+ </>
)}
- {plugin === Plugins.GitLab && (
- <GitLabTransformation
- transformation={transformation}
- setTransformation={setTransformation}
- />
- )}
+ {(type === 'create' || (type === 'createByExist' && selectedRule)) && (
+ <>
+ <Divider />
+ <div className='block'>
+ {plugin === Plugins.GitHub && (
+ <GitHubTransformation
+ transformation={transformation}
+ setTransformation={onChangeTransformation}
+ />
+ )}
+
+ {plugin === Plugins.JIRA && (
+ <JIRATransformation
+ connectionId={connectionId}
+ transformation={transformation}
+ setTransformation={onChangeTransformation}
+ />
+ )}
+
+ {plugin === Plugins.GitLab && (
+ <GitLabTransformation
+ transformation={transformation}
+ setTransformation={onChangeTransformation}
+ />
+ )}
+
+ {plugin === Plugins.Jenkins && (
+ <JenkinsTransformation
+ transformation={transformation}
+ setTransformation={onChangeTransformation}
+ />
+ )}
- {plugin === Plugins.Jenkins && (
- <JenkinsTransformation
- transformation={transformation}
- setTransformation={setTransformation}
- />
+ <ButtonGroup>
+ <Button
+ outlined
+ intent={Intent.PRIMARY}
+ text='Cancel and Go Back'
+ onClick={onCancel}
+ />
+ <Button
+ outlined
+ disabled={!name}
+ loading={saving}
+ intent={Intent.PRIMARY}
+ text='Save'
+ onClick={onSave}
+ />
+ </ButtonGroup>
+ </div>
+ </>
)}
- <ButtonGroup>
- <Button
- outlined
- intent={Intent.PRIMARY}
- text='Cancel and Go Back'
- onClick={onCancel}
- />
- <Button
- outlined
- disabled={!name}
- loading={saving}
- intent={Intent.PRIMARY}
- text='Save'
- onClick={onSave}
- />
- </ButtonGroup>
- </S.Container>
+ </S.Wrapper>
)
}
diff --git a/config-ui/src/plugins/common/transformation/styled.ts
b/config-ui/src/plugins/common/transformation/styled.ts
index a6acb1f85..726f7dbba 100644
--- a/config-ui/src/plugins/common/transformation/styled.ts
+++ b/config-ui/src/plugins/common/transformation/styled.ts
@@ -18,23 +18,43 @@
import styled from '@emotion/styled'
-export const Container = styled.div`
- margin-top: 24px;
- padding: 24px;
- font-size: 12px;
- color: #292b3f;
- background-color: #fff;
- box-shadow: 0px 2.4px 4.8px -0.8px rgba(0, 0, 0, 0.1),
- 0px 1.6px 8px rgba(0, 0, 0, 0.07);
- border-radius: 8px;
-
- & > .bp4-button-group {
- display: block;
+export const Wrapper = styled.div`
+ .block {
+ padding: 8px 16px;
+ }
+
+ .item + .item {
margin-top: 16px;
- text-align: right;
+ }
+
+ h3 {
+ margin: 0 0 8px;
- .bp4-button + .bp4-button {
- margin-left: 4px;
+ .bp4-tag {
+ margin-left: 6px;
}
}
+
+ p {
+ margin: 0 0 8px;
+ }
+
+ .bp4-form-group {
+ display: flex;
+ align-items: center;
+
+ .bp4-label {
+ flex: 0 0 150px;
+ }
+
+ .bp4-form-content {
+ flex: auto;
+ }
+ }
+
+ .bp4-button-group {
+ display: flex;
+ justify-content: flex-end;
+ margin-top: 16px;
+ }
`
diff --git a/config-ui/src/pages/blueprint/create/hooks/use-blueprint.ts
b/config-ui/src/plugins/common/transformation/types.ts
similarity index 82%
rename from config-ui/src/pages/blueprint/create/hooks/use-blueprint.ts
rename to config-ui/src/plugins/common/transformation/types.ts
index d71c538af..7edac9e09 100644
--- a/config-ui/src/pages/blueprint/create/hooks/use-blueprint.ts
+++ b/config-ui/src/plugins/common/transformation/types.ts
@@ -16,10 +16,13 @@
*
*/
-import { useContext } from 'react'
+export type TransformationType = 'create' | 'createByExist' | 'selectExist'
-import { BlueprintContext } from './blueprint-context'
-
-export const useBlueprint = () => {
- return useContext(BlueprintContext)
+export type RuleItem = {
+ id: ID
+ name: string
}
+
+export type ScopeItem = {
+ name: string
+} & any
diff --git a/config-ui/src/plugins/common/transformation/use-transformation.ts
b/config-ui/src/plugins/common/transformation/use-transformation.ts
index 7aeca7cb5..443a39ae0 100644
--- a/config-ui/src/plugins/common/transformation/use-transformation.ts
+++ b/config-ui/src/plugins/common/transformation/use-transformation.ts
@@ -18,35 +18,93 @@
import { useState, useEffect, useMemo } from 'react'
+import { Plugins } from '@/plugins'
import { operator } from '@/utils'
+import type { RuleItem, ScopeItem } from './types'
import { defaultConfig } from './config'
-import { createTransformation } from './api'
+import * as API from './api'
export interface UseTransformationProps {
- plugin: string
+ plugin: Plugins
+ connectionId: ID
+ scopeIds: ID[]
name: string
- initialValues?: any
- onSaveAfter?: (tid: string | number) => void
+ selectedRule?: RuleItem
+ selectedScope?: ScopeItem[]
+ onSave?: () => void
}
export const useTransformation = ({
plugin,
+ connectionId,
+ scopeIds,
name,
- initialValues,
- onSaveAfter
+ selectedRule,
+ selectedScope,
+ onSave
}: UseTransformationProps) => {
+ const [loading, setLoading] = useState(false)
+ const [rules, setRules] = useState<RuleItem[]>([])
+ const [scope, setScope] = useState<ScopeItem[]>([])
const [saving, setSaving] = useState(false)
const [transformation, setTransformation] = useState({})
useEffect(() => {
- setTransformation(initialValues ? initialValues : defaultConfig[plugin])
- }, [initialValues, plugin])
+ setTransformation(selectedRule ? selectedRule : defaultConfig[plugin])
+ }, [selectedRule])
+
+ const getRules = async () => {
+ const res = await API.getRules(plugin)
+ setRules(res)
+ }
+
+ const getScope = async () => {
+ const res = await Promise.all(
+ scopeIds.map((id) => API.getDataScopeRepo(plugin, connectionId, id))
+ )
+ setScope(res)
+ }
+
+ const init = async () => {
+ setLoading(true)
+ try {
+ await getRules()
+ await getScope()
+ } finally {
+ setLoading(false)
+ }
+ }
+
+ useEffect(() => {
+ init()
+ }, [])
+
+ const handleUpdateScope = async (tid?: ID) => {
+ if (!tid) return
+
+ const payload = (selectedScope ?? []).map((sc: any) => ({
+ ...sc,
+ transformationRuleId: tid
+ }))
+
+ console.log(payload)
+
+ const [success] = await operator(() =>
+ API.updateDataScope(plugin, connectionId, {
+ data: payload
+ })
+ )
+
+ if (success) {
+ onSave?.()
+ }
+ }
const handleSave = async () => {
const [success, res] = await operator(
() =>
- createTransformation(plugin, {
+ API.createTransformation(plugin, {
...transformation,
name
}),
@@ -56,17 +114,53 @@ export const useTransformation = ({
)
if (success) {
- onSaveAfter?.(res.id)
+ const payload = (selectedScope ?? []).map((sc: any) => ({
+ ...sc,
+ transformationRuleId: res.id
+ }))
+
+ if (payload.length) {
+ API.updateDataScope(plugin, connectionId, {
+ data: payload
+ })
+ }
+
+ onSave?.()
}
}
return useMemo(
() => ({
+ loading,
+ rules,
+ scope,
saving,
transformation,
- setTransformation,
- onSave: handleSave
+ getScopeKey(sc: any) {
+ switch (true) {
+ case plugin === Plugins.GitHub:
+ return sc.githubId
+ case plugin === Plugins.JIRA:
+ return sc.boardId
+ case plugin === Plugins.GitLab:
+ return sc.gitlabId
+ case plugin === Plugins.Jenkins:
+ return sc.fullName
+ }
+ },
+ onSave: handleSave,
+ onUpdateScope: handleUpdateScope,
+ onChangeTransformation: setTransformation
}),
- [saving, transformation, name, onSaveAfter]
+ [
+ loading,
+ rules,
+ scope,
+ saving,
+ transformation,
+ plugin,
+ selectedScope,
+ onSave
+ ]
)
}
diff --git a/config-ui/src/plugins/github/data-scope.tsx
b/config-ui/src/plugins/github/data-scope.tsx
index 830eab46d..386e8721a 100644
--- a/config-ui/src/plugins/github/data-scope.tsx
+++ b/config-ui/src/plugins/github/data-scope.tsx
@@ -62,7 +62,7 @@ export const GitHubDataScope = ({
)}
onChangeItems={handleChangeMillerColumnsItems}
/>
- <h5>Add repositories outside of your organizations</h5>
+ <h4>Add repositories outside of your organizations</h4>
<p>Search for repositories and add to them</p>
<RepoSelector
connectionId={connectionId}
diff --git a/config-ui/src/plugins/github/transformation.tsx
b/config-ui/src/plugins/github/transformation.tsx
index ba5c9d18d..e3c64cf35 100644
--- a/config-ui/src/plugins/github/transformation.tsx
+++ b/config-ui/src/plugins/github/transformation.tsx
@@ -27,8 +27,6 @@ import {
AdditionalSettings
} from './components'
-import * as S from './styled'
-
interface Props {
transformation: any
setTransformation: React.Dispatch<React.SetStateAction<any>>
@@ -36,13 +34,13 @@ interface Props {
export const GitHubTransformation = ({ ...props }: Props) => {
return (
- <S.TransformationWrapper>
+ <>
<IssueTracking {...props} />
<Divider />
<CiCd {...props} />
<Divider />
<CodeReview {...props} />
<AdditionalSettings {...props} />
- </S.TransformationWrapper>
+ </>
)
}
diff --git a/config-ui/src/plugins/webook/connection/index.tsx
b/config-ui/src/plugins/webook/connection/index.tsx
index bd9330867..4b23dae57 100644
--- a/config-ui/src/plugins/webook/connection/index.tsx
+++ b/config-ui/src/plugins/webook/connection/index.tsx
@@ -84,9 +84,7 @@ export const WebHookConnection = () => {
onClick={() => handleShowDialog('add')}
/>
</ButtonGroup>
- <S.Inner>
- <Table loading={loading} columns={columns} dataSource={connections} />
- </S.Inner>
+ <Table loading={loading} columns={columns} dataSource={connections} />
{type === 'add' && (
<CreateDialog
isOpen
diff --git a/config-ui/src/plugins/webook/connection/styled.ts
b/config-ui/src/plugins/webook/connection/styled.ts
index 9ff4886f1..a4f511ab1 100644
--- a/config-ui/src/plugins/webook/connection/styled.ts
+++ b/config-ui/src/plugins/webook/connection/styled.ts
@@ -18,14 +18,10 @@
import styled from 'styled-components'
-export const Wrapper = styled.div``
-
-export const Inner = styled.div`
- margin-top: 16px;
- background-color: #fff;
- box-shadow: 0px 2.4px 4.8px -0.8px rgba(0, 0, 0, 0.1),
- 0px 1.6px 8px rgba(0, 0, 0, 0.07);
- border-radius: 8px;
+export const Wrapper = styled.div`
+ .bp4-button-group {
+ margin-bottom: 16px;
+ }
`
export const Action = styled.div`