Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/99 - Updating to V2 and removing hardcoded GetColumns values #109

Merged
merged 34 commits into from
Feb 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4608983
checkpoint
neocybereth Feb 14, 2019
d4653ac
checkpoint
neocybereth Feb 14, 2019
9b1d446
checkpoint
neocybereth Feb 14, 2019
1777a87
checkpoint
neocybereth Feb 14, 2019
f70206a
updated column display
neocybereth Feb 14, 2019
c3772a8
updates
neocybereth Feb 14, 2019
8e39c56
checkpoint
neocybereth Feb 14, 2019
82bd21f
updates
neocybereth Feb 14, 2019
e553a8c
updated first highlighted operations
neocybereth Feb 18, 2019
c0dbbaa
updated changeNetwork to v2
neocybereth Feb 18, 2019
1d7b808
added notes about update to v2 for submitFilters in thunks
neocybereth Feb 18, 2019
9af15ff
final updates
neocybereth Feb 18, 2019
407694b
cleanup
neocybereth Feb 19, 2019
dac5de8
updated sorting to show most recent first
neocybereth Feb 19, 2019
5ad153b
updated sorting and inital selected values
neocybereth Feb 19, 2019
91de399
checkpoint/notes
neocybereth Feb 21, 2019
8c903cb
updated initial call
neocybereth Feb 21, 2019
4df6c67
remove fetch attributes
neocybereth Feb 23, 2019
0da3108
remove fetchAttributes on Filter Panel
neocybereth Feb 24, 2019
b8d8a8a
pass CustomTable props to CustomTableRow
neocybereth Feb 24, 2019
fbdd987
remove superfluous getATtributesForQuery function
neocybereth Feb 24, 2019
6097751
updated getAttributeNames function
neocybereth Feb 24, 2019
81b10d7
remove attribute fetching from FilterPanel and add to thunks
neocybereth Feb 24, 2019
89db341
changes to App
neocybereth Feb 24, 2019
8663d3a
removed extra imports from CustomTableRow
neocybereth Feb 24, 2019
9e64393
checkpoint
neocybereth Feb 25, 2019
7fec369
cleanup
neocybereth Feb 25, 2019
439889f
checkpoint
neocybereth Feb 25, 2019
5b7f13b
checkpoint
neocybereth Feb 25, 2019
d03968a
checkpoint
neocybereth Feb 26, 2019
80ca783
breakthrough
neocybereth Feb 26, 2019
8795f0a
success
neocybereth Feb 26, 2019
6408b62
cleanup
neocybereth Feb 26, 2019
0e6d32a
cleanup
neocybereth Feb 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
73 changes: 45 additions & 28 deletions src/components/ColumnsDisplay/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import * as React from 'react';
import { connect } from 'react-redux';
import { getEntity, getColumns } from '../../reducers/app/selectors';
import { getEntity, getAttributes } from '../../reducers/app/selectors';
import { setColumns } from '../../reducers/app/thunks';
import styled from 'styled-components';
import { withStyles } from '@material-ui/core/styles';
import Checkbox from '@material-ui/core/Checkbox';
import ListItemText from '@material-ui/core/ListItemText';
import getColumnData from 'src/utils/getColumns';
import Button from '@material-ui/core/Button';
import Menu from '@material-ui/core/Menu';
import MenuItem from '@material-ui/core/MenuItem';
Expand Down Expand Up @@ -171,15 +170,19 @@ const styles = {
};

interface SelectedColumnsData {
dataIndex: string;
title: string;
key: string;
cardinality: null | number;
dataType: string;
displayName: string;
entity: string;
keyType: string;
name: string;
}

type Props = {
selectedColumns: any;
selectedEntity: string;
attributes: any;
setColumns: (entity: string, items: object[]) => void;
selectedColumns: object[];
classes: any;
};

Expand All @@ -197,32 +200,38 @@ class ColumnDisplay extends React.Component<Props, States> {
};

componentDidMount() {
const { selectedColumns } = this.props;
const { selectedColumns, selectedEntity } = this.props;
this.setState({
selected: [...selectedColumns],
selected: [...selectedColumns[selectedEntity]],
});
}

