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 dcf884484 refactor(config-ui): the blueprint setting page (#3932)
dcf884484 is described below
commit dcf8844848dc323f718b9d3a4113c2d315933415
Author: 青湛 <[email protected]>
AuthorDate: Thu Dec 15 10:33:22 2022 +0800
refactor(config-ui): the blueprint setting page (#3932)
---
config-ui/src/config/cron.ts | 11 +-
.../pages/blueprint/detail/blueprint-detail.tsx | 21 +-
.../detail/{types.ts => components/index.ts} | 10 +-
.../detail/components/update-name-dialog/index.tsx | 60 ++++++
.../components/update-policy-dialog/index.tsx | 85 ++++++++
.../components/update-scope-dialog/index.tsx | 69 ++++++
.../update-transformation-dialog/index.tsx} | 39 +++-
.../pages/blueprint/detail/panel/configuration.tsx | 235 +++++++++++++++++++++
.../detail/{types.ts => panel/status.tsx} | 9 +-
.../pages/blueprint/detail/{types.ts => styled.ts} | 61 +++++-
config-ui/src/pages/blueprint/detail/types.ts | 24 +++
config-ui/src/pages/blueprint/detail/use-detail.ts | 27 ++-
12 files changed, 617 insertions(+), 34 deletions(-)
diff --git a/config-ui/src/config/cron.ts b/config-ui/src/config/cron.ts
index bb396ca72..38fa11937 100644
--- a/config-ui/src/config/cron.ts
+++ b/config-ui/src/config/cron.ts
@@ -16,6 +16,8 @@
*
*/
+import parser from 'cron-parser'
+
export const cronPresets = [
{
label: 'Hourly',
@@ -46,7 +48,8 @@ export const getCron = (isManual: boolean, config: string) =>
{
label: 'Manual',
value: 'manual',
description: 'Manual',
- config: ''
+ config: '',
+ nextTime: ''
}
}
@@ -55,13 +58,15 @@ export const getCron = (isManual: boolean, config: string)
=> {
return preset
? {
...preset,
- value: preset.config
+ value: preset.config,
+ nextTime: parser.parseExpression(preset.config).next().toString()
}
: {
label: 'Custom',
value: 'custom',
description: 'Custom',
- config
+ config,
+ nextTime: parser.parseExpression(config).next().toString()
}
}
diff --git a/config-ui/src/pages/blueprint/detail/blueprint-detail.tsx
b/config-ui/src/pages/blueprint/detail/blueprint-detail.tsx
index 663bac67c..6efa3834c 100644
--- a/config-ui/src/pages/blueprint/detail/blueprint-detail.tsx
+++ b/config-ui/src/pages/blueprint/detail/blueprint-detail.tsx
@@ -20,21 +20,23 @@ import React, { useState } from 'react'
import type { TabId } from '@blueprintjs/core'
import { Tabs, Tab } from '@blueprintjs/core'
-// TO-DO: use new panel to replace it
-import Status from '@/pages/blueprints/blueprint-detail'
-import Configuration from '@/pages/blueprints/blueprint-settings'
-
import { PageLoading } from '@/components'
import type { UseDetailProps } from './use-detail'
import { useDetail } from './use-detail'
+import { Configuration } from './panel/configuration'
+// TO-DO: use new panel to replace it
+// import { Status } from './panel/status'
+import Status from '@/pages/blueprints/blueprint-detail'
interface Props extends UseDetailProps {}
export const BlueprintDetail = ({ id }: Props) => {
const [activeTab, setActiveTab] = useState<TabId>('configuration')
- const { loading, blueprint, saving, onUpdate } = useDetail({ id })
+ const { loading, blueprint, connections, saving, onUpdate } = useDetail({
+ id
+ })
if (loading || !blueprint) {
return <PageLoading />
@@ -46,7 +48,14 @@ export const BlueprintDetail = ({ id }: Props) => {
<Tab
id='configuration'
title='Configuration'
- panel={<Configuration id={id} />}
+ panel={
+ <Configuration
+ blueprint={blueprint}
+ connections={connections}
+ saving={saving}
+ onUpdate={onUpdate}
+ />
+ }
/>
</Tabs>
)
diff --git a/config-ui/src/pages/blueprint/detail/types.ts
b/config-ui/src/pages/blueprint/detail/components/index.ts
similarity index 83%
copy from config-ui/src/pages/blueprint/detail/types.ts
copy to config-ui/src/pages/blueprint/detail/components/index.ts
index cc55cda89..3d9f70e7c 100644
--- a/config-ui/src/pages/blueprint/detail/types.ts
+++ b/config-ui/src/pages/blueprint/detail/components/index.ts
@@ -16,9 +16,7 @@
*
*/
-export type BlueprintType = {
- id: ID
- name: string
- isManual: boolean
- cronConfig: string
-}
+export * from './update-name-dialog'
+export * from './update-policy-dialog'
+export * from './update-scope-dialog'
+export * from './update-transformation-dialog'
diff --git
a/config-ui/src/pages/blueprint/detail/components/update-name-dialog/index.tsx
b/config-ui/src/pages/blueprint/detail/components/update-name-dialog/index.tsx
new file mode 100644
index 000000000..b8f500396
--- /dev/null
+++
b/config-ui/src/pages/blueprint/detail/components/update-name-dialog/index.tsx
@@ -0,0 +1,60 @@
+/*
+ * 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, useEffect } from 'react'
+import { InputGroup } from '@blueprintjs/core'
+
+import { Dialog } from '@/components'
+
+interface Props {
+ name: string
+ saving: boolean
+ onCancel: () => void
+ onSubmit: (name: string) => void
+}
+
+export const UpdateNameDialog = ({
+ saving,
+ onCancel,
+ onSubmit,
+ ...props
+}: Props) => {
+ const [name, setName] = useState('')
+
+ useEffect(() => {
+ setName(props.name)
+ }, [props.name])
+
+ return (
+ <Dialog
+ isOpen
+ title='Change Blueprint Name'
+ okText='Save'
+ okDisabled={!name || name === props.name}
+ okLoading={saving}
+ onCancel={onCancel}
+ onOk={() => onSubmit(name)}
+ >
+ <h3>Blueprint Name</h3>
+ <p>
+ Give your Blueprint a unique name to help you identify it in the
future.
+ </p>
+ <InputGroup value={name} onChange={(e) => setName(e.target.value)} />
+ </Dialog>
+ )
+}
diff --git
a/config-ui/src/pages/blueprint/detail/components/update-policy-dialog/index.tsx
b/config-ui/src/pages/blueprint/detail/components/update-policy-dialog/index.tsx
new file mode 100644
index 000000000..cf5469363
--- /dev/null
+++
b/config-ui/src/pages/blueprint/detail/components/update-policy-dialog/index.tsx
@@ -0,0 +1,85 @@
+/*
+ * 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, useEffect } from 'react'
+
+import { Dialog } from '@/components'
+import { SyncPolicy } from '@/plugins'
+
+interface Props {
+ isManual: boolean
+ cronConfig: string
+ skipOnFail: boolean
+ createdDateAfter: string | null
+ saving: boolean
+ onCancel: () => void
+ onSubmit: (params: any) => Promise<void>
+}
+
+export const UpdatePolicyDialog = ({
+ saving,
+ onCancel,
+ onSubmit,
+ ...props
+}: Props) => {
+ const [isManual, setIsManual] = useState(false)
+ const [cronConfig, setCronConfig] = useState('')
+ const [skipOnFail, setSkipOnFail] = useState(false)
+ const [createdDateAfter, setCreatedDateAfter] = useState<string | null>(null)
+
+ useEffect(() => {
+ setIsManual(props.isManual)
+ setCronConfig(props.cronConfig)
+ setSkipOnFail(props.skipOnFail)
+ setCreatedDateAfter(props.createdDateAfter)
+ }, [props])
+
+ const handleSubmit = () => {
+ onSubmit({
+ isManual,
+ cronConfig,
+ skipOnFail,
+ createdDateAfter
+ })
+ }
+
+ return (
+ <Dialog
+ isOpen
+ title='Change Sync Policy'
+ style={{
+ width: 720
+ }}
+ okText='Save'
+ okLoading={saving}
+ onCancel={onCancel}
+ onOk={handleSubmit}
+ >
+ <SyncPolicy
+ isManual={isManual}
+ cronConfig={cronConfig}
+ skipOnFail={skipOnFail}
+ createdDateAfter={createdDateAfter}
+ onChangeIsManual={setIsManual}
+ onChangeCronConfig={setCronConfig}
+ onChangeSkipOnFail={setSkipOnFail}
+ onChangeCreatedDateAfter={setCreatedDateAfter}
+ />
+ </Dialog>
+ )
+}
diff --git
a/config-ui/src/pages/blueprint/detail/components/update-scope-dialog/index.tsx
b/config-ui/src/pages/blueprint/detail/components/update-scope-dialog/index.tsx
new file mode 100644
index 000000000..85803d5ab
--- /dev/null
+++
b/config-ui/src/pages/blueprint/detail/components/update-scope-dialog/index.tsx
@@ -0,0 +1,69 @@
+/*
+ * 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 { Dialog } from '@/components'
+import { DataScope } from '@/plugins'
+
+import type { ConnectionItemType } from '../../types'
+
+interface Props {
+ connection?: ConnectionItemType
+ onCancel: () => void
+ onSubmit: (connection: any) => void
+}
+
+export const UpdateScopeDialog = ({
+ connection,
+ onCancel,
+ onSubmit
+}: Props) => {
+ if (!connection) return null
+
+ const { plugin, connectionId, entities } = connection
+
+ const handleSaveScope = (sc: any) => {
+ onSubmit({
+ plugin,
+ connectionId,
+ scopes: sc.map((it: any) => ({
+ ...it,
+ id: `${it.id}`
+ }))
+ })
+ }
+
+ return (
+ <Dialog
+ isOpen
+ title='Change Data Scope'
+ footer={null}
+ style={{ width: 900 }}
+ onCancel={onCancel}
+ >
+ <DataScope
+ plugin={plugin}
+ connectionId={connectionId}
+ entities={entities}
+ onCancel={onCancel}
+ onSave={handleSaveScope}
+ />
+ </Dialog>
+ )
+}
diff --git a/config-ui/src/pages/blueprint/detail/types.ts
b/config-ui/src/pages/blueprint/detail/components/update-transformation-dialog/index.tsx
similarity index 51%
copy from config-ui/src/pages/blueprint/detail/types.ts
copy to
config-ui/src/pages/blueprint/detail/components/update-transformation-dialog/index.tsx
index cc55cda89..fc16400bf 100644
--- a/config-ui/src/pages/blueprint/detail/types.ts
+++
b/config-ui/src/pages/blueprint/detail/components/update-transformation-dialog/index.tsx
@@ -16,9 +16,38 @@
*
*/
-export type BlueprintType = {
- id: ID
- name: string
- isManual: boolean
- cronConfig: string
+import React from 'react'
+
+import { Dialog } from '@/components'
+import { Transformation } from '@/plugins'
+
+import type { ConnectionItemType } from '../../types'
+
+interface Props {
+ connection?: ConnectionItemType
+ onCancel: () => void
+}
+
+export const UpdateTransformationDialog = ({ connection, onCancel }: Props) =>
{
+ if (!connection) return null
+
+ const { plugin, connectionId, scopeIds } = connection
+
+ return (
+ <Dialog
+ isOpen
+ title='Change Data Scope'
+ footer={null}
+ style={{ width: 900 }}
+ onCancel={onCancel}
+ >
+ <Transformation
+ plugin={plugin}
+ connectionId={connectionId}
+ scopeIds={scopeIds}
+ onCancel={onCancel}
+ onSave={onCancel}
+ />
+ </Dialog>
+ )
}
diff --git a/config-ui/src/pages/blueprint/detail/panel/configuration.tsx
b/config-ui/src/pages/blueprint/detail/panel/configuration.tsx
new file mode 100644
index 000000000..97fd20a6a
--- /dev/null
+++ b/config-ui/src/pages/blueprint/detail/panel/configuration.tsx
@@ -0,0 +1,235 @@
+/*
+ * 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 } from 'react'
+import { Icon, Colors } from '@blueprintjs/core'
+import dayjs from 'dayjs'
+
+import { Table, ColumnType } from '@/components'
+import { getCron } from '@/config'
+import { DataScopeList } from '@/plugins'
+
+import type { BlueprintType, ConnectionItemType } from '../types'
+import {
+ UpdateNameDialog,
+ UpdatePolicyDialog,
+ UpdateScopeDialog,
+ UpdateTransformationDialog
+} from '../components'
+import * as S from '../styled'
+
+type Type = 'name' | 'frequency' | 'scope' | 'transformation'
+
+interface Props {
+ blueprint: BlueprintType
+ connections: ConnectionItemType[]
+ saving: boolean
+ onUpdate: (bp: any) => Promise<void>
+}
+
+export const Configuration = ({
+ blueprint,
+ connections,
+ saving,
+ onUpdate
+}: Props) => {
+ const [type, setType] = useState<Type>()
+ const [curConnection, setCurConnection] = useState<ConnectionItemType>()
+
+ const cron = useMemo(
+ () => getCron(blueprint.isManual, blueprint.cronConfig),
+ [blueprint]
+ )
+
+ const handleCancel = () => {
+ setType(undefined)
+ }
+
+ const handleUpdateName = async (name: string) => {
+ await onUpdate({ name })
+ handleCancel()
+ }
+
+ const handleUpdatePolicy = async (policy: any) => {
+ await onUpdate(policy)
+ handleCancel
+ }
+
+ const handleUpdateConnection = async (updated: any) => {
+ await onUpdate({
+ settings: {
+ version: '2.0.0',
+ connections: blueprint.settings.connections.map((cs) =>
+ cs.plugin === updated.plugin &&
+ cs.connectionId === updated.connectionId
+ ? updated
+ : cs
+ )
+ }
+ })
+ }
+
+ const columns = useMemo(
+ () =>
+ [
+ {
+ title: 'Data Connections',
+ dataIndex: ['icon', 'name'],
+ key: 'connection',
+ render: ({
+ icon,
+ name
+ }: Pick<ConnectionItemType, 'icon' | 'name'>) => (
+ <S.ConnectionColumn>
+ <img src={icon} alt='' />
+ <span>{name}</span>
+ </S.ConnectionColumn>
+ )
+ },
+ {
+ title: 'Data Entities',
+ dataIndex: 'entities',
+ key: 'entities',
+ render: (val: string[]) => (
+ <>
+ {val.map((it) => (
+ <div>{it}</div>
+ ))}
+ </>
+ )
+ },
+ {
+ title: 'Data Scope and Transformation',
+ dataIndex: ['plugin', 'connectionId', 'scopeIds'],
+ key: 'sopce',
+ render: ({
+ plugin,
+ connectionId,
+ scopeIds
+ }: Pick<
+ ConnectionItemType,
+ 'plugin' | 'connectionId' | 'scopeIds'
+ >) => (
+ <DataScopeList
+ groupByTs
+ plugin={plugin}
+ connectionId={connectionId}
+ scopeIds={scopeIds}
+ />
+ )
+ },
+ {
+ title: '',
+ key: 'action',
+ align: 'center',
+ render: (_, row: ConnectionItemType) => (
+ <S.ActionColumn>
+ <div
+ className='item'
+ onClick={() => {
+ setType('scope')
+ setCurConnection(row)
+ }}
+ >
+ <Icon icon='annotation' color={Colors.BLUE2} />
+ <span>Change Data Scope</span>
+ </div>
+ <div
+ className='item'
+ onClick={() => {
+ setType('transformation')
+ setCurConnection(row)
+ }}
+ >
+ <Icon icon='annotation' color={Colors.BLUE2} />
+ <span>Change Transformation</span>
+ </div>
+ </S.ActionColumn>
+ )
+ }
+ ] as ColumnType<ConnectionItemType>,
+ []
+ )
+
+ return (
+ <S.ConfigurationPanel>
+ <div className='top'>
+ <div className='block'>
+ <h3>Name</h3>
+ <div className='detail'>
+ <span>{blueprint.name}</span>
+ <Icon
+ icon='annotation'
+ color={Colors.BLUE2}
+ onClick={() => setType('name')}
+ />
+ </div>
+ </div>
+ <div className='block'>
+ <h3>Sync Policy</h3>
+ <div className='detail'>
+ <span>
+ {cron.label}({dayjs(cron.nextTime).format('HH:mm A')})
+ </span>
+ <Icon
+ icon='annotation'
+ color={Colors.BLUE2}
+ onClick={() => setType('frequency')}
+ />
+ </div>
+ </div>
+ </div>
+ <div className='bottom'>
+ <h3>Data Scope and Transformation</h3>
+ <Table columns={columns} dataSource={connections} />
+ </div>
+ {type === 'name' && (
+ <UpdateNameDialog
+ name={blueprint.name}
+ saving={saving}
+ onCancel={handleCancel}
+ onSubmit={handleUpdateName}
+ />
+ )}
+ {type === 'frequency' && (
+ <UpdatePolicyDialog
+ isManual={blueprint.isManual}
+ cronConfig={blueprint.cronConfig}
+ skipOnFail={blueprint.skipOnFail}
+ createdDateAfter={blueprint.createdDateAfter}
+ saving={saving}
+ onCancel={handleCancel}
+ onSubmit={handleUpdatePolicy}
+ />
+ )}
+ {type === 'scope' && (
+ <UpdateScopeDialog
+ connection={curConnection}
+ onCancel={handleCancel}
+ onSubmit={handleUpdateConnection}
+ />
+ )}
+ {type === 'transformation' && (
+ <UpdateTransformationDialog
+ connection={curConnection}
+ onCancel={handleCancel}
+ />
+ )}
+ </S.ConfigurationPanel>
+ )
+}
diff --git a/config-ui/src/pages/blueprint/detail/types.ts
b/config-ui/src/pages/blueprint/detail/panel/status.tsx
similarity index 89%
copy from config-ui/src/pages/blueprint/detail/types.ts
copy to config-ui/src/pages/blueprint/detail/panel/status.tsx
index cc55cda89..262dd52b9 100644
--- a/config-ui/src/pages/blueprint/detail/types.ts
+++ b/config-ui/src/pages/blueprint/detail/panel/status.tsx
@@ -16,9 +16,8 @@
*
*/
-export type BlueprintType = {
- id: ID
- name: string
- isManual: boolean
- cronConfig: string
+import React from 'react'
+
+export const Status = () => {
+ return <div>Status</div>
}
diff --git a/config-ui/src/pages/blueprint/detail/types.ts
b/config-ui/src/pages/blueprint/detail/styled.ts
similarity index 51%
copy from config-ui/src/pages/blueprint/detail/types.ts
copy to config-ui/src/pages/blueprint/detail/styled.ts
index cc55cda89..f821b1f50 100644
--- a/config-ui/src/pages/blueprint/detail/types.ts
+++ b/config-ui/src/pages/blueprint/detail/styled.ts
@@ -16,9 +16,58 @@
*
*/
-export type BlueprintType = {
- id: ID
- name: string
- isManual: boolean
- cronConfig: string
-}
+import styled from 'styled-components'
+
+export const ConfigurationPanel = styled.div`
+ .top {
+ display: flex;
+ align-items: flex-start;
+
+ .block + .block {
+ margin-left: 32px;
+ }
+
+ h3 {
+ margin: 0 0 8px;
+ }
+
+ .detail {
+ .bp4-icon {
+ margin-left: 4px;
+ cursor: pointer;
+ }
+ }
+ }
+
+ .bottom {
+ margin-top: 32px;
+ }
+`
+
+export const ConnectionColumn = styled.div`
+ display: flex;
+ align-items: center;
+
+ img {
+ margin-right: 4px;
+ width: 20px;
+ }
+`
+
+export const ActionColumn = styled.div`
+ display: flex;
+ flex-direction: column;
+ align-items: flex-start;
+
+ .item + .item {
+ margin-top: 8px;
+ }
+
+ .item {
+ cursor: pointer;
+
+ .bp4-icon {
+ margin-right: 4px;
+ }
+ }
+`
diff --git a/config-ui/src/pages/blueprint/detail/types.ts
b/config-ui/src/pages/blueprint/detail/types.ts
index cc55cda89..67a13fb2e 100644
--- a/config-ui/src/pages/blueprint/detail/types.ts
+++ b/config-ui/src/pages/blueprint/detail/types.ts
@@ -16,9 +16,33 @@
*
*/
+import { Plugins } from '@/plugins'
+
+export type ConnectionItemType = {
+ icon: string
+ name: string
+ connectionId: ID
+ plugin: Plugins
+ entities: string[]
+ scopeIds: ID[]
+}
+
export type BlueprintType = {
id: ID
name: string
isManual: boolean
cronConfig: string
+ skipOnFail: boolean
+ createdDateAfter: null | string
+ settings: {
+ version: string
+ connections: Array<{
+ plugin: Plugins
+ connectionId: ID
+ scopes: Array<{
+ id: ID
+ entities: string[]
+ }>
+ }>
+ }
}
diff --git a/config-ui/src/pages/blueprint/detail/use-detail.ts
b/config-ui/src/pages/blueprint/detail/use-detail.ts
index 8351d18f3..d3bfe1335 100644
--- a/config-ui/src/pages/blueprint/detail/use-detail.ts
+++ b/config-ui/src/pages/blueprint/detail/use-detail.ts
@@ -19,8 +19,9 @@
import { useState, useEffect, useMemo } from 'react'
import { operator } from '@/utils'
+import { Plugins } from '@/registry'
-import type { BlueprintType } from './types'
+import type { BlueprintType, ConnectionItemType } from './types'
import * as API from './api'
export interface UseDetailProps {
@@ -31,12 +32,31 @@ export const useDetail = ({ id }: UseDetailProps) => {
const [loading, setLoading] = useState(false)
const [saving, setSaving] = useState(false)
const [blueprint, setBlueprint] = useState<BlueprintType>()
+ const [connections, setConnections] = useState<ConnectionItemType[]>([])
+
+ const transformConnection = (connections: any) => {
+ return connections
+ .map((cs: any) => {
+ const plugin = Plugins.find((plugin) => plugin.id === cs.plugin) as any
+ if (!plugin) return null
+ return {
+ icon: `/${plugin.icon}`,
+ name: plugin.name,
+ connectionId: cs.connectionId,
+ entities: cs.scopes[0].entities,
+ plugin: cs.plugin,
+ scopeIds: cs.scopes.map((sc: any) => sc.id)
+ }
+ })
+ .filter(Boolean)
+ }
const getBlueprint = async () => {
setLoading(true)
try {
const res = await API.getBlueprint(id)
setBlueprint(res)
+ setConnections(transformConnection(res.settings.connections))
} finally {
setLoading(false)
}
@@ -59,7 +79,7 @@ export const useDetail = ({ id }: UseDetailProps) => {
)
if (success) {
- setBlueprint(res)
+ getBlueprint()
}
}
@@ -68,8 +88,9 @@ export const useDetail = ({ id }: UseDetailProps) => {
loading,
saving,
blueprint,
+ connections,
onUpdate: handleUpdate
}),
- [loading, saving, blueprint]
+ [loading, saving, blueprint, connections]
)
}