|
1 | 1 | <script lang="ts"> |
| 2 | + /* eslint-disable @typescript-eslint/no-confusing-void-expression */ |
| 3 | +
|
2 | 4 | import type { MouseEventHandler } from "svelte/elements"; |
3 | | - import { addFilter, escape_for_regex } from "."; |
| 5 | +
|
4 | 6 | import type { AccountJournalEntry } from "../api/validators"; |
5 | 7 | import type { Document, EntryMetadata, Transaction } from "../entries"; |
6 | 8 | import { type Entry } from "../entries"; |
|
10 | 12 | import { currency_name } from "../stores"; |
11 | 13 | import { ctx } from "../stores/format"; |
12 | 14 | import type { JournalShowEntry } from "../stores/journal"; |
| 15 | + import { addFilter, escape_for_regex } from "."; |
13 | 16 |
|
14 | 17 | interface Props { |
15 | 18 | index: number; |
|
62 | 65 | return liClasses; |
63 | 66 | }); |
64 | 67 |
|
65 | | - const unitRegex = /([\d\.\-]+)\s+(\w+)/; |
66 | | - const costRegex = /\{([\d\.\-]+)\s+(\w+),\s([\w\-]+)\}/; |
67 | | - const priceRegex = /@\s([\d\.\-]+)\s+(\w+)/; |
| 68 | + const unitRegex = /([\d.-]+)\s+(\w+)/; |
| 69 | + const costRegex = /\{([\d.-]+)\s+(\w+),\s([\w-]+)\}/; |
| 70 | + const priceRegex = /@\s([\d.-]+)\s+(\w+)/; |
68 | 71 |
|
69 | 72 | type PostingAmounts = [ |
70 | 73 | [amount: string, currency: string], |
|
73 | 76 | ]; |
74 | 77 |
|
75 | 78 | function splitPostingAmount(str: string): PostingAmounts { |
76 | | - const amount = str.match(unitRegex)!; |
77 | | - const cost = str.match(costRegex); |
78 | | - const price = str.match(priceRegex); |
| 79 | + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion |
| 80 | + const amount = unitRegex.exec(str)!; |
| 81 | + const cost = costRegex.exec(str); |
| 82 | + const price = priceRegex.exec(str); |
79 | 83 |
|
80 | 84 | return [ |
81 | 85 | [amount[1], amount[2]], |
|
93 | 97 |
|
94 | 98 | type ClickHandler = MouseEventHandler<HTMLElement>; |
95 | 99 |
|
96 | | - const clickTagLink: ClickHandler = ({ currentTarget }) => |
| 100 | + const clickTagLink: ClickHandler = ({ currentTarget }) => { |
97 | 101 | addFilter(currentTarget.innerText); |
| 102 | + }; |
98 | 103 |
|
99 | 104 | // Note: any special characters in the payee string are escaped so the |
100 | 105 | // filter matches against the payee literally. |
101 | | - const clickPayee: ClickHandler = ({ currentTarget }) => |
| 106 | + const clickPayee: ClickHandler = ({ currentTarget }) => { |
102 | 107 | addFilter(`payee:"^${escape_for_regex(currentTarget.innerText)}$"`); |
| 108 | + }; |
103 | 109 |
|
104 | 110 | const clickMetaKey: ClickHandler = ({ currentTarget }) => { |
105 | 111 | const expr = `${currentTarget.innerText}""`; |
|
127 | 133 | </script> |
128 | 134 |
|
129 | 135 | {#snippet amount(amount: Amount | RawAmount, cls: string)} |
| 136 | + <!-- eslint-disable-next-line @typescript-eslint/strict-boolean-expressions --> |
130 | 137 | {#if !amount.number} |
131 | 138 | <span class={cls}></span> |
132 | 139 | {:else} |
|
283 | 290 | {@render metadataIndicators(e.meta)} |
284 | 291 | {#if e.t === "Transaction"} |
285 | 292 | {#each e.postings as posting, index (index)} |
286 | | - <span class={posting.flag ? flagToTypes(posting.flag) : null}></span> |
| 293 | + <span class={posting.flag != null ? flagToTypes(posting.flag) : null} |
| 294 | + ></span> |
287 | 295 | {@render metadataIndicators(posting.meta)} |
288 | 296 | {/each} |
289 | 297 | {/if} |
|
302 | 310 | {#if showChangeAndBalance} |
303 | 311 | {#if e.t === "Transaction"} |
304 | 312 | <span class="change num"> |
305 | | - {#each Object.entries(change ?? {}) as [currency, number]} |
306 | | - {$ctx.amount(number, currency)}<br /> |
307 | | - {/each} |
| 313 | + {#if change} |
| 314 | + {#each Object.entries(change) as [currency, number], index (index)} |
| 315 | + <!-- eslint-disable-next-line @typescript-eslint/no-unsafe-argument --> |
| 316 | + {$ctx.amount(number, currency)}<br /> |
| 317 | + {/each} |
| 318 | + {/if} |
308 | 319 | </span> |
309 | 320 | {/if} |
310 | 321 | <span class="num"> |
311 | | - {#each Object.entries(balance ?? {}) as [currency, number]} |
312 | | - {$ctx.amount(number, currency)}<br /> |
313 | | - {/each} |
| 322 | + {#if balance} |
| 323 | + {#each Object.entries(balance) as [currency, number], index (index)} |
| 324 | + <!-- eslint-disable-next-line @typescript-eslint/no-unsafe-argument --> |
| 325 | + {$ctx.amount(number, currency)}<br /> |
| 326 | + {/each} |
| 327 | + {/if} |
314 | 328 | </span> |
315 | 329 | {/if} |
316 | 330 | </p> |
317 | 331 | {@render metadata(e.meta, e.entry_hash)} |
318 | 332 | {#if showPostings && e.t === "Transaction" && e.postings.length > 0} |
319 | 333 | <ul class="postings"> |
320 | 334 | {#each e.postings as posting, index (index)} |
321 | | - <li class={posting.flag ? flagToTypes(posting.flag) : null}> |
| 335 | + <li class={posting.flag != null ? flagToTypes(posting.flag) : null}> |
322 | 336 | <p> |
323 | 337 | <span class="datecell"></span> |
324 | 338 | <span class="flag">{posting.flag ?? ""}</span> |
|
0 commit comments