orenccl commented on code in PR #6025:
URL: https://github.com/apache/gravitino/pull/6025#discussion_r1898537514


##########
web/web/src/app/metalakes/metalake/MetalakeView.js:
##########
@@ -124,7 +140,9 @@ const MetalakeView = () => {
                 routeParams.schema ? `{{${routeParams.schema}}}` : ''
               }${routeParams.table ? `{{${routeParams.table}}}` : ''}${
                 routeParams.fileset ? `{{${routeParams.fileset}}}` : ''
-              }${routeParams.topic ? `{{${routeParams.topic}}}` : ''}`
+              }${routeParams.topic ? `{{${routeParams.topic}}}` : ''}${
+                routeParams.model ? `{{${routeParams.model}}}` : ''
+              }${routeParams.version ? `{{${routeParams.version}}}` : ''}`

Review Comment:
   This code is hard to read. Consider improving the formatting or simplifying 
it.



##########
docs/webui.md:
##########
@@ -527,19 +575,137 @@ Displays a confirmation dialog, clicking on the `DROP` 
button drops this fileset
 ![delete-fileset](./assets/webui/delete-fileset.png)
 
 ### Topic
+Click the kafka schema tree node on the left sidebar or the schema name link 
in the table cell.
+
+Displays the list topics of the schema.
+
+![list-topics](./assets/webui/list-topics.png)
+
+#### Create topic
+
+Click on the `CREATE TOPIC` button displays the dialog to create a topic.
+
+![create-topic](./assets/webui/create-topic.png)
+
+Creating a topic needs these fields:
+
+1. **Name**(**_required_**): the name of the topic.
+2. **Comment**(_optional_): the comment of the topic.
+3. **Properties**(_optional_): Click on the `ADD PROPERTY` button to add 
custom properties.
+
+#### Show topic details
+
+Click on the action icon <Icon icon='bx:show-alt' fontSize='24' /> in the 
table cell.
+
+You can see the detailed information of this topic in the drawer component on 
the right.
+
+![topic-details](./assets/webui/topic-drawer-details.png)
+
+Click the topic tree node on the left sidebar or the topic name link in the 
table cell.
+
+You can see the detailed information on the right page.
 
 ![topic-details](./assets/webui/topic-details.png)
 
+#### Edit topic
+
+Click on the action icon <Icon icon='mdi:square-edit-outline' fontSize='24' /> 
in the table cell.
+
+Displays the dialog for modifying fields of the selected topic.
+
+![update-topic-dialog](./assets/webui/update-topic-dialog.png)
+
+#### Drop topic
+
+Click on the action icon <Icon icon='mdi:delete-outline' fontSize='24' 
color='red' /> in the table cell.
+
+Displays a confirmation dialog, clicking on the `DROP` button drops this 
fileset.

Review Comment:
   ... drop this topic.