componentWillReceiveProps(nextProps: Props) {
if (nextProps.selectedColumns !== this.state.selected) {
componentDidUpdate(prevProps: Props) {
const { selectedColumns, selectedEntity } = this.props;
if (
prevProps.selectedColumns[selectedEntity] !==
selectedColumns[selectedEntity] ||
selectedEntity !== prevProps.selectedEntity
) {
this.setState({
selected: [...nextProps.selectedColumns],
selected: [...selectedColumns[selectedEntity]],
});
}
}

handleSubmit = event => {
const { selected } = this.state;
const { selectedEntity, setColumns } = this.props;
const { selectedEntity, setColumns, selectedColumns } = this.props;
event.preventDefault();
this.setState({ anchorEl: null });
this.setState({ selected: [...selectedColumns[selectedEntity]] });
setColumns(selectedEntity, selected);
};

handleChange = (name: SelectedColumnsData) => event => {
const { selected } = this.state;
const positionInArray = selected.findIndex(
selected => selected.dataIndex === name.dataIndex
selected => selected.name === name.name
);
if (positionInArray === -1 && selected.length <= 5) {
this.setState({
Expand All @@ -237,8 +246,11 @@ class ColumnDisplay extends React.Component<Props, States> {
};

cancelChange = () => {
const { selectedColumns } = this.props;
this.setState({ selected: [...selectedColumns], anchorEl: null });
const { selectedColumns, selectedEntity } = this.props;
this.setState({
selected: [...selectedColumns[selectedEntity]],
anchorEl: null,
});
};

handleClick = event => {
Expand All @@ -257,7 +269,7 @@ class ColumnDisplay extends React.Component<Props, States> {
};

render() {
const { selectedEntity, selectedColumns, classes } = this.props;
const { selectedEntity, classes, attributes } = this.props;
const { anchorEl, fadeBottom, selected } = this.state;
let tab;
switch (selectedEntity) {
Expand All @@ -271,8 +283,8 @@ class ColumnDisplay extends React.Component<Props, States> {
tab = 'accounts';
break;
}
const selectedDataIndex = selected.map(selected => {
return selected.dataIndex;
const selectedName = selected.map(selected => {
return selected.name;
});

return (
Expand All @@ -282,31 +294,36 @@ class ColumnDisplay extends React.Component<Props, States> {
aria-haspopup="true"
onClick={this.handleClick}
>
Columns ({selectedColumns.length})
Columns ({selected.length})
<ArrowIcon />
</ButtonShell>
<MenuContainer>
<Menu id="simple-menu" anchorEl={anchorEl} open={Boolean(anchorEl)} onClose={this.cancelChange}>
<Menu
id="simple-menu"
anchorEl={anchorEl}
open={Boolean(anchorEl)}
onClose={this.cancelChange}
>
<NestedTitle>Select Up to 6 Columns to Display</NestedTitle>
<MenuContents onScroll={this.handleScroll}>
<FadeTop />
{getColumnData(tab).map(name => (
{attributes.map((name, index) => (
<MenuItem
className={
selected.length >= 6 &&
selectedDataIndex.indexOf(name.dataIndex) === -1
selectedName.indexOf(name.name) === -1
? classes.removeSelector
: null
}
classes={{ root: classes.menuItem }}
onClick={this.handleChange(name)}
key={name.key}
value={name.dataIndex}
key={index}
value={name.name}
>
<Checkbox
className={
selected.length >= 6 &&
selectedDataIndex.indexOf(name.dataIndex) === -1
selectedName.indexOf(name.name) === -1
? classes.removeSelector
: null
}
Expand All @@ -315,9 +332,9 @@ class ColumnDisplay extends React.Component<Props, States> {
checked: classes.checked,
}}
disableRipple={true}
checked={selectedDataIndex.indexOf(name.dataIndex) > -1}
checked={selectedName.indexOf(name.name) > -1}
/>
<ListItemText primary={name.title} />
<ListItemText primary={name.displayName} />
<DraggableIcon />
</MenuItem>
))}
Expand All @@ -339,7 +356,7 @@ class ColumnDisplay extends React.Component<Props, States> {

const mapStateToProps = state => ({
selectedEntity: getEntity(state),
selectedColumns: getColumns(state),
attributes: getAttributes(state),
});

const mapDispatchToProps = dispatch => ({
Expand Down
71 changes: 33 additions & 38 deletions src/components/CustomTableRow/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import * as React from 'react';
import * as moment from 'moment';
import { connect } from 'react-redux';
import { getColumns, getNetwork } from '../../reducers/app/selectors';
import styled from 'styled-components';
import TableCell from '@material-ui/core/TableCell';
import TableRow from '@material-ui/core/TableRow';
Expand Down Expand Up @@ -50,46 +48,47 @@ interface Props {
network: string;
}

export const displayType = (network, shortenedItem, item, dataIndex) => {
if (dataIndex === 'accountId' || dataIndex === 'manager') {
export const displayType = (network, shortenedItem, item, name) => {
if (name === 'account_id' || name === 'manager') {
return (
<React.Fragment>
<StyledCircle1 />
<StyledCircle2 />
<ExplorerLink
href={`https://${network}.tzscan.io/${item[dataIndex]}`}
href={`https://${network}.tzscan.io/${item[name]}`}
target="_blank"
>
{shortenedItem[dataIndex]}
{shortenedItem[name]}
</ExplorerLink>
</React.Fragment>
);
} else if (
dataIndex === 'predecessor' ||
dataIndex === 'hash' ||
dataIndex === 'blockId' ||
dataIndex === 'blockHash' ||
dataIndex === 'operationGroupHash'
name === 'predecessor' ||
name === 'hash' ||
name === 'block_id' ||
name === 'block_hash' ||
name === 'operation_group_hash' ||
name === 'delegate'
) {
return (
<React.Fragment>
<ExplorerLink
href={`https://${network}.tzscan.io/${item[dataIndex]}`}
href={`https://${network}.tzscan.io/${item[name]}`}
target="_blank"
>
{shortenedItem[dataIndex]}
{shortenedItem[name]}
</ExplorerLink>
</React.Fragment>
);
} else if (
dataIndex === 'protocol' ||
dataIndex === 'context' ||
dataIndex === 'operationsHash' ||
dataIndex === 'signature'
name === 'protocol' ||
name === 'context' ||
name === 'operations_hash' ||
name === 'signature'
) {
return shortenedItem[dataIndex];
return shortenedItem[name];
} else {
return item[dataIndex];
return item[name];
}
};

Expand All @@ -98,13 +97,18 @@ const CustomTableRow: React.StatelessComponent<Props> = props => {
const shortenedItem = { ...item };
let itemsArray = Object.keys(shortenedItem);
itemsArray.forEach(hash => {
if (
if (item[hash] === null) {
return;
} else if (
hash.toLowerCase().includes('hash') ||
hash.toLowerCase().includes('predecessor') ||
hash.toLowerCase().includes('accountid') ||
hash.toLowerCase().includes('blockid') ||
// hash.toLowerCase().includes('manager') ||
hash.toLowerCase().includes('account_id') ||
hash.toLowerCase().includes('block_id') ||
hash.toLowerCase() === 'manager' ||
hash.toLowerCase().includes('protocol') ||
hash.toLowerCase().includes('block_hash') ||
hash.toLowerCase() === 'delegate' ||
hash.toLowerCase().includes('operation_group_hash') ||
hash.toLowerCase().includes('context') ||
hash.toLowerCase().includes('signature')
) {
Expand All @@ -119,17 +123,16 @@ const CustomTableRow: React.StatelessComponent<Props> = props => {
}
return shortenedItem[hash];
});

return (
<TableRowWrapper>
{selectedColumns.map(column => {
{selectedColumns.map((column, index) => {
return (
<StyledCell key={column.key}>
{column.dataIndex === 'timestamp' ? (
moment(item[column.dataIndex]).format('dd MM YYYY h:mm:ss a')
<StyledCell key={index}>
{column.name === 'timestamp' ? (
moment(item[column.name]).format('dd MM YYYY h:mm:ss a')
) : (
<SpanContainer>
{displayType(network, shortenedItem, item, column.dataIndex)}
{displayType(network, shortenedItem, item, column.name)}
</SpanContainer>
)}
</StyledCell>
Expand All @@ -139,12 +142,4 @@ const CustomTableRow: React.StatelessComponent<Props> = props => {
);
};

const mapStateToProps = (state: any) => ({
network: getNetwork(state),
selectedColumns: getColumns(state),
});

export default connect(
mapStateToProps,
null
)(CustomTableRow);
export default CustomTableRow;