laserninja commented on code in PR #12900: URL: https://github.com/apache/gravitino/pull/12900#discussion_r4279001703
########## web-v2/web/src/app/catalogs/rightContent/entitiesContent/SemanticModelDetailsPage.js: ########## @@ -0,0 +1,700 @@ +/* + * 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 { useMemo, useState } from 'react' +import { + Button, + Divider, + Flex, + Modal, + Popover, + Space, + Spin, + Table, + Tabs, + Tag, + Tooltip, + Typography, + message +} from 'antd' +import { useAntdColumnResize } from 'react-antd-column-resize' +import useResizeObserver from 'use-resize-observer' +import { useRouter, useSearchParams } from 'next/navigation' +import Tags from '@/components/CustomTags' +import GetOwner from '@/components/GetOwner' +import Icons from '@/components/Icons' +import PropertiesContent from '@/components/PropertiesContent' +import { useAppDispatch, useAppSelector } from '@/lib/hooks/useStore' +import { getSemanticModelDetails } from '@/lib/store/metalakes' +import { copyToClipboard } from '@/lib/utils' +import { formatToDateTime, isValidDate } from '@/lib/utils/date' +import { formatSemanticModelDefinition } from '@/lib/utils/semanticModel' +import SemanticModelAIContext from './SemanticModelAIContext' +import SemanticModelExport from './SemanticModelExport' +import SemanticModelExtensions from './SemanticModelExtensions' +import CreateSemanticModelDialog from '../CreateSemanticModelDialog' +import SemanticMetadataEditor from '../SemanticMetadataEditor' + +const { Title, Paragraph } = Typography + +const sourceFullName = source => { + if (!source) { + return '-' + } + + return [...(source.namespace || []), source.name].filter(Boolean).join('.') +} + +const renderExpression = expression => { + const dialects = expression?.dialects || [] + + if (!dialects.length) { + return <span>-</span> + } + + return ( + <div className='min-w-0 space-y-2'> + {dialects.map((dialect, index) => ( + <div key={`${dialect?.dialect}-${index}`}> + <Tag>{dialect?.dialect}</Tag> + <pre className='m-0 max-h-64 overflow-auto whitespace-pre-wrap break-words font-mono text-xs [overflow-wrap:anywhere]'> Review Comment: Implemented the dialect-preview follow-up in 6a368938a. Multi-dialect rows have a compact selector that changes only that row’s two-line preview. View SQL opens the same selection; choosing a dialect there updates the preview too. A single dialect retains its static label, and All dialects remains available in the full viewer. Field and metric tests verify independent row selections and an unchanged model definition. ########## web-v2/web/src/app/catalogs/rightContent/ImportSemanticModelDialog.js: ########## @@ -0,0 +1,115 @@ +/* + * 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 { Alert, Button, Modal, Space, Typography, Upload, message } from 'antd' +import { UploadOutlined } from '@ant-design/icons' +import { importSemanticModelApi } from '@/lib/api/semanticModels' +import { useAppDispatch } from '@/lib/hooks/useStore' +import { fetchSemanticModels } from '@/lib/store/metalakes' +import { semanticModelErrorMessage } from '@/lib/utils/semanticModel' + +export default function ImportSemanticModelDialog({ open, setOpen, metalake, catalog, schema }) { + const dispatch = useAppDispatch() + const [file, setFile] = useState(null) + const [loading, setLoading] = useState(false) + const [error, setError] = useState('') + + const importDocument = async () => { + if (!file || loading) return + setLoading(true) + setError('') + try { + const document = await file.text() + if (!document.trim()) throw new Error('The selected file is empty.') + + const response = await importSemanticModelApi({ + metalake, + catalog, + schema, + document, + format: file.name.toLowerCase().endsWith('.json') ? 'json' : 'yaml' + }) + if (!response?.semanticModel) throw new Error('Import returned an empty response.') + await dispatch(fetchSemanticModels({ metalake, catalog, schema, init: true })) + message.success('Semantic Model imported') + setOpen(false) + } catch (err) { + setError(semanticModelErrorMessage(err, 'Failed to import the OSSIE document.')) + } finally { + setLoading(false) + } + } + + return ( + <Modal + title='Import OSSIE document' + open={open} + onCancel={() => setOpen(false)} + onOk={importDocument} + okText='Import' + confirmLoading={loading} + okButtonProps={{ disabled: !file, 'data-refer': 'import-semantic-model-submit' }} + cancelButtonProps={{ disabled: loading }} + closable={!loading} + maskClosable={!loading} + keyboard={!loading} + > + <Space direction='vertical' className='w-full' size='middle'> + <Typography.Paragraph className='mb-0'> + Select a standalone OSSIE YAML or JSON document to create a Semantic Model in this schema. + </Typography.Paragraph> + <Upload + accept='.yaml,.yml,.json' + maxCount={1} + disabled={loading} + fileList={file ? [file] : []} + beforeUpload={selected => { Review Comment: Refined the preview layout in 6a368938a. Destination schema is visible before selection, the parsed model name is emphasized above a compact four-count summary, and a selected file has Replace file, format/size, and an explicit Remove file action. Existing parsing checks and the fixed footer remain. Verified malformed-file correction, replacement, server failure, and retry in the browser. -- 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]
