laserninja commented on code in PR #12900:
URL: https://github.com/apache/gravitino/pull/12900#discussion_r4278997093


##########
web-v2/web/src/lib/store/metalakes/index.js:
##########
@@ -3086,6 +3298,40 @@ export const appMetalakesSlice = createSlice({
         toast.error(action.error.message)
       }
     })
+    builder.addCase(fetchSemanticModels.pending, (state, action) => {
+      const key = semanticModelSchemaKey(action.meta.arg)
+      state.semanticModelRequests[key] = { requestId: action.meta.requestId }
+      state.semanticModelListRequestId = action.meta.requestId
+    })
+    builder.addCase(fetchSemanticModels.fulfilled, (state, action) => {
+      if (action.payload.stale) return
+      const request = state.semanticModelRequests[action.payload.schemaKey]
+      if (request && request.requestId !== action.meta.requestId) return
+      if (request) request.semanticModels = action.payload.semanticModels
+      if (!state.semanticModelListRequestId || 
state.semanticModelListRequestId === action.meta.requestId) {
+        state.semanticModels = action.payload.semanticModels
+      }
+    })
+    builder.addCase(fetchSemanticModels.rejected, (state, action) => {
+      if (action.error.name !== 'CanceledError' && 
!action.error.message.includes('CanceledError')) {
+        toast.error(action.error.message)
+      }
+    })
+    builder.addCase(getSemanticModelDetails.fulfilled, (state, action) => {
+      if (action.payload.init) {
+        state.activatedDetails = action.payload.semanticModel
+      }

Review Comment:
   Fixed in 6a368938a. Detail and tag responses are guarded by the active 
request, and navigation cancels the previous detail load and its loading/tag 
follow-ups. Editors reset on route changes; completed saves cannot refresh or 
navigate after leaving the model. Controlled-order tests cover another model, a 
pending model, and another entity type. Chromium also verifies that releasing A 
after B loads leaves B and its editor unchanged.



##########
web-v2/web/src/app/catalogs/rightContent/entitiesContent/SemanticModelExtensions.js:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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 } from 'react'
+import { Button, Typography } from 'antd'
+import SemanticMetadataSection from './SemanticMetadataSection'
+
+function ExtensionData({ data }) {
+  const [raw, setRaw] = useState(false)
+  let formatted
+  try {
+    const parsed = JSON.parse(data)
+    if (parsed && typeof parsed === 'object') formatted = 
JSON.stringify(parsed, null, 2)

Review Comment:
   Fixed in 6a368938a. Formatting now changes whitespace around the original 
JSON tokens instead of serializing parsed numeric values. Large integers, 
precise decimals, exponent notation, negative zero, duplicate keys, and string 
escapes remain intact. Added formatter and viewer regressions, including the 
exact example, and verified it in Chromium.



##########
web-v2/web/src/app/catalogs/rightContent/CreateSemanticModelDialog.js:
##########
@@ -0,0 +1,279 @@
+/*
+ * 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 React, { useEffect, useRef, useState } from 'react'
+import { Form, Input, Modal, Spin, Typography } from 'antd'
+import { useScrolling } from 'react-use'
+import RenderPropertiesFormItem from '@/components/EntityPropertiesFormItem'
+import { validateMessages, dialogContentMaxHeigth, mismatchName } from 
'@/config'
+import { nameRegex } from '@/lib/utils/regex'
+import { useResetFormOnCloseModal } from '@/lib/hooks/use-reset'
+import { cn } from '@/lib/utils/tailwind'
+import { useAppDispatch } from '@/lib/hooks/useStore'
+import {
+  formatSemanticModelDefinition,
+  genSemanticModelUpdates,
+  parseSemanticModelDefinition
+} from '@/lib/utils/semanticModel'
+import { createSemanticModel, updateSemanticModel, getSemanticModelDetails } 
from '@/lib/store/metalakes'
+
+const { Paragraph } = Typography
+const { TextArea } = Input
+
+const definitionPlaceholder = `{
+  "datasets": [
+    {
+      "name": "orders",
+      "source": { "namespace": ["sales", "mart"], "name": "orders" },
+      "fields": []
+    }
+  ]
+}`
+
+const defaultValues = {
+  name: '',
+  comment: '',
+  definition: '',
+  properties: []
+}
+
+export default function CreateSemanticModelDialog({ ...props }) {
+  const { open, setOpen, metalake, catalog, schema, editSemanticModel, onSaved 
} = props
+  const [confirmLoading, setConfirmLoading] = useState(false)
+  const [isLoading, setIsLoading] = useState(false)
+  const [cacheData, setCacheData] = useState()
+  const scrollRef = useRef(null)
+  const loadedRef = useRef(false)
+  const scrolling = useScrolling(scrollRef)
+  const [bottomShadow, setBottomShadow] = useState(false)
+  const [topShadow, setTopShadow] = useState(false)
+  const [form] = Form.useForm()
+  const dispatch = useAppDispatch()
+
+  useResetFormOnCloseModal({
+    form,
+    open
+  })
+
+  const handScroll = () => {
+    if (scrollRef.current) {
+      const { scrollTop, scrollHeight, clientHeight } = scrollRef.current
+      if (scrollHeight > clientHeight + scrollTop) {
+        setTopShadow(true)
+        setBottomShadow(scrollTop > 0)
+      } else if (scrollHeight === clientHeight + scrollTop) {
+        setTopShadow(false)
+        setBottomShadow(scrollTop > 0)
+      }
+    }
+  }
+
+  useEffect(() => {
+    scrollRef.current && handScroll()
+  }, [scrolling])
+
+  useEffect(() => {
+    if (open && editSemanticModel && !loadedRef.current) {
+      loadedRef.current = true
+
+      const initLoad = async () => {
+        setIsLoading(true)
+        try {
+          const { payload } = await dispatch(
+            getSemanticModelDetails({ metalake, catalog, schema, 
semanticModel: editSemanticModel })
+          )
+          const loaded = payload?.semanticModel
+          setCacheData(loaded)
+          form.setFieldValue('name', loaded?.name)
+          form.setFieldValue('comment', loaded?.comment)
+          form.setFieldValue('definition', 
formatSemanticModelDefinition(loaded?.definition))
+          let index = 0
+          Object.entries(loaded?.properties || {}).forEach(([key, value]) => {
+            form.setFieldValue(['properties', index, 'key'], key)
+            form.setFieldValue(['properties', index, 'value'], value)
+            index++
+          })
+          setIsLoading(false)
+        } catch (e) {
+          setIsLoading(false)
+        }
+      }
+      initLoad()
+    }
+
+    // Reset loadedRef when dialog closes
+    if (!open) {
+      loadedRef.current = false
+    }
+  }, [open, editSemanticModel, metalake, catalog, schema])
+
+  const validateDefinition = (rule, value) => {
+    const { errors } = parseSemanticModelDefinition(value)
+
+    return errors.length
+      ? Promise.reject(
+          <ul className='list-disc pl-4'>
+            {errors.map(error => (
+              <li key={error}>{error}</li>
+            ))}
+          </ul>
+        )
+      : Promise.resolve()
+  }
+
+  const handleSubmit = e => {
+    e.preventDefault()
+    form
+      .validateFields()
+      .then(async values => {
+        const { definition } = parseSemanticModelDefinition(values.definition)
+
+        setConfirmLoading(true)
+
+        const submitData = {
+          name: values.name.trim(),
+          comment: values.comment,
+          definition,
+          properties: Object.fromEntries((values.properties || []).map(({ key, 
value }) => [key, value]))
+        }
+
+        let result
+        if (editSemanticModel) {
+          const updates = genSemanticModelUpdates(cacheData, submitData)
+          if (updates.length) {
+            result = await dispatch(
+              updateSemanticModel({
+                metalake,
+                catalog,
+                schema,
+                semanticModel: editSemanticModel,
+                data: { updates }
+              })
+            )
+          }
+        } else {
+          result = await dispatch(createSemanticModel({ data: submitData, 
metalake, catalog, schema }))
+        }
+
+        if (!result?.payload?.err && !result?.error) {
+          setOpen(false)
+          if (result) await onSaved?.(result.payload)
+        }
+      })
+      .catch(info => {
+        if (info?.errorFields?.length) {
+          form.scrollToField(info.errorFields[0].name)
+        } else {
+          console.error(info)
+        }
+      })
+      .finally(() => setConfirmLoading(false))
+  }
+
+  const handleCancel = () => {
+    setOpen(false)
+  }
+
+  return (
+    <>
+      <Modal
+        title={!editSemanticModel ? 'Create Semantic Model' : 'Edit Semantic 
Model'}
+        open={open}
+        onOk={handleSubmit}
+        okText='Submit'
+        okButtonProps={{
+          'data-refer': 'handle-submit-semantic-model',
+          disabled: isLoading || (!!editSemanticModel && !cacheData)
+        }}
+        maskClosable={false}
+        keyboard={false}
+        width={800}
+        confirmLoading={confirmLoading}
+        onCancel={handleCancel}
+      >
+        <Paragraph type='secondary'>
+          {!editSemanticModel
+            ? 'Create a new semantic model.'
+            : `Edit the semantic model ${editSemanticModel}. The definition is 
replaced as a whole.`}
+        </Paragraph>
+        <div
+          className={cn('relative', {
+            'after:absolute after:-bottom-10 after:left-0 after:right-0 
after:h-10 after:shadow-[0px_-10px_8px_-8px_rgba(5,5,5,0.1)]':
+              topShadow,
+            'before:absolute before:-top-10 before:left-0 before:right-0 
before:h-10 before:z-10 before:shadow-[0px_10px_8px_-8px_rgba(5,5,5,0.1)]':
+              bottomShadow
+          })}
+        >
+          <div className='overflow-auto' style={{ maxHeight: 
`${dialogContentMaxHeigth}px` }} ref={scrollRef}>
+            <Spin spinning={isLoading}>
+              <Form
+                form={form}
+                initialValues={defaultValues}
+                layout='vertical'
+                name='semanticModelForm'
+                validateMessages={validateMessages}
+              >
+                <Form.Item
+                  name='name'
+                  label='Semantic Model Name'
+                  rules={[{ required: true }, { type: 'string', max: 64 }, { 
pattern: new RegExp(nameRegex) }]}

Review Comment:
   Removed the ossie-specific restriction in 6a368938a. Required-name, length, 
and normal pattern validation remain. Added create and rename regressions 
showing that ossie is accepted.



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