/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import { useState } from 'react';
import {
Box,
Button,
CollectionPreferences,
Pagination,
TextFilter,
Table
} from '@awsui/components-react';
import {
PAGE_SELECTOR_OPTIONS,
DEFAULT_PREFERENCES,
getColumnDefinitions,
getContentSelectorOptions
} from '../resources/schemaattr-table-config.jsx';
import { useCollection } from '@awsui/collection-hooks';
import TableHeader from './TableHeader.jsx';
const SchemaAttributesTable = (props) => {
const [preferences, setPreferences] = useState(DEFAULT_PREFERENCES);
const [contentAttributes, ] = useState(getContentSelectorOptions());
const { items, actions, collectionProps, filterProps, paginationProps, filteredItemsCount } = useCollection(
props.items,
{
pagination: { pageSize: preferences.pageSize },
sorting: {},
filtering: {
noMatch: (
No matches
No results match your query
)
}
}
);
// Keeps track of how many applications are selected
function headerCounter(selectedApps, applications) {
return selectedApps.length
? `(${selectedApps.length} of ${applications.length})`
: `(${applications.length})`;
}
function filterCounter(count) {
return `${count} ${count === 1 ? 'match' : 'matches'}`;
}
//moved up to handler
// function handleSelectionChange(detail) {
// detail.preventDefault();
// props.handleSelectionChange(detail.selectedItems);
// }
async function handleOnRowClick(detail) {
if (props.handleSelectionChange){
let selectedItem = []
selectedItem.push(detail.item);
await props.handleSelectionChange(selectedItem);
}
}
function handleConfirmPreferences(detail) {
let lPreferences = detail;
lPreferences.trackBy = DEFAULT_PREFERENCES.trackBy;
setPreferences(lPreferences);
}
return (
}
preferences={
handleConfirmPreferences(detail)}
pageSizePreference={{
title: 'Page size',
options: PAGE_SELECTOR_OPTIONS
}}
visibleContentPreference={{
title: 'Select visible columns',
options: contentAttributes
}}
wrapLinesPreference={{
label: 'Wrap lines',
description: 'Check to see all the text and wrap the lines'
}}
/>
}
wrapLines={preferences.wrapLines}
selectedItems={props.selectedItems ? props.selectedItems : []}
onSelectionChange={props.handleSelectionChange ? ({ detail }) => props.handleSelectionChange(detail.selectedItems) : null}
onRowClick={({ detail }) => handleOnRowClick(detail)}
selectionType={props.handleSelectionChange ? 'single' : undefined}
pagination={}
filter={
}
/>
);
};
export default SchemaAttributesTable;