/** ******************************************************************************************************************* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed 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 { FC, useMemo, useState, useCallback } from 'react'; import CollectionPreferences, { CollectionPreferencesProps, } from '@cloudscape-design/components/collection-preferences'; import { NonCancelableEventHandler } from '@cloudscape-design/components/internal/events'; import FullDataTable from './components/FullDataTable'; import RemoteUpdateTable from './components/RemoteUpdateTable'; import { TableProps } from './types'; import { DEFAULT_COLLECTION_PREFERENCES_TITLE, DEFAULT_COLLECTION_PREFERENCES_CONFRIM_LABEL, DEFAULT_COLLECTION_PREFERENCES_CANCEL_LABEL, DEFAULT_PAGE_SIZE_OPTIONS, } from './config'; /** * A table presents data in a two-dimensional format, arranged in columns and rows in a rectangular form. * */ const Table: FC = ({ disableSettings, preferences: collectionPreferenceComponent, ...props }) => { const [preferences, setPreferences] = useState({ pageSize: props.defaultPageSize, visibleContent: props.columnDefinitions.map((cd) => cd.id || ''), }); const visibleContentOptions = useMemo(() => { return [ { label: 'Main properties', options: props.columnDefinitions.map((cd) => ({ id: cd.id || '', label: (typeof cd.header === 'string' ? cd.header : cd.id) || '', })), }, ]; }, [props.columnDefinitions]); const handlePreferenceChange: NonCancelableEventHandler> = useCallback( ({ detail }) => { setPreferences(detail); }, [] ); const preferenceComponent = useMemo(() => { if (disableSettings) { return undefined; } if (collectionPreferenceComponent) { return collectionPreferenceComponent; } return ( ); }, [ disableSettings, preferences, props.collectionPreferencesProps, collectionPreferenceComponent, visibleContentOptions, handlePreferenceChange, ]); if ('onFetchData' in props && typeof props.onFetchData === 'function') { return ; } return ; }; export default Table; export * from './types'; export * from './config';