mchades commented on code in PR #12900: URL: https://github.com/apache/gravitino/pull/12900#discussion_r4267324328
########## web-v2/web/src/app/catalogs/rightContent/entitiesContent/SemanticModelExtensions.js: ########## @@ -0,0 +1,42 @@ +/* + * 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 { Collapse, Typography } from 'antd' + +export default function SemanticModelExtensions({ extensions, label }) { + if (!extensions?.length) return null + + return ( + <section aria-label={label} className='mb-3'> + <Typography.Title level={5}>{label}</Typography.Title> + <Collapse + size='small' Review Comment: Visual: Use consistent headings for peer metadata sections Vendor Extensions uses a separate 16px semibold heading, while AI Context uses a 14px regular accordion label; its nested Instructions/Synonyms headings are heavier than the parent. This gives peer metadata sections an inconsistent hierarchy. Please use a shared section-heading style for AI Context and Vendor Extensions, with consistent weight, spacing and header height, and keep nested headings visually subordinate using the existing theme tokens. ########## web-v2/web/src/app/catalogs/rightContent/entitiesContent/SemanticModelExtensions.js: ########## @@ -0,0 +1,42 @@ +/* + * 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 { Collapse, Typography } from 'antd' + +export default function SemanticModelExtensions({ extensions, label }) { + if (!extensions?.length) return null + + return ( + <section aria-label={label} className='mb-3'> + <Typography.Title level={5}>{label}</Typography.Title> + <Collapse + size='small' + items={extensions.map((extension, index) => ({ + key: String(index), + label: extension.vendorName, + children: ( + <pre className='m-0 max-h-64 overflow-auto whitespace-pre-wrap break-all font-mono text-xs'> + {extension.data} Review Comment: Visual: Make structured vendor data easier to scan For extension data containing a JSON object or array, please offer an indented read-only representation. The populated example currently renders the whole object as a dense line, while additional AI-context keys and Definition JSON are formatted. Preserve arbitrary non-JSON text and make the original raw value available; this should only change presentation, not rewrite the stored extension data. ########## 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]'> + {dialect?.expression} + </pre> + </div> + ))} + </div> + ) +} + +const topAlignedColumns = columns => + columns.map(column => ({ ...column, onCell: () => ({ style: { verticalAlign: 'top' } }) })) + +const renderColumns = columns => <span className='font-mono text-xs'>{(columns || []).join(', ') || '-'}</span> + +const hasMetadata = entity => !!entity.aiContext || entity.customExtensions?.length > 0 + +const renderMetadata = (entity, label) => ( + <> + <SemanticModelAIContext context={entity?.aiContext} label={`${label} AI Context`} /> + <SemanticModelExtensions extensions={entity?.customExtensions} label={`${label} Vendor Extensions`} /> + </> +) + +export default function SemanticModelDetailsPage() { + const searchParams = useSearchParams() + const router = useRouter() + const dispatch = useAppDispatch() + const metalake = searchParams.get('metalake') + const catalog = searchParams.get('catalog') + const schema = searchParams.get('schema') + const semanticModelName = searchParams.get('semanticModel') + const auth = useAppSelector(state => state.auth) + const { anthEnable } = auth + const store = useAppSelector(state => state.metalakes) + const semanticModel = store.activatedDetails + const [tabKey, setTabKey] = useState('Datasets') + const [openEdit, setOpenEdit] = useState(false) + const [metadataEdit, setMetadataEdit] = useState(null) + const [fieldContext, setFieldContext] = useState(null) + const { ref, width } = useResizeObserver() + + const definition = semanticModel?.definition + const properties = semanticModel?.properties + const createdAt = semanticModel?.audit?.createTime + const createdAtText = !createdAt || !isValidDate(createdAt) ? '-' : formatToDateTime(createdAt) + const lastModifiedAt = semanticModel?.audit?.lastModifiedTime + const lastModifiedText = !lastModifiedAt || !isValidDate(lastModifiedAt) ? '-' : formatToDateTime(lastModifiedAt) + const metadataObjectFullName = `${catalog}.${schema}.${semanticModelName}` + + const datasets = useMemo( + () => (definition?.datasets || []).map(dataset => ({ ...dataset, key: dataset.name })), + [definition] + ) + + const relationships = useMemo( + () => (definition?.relationships || []).map(relationship => ({ ...relationship, key: relationship.name })), + [definition] + ) + + const metrics = useMemo( + () => (definition?.metrics || []).map(metric => ({ ...metric, key: metric.name })), + [definition] + ) + + const definitionText = useMemo(() => formatSemanticModelDefinition(definition), [definition]) + + const tagContent = ( + <div> + <Tags readOnly={true} metadataObjectType={'semantic_model'} metadataObjectFullName={metadataObjectFullName} /> + </div> + ) + + const propertyContent = <PropertiesContent properties={properties} /> + + const onSaved = async updated => { + if (updated.name !== semanticModelName) { + const params = new URLSearchParams(searchParams.toString()) + params.set('semanticModel', updated.name) + router.replace(`/catalogs?${params.toString()}`) + } else { + await dispatch(getSemanticModelDetails({ metalake, catalog, schema, semanticModel: updated.name, init: true })) + } + } + + const onCopyDefinition = async () => { + try { + await copyToClipboard(definitionText) + message.success('Definition copied!') + } catch (err) { + console.error('Failed to copy definition: ', err) + message.error('Failed to copy definition') + } + } + + const datasetColumns = useMemo( + () => [ + { + title: 'Dataset Name', + dataIndex: 'name', + key: 'name', + width: 200, + ellipsis: true, + sorter: (a, b) => a.name.toLowerCase().localeCompare(b.name.toLowerCase()) + }, + { + title: 'Source', + dataIndex: 'source', + key: 'source', + width: 260, + ellipsis: true, + render: source => <span className='font-mono text-xs'>{sourceFullName(source)}</span> + }, + { + title: 'Primary Key', + dataIndex: 'primaryKey', + key: 'primaryKey', + width: 180, + ellipsis: true, + render: renderColumns + }, + { + title: 'Unique Keys', + dataIndex: 'uniqueKeys', + key: 'uniqueKeys', + width: 220, + render: keys => + keys?.length ? ( + <Space direction='vertical' size={4}> + {keys.map((columns, index) => ( + <Tag key={index}>{renderColumns(columns)}</Tag> + ))} + </Space> + ) : ( + <span>-</span> + ) + }, + { + title: 'Fields', + dataIndex: 'fields', + key: 'fields', + width: 80, + render: fields => <span>{(fields || []).length}</span> + }, + { + title: 'Description', + dataIndex: 'description', + key: 'description', + ellipsis: true, + render: description => <span>{description || '-'}</span> + }, + { + title: 'Actions', + key: 'actions', + width: 90, + render: (_, record) => ( + <Button + size='small' + aria-label={`Edit dataset ${record.name}`} + onClick={() => setMetadataEdit({ kind: 'dataset', name: record.name })} + > + Edit + </Button> + ) + } + ], + [] + ) + + const fieldColumns = useMemo( + () => [ + { + title: 'Field Name', + dataIndex: 'name', + key: 'name', + width: 220, + render: (name, field) => ( + <div className='break-words'> + <div>{name}</div> + {field.label && <Typography.Text type='secondary'>{field.label}</Typography.Text>} + <div> + {' '} + {field.aiContext && (typeof field.aiContext === 'string' || Object.keys(field.aiContext).length > 0) && ( + <Button + size='small' + type='link' + aria-label={`${field.name} AI Context`} + onClick={() => setFieldContext(field)} + > + AI Context + </Button> + )} + </div> + </div> + ) + }, + { + title: 'Data Type', + dataIndex: 'datatype', + key: 'datatype', + width: 140, + render: datatype => (datatype ? <Tag>{datatype}</Tag> : <span>-</span>) Review Comment: Visual: Reuse the existing data-type badge palette Fields and metrics currently render every data type as the same neutral tag. Table/View columns already distinguish numeric and string families through ColumnTypeColorEnum, so semantic metadata loses that familiar visual cue. Please map semantic data types to the existing palette in a shared field/metric renderer, retaining the textual label and a neutral fallback for unmapped types. ########## 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: Visual follow-up for the full-expression view: the current SQL uses 12px text with a 16px line height, while ViewDetailsPage uses text-sm leading-6 inside a padded, bordered code area. Please reuse that more readable typography and subtle code treatment for expanded SQL, keeping the dialect label distinct from the expression. The compact list preview can remain small; this complements the density change above. -- 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]