##########
web/web/src/app/metalakes/metalake/rightContent/LinkVersionDialog.js:
##########
@@ -0,0 +1,504 @@
+/*
+ * 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.
+ */
+
+'use client'
+
+import { useState, forwardRef, useEffect, Fragment } from 'react'
+
+import {
+  Box,
+  Button,
+  Dialog,
+  DialogActions,
+  DialogContent,
+  Fade,
+  FormControl,
+  FormHelperText,
+  Grid,
+  IconButton,
+  InputLabel,
+  TextField,
+  Typography
+} from '@mui/material'
+
+import Icon from '@/components/Icon'
+
+import { useAppDispatch } from '@/lib/hooks/useStore'
+import { linkVersion } from '@/lib/store/metalakes'
+
+import * as yup from 'yup'
+import { useForm, Controller, useFieldArray } from 'react-hook-form'
+import { yupResolver } from '@hookform/resolvers/yup'
+
+import { groupBy } from 'lodash-es'
+import { keyRegex } from '@/lib/utils/regex'
+import { useSearchParams } from 'next/navigation'
+import { useAppSelector } from '@/lib/hooks/useStore'
+
+const defaultValues = {
+  uri: '',
+  aliases: [{ name: '' }],
+  comment: '',
+  propItems: []
+}
+
+const schema = yup.object().shape({
+  uri: yup.string().required(),
+  aliases: yup
+    .array()
+    .of(
+      yup.object().shape({
+        name: yup
+          .string()
+          .required('This aliase is required')
+          .test('not-number', 'Aliase cannot be a number or numeric string', 
value => {
+            return value === undefined || isNaN(Number(value))
+          })
+      })
+    )
+    .test('unique', 'Aliase must be unique', (aliases, ctx) => {
+      const values = aliases?.filter(a => !!a.name).map(a => a.name)
+      const duplicates = values.filter((value, index, self) => 
self.indexOf(value) !== index)
+
+      if (duplicates.length > 0) {
+        const duplicateIndex = values.lastIndexOf(duplicates[0])
+
+        return ctx.createError({
+          path: `aliases.${duplicateIndex}.name`,
+          message: 'This aliase is duplicated'
+        })
+      }
+
+      return true
+    }),
+  propItems: yup.array().of(
+    yup.object().shape({
+      required: yup.boolean(),
+      key: yup.string().required(),
+      value: yup.string().when('required', {
+        is: true,
+        then: schema => schema.required()
+      })
+    })
+  )
+})
+
+const Transition = forwardRef(function Transition(props, ref) {
+  return <Fade ref={ref} {...props} />
+})
+
+const LinkVersionDialog = props => {
+  const { open, setOpen, type = 'create', data = {} } = props
+  const searchParams = useSearchParams()
+  const metalake = searchParams.get('metalake')
+  const catalog = searchParams.get('catalog')
+  const schemaName = searchParams.get('schema')
+  const catalogType = searchParams.get('type')
+  const model = searchParams.get('model')
+  const [innerProps, setInnerProps] = useState([])
+  const dispatch = useAppDispatch()
+  const store = useAppSelector(state => state.metalakes)
+  const [cacheData, setCacheData] = useState()
+
+  const {
+    control,
+    reset,
+    watch,
+    setValue,
+    getValues,
+    handleSubmit,
+    trigger,
+    formState: { errors }
+  } = useForm({
+    defaultValues,
+    mode: 'all',
+    resolver: yupResolver(schema)
+  })
+
+  const handleFormChange = ({ index, event }) => {
+    let data = [...innerProps]
+    data[index][event.target.name] = event.target.value
+
+    if (event.target.name === 'key') {
+      const invalidKey = !keyRegex.test(event.target.value)
+      data[index].invalid = invalidKey
+    }
+
+    const nonEmptyKeys = data.filter(item => item.key.trim() !== '')
+    const grouped = groupBy(nonEmptyKeys, 'key')
+    const duplicateKeys = Object.keys(grouped).some(key => grouped[key].length 
> 1)

Review Comment:
   Just realize `groupBy` does not trim `key`.
   So " key1" and "key1" may not be detected as duplicates, right?
   
   ```javascript
   const nonEmptyKeys = data
     .filter(item => item.key.trim() !== '') // Filter out empty keys
     .map(item => ({ ...item, key: item.key.trim() })); // Trim the key
   
   const grouped = groupBy(nonEmptyKeys, 'key'); // Group by the trimmed key
   ```



##########
docs/webui.md:
##########
@@ -527,19 +575,137 @@ Displays a confirmation dialog, clicking on the `DROP` 
button drops this fileset
 ![delete-fileset](./assets/webui/delete-fileset.png)
 
 ### Topic
+Click the kafka schema tree node on the left sidebar or the schema name link 
in the table cell.
+
+Displays the list topics of the schema.
+
+![list-topics](./assets/webui/list-topics.png)
+
+#### Create topic
+
+Click on the `CREATE TOPIC` button displays the dialog to create a topic.
+
+![create-topic](./assets/webui/create-topic.png)
+
+Creating a topic needs these fields:
+
+1. **Name**(**_required_**): the name of the topic.
+2. **Comment**(_optional_): the comment of the topic.
+3. **Properties**(_optional_): Click on the `ADD PROPERTY` button to add 
custom properties.
+
+#### Show topic details
+
+Click on the action icon <Icon icon='bx:show-alt' fontSize='24' /> in the 
table cell.
+
+You can see the detailed information of this topic in the drawer component on 
the right.
+
+![topic-details](./assets/webui/topic-drawer-details.png)
+
+Click the topic tree node on the left sidebar or the topic name link in the 
table cell.
+
+You can see the detailed information on the right page.
 
 ![topic-details](./assets/webui/topic-details.png)
 
+#### Edit topic
+
+Click on the action icon <Icon icon='mdi:square-edit-outline' fontSize='24' /> 
in the table cell.
+
+Displays the dialog for modifying fields of the selected topic.
+
+![update-topic-dialog](./assets/webui/update-topic-dialog.png)
+
+#### Drop topic
+
+Click on the action icon <Icon icon='mdi:delete-outline' fontSize='24' 
color='red' /> in the table cell.
+
+Displays a confirmation dialog, clicking on the `DROP` button drops this 
fileset.
+
+![delete-topic](./assets/webui/delete-topic.png)
+
+### Model
+Click the model schema tree node on the left sidebar or the schema name link 
in the table cell.
+
+Displays the list model of the schema.
+
+![list-models](./assets/webui/list-models.png)
+
+#### Register model
+
+Click on the `REGISTER MODEL` button displays the dialog to register a model.
+
+![register-model](./assets/webui/register-model.png)
+
+Register a model needs these fields:
+
+1. **Name**(**_required_**): the name of the model.
+2. **Comment**(_optional_): the comment of the model.
+3. **Properties**(_optional_): Click on the `ADD PROPERTY` button to add 
custom properties.
+
+#### Show model details
+
+Click on the action icon <Icon icon='bx:show-alt' fontSize='24' /> in the 
table cell.
+
+You can see the detailed information of this model in the drawer component on 
the right.
+
+![model-details](./assets/webui/model-details.png)
+
+#### Drop model
+
+Click on the action icon <Icon icon='mdi:delete-outline' fontSize='24' 
color='red' /> in the table cell.
+
+Displays a confirmation dialog, clicking on the `DROP` button drops this model.
+
+![delete-model](./assets/webui/delete-model.png)
+
+### Version
+Click the model tree node on the left sidebar or the model name link in the 
table cell.
+
+Displays the list versions of the model.
+
+![list-model-versions](./assets/webui/list-model-versions.png)
+
+#### Link version
+
+Click on the `LINK VERSION` button displays the dialog to link a version.
+
+![link-version](./assets/webui/link-version.png)
+
+Link a version needs these fields:
+
+1. **URI**(**_required_**): the uri of the version.
+2. **Aliases**(**_required_**): the aliases of the version, aliase cannot be 
number or number string.
+3. **Comment**(_optional_): the comment of the model.
+4. **Properties**(_optional_): Click on the `ADD PROPERTY` button to add 
custom properties.
+
+#### Show version details
+
+Click on the action icon <Icon icon='bx:show-alt' fontSize='24' /> in the 
table cell.
+
+You can see the detailed information of this version in the drawer component 
on the right.
+
+![version-details](./assets/webui/version-details.png)
+
+#### Drop version
+
+Click on the action icon <Icon icon='mdi:delete-outline' fontSize='24' 
color='red' /> in the table cell.
+
+Displays a confirmation dialog, clicking on the `DROP` button drops this model.

Review Comment:
   ... drop this version?



##########
web/web/src/app/metalakes/metalake/rightContent/LinkVersionDialog.js:
##########
@@ -0,0 +1,504 @@
+/*
+ * 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.
+ */
+
+'use client'
+
+import { useState, forwardRef, useEffect, Fragment } from 'react'
+
+import {
+  Box,
+  Button,
+  Dialog,
+  DialogActions,
+  DialogContent,
+  Fade,
+  FormControl,
+  FormHelperText,
+  Grid,
+  IconButton,
+  InputLabel,
+  TextField,
+  Typography
+} from '@mui/material'
+
+import Icon from '@/components/Icon'
+
+import { useAppDispatch } from '@/lib/hooks/useStore'
+import { linkVersion } from '@/lib/store/metalakes'
+
+import * as yup from 'yup'
+import { useForm, Controller, useFieldArray } from 'react-hook-form'
+import { yupResolver } from '@hookform/resolvers/yup'
+
+import { groupBy } from 'lodash-es'
+import { keyRegex } from '@/lib/utils/regex'
+import { useSearchParams } from 'next/navigation'
+import { useAppSelector } from '@/lib/hooks/useStore'
+
+const defaultValues = {
+  uri: '',
+  aliases: [{ name: '' }],
+  comment: '',
+  propItems: []
+}
+
+const schema = yup.object().shape({
+  uri: yup.string().required(),
+  aliases: yup
+    .array()
+    .of(
+      yup.object().shape({
+        name: yup
+          .string()
+          .required('This aliase is required')
+          .test('not-number', 'Aliase cannot be a number or numeric string', 
value => {
+            return value === undefined || isNaN(Number(value))
+          })
+      })
+    )
+    .test('unique', 'Aliase must be unique', (aliases, ctx) => {
+      const values = aliases?.filter(a => !!a.name).map(a => a.name)
+      const duplicates = values.filter((value, index, self) => 
self.indexOf(value) !== index)
+
+      if (duplicates.length > 0) {
+        const duplicateIndex = values.lastIndexOf(duplicates[0])
+
+        return ctx.createError({
+          path: `aliases.${duplicateIndex}.name`,
+          message: 'This aliase is duplicated'
+        })
+      }
+
+      return true
+    }),
+  propItems: yup.array().of(
+    yup.object().shape({
+      required: yup.boolean(),
+      key: yup.string().required(),
+      value: yup.string().when('required', {
+        is: true,
+        then: schema => schema.required()
+      })
+    })
+  )
+})
+
+const Transition = forwardRef(function Transition(props, ref) {
+  return <Fade ref={ref} {...props} />
+})
+
+const LinkVersionDialog = props => {
+  const { open, setOpen, type = 'create', data = {} } = props
+  const searchParams = useSearchParams()
+  const metalake = searchParams.get('metalake')
+  const catalog = searchParams.get('catalog')
+  const schemaName = searchParams.get('schema')
+  const catalogType = searchParams.get('type')
+  const model = searchParams.get('model')
+  const [innerProps, setInnerProps] = useState([])
+  const dispatch = useAppDispatch()
+  const store = useAppSelector(state => state.metalakes)
+  const [cacheData, setCacheData] = useState()
+
+  const {
+    control,
+    reset,
+    watch,
+    setValue,
+    getValues,
+    handleSubmit,
+    trigger,
+    formState: { errors }
+  } = useForm({
+    defaultValues,
+    mode: 'all',
+    resolver: yupResolver(schema)
+  })
+
+  const handleFormChange = ({ index, event }) => {
+    let data = [...innerProps]
+    data[index][event.target.name] = event.target.value
+
+    if (event.target.name === 'key') {
+      const invalidKey = !keyRegex.test(event.target.value)
+      data[index].invalid = invalidKey
+    }
+
+    const nonEmptyKeys = data.filter(item => item.key.trim() !== '')
+    const grouped = groupBy(nonEmptyKeys, 'key')
+    const duplicateKeys = Object.keys(grouped).some(key => grouped[key].length 
> 1)
+
+    if (duplicateKeys) {
+      data[index].hasDuplicateKey = duplicateKeys
+    } else {
+      data.forEach(it => (it.hasDuplicateKey = false))
+    }
+
+    setInnerProps(data)
+    setValue('propItems', data)
+  }
+
+  const addFields = () => {
+    const duplicateKeys = innerProps
+      .filter(item => item.key.trim() !== '')
+      .some(
+        (item, index, filteredItems) =>
+          filteredItems.findIndex(otherItem => otherItem !== item && 
otherItem.key.trim() === item.key.trim()) !== -1

Review Comment:
   Can just detect `innerProps.some(item => item.hasDuplicateKey)`?



##########
web/web/src/app/metalakes/metalake/rightContent/LinkVersionDialog.js:
##########
@@ -0,0 +1,504 @@
+/*
+ * 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.
+ */
+
+'use client'
+
+import { useState, forwardRef, useEffect, Fragment } from 'react'
+
+import {
+  Box,
+  Button,
+  Dialog,
+  DialogActions,
+  DialogContent,
+  Fade,
+  FormControl,
+  FormHelperText,
+  Grid,
+  IconButton,
+  InputLabel,
+  TextField,
+  Typography
+} from '@mui/material'
+
+import Icon from '@/components/Icon'
+
+import { useAppDispatch } from '@/lib/hooks/useStore'
+import { linkVersion } from '@/lib/store/metalakes'
+
+import * as yup from 'yup'
+import { useForm, Controller, useFieldArray } from 'react-hook-form'
+import { yupResolver } from '@hookform/resolvers/yup'
+
+import { groupBy } from 'lodash-es'
+import { keyRegex } from '@/lib/utils/regex'
+import { useSearchParams } from 'next/navigation'
+import { useAppSelector } from '@/lib/hooks/useStore'
+
+const defaultValues = {
+  uri: '',
+  aliases: [{ name: '' }],
+  comment: '',
+  propItems: []
+}
+
+const schema = yup.object().shape({
+  uri: yup.string().required(),
+  aliases: yup
+    .array()
+    .of(
+      yup.object().shape({
+        name: yup
+          .string()
+          .required('This aliase is required')
+          .test('not-number', 'Aliase cannot be a number or numeric string', 
value => {
+            return value === undefined || isNaN(Number(value))
+          })
+      })
+    )
+    .test('unique', 'Aliase must be unique', (aliases, ctx) => {
+      const values = aliases?.filter(a => !!a.name).map(a => a.name)
+      const duplicates = values.filter((value, index, self) => 
self.indexOf(value) !== index)
+
+      if (duplicates.length > 0) {
+        const duplicateIndex = values.lastIndexOf(duplicates[0])
+
+        return ctx.createError({
+          path: `aliases.${duplicateIndex}.name`,
+          message: 'This aliase is duplicated'
+        })
+      }
+
+      return true
+    }),
+  propItems: yup.array().of(
+    yup.object().shape({
+      required: yup.boolean(),
+      key: yup.string().required(),
+      value: yup.string().when('required', {
+        is: true,
+        then: schema => schema.required()
+      })
+    })
+  )
+})
+
+const Transition = forwardRef(function Transition(props, ref) {
+  return <Fade ref={ref} {...props} />
+})
+
+const LinkVersionDialog = props => {
+  const { open, setOpen, type = 'create', data = {} } = props
+  const searchParams = useSearchParams()
+  const metalake = searchParams.get('metalake')
+  const catalog = searchParams.get('catalog')
+  const schemaName = searchParams.get('schema')
+  const catalogType = searchParams.get('type')
+  const model = searchParams.get('model')
+  const [innerProps, setInnerProps] = useState([])
+  const dispatch = useAppDispatch()
+  const store = useAppSelector(state => state.metalakes)
+  const [cacheData, setCacheData] = useState()
+
+  const {
+    control,
+    reset,
+    watch,
+    setValue,
+    getValues,
+    handleSubmit,
+    trigger,
+    formState: { errors }
+  } = useForm({
+    defaultValues,
+    mode: 'all',
+    resolver: yupResolver(schema)
+  })
+
+  const handleFormChange = ({ index, event }) => {
+    let data = [...innerProps]
+    data[index][event.target.name] = event.target.value
+
+    if (event.target.name === 'key') {
+      const invalidKey = !keyRegex.test(event.target.value)
+      data[index].invalid = invalidKey
+    }
+
+    const nonEmptyKeys = data.filter(item => item.key.trim() !== '')
+    const grouped = groupBy(nonEmptyKeys, 'key')
+    const duplicateKeys = Object.keys(grouped).some(key => grouped[key].length 
> 1)
+
+    if (duplicateKeys) {
+      data[index].hasDuplicateKey = duplicateKeys
+    } else {
+      data.forEach(it => (it.hasDuplicateKey = false))
+    }
+
+    setInnerProps(data)
+    setValue('propItems', data)
+  }
+
+  const addFields = () => {
+    const duplicateKeys = innerProps
+      .filter(item => item.key.trim() !== '')
+      .some(
+        (item, index, filteredItems) =>
+          filteredItems.findIndex(otherItem => otherItem !== item && 
otherItem.key.trim() === item.key.trim()) !== -1
+      )
+
+    if (duplicateKeys) {
+      return
+    }
+
+    let newField = { key: '', value: '', required: false }
+
+    setInnerProps([...innerProps, newField])
+    setValue('propItems', [...innerProps, newField])
+  }
+
+  const removeFields = index => {
+    let data = [...innerProps]
+    data.splice(index, 1)
+    setInnerProps(data)
+    setValue('propItems', data)
+  }
+
+  const { fields, append, remove } = useFieldArray({
+    control,
+    name: 'aliases'
+  })
+
+  const watchAliases = watch('aliases')
+
+  const handleClose = () => {
+    reset()
+    setInnerProps([])
+    setValue('propItems', [])
+    setOpen(false)
+  }
+
+  const handleClickSubmit = e => {
+    e.preventDefault()
+
+    return handleSubmit(onSubmit(getValues()), onError)
+  }
+
+  const onSubmit = data => {
+    const duplicateKeys = innerProps
+      .filter(item => item.key.trim() !== '')
+      .some(
+        (item, index, filteredItems) =>
+          filteredItems.findIndex(otherItem => otherItem !== item && 
otherItem.key.trim() === item.key.trim()) !== -1
+      )
+
+    const invalidKeys = innerProps.some(i => i.invalid)
+
+    if (duplicateKeys || invalidKeys) {
+      return
+    }
+
+    trigger()
+
+    schema
+      .validate(data)
+      .then(() => {
+        const properties = innerProps.reduce((acc, item) => {
+          acc[item.key] = item.value
+
+          return acc
+        }, {})
+
+        const schemaData = {
+          uri: data.uri,
+          aliases: data.aliases.map(alias => alias.name),
+          comment: data.comment,
+          properties
+        }
+
+        if (type === 'create') {
+          console.log('create version', schemaData)
+          dispatch(
+            linkVersion({ data: schemaData, metalake, catalog, schema: 
schemaName, type: catalogType, model })
+          ).then(res => {
+            if (!res.payload?.err) {
+              handleClose()
+            }
+          })
+        }
+      })
+      .catch(err => {
+        console.error('valid error', err)

Review Comment:
   `valid error` seems a bit unclear or weird.



##########
web/web/src/app/metalakes/metalake/rightContent/LinkVersionDialog.js:
##########
@@ -0,0 +1,504 @@
+/*
+ * 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.
+ */
+
+'use client'
+
+import { useState, forwardRef, useEffect, Fragment } from 'react'
+
+import {
+  Box,
+  Button,
+  Dialog,
+  DialogActions,
+  DialogContent,
+  Fade,
+  FormControl,
+  FormHelperText,
+  Grid,
+  IconButton,
+  InputLabel,
+  TextField,
+  Typography
+} from '@mui/material'
+
+import Icon from '@/components/Icon'
+
+import { useAppDispatch } from '@/lib/hooks/useStore'
+import { linkVersion } from '@/lib/store/metalakes'
+
+import * as yup from 'yup'
+import { useForm, Controller, useFieldArray } from 'react-hook-form'
+import { yupResolver } from '@hookform/resolvers/yup'
+
+import { groupBy } from 'lodash-es'
+import { keyRegex } from '@/lib/utils/regex'
+import { useSearchParams } from 'next/navigation'
+import { useAppSelector } from '@/lib/hooks/useStore'
+
+const defaultValues = {
+  uri: '',
+  aliases: [{ name: '' }],
+  comment: '',
+  propItems: []
+}
+
+const schema = yup.object().shape({
+  uri: yup.string().required(),
+  aliases: yup
+    .array()
+    .of(
+      yup.object().shape({
+        name: yup
+          .string()
+          .required('This aliase is required')
+          .test('not-number', 'Aliase cannot be a number or numeric string', 
value => {
+            return value === undefined || isNaN(Number(value))
+          })
+      })
+    )
+    .test('unique', 'Aliase must be unique', (aliases, ctx) => {
+      const values = aliases?.filter(a => !!a.name).map(a => a.name)
+      const duplicates = values.filter((value, index, self) => 
self.indexOf(value) !== index)
+
+      if (duplicates.length > 0) {
+        const duplicateIndex = values.lastIndexOf(duplicates[0])
+
+        return ctx.createError({
+          path: `aliases.${duplicateIndex}.name`,
+          message: 'This aliase is duplicated'
+        })
+      }
+
+      return true
+    }),
+  propItems: yup.array().of(
+    yup.object().shape({
+      required: yup.boolean(),
+      key: yup.string().required(),
+      value: yup.string().when('required', {
+        is: true,
+        then: schema => schema.required()
+      })
+    })
+  )
+})
+
+const Transition = forwardRef(function Transition(props, ref) {
+  return <Fade ref={ref} {...props} />
+})
+
+const LinkVersionDialog = props => {
+  const { open, setOpen, type = 'create', data = {} } = props
+  const searchParams = useSearchParams()
+  const metalake = searchParams.get('metalake')
+  const catalog = searchParams.get('catalog')
+  const schemaName = searchParams.get('schema')
+  const catalogType = searchParams.get('type')
+  const model = searchParams.get('model')
+  const [innerProps, setInnerProps] = useState([])
+  const dispatch = useAppDispatch()
+  const store = useAppSelector(state => state.metalakes)
+  const [cacheData, setCacheData] = useState()
+
+  const {
+    control,
+    reset,
+    watch,
+    setValue,
+    getValues,
+    handleSubmit,
+    trigger,
+    formState: { errors }
+  } = useForm({
+    defaultValues,
+    mode: 'all',
+    resolver: yupResolver(schema)
+  })
+
+  const handleFormChange = ({ index, event }) => {
+    let data = [...innerProps]
+    data[index][event.target.name] = event.target.value
+
+    if (event.target.name === 'key') {
+      const invalidKey = !keyRegex.test(event.target.value)
+      data[index].invalid = invalidKey
+    }
+
+    const nonEmptyKeys = data.filter(item => item.key.trim() !== '')
+    const grouped = groupBy(nonEmptyKeys, 'key')
+    const duplicateKeys = Object.keys(grouped).some(key => grouped[key].length 
> 1)
+
+    if (duplicateKeys) {
+      data[index].hasDuplicateKey = duplicateKeys
+    } else {
+      data.forEach(it => (it.hasDuplicateKey = false))
+    }
+
+    setInnerProps(data)
+    setValue('propItems', data)
+  }
+
+  const addFields = () => {
+    const duplicateKeys = innerProps
+      .filter(item => item.key.trim() !== '')
+      .some(
+        (item, index, filteredItems) =>
+          filteredItems.findIndex(otherItem => otherItem !== item && 
otherItem.key.trim() === item.key.trim()) !== -1
+      )
+
+    if (duplicateKeys) {
+      return
+    }
+
+    let newField = { key: '', value: '', required: false }
+
+    setInnerProps([...innerProps, newField])
+    setValue('propItems', [...innerProps, newField])
+  }
+
+  const removeFields = index => {
+    let data = [...innerProps]
+    data.splice(index, 1)
+    setInnerProps(data)
+    setValue('propItems', data)
+  }
+
+  const { fields, append, remove } = useFieldArray({
+    control,
+    name: 'aliases'
+  })
+
+  const watchAliases = watch('aliases')
+
+  const handleClose = () => {
+    reset()
+    setInnerProps([])
+    setValue('propItems', [])
+    setOpen(false)
+  }
+
+  const handleClickSubmit = e => {
+    e.preventDefault()
+
+    return handleSubmit(onSubmit(getValues()), onError)
+  }
+
+  const onSubmit = data => {
+    const duplicateKeys = innerProps
+      .filter(item => item.key.trim() !== '')
+      .some(
+        (item, index, filteredItems) =>
+          filteredItems.findIndex(otherItem => otherItem !== item && 
otherItem.key.trim() === item.key.trim()) !== -1

Review Comment:
   Can just detect `const hasError = innerProps.some(prop => 
prop.hasDuplicateKey || prop.invalid)`?



##########
web/web/src/app/metalakes/metalake/rightContent/RegisterModelDialog.js:
##########
@@ -0,0 +1,415 @@
+/*
+ * 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.
+ */
+
+'use client'
+
+import { useState, forwardRef, useEffect, Fragment } from 'react'
+
+import {
+  Box,
+  Button,
+  Dialog,
+  DialogActions,
+  DialogContent,
+  Fade,
+  FormControl,
+  FormHelperText,
+  Grid,
+  IconButton,
+  InputLabel,
+  TextField,
+  Typography
+} from '@mui/material'
+
+import Icon from '@/components/Icon'
+
+import { useAppDispatch } from '@/lib/hooks/useStore'
+import { registerModel } from '@/lib/store/metalakes'
+
+import * as yup from 'yup'
+import { useForm, Controller } from 'react-hook-form'
+import { yupResolver } from '@hookform/resolvers/yup'
+
+import { groupBy } from 'lodash-es'
+import { nameRegex, nameRegexDesc, keyRegex } from '@/lib/utils/regex'
+import { useSearchParams } from 'next/navigation'
+import { useAppSelector } from '@/lib/hooks/useStore'
+
+const defaultValues = {
+  name: '',
+  comment: '',
+  propItems: []
+}
+
+const schema = yup.object().shape({
+  name: yup.string().required().matches(nameRegex, nameRegexDesc),
+  propItems: yup.array().of(
+    yup.object().shape({
+      required: yup.boolean(),
+      key: yup.string().required(),
+      value: yup.string().when('required', {
+        is: true,
+        then: schema => schema.required()
+      })
+    })
+  )
+})
+
+const Transition = forwardRef(function Transition(props, ref) {
+  return <Fade ref={ref} {...props} />
+})
+
+const RegisterModelDialog = props => {
+  const { open, setOpen, type = 'create', data = {} } = props
+  const searchParams = useSearchParams()
+  const metalake = searchParams.get('metalake')
+  const catalog = searchParams.get('catalog')
+  const schemaName = searchParams.get('schema')
+  const catalogType = searchParams.get('type')
+  const [innerProps, setInnerProps] = useState([])
+  const dispatch = useAppDispatch()
+  const store = useAppSelector(state => state.metalakes)
+  const [cacheData, setCacheData] = useState()
+
+  const {
+    control,
+    reset,
+    watch,
+    setValue,
+    getValues,
+    handleSubmit,
+    trigger,
+    formState: { errors }
+  } = useForm({
+    defaultValues,
+    mode: 'all',
+    resolver: yupResolver(schema)
+  })
+
+  const handleFormChange = ({ index, event }) => {
+    let data = [...innerProps]
+    data[index][event.target.name] = event.target.value
+
+    if (event.target.name === 'key') {
+      const invalidKey = !keyRegex.test(event.target.value)
+      data[index].invalid = invalidKey
+    }
+
+    const nonEmptyKeys = data.filter(item => item.key.trim() !== '')

Review Comment:
   Same issue with other comment.



##########
web/web/src/app/metalakes/metalake/rightContent/LinkVersionDialog.js:
##########
@@ -0,0 +1,504 @@
+/*
+ * 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.
+ */
+
+'use client'
+
+import { useState, forwardRef, useEffect, Fragment } from 'react'
+
+import {
+  Box,
+  Button,
+  Dialog,
+  DialogActions,
+  DialogContent,
+  Fade,
+  FormControl,
+  FormHelperText,
+  Grid,
+  IconButton,
+  InputLabel,
+  TextField,
+  Typography
+} from '@mui/material'
+
+import Icon from '@/components/Icon'
+
+import { useAppDispatch } from '@/lib/hooks/useStore'
+import { linkVersion } from '@/lib/store/metalakes'
+
+import * as yup from 'yup'
+import { useForm, Controller, useFieldArray } from 'react-hook-form'
+import { yupResolver } from '@hookform/resolvers/yup'
+
+import { groupBy } from 'lodash-es'
+import { keyRegex } from '@/lib/utils/regex'
+import { useSearchParams } from 'next/navigation'
+import { useAppSelector } from '@/lib/hooks/useStore'
+
+const defaultValues = {
+  uri: '',
+  aliases: [{ name: '' }],
+  comment: '',
+  propItems: []
+}
+
+const schema = yup.object().shape({
+  uri: yup.string().required(),
+  aliases: yup
+    .array()
+    .of(
+      yup.object().shape({
+        name: yup
+          .string()
+          .required('This aliase is required')
+          .test('not-number', 'Aliase cannot be a number or numeric string', 
value => {
+            return value === undefined || isNaN(Number(value))
+          })
+      })
+    )
+    .test('unique', 'Aliase must be unique', (aliases, ctx) => {
+      const values = aliases?.filter(a => !!a.name).map(a => a.name)
+      const duplicates = values.filter((value, index, self) => 
self.indexOf(value) !== index)
+
+      if (duplicates.length > 0) {
+        const duplicateIndex = values.lastIndexOf(duplicates[0])
+
+        return ctx.createError({
+          path: `aliases.${duplicateIndex}.name`,
+          message: 'This aliase is duplicated'
+        })
+      }
+
+      return true
+    }),
+  propItems: yup.array().of(
+    yup.object().shape({
+      required: yup.boolean(),
+      key: yup.string().required(),
+      value: yup.string().when('required', {
+        is: true,
+        then: schema => schema.required()
+      })
+    })
+  )
+})
+
+const Transition = forwardRef(function Transition(props, ref) {
+  return <Fade ref={ref} {...props} />
+})
+
+const LinkVersionDialog = props => {
+  const { open, setOpen, type = 'create', data = {} } = props
+  const searchParams = useSearchParams()
+  const metalake = searchParams.get('metalake')
+  const catalog = searchParams.get('catalog')
+  const schemaName = searchParams.get('schema')
+  const catalogType = searchParams.get('type')
+  const model = searchParams.get('model')
+  const [innerProps, setInnerProps] = useState([])
+  const dispatch = useAppDispatch()
+  const store = useAppSelector(state => state.metalakes)
+  const [cacheData, setCacheData] = useState()
+
+  const {
+    control,
+    reset,
+    watch,
+    setValue,
+    getValues,
+    handleSubmit,
+    trigger,
+    formState: { errors }
+  } = useForm({
+    defaultValues,
+    mode: 'all',
+    resolver: yupResolver(schema)
+  })
+
+  const handleFormChange = ({ index, event }) => {
+    let data = [...innerProps]
+    data[index][event.target.name] = event.target.value
+
+    if (event.target.name === 'key') {
+      const invalidKey = !keyRegex.test(event.target.value)
+      data[index].invalid = invalidKey
+    }
+
+    const nonEmptyKeys = data.filter(item => item.key.trim() !== '')
+    const grouped = groupBy(nonEmptyKeys, 'key')
+    const duplicateKeys = Object.keys(grouped).some(key => grouped[key].length 
> 1)
+
+    if (duplicateKeys) {
+      data[index].hasDuplicateKey = duplicateKeys
+    } else {
+      data.forEach(it => (it.hasDuplicateKey = false))
+    }
+
+    setInnerProps(data)
+    setValue('propItems', data)
+  }
+
+  const addFields = () => {
+    const duplicateKeys = innerProps
+      .filter(item => item.key.trim() !== '')
+      .some(
+        (item, index, filteredItems) =>
+          filteredItems.findIndex(otherItem => otherItem !== item && 
otherItem.key.trim() === item.key.trim()) !== -1
+      )
+
+    if (duplicateKeys) {
+      return
+    }
+
+    let newField = { key: '', value: '', required: false }
+
+    setInnerProps([...innerProps, newField])
+    setValue('propItems', [...innerProps, newField])
+  }
+
+  const removeFields = index => {
+    let data = [...innerProps]
+    data.splice(index, 1)
+    setInnerProps(data)
+    setValue('propItems', data)
+  }
+
+  const { fields, append, remove } = useFieldArray({
+    control,
+    name: 'aliases'
+  })
+
+  const watchAliases = watch('aliases')
+
+  const handleClose = () => {
+    reset()
+    setInnerProps([])
+    setValue('propItems', [])
+    setOpen(false)
+  }
+
+  const handleClickSubmit = e => {
+    e.preventDefault()
+
+    return handleSubmit(onSubmit(getValues()), onError)
+  }
+
+  const onSubmit = data => {
+    const duplicateKeys = innerProps
+      .filter(item => item.key.trim() !== '')
+      .some(
+        (item, index, filteredItems) =>
+          filteredItems.findIndex(otherItem => otherItem !== item && 
otherItem.key.trim() === item.key.trim()) !== -1
+      )
+
+    const invalidKeys = innerProps.some(i => i.invalid)
+
+    if (duplicateKeys || invalidKeys) {
+      return
+    }
+
+    trigger()
+
+    schema
+      .validate(data)
+      .then(() => {
+        const properties = innerProps.reduce((acc, item) => {
+          acc[item.key] = item.value
+
+          return acc
+        }, {})
+
+        const schemaData = {
+          uri: data.uri,
+          aliases: data.aliases.map(alias => alias.name),
+          comment: data.comment,
+          properties
+        }
+
+        if (type === 'create') {
+          console.log('create version', schemaData)
+          dispatch(
+            linkVersion({ data: schemaData, metalake, catalog, schema: 
schemaName, type: catalogType, model })
+          ).then(res => {
+            if (!res.payload?.err) {
+              handleClose()
+            }
+          })
+        }
+      })
+      .catch(err => {
+        console.error('valid error', err)
+      })
+  }
+
+  const onError = errors => {
+    console.error('fields error', errors)
+  }
+
+  useEffect(() => {
+    if (open && JSON.stringify(data) !== '{}') {
+      const { properties = {} } = data
+
+      setCacheData(data)
+      setValue('uri', data.uri)
+      setValue('comment', data.comment)
+
+      const propsItems = Object.entries(properties).map(([key, value]) => {
+        return {
+          key,
+          value
+        }
+      })
+
+      setInnerProps(propsItems)
+      setValue('propItems', propsItems)
+    }
+  }, [open, data, setValue, type])
+
+  return (
+    <Dialog fullWidth maxWidth='sm' scroll='body' 
TransitionComponent={Transition} open={open} onClose={handleClose}>
+      <form onSubmit={e => handleClickSubmit(e)}>
+        <DialogContent
+          sx={{
+            position: 'relative',
+            pb: theme => `${theme.spacing(8)} !important`,
+            px: theme => [`${theme.spacing(5)} !important`, 
`${theme.spacing(15)} !important`],
+            pt: theme => [`${theme.spacing(8)} !important`, 
`${theme.spacing(12.5)} !important`]
+          }}
+        >
+          <IconButton
+            size='small'
+            onClick={() => handleClose()}
+            sx={{ position: 'absolute', right: '1rem', top: '1rem' }}
+          >
+            <Icon icon='bx:x' />
+          </IconButton>
+          <Box sx={{ mb: 8, textAlign: 'center' }}>
+            <Typography variant='h5' sx={{ mb: 3 }}>
+              {type === 'create' ? 'Link' : 'Edit'} Version
+            </Typography>
+          </Box>
+
+          <Grid container spacing={6}>
+            <Grid item xs={12}>
+              <FormControl fullWidth>
+                <Controller
+                  name='uri'
+                  control={control}
+                  rules={{ required: true }}
+                  render={({ field: { value, onChange } }) => (
+                    <TextField
+                      value={value}
+                      label='URI'
+                      onChange={onChange}
+                      placeholder=''
+                      disabled={type === 'update'}
+                      error={Boolean(errors.uri)}
+                      data-refer='link-uri-field'
+                    />
+                  )}
+                />
+                {errors.uri && <FormHelperText sx={{ color: 'error.main' 
}}>{errors.uri.message}</FormHelperText>}
+              </FormControl>
+            </Grid>
+
+            <Grid item xs={12}>
+              {fields.map((field, index) => {
+                return (
+                  <Grid key={index} item xs={12} sx={{ '& + &': { mt: 2 } }}>
+                    <FormControl fullWidth>
+                      <Box
+                        key={field.id}
+                        sx={{ display: 'flex', alignItems: 'center', 
justifyContent: 'space-between' }}
+                        data-refer={`version-aliases-${index}`}
+                      >
+                        <Box sx={{ flexGrow: 1 }}>
+                          <Controller
+                            name={`aliases.${index}.name`}
+                            control={control}
+                            render={({ field }) => (
+                              <TextField
+                                {...field}
+                                onChange={event => {
+                                  field.onChange(event)
+                                  trigger('aliases')
+                                }}
+                                label={`Aliase ${index + 1}`}
+                                error={!!errors.aliases?.[index]?.name || 
!!errors.aliases?.message}

Review Comment:
   Why using `!!`?



##########
web/web/src/app/metalakes/metalake/rightContent/RegisterModelDialog.js:
##########
@@ -0,0 +1,415 @@
+/*
+ * 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.
+ */
+
+'use client'
+
+import { useState, forwardRef, useEffect, Fragment } from 'react'
+
+import {
+  Box,
+  Button,
+  Dialog,
+  DialogActions,
+  DialogContent,
+  Fade,
+  FormControl,
+  FormHelperText,
+  Grid,
+  IconButton,
+  InputLabel,
+  TextField,
+  Typography
+} from '@mui/material'
+
+import Icon from '@/components/Icon'
+
+import { useAppDispatch } from '@/lib/hooks/useStore'
+import { registerModel } from '@/lib/store/metalakes'
+
+import * as yup from 'yup'
+import { useForm, Controller } from 'react-hook-form'
+import { yupResolver } from '@hookform/resolvers/yup'
+
+import { groupBy } from 'lodash-es'
+import { nameRegex, nameRegexDesc, keyRegex } from '@/lib/utils/regex'
+import { useSearchParams } from 'next/navigation'
+import { useAppSelector } from '@/lib/hooks/useStore'
+
+const defaultValues = {
+  name: '',
+  comment: '',
+  propItems: []
+}
+
+const schema = yup.object().shape({
+  name: yup.string().required().matches(nameRegex, nameRegexDesc),
+  propItems: yup.array().of(
+    yup.object().shape({
+      required: yup.boolean(),
+      key: yup.string().required(),
+      value: yup.string().when('required', {
+        is: true,
+        then: schema => schema.required()
+      })
+    })
+  )
+})
+
+const Transition = forwardRef(function Transition(props, ref) {
+  return <Fade ref={ref} {...props} />
+})
+
+const RegisterModelDialog = props => {
+  const { open, setOpen, type = 'create', data = {} } = props
+  const searchParams = useSearchParams()
+  const metalake = searchParams.get('metalake')
+  const catalog = searchParams.get('catalog')
+  const schemaName = searchParams.get('schema')
+  const catalogType = searchParams.get('type')
+  const [innerProps, setInnerProps] = useState([])
+  const dispatch = useAppDispatch()
+  const store = useAppSelector(state => state.metalakes)
+  const [cacheData, setCacheData] = useState()
+
+  const {
+    control,
+    reset,
+    watch,
+    setValue,
+    getValues,
+    handleSubmit,
+    trigger,
+    formState: { errors }
+  } = useForm({
+    defaultValues,
+    mode: 'all',
+    resolver: yupResolver(schema)
+  })
+
+  const handleFormChange = ({ index, event }) => {
+    let data = [...innerProps]
+    data[index][event.target.name] = event.target.value
+
+    if (event.target.name === 'key') {
+      const invalidKey = !keyRegex.test(event.target.value)
+      data[index].invalid = invalidKey
+    }
+
+    const nonEmptyKeys = data.filter(item => item.key.trim() !== '')
+    const grouped = groupBy(nonEmptyKeys, 'key')
+    const duplicateKeys = Object.keys(grouped).some(key => grouped[key].length 
> 1)
+
+    if (duplicateKeys) {
+      data[index].hasDuplicateKey = duplicateKeys
+    } else {
+      data.forEach(it => (it.hasDuplicateKey = false))
+    }
+
+    setInnerProps(data)
+    setValue('propItems', data)
+  }
+
+  const addFields = () => {
+    const duplicateKeys = innerProps
+      .filter(item => item.key.trim() !== '')
+      .some(
+        (item, index, filteredItems) =>
+          filteredItems.findIndex(otherItem => otherItem !== item && 
otherItem.key.trim() === item.key.trim()) !== -1

Review Comment:
   Same issue with other comment.



##########
web/web/src/app/metalakes/metalake/rightContent/RegisterModelDialog.js:
##########
@@ -0,0 +1,415 @@
+/*
+ * 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.
+ */
+
+'use client'
+
+import { useState, forwardRef, useEffect, Fragment } from 'react'
+
+import {
+  Box,
+  Button,
+  Dialog,
+  DialogActions,
+  DialogContent,
+  Fade,
+  FormControl,
+  FormHelperText,
+  Grid,
+  IconButton,
+  InputLabel,
+  TextField,
+  Typography
+} from '@mui/material'
+
+import Icon from '@/components/Icon'
+
+import { useAppDispatch } from '@/lib/hooks/useStore'
+import { registerModel } from '@/lib/store/metalakes'
+
+import * as yup from 'yup'
+import { useForm, Controller } from 'react-hook-form'
+import { yupResolver } from '@hookform/resolvers/yup'
+
+import { groupBy } from 'lodash-es'
+import { nameRegex, nameRegexDesc, keyRegex } from '@/lib/utils/regex'
+import { useSearchParams } from 'next/navigation'
+import { useAppSelector } from '@/lib/hooks/useStore'
+
+const defaultValues = {
+  name: '',
+  comment: '',
+  propItems: []
+}
+
+const schema = yup.object().shape({
+  name: yup.string().required().matches(nameRegex, nameRegexDesc),
+  propItems: yup.array().of(
+    yup.object().shape({
+      required: yup.boolean(),
+      key: yup.string().required(),
+      value: yup.string().when('required', {
+        is: true,
+        then: schema => schema.required()
+      })
+    })
+  )
+})
+
+const Transition = forwardRef(function Transition(props, ref) {
+  return <Fade ref={ref} {...props} />
+})
+
+const RegisterModelDialog = props => {
+  const { open, setOpen, type = 'create', data = {} } = props
+  const searchParams = useSearchParams()
+  const metalake = searchParams.get('metalake')
+  const catalog = searchParams.get('catalog')
+  const schemaName = searchParams.get('schema')
+  const catalogType = searchParams.get('type')
+  const [innerProps, setInnerProps] = useState([])
+  const dispatch = useAppDispatch()
+  const store = useAppSelector(state => state.metalakes)
+  const [cacheData, setCacheData] = useState()
+
+  const {
+    control,
+    reset,
+    watch,
+    setValue,
+    getValues,
+    handleSubmit,
+    trigger,
+    formState: { errors }
+  } = useForm({
+    defaultValues,
+    mode: 'all',
+    resolver: yupResolver(schema)
+  })
+
+  const handleFormChange = ({ index, event }) => {
+    let data = [...innerProps]
+    data[index][event.target.name] = event.target.value
+
+    if (event.target.name === 'key') {
+      const invalidKey = !keyRegex.test(event.target.value)
+      data[index].invalid = invalidKey
+    }
+
+    const nonEmptyKeys = data.filter(item => item.key.trim() !== '')
+    const grouped = groupBy(nonEmptyKeys, 'key')
+    const duplicateKeys = Object.keys(grouped).some(key => grouped[key].length 
> 1)
+
+    if (duplicateKeys) {
+      data[index].hasDuplicateKey = duplicateKeys
+    } else {
+      data.forEach(it => (it.hasDuplicateKey = false))
+    }
+
+    setInnerProps(data)
+    setValue('propItems', data)
+  }
+
+  const addFields = () => {
+    const duplicateKeys = innerProps
+      .filter(item => item.key.trim() !== '')
+      .some(
+        (item, index, filteredItems) =>
+          filteredItems.findIndex(otherItem => otherItem !== item && 
otherItem.key.trim() === item.key.trim()) !== -1
+      )
+
+    if (duplicateKeys) {
+      return
+    }
+
+    let newField = { key: '', value: '', required: false }
+
+    setInnerProps([...innerProps, newField])
+    setValue('propItems', [...innerProps, newField])
+  }
+
+  const removeFields = index => {
+    let data = [...innerProps]
+    data.splice(index, 1)
+    setInnerProps(data)
+    setValue('propItems', data)
+  }
+
+  const handleClose = () => {
+    reset()
+    setInnerProps([])
+    setValue('propItems', [])
+    setOpen(false)
+  }
+
+  const handleClickSubmit = e => {
+    e.preventDefault()
+
+    return handleSubmit(onSubmit(getValues()), onError)
+  }
+
+  const onSubmit = data => {
+    const duplicateKeys = innerProps
+      .filter(item => item.key.trim() !== '')
+      .some(
+        (item, index, filteredItems) =>
+          filteredItems.findIndex(otherItem => otherItem !== item && 
otherItem.key.trim() === item.key.trim()) !== -1

Review Comment:
   Same issue with other comment.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to