-
Notifications
You must be signed in to change notification settings - Fork 96
/
uncleared.tsx
116 lines (104 loc) · 3.24 KB
/
uncleared.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import * as React from "react";
import styled from "styled-components";
import { UnclearedPosting } from "./server_connection";
import { AssociatedDataViewController, AssociatedDataViewContext } from "./app";
import { JournalLineReference } from "./invalid_references";
import { EventSubscription } from "fbemitter";
import {
ServerVirtualListComponent,
ServerVirtualListState
} from "./server_virtual_list";
class UnclearedVirtualListComponent extends ServerVirtualListComponent<
UnclearedPosting
> {}
const UnclearedPostingsList = styled(UnclearedVirtualListComponent)`
overflow-y: scroll;
flex: 1;
`;
const UnclearedPostingElement = styled.div`
cursor: pointer;
padding: 12px 8px;
border-bottom: 1px solid var(--color-main-accent);
min-width: 100%;
box-sizing: border-box;
:hover {
background-color: var(--color-hover-bg);
color: var(--color-hover-text);
}
`;
const UnclearedPostingFormattedElement = styled.div`
font-family: var(--font-fam-mono);
font-size: var(--font-size-mono-reg);
white-space: pre;
`;
const UnclearedPostingSource = styled.div`
font-size: var(--font-size-sans-small);
border-top: 1px solid var(--color-main-accent);
margin: 6px 0 2px;
padding: 6px 0 0px;
white-space: nowrap;
`;
interface UnclearedPostingsComponentProps {
listState: ServerVirtualListState<UnclearedPosting>;
}
interface UnclearedPostingComponentProps {
entry: UnclearedPosting;
}
export class UnclearedPostingComponent extends React.PureComponent<
UnclearedPostingComponentProps
> {
private dataViewController?: AssociatedDataViewController;
render() {
const { entry } = this.props;
const filename = entry.transaction.meta && entry.transaction.meta.filename;
const lineno = entry.transaction.meta && entry.transaction.meta.lineno;
const account = entry.posting.account;
const formattedText = entry.transaction_formatted;
return (
<AssociatedDataViewContext.Consumer>
{dataViewController => {
this.dataViewController = dataViewController;
return (
<UnclearedPostingElement onClick={this.handleClick}>
<UnclearedPostingFormattedElement>
{formattedText}
</UnclearedPostingFormattedElement>
{filename && <UnclearedPostingSource>
<div>
<em>Account:</em> {account}
</div>
<div>
<em>File:</em> {filename}
{lineno !== undefined && `:${lineno}`}
</div>
</UnclearedPostingSource>}
</UnclearedPostingElement>
);
}}
</AssociatedDataViewContext.Consumer>
);
}
private handleClick = () => {
const { dataViewController } = this;
dataViewController!.selectFileByMeta(this.props.entry.transaction.meta);
};
}
export class UnclearedPostingsComponent extends React.PureComponent<
UnclearedPostingsComponentProps
> {
private renderItem(
entry: UnclearedPosting,
index: number,
ref: React.RefObject<any>
) {
return <UnclearedPostingComponent key={index} ref={ref} entry={entry} />;
}
render() {
return (
<UnclearedPostingsList
listState={this.props.listState}
renderItem={this.renderItem}
/>
);
}
}