// External imports import * as React from "react" import { advancedObjectHelper, AdvancedDataType } from "fawkes-server/build/support" // Internal imports import * as ce from "../../../../helpers/componentEnhancer" import { AdvancedTablePropertyToDisplay } from "../../../../helpers/advancedTable" import Icon from "../../icon" export interface ParentProps { property: advancedObjectHelper.AdvancedObjectPropertyPublic propertyDisplayOptions: AdvancedTablePropertyToDisplay dataType: AdvancedDataType currentOrderBy: Array< advancedObjectHelper.AdvancedObjectGetRecordListOrderByOption > setOrderBy: ( orderBy: Array< advancedObjectHelper.AdvancedObjectGetRecordListOrderByOption > ) => void } interface StateProps {} interface DispatchProps {} interface LocalState {} class AdvancedTableHeadCell extends React.Component< ParentProps & StateProps & DispatchProps & ce.EnhancedPropsPrivate, LocalState > { currentFirstOrderByCriterium() { return this.props.currentOrderBy[0] } isOrderedByThis() { return ( this.currentFirstOrderByCriterium() && this.currentFirstOrderByCriterium().propertyName === this.props.propertyDisplayOptions.propertyName ) } isOrderedByThisAscending() { return ( this.isOrderedByThis() && !this.currentFirstOrderByCriterium().descending ) } generateNewOrderBy(): Array< advancedObjectHelper.AdvancedObjectGetRecordListOrderByOption > { const nowOrderByDescending = this.isOrderedByThisAscending() return [ { propertyName: this.props.propertyDisplayOptions.propertyName, descending: nowOrderByDescending }, ...this.props.currentOrderBy ].splice(0, 5) } generateCssClass(): string { let classesArray = [] if (this.props.property.orderByAllowed) classesArray.push("sortable") return classesArray.join(" ") } render() { return ( this.props.setOrderBy(this.generateNewOrderBy()) : null } className={this.generateCssClass()} style={{ width: this.props.propertyDisplayOptions.defaultWidth }} > {(this.props.propertyDisplayOptions && this.props.propertyDisplayOptions.columnTitle) || ""} {this.isOrderedByThis() ? ( {this.isOrderedByThisAscending() ? : null} {!this.isOrderedByThisAscending() ? ( ) : null} ) : null} ) } } const stateMappings: ce.StateMappings = (s, props) => ({}) const dispatchMappings: ce.DispatchMappings = (d, props) => ({}) export default ((): React.ComponentType => ce.enhance(AdvancedTableHeadCell, { stateMappings, dispatchMappings }))()