import { RootState } from "../../store/store";
import DataExplorer from "../../components/data-explorer/data-explorer";
import { getDataExplorer } from "../../store/data-explorer/data-explorer-reducer";
+import { Dispatch } from "redux";
+import actions from "../../store/data-explorer/data-explorer-action";
+import { DataColumn } from "../../components/data-table/data-column";
+import { DataTableFilterItem } from "../../components/data-table-filters/data-table-filters";
+import { ContextMenuAction, ContextMenuActionGroup } from "../../components/context-menu/context-menu";
+
+interface Props {
+ id: string;
+ contextActions: ContextMenuActionGroup[];
+ onRowClick: (item: any) => void;
+ onContextAction: (action: ContextMenuAction, item: any) => void;
+}
+
+const mapStateToProps = (state: RootState, { id, contextActions }: Props) =>
+ getDataExplorer(state.dataExplorer, id);
+
+const mapDispatchToProps = (dispatch: Dispatch, { id, contextActions, onRowClick, onContextAction }: Props) => ({
+ onSearch: (searchValue: string) => {
+ dispatch(actions.SET_SEARCH_VALUE({ id, searchValue }));
+ },
+
+ onColumnToggle: (column: DataColumn<any>) => {
+ dispatch(actions.TOGGLE_COLUMN({ id, columnName: column.name }));
+ },
+
+ onSortToggle: (column: DataColumn<any>) => {
+ dispatch(actions.TOGGLE_SORT({ id, columnName: column.name }));
+ },
+
+ onFiltersChange: (filters: DataTableFilterItem[], column: DataColumn<any>) => {
+ dispatch(actions.SET_FILTERS({ id, columnName: column.name, filters }));
+ },
+
+ onChangePage: (page: number) => {
+ dispatch(actions.SET_PAGE({ id, page }));
+ },
+
+ onChangeRowsPerPage: (rowsPerPage: number) => {
+ dispatch(actions.SET_ROWS_PER_PAGE({ id, rowsPerPage }));
+ },
+
+ contextActions,
+
+ onRowClick,
+
+ onContextAction
+});
+
+export default connect(mapStateToProps, mapDispatchToProps)(DataExplorer);
-export default connect((state: RootState, props: { id: string }) =>
- getDataExplorer(state.dataExplorer, props.id)
-)(DataExplorer);
import { Grid, Typography, Button, Toolbar, StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core';
import { formatDate, formatFileSize } from '../../common/formatters';
import DataExplorer from "../../views-components/data-explorer/data-explorer";
-import { DataColumn, toggleSortDirection } from '../../components/data-table/data-column';
-import { DataTableFilterItem } from '../../components/data-table-filters/data-table-filters';
import { ContextMenuAction } from '../../components/context-menu/context-menu';
import { DispatchProp, connect } from 'react-redux';
import actions from "../../store/data-explorer/data-explorer-action";
<DataExplorer
id={PROJECT_PANEL_ID}
contextActions={contextMenuActions}
- onColumnToggle={this.toggleColumn}
- onFiltersChange={this.changeFilters}
onRowClick={this.props.onItemClick}
- onSortToggle={this.toggleSort}
- onSearch={this.search}
- onContextAction={this.executeAction}
- onChangePage={this.changePage}
- onChangeRowsPerPage={this.changeRowsPerPage} />;
+ onContextAction={this.executeAction} />;
</div>;
}
- componentDidMount() {
- this.props.dispatch(actions.SET_COLUMNS({ id: PROJECT_PANEL_ID, columns }));
- }
-
componentWillReceiveProps({ match, currentItemId }: ProjectPanelProps) {
if (match.params.id !== currentItemId) {
this.props.onItemRouteChange(match.params.id);
}
}
- toggleColumn = (toggledColumn: DataColumn<ProjectPanelItem>) => {
- this.props.dispatch(actions.TOGGLE_COLUMN({ id: PROJECT_PANEL_ID, columnName: toggledColumn.name }));
- }
-
- toggleSort = (column: DataColumn<ProjectPanelItem>) => {
- this.props.dispatch(actions.TOGGLE_SORT({ id: PROJECT_PANEL_ID, columnName: column.name }));
- }
-
- changeFilters = (filters: DataTableFilterItem[], column: DataColumn<ProjectPanelItem>) => {
- this.props.dispatch(actions.SET_FILTERS({ id: PROJECT_PANEL_ID, columnName: column.name, filters }));
- }
-
executeAction = (action: ContextMenuAction, item: ProjectPanelItem) => {
alert(`Executing ${action.name} on ${item.name}`);
}
- search = (searchValue: string) => {
- this.props.dispatch(actions.SET_SEARCH_VALUE({ id: PROJECT_PANEL_ID, searchValue }));
- }
-
- changePage = (page: number) => {
- this.props.dispatch(actions.SET_PAGE({ id: PROJECT_PANEL_ID, page }));
- }
-
- changeRowsPerPage = (rowsPerPage: number) => {
- this.props.dispatch(actions.SET_ROWS_PER_PAGE({ id: PROJECT_PANEL_ID, rowsPerPage }));
- }
-
}
type CssRules = "toolbar" | "button";
{item.status || "-"}
</Typography>;
-const columns: DataColumns<ProjectPanelItem> = [{
+export const columns: DataColumns<ProjectPanelItem> = [{
name: "Name",
selected: true,
sortDirection: "desc",