Copilot commented on code in PR #9759: URL: https://github.com/apache/gravitino/pull/9759#discussion_r2707068802
########## web/web/src/app/catalogs/rightContent/entitiesContent/DataPreview.js: ########## @@ -0,0 +1,136 @@ +/* + * 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 { Alert, Spin, Table } from 'antd' + +// import { useTablePreview } from '@/hooks' + +export default function DataPreview({ ...props }) { + const { currentMetalake, catalog, schema, table } = props.namespaces + + // const { data: previewData, isInitialLoading: isLoading } = useTablePreview( + // { + // keepPreviousData: true, + // }, + // { metalake: currentMetalake, catalog, schema, table } as metadataParams, + // currentMetalake !== '', + // ) + + const getPreviewData = (type, value) => { + if (typeof type === 'string') { + if (value === null) return 'NULL' + if (value === 0) return '0' + if (type === 'boolean' && value !== null) return value ? 'true' : 'false' + + return value || '-' + } else { + const tCom = type?.type + switch (tCom) { + case 'struct': + return `{${Object.entries(value) + .map(([k, v]) => `${k}=${getPreviewData(type?.fields.find(f => f.name === k)?.type, v)}`) + .join(', ')}}` + case 'map': + return `{${Object.entries(value) + .map(([k, v]) => `${getPreviewData(type?.keyType, k)}=${getPreviewData(type?.valueType, v)}`) + .join(', ')}}` + case 'list': + return `[${value.map(v => getPreviewData(type?.elementType, v)).join(', ')}]` + default: + return '-' + } + } + } + + const columns = + previewData?.columns?.map(col => { + return { + title: col.name, + dataIndex: col.name, + key: col.name, + width: 150, + ellipsis: true, + render: text => { + if (text === null) { + return 'NULL' + } else if (!text && col.type !== 'boolean' && Number.isNaN(text)) { + return '-' + } else if (typeof col.type === 'string') { + return getPreviewData(col.type, text) + } else if (typeof col.type === 'object') { + const t = col.type?.type + switch (t) { + case 'struct': + return `{${Object.entries(text) + .map( + ([key, value]) => + `${key}=${getPreviewData(col.type?.fields.find(f => f.name === key)?.type, value)}` + ) + .join(', ')}}` + case 'map': + return `{${Object.entries(text) + .map( + ([key, value]) => + `${getPreviewData(col.type?.keyType, key)}=${getPreviewData(col.type?.valueType, value)}` + ) + .join(', ')}}` + case 'list': + return `[${text.map(v => getPreviewData(col.type?.elementType, v)).join(', ')}]` + default: + return '-' + } + } + } + } + }) || [] + + const tableData = + previewData?.results?.map((col, index) => { + return { + ...col, + key: index + } + }) || [] + + return ( + <Spin spinning={isLoading}> + {previewData?.statusCode === 0 && ( + <Table + columns={columns} + dataSource={tableData} + style={{ maxHeight: 'calc(100vh - 28rem)' }} + scroll={{ y: 'calc(100vh - 34rem)' }} + /> + )} + {previewData?.statusCode === 1 && ( + <Alert + message={t('common.previewWarning', { table: `${catalog}.${schema}.${table}` })} Review Comment: The function `t` is not imported or defined. This appears to be a missing i18n translation function. ########## web/web/src/app/metalakes/page.js: ########## @@ -19,55 +19,381 @@ 'use client' -import { useCallback, useState } from 'react' -import { Grid, Card } from '@mui/material' -import TableHeader from './TableHeader' -import DetailsDrawer from '@/components/DetailsDrawer' -import CreateMetalakeDialog from './CreateMetalakeDialog' +import { useCallback, useState, useMemo, useEffect, createContext } from 'react' import dynamic from 'next/dynamic' -import Loading from '@/app/rootLayout/Loading' +import Loading from '@/components/Loading' +import SectionContainer from '@/components/SectionContainer' +import { useRouter } from 'next/navigation' +import { useAppSelector, useAppDispatch } from '@/lib/hooks/useStore' +import { Button, Dropdown, Flex, Input, Modal, Popover, Space, Spin, Table, Tooltip, Typography } from 'antd' +import { ExclamationCircleFilled, PlusOutlined } from '@ant-design/icons' +import { useAntdColumnResize } from 'react-antd-column-resize' +import { + fetchMetalakes, + deleteMetalake, + resetTree, + switchMetalakeInUse, + resetMetalakeStore +} from '@/lib/store/metalakes' +import { to } from '@/lib/utils' +import { formatToDateTime } from '@/lib/utils/date' +import Icons from '@/components/Icons' +import GetOwner from '@/components/GetOwner' +import PropertiesContent from '@/components/PropertiesContent' -const DynamicTableBody = dynamic(() => import('./TableBody'), { - loading: () => <Loading height={'200px'} />, +const CreateMetalakeDialog = dynamic(() => import('./CreateMetalakeDialog'), { + loading: () => <Loading />, ssr: false }) +const SetOwnerDialog = dynamic(() => import('@/components/SetOwnerDialog'), { + loading: () => <Loading />, + ssr: false +}) + +const ConfirmInput = dynamic(() => import('@/components/ConfirmInput'), { + loading: () => <Loading />, + ssr: false +}) + +const { Title, Paragraph } = Typography +const { Search } = Input + const MetalakeList = () => { - const [value, setValue] = useState('') - const [openDrawer, setOpenDrawer] = useState(false) - const [drawerData, setDrawerData] = useState() - const [openDialog, setOpenDialog] = useState(false) - const [dialogData, setDialogData] = useState({}) - const [dialogType, setDialogType] = useState('create') + const [open, setOpen] = useState(false) + const [openOwner, setOpenOwner] = useState(false) + const [editMetalake, setEditMetalake] = useState('') + const [metadataObjectFullName, setMetadataObjectFullName] = useState('') + const router = useRouter() + const [modal, contextHolder] = Modal.useModal() + const [search, setSearch] = useState('') + const [ownerRefreshKey, setOwnerRefreshKey] = useState(0) + const auth = useAppSelector(state => state.auth) + const { serviceAdmins, authUser, anthEnable } = auth + const dispatch = useAppDispatch() + const store = useAppSelector(state => state.metalakes) + const [tableData, setTableData] = useState([]) + + useEffect(() => { + dispatch(resetMetalakeStore()) + dispatch(fetchMetalakes()) + }, [dispatch]) + + useEffect(() => { + const filteredData = store.metalakes + .filter(i => i.name.toLowerCase().includes(search.toLowerCase())) + .map(i => ({ ...i, key: i.name })) + + setTableData(filteredData) + }, [dispatch, store.metalakes, search]) + + const onSearchTable = e => { + const { value } = e.target + setSearch(value) + } + + const handleCreateMetalake = () => { + setEditMetalake('') + setOpen(true) + } + + const handleEditMetalake = metalake => { + setEditMetalake(metalake) + setOpen(true) + } + + const handleToCatalogsPage = metalake => { + dispatch(resetTree()) + router.push(`/catalogs?metalake=${metalake}&catalogType=relational`) + } - const handleFilter = useCallback(val => { - setValue(val) - }, []) + const handleSetOwner = metalake => { + setMetadataObjectFullName(metalake) + setOpenOwner(true) + } + + const handleOwnerDialogClose = (open, refresh) => { + setOpenOwner(open) + if (refresh) setOwnerRefreshKey(k => k + 1) + } + + const propertyContent = properties => <PropertiesContent properties={properties} /> + + const showDeleteConfirm = (NameContext, metalake, type, isInUse = false) => { + let confirmInput = '' + let validateFn = null + + const setConfirmInput = value => { + confirmInput = value + } + + const registerValidate = fn => { + validateFn = fn + } + + modal.confirm({ + title: `Are you sure to delete the ${type} ${name}?`, Review Comment: The variable `name` is used but not defined in the function scope. This should be `metalake` based on the function signature. ```suggestion title: `Are you sure to delete the ${type} ${metalake}?`, ``` ########## web/web/src/app/catalogs/rightContent/entitiesContent/DataPreview.js: ########## @@ -0,0 +1,136 @@ +/* + * 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 { Alert, Spin, Table } from 'antd' + +// import { useTablePreview } from '@/hooks' + +export default function DataPreview({ ...props }) { + const { currentMetalake, catalog, schema, table } = props.namespaces + + // const { data: previewData, isInitialLoading: isLoading } = useTablePreview( + // { + // keepPreviousData: true, + // }, + // { metalake: currentMetalake, catalog, schema, table } as metadataParams, + // currentMetalake !== '', + // ) + + const getPreviewData = (type, value) => { + if (typeof type === 'string') { + if (value === null) return 'NULL' + if (value === 0) return '0' + if (type === 'boolean' && value !== null) return value ? 'true' : 'false' + + return value || '-' + } else { + const tCom = type?.type + switch (tCom) { + case 'struct': + return `{${Object.entries(value) + .map(([k, v]) => `${k}=${getPreviewData(type?.fields.find(f => f.name === k)?.type, v)}`) + .join(', ')}}` + case 'map': + return `{${Object.entries(value) + .map(([k, v]) => `${getPreviewData(type?.keyType, k)}=${getPreviewData(type?.valueType, v)}`) + .join(', ')}}` + case 'list': + return `[${value.map(v => getPreviewData(type?.elementType, v)).join(', ')}]` + default: + return '-' + } + } + } + + const columns = + previewData?.columns?.map(col => { + return { + title: col.name, + dataIndex: col.name, + key: col.name, + width: 150, + ellipsis: true, + render: text => { + if (text === null) { + return 'NULL' + } else if (!text && col.type !== 'boolean' && Number.isNaN(text)) { + return '-' + } else if (typeof col.type === 'string') { + return getPreviewData(col.type, text) + } else if (typeof col.type === 'object') { + const t = col.type?.type + switch (t) { + case 'struct': + return `{${Object.entries(text) + .map( + ([key, value]) => + `${key}=${getPreviewData(col.type?.fields.find(f => f.name === key)?.type, value)}` + ) + .join(', ')}}` + case 'map': + return `{${Object.entries(text) + .map( + ([key, value]) => + `${getPreviewData(col.type?.keyType, key)}=${getPreviewData(col.type?.valueType, value)}` + ) + .join(', ')}}` + case 'list': + return `[${text.map(v => getPreviewData(col.type?.elementType, v)).join(', ')}]` + default: + return '-' + } + } + } + } + }) || [] + + const tableData = + previewData?.results?.map((col, index) => { + return { + ...col, + key: index + } + }) || [] + + return ( + <Spin spinning={isLoading}> Review Comment: The variable `isLoading` is undefined because the `useTablePreview` hook is commented out. ########## web/web/src/app/catalogs/rightContent/entitiesContent/DataPreview.js: ########## @@ -0,0 +1,136 @@ +/* + * 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 { Alert, Spin, Table } from 'antd' + +// import { useTablePreview } from '@/hooks' + +export default function DataPreview({ ...props }) { + const { currentMetalake, catalog, schema, table } = props.namespaces + + // const { data: previewData, isInitialLoading: isLoading } = useTablePreview( + // { + // keepPreviousData: true, + // }, + // { metalake: currentMetalake, catalog, schema, table } as metadataParams, + // currentMetalake !== '', + // ) + + const getPreviewData = (type, value) => { + if (typeof type === 'string') { + if (value === null) return 'NULL' + if (value === 0) return '0' + if (type === 'boolean' && value !== null) return value ? 'true' : 'false' + + return value || '-' + } else { + const tCom = type?.type + switch (tCom) { + case 'struct': + return `{${Object.entries(value) + .map(([k, v]) => `${k}=${getPreviewData(type?.fields.find(f => f.name === k)?.type, v)}`) + .join(', ')}}` + case 'map': + return `{${Object.entries(value) + .map(([k, v]) => `${getPreviewData(type?.keyType, k)}=${getPreviewData(type?.valueType, v)}`) + .join(', ')}}` + case 'list': + return `[${value.map(v => getPreviewData(type?.elementType, v)).join(', ')}]` + default: + return '-' + } + } + } + + const columns = + previewData?.columns?.map(col => { Review Comment: The variable `previewData` is undefined. The commented-out hook `useTablePreview` is not being used, so `previewData` will always be undefined causing runtime errors. -- 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]
