import * as React from 'react'; import { MmuiProps, MmuiState, MmuiCommonComponent } from '../common'; /** * Selection Filter UI Component */ export class MmuiSelectionFilterComponent< P extends MmuiProps, S extends MmuiState > extends MmuiCommonComponent { constructor(props) { super(props); } /** * @return this component's initial state. */ getInitialComponentState(): any { const state = { mode: '', isVisible: false, selectedRowIds: [], sourceUpdatedAt: null, }; return state; } componentDidUpdate(): void { const componentState = this.getComponentState(); if (componentState.operation === 'update') { const selectedRowIds = this.props.store.shared.selectedRowIds; this.setComponentState({ isVisible: selectedRowIds.length > 0, numSelected: selectedRowIds.length, operation: '', }); } } /** * On Filter Event Listener * @param e */ onFilter = (e) => { e.preventDefault(); this.props.setToStore(['shared', 'operation'], 'filter_apply'); }; /** * * On Filter Event Listener * @param e */ onClear = (e) => { e.preventDefault(); this.props.setToStore(['shared', 'operation'], 'filter_clear'); }; render() { const componentState = this.getComponentState(); if ( componentState === undefined || componentState === null || !componentState.isVisible ) { return null; } return (
{componentState.numSelected} Selected
Clear Selection
filter
); } }