You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by GitBox <gi...@apache.org> on 2022/12/14 04:58:42 UTC

[GitHub] [incubator-devlake] likyh commented on a diff in pull request #3925: refactor(config-ui): the create blueprint page

likyh commented on code in PR #3925:
URL: https://github.com/apache/incubator-devlake/pull/3925#discussion_r1048017799


##########
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)

Review Comment:
   delete debug code



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@devlake.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org