-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Calculated Columns Title is shown (#349)
- Loading branch information
Showing
24 changed files
with
306 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import Table from './src/console-table-printer'; | ||
import { printSimpleTable as printTable } from './src/internalTable/internal-table-printer'; | ||
|
||
import { COLOR, ALIGNMENT } from './src/utils/table-constants'; | ||
import { COLOR, ALIGNMENT } from './src/models/external-table'; | ||
|
||
export { Table, printTable, COLOR, ALIGNMENT }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { COLOR } from '../models/common'; | ||
import { ColumnOptionsRaw } from '../models/external-table'; | ||
import { Column } from '../models/internal-table'; | ||
import { defaultRowAlignment } from '../utils/table-constants'; | ||
|
||
export const objIfExists = (key: string, val: any) => { | ||
if (!val) { | ||
return {}; | ||
} | ||
|
||
return { | ||
[key]: val, | ||
}; | ||
}; | ||
|
||
export const rawColumnToInternalColumn = ( | ||
column: ColumnOptionsRaw | ||
): Column => ({ | ||
name: column.name, | ||
title: column.title || column.name, | ||
...objIfExists('color', column.color as COLOR), | ||
...objIfExists('maxLen', column.maxLen), | ||
alignment: column.alignment || defaultRowAlignment, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
import { alignments, colors } from '../utils/table-constants'; | ||
|
||
export type ALIGNMENT = typeof alignments[number]; | ||
|
||
export type COLOR = typeof colors[number]; | ||
export interface Dictionary { | ||
[key: string]: any; | ||
} | ||
export interface Row { | ||
color: COLOR; | ||
text: Dictionary; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { ALIGNMENT, COLOR, Dictionary } from './common'; | ||
import { TABLE_STYLE_DETAILS } from './internal-table'; | ||
|
||
export { ALIGNMENT, COLOR }; | ||
|
||
export interface ColumnOptionsRaw { | ||
name: string; // unique id | ||
title?: string; // the value that will be printed, if not present this will be 'name' | ||
alignment?: ALIGNMENT; | ||
color?: COLOR; | ||
maxLen?: number; | ||
} | ||
|
||
export interface ComputedColumn extends ColumnOptionsRaw { | ||
function: (arg0: any) => any; | ||
} | ||
|
||
export type RowSortFunction = (row1: any, row2: any) => number; | ||
|
||
export type RowFilterFunction = (row: any) => Boolean; | ||
|
||
export interface ComplexOptions { | ||
style?: TABLE_STYLE_DETAILS; | ||
title?: string; | ||
columns?: ColumnOptionsRaw[]; | ||
sort?: RowSortFunction; | ||
filter?: RowFilterFunction; | ||
enabledColumns?: string[]; | ||
disabledColumns?: string[]; | ||
computedColumns?: ComputedColumn[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Testing column alignment all kind of alignments are working 1`] = ` | ||
"ββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββ | ||
[37mβ[0m[37m [0m[01mred_left_align_index[0m[37m β[0m[37m [0m[01m right_align_text[0m[37m β[0m[37m [0m[01mgreen_value_center[0m[37m β[0m | ||
ββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββββββΌβββββββββββββββββββββ€ | ||
[37mβ[0m[37m [0m[31m2 [0m[37m β[0m[37m [0m[34m This row is blue[0m[37m β[0m[37m [0m[32m 10.212 [0m[37m β[0m | ||
[37mβ[0m[37m [0m[31m3 [0m[37m β[0m[37m [0m[31m I would like some red wine please[0m[37m β[0m[37m [0m[32m 10.212 [0m[37m β[0m | ||
[37mβ[0m[37m [0m[31m4 [0m[37m β[0m[37m [0m[36m I would like some cyan wine please[0m[37m β[0m[37m [0m[32m 10.212 [0m[37m β[0m | ||
[37mβ[0m[37m [0m[31m5 [0m[37m β[0m[37m [0m[01mI would like some white_bold wine please[0m[37m β[0m[37m [0m[32m 10.212 [0m[37m β[0m | ||
[37mβ[0m[37m [0m[31m6 [0m[37m β[0m[37m [0m[38m I would like some crimson sky please[0m[37m β[0m[37m [0m[32m 10.212 [0m[37m β[0m | ||
[37mβ[0m[37m [0m[31m7 [0m[37m β[0m[37m [0m[32m I would like some green gemuse please[0m[37m β[0m[37m [0m[32m 20 [0m[37m β[0m | ||
[37mβ[0m[37m [0m[31m8 [0m[37m β[0m[37m [0m[33m I would like some gelb bananen bitte[0m[37m β[0m[37m [0m[32m 100 [0m[37m β[0m | ||
ββββββββββββββββββββββββ΄βββββββββββββββββββββββββββββββββββββββββββ΄βββββββββββββββββββββ" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Example: Print a simple Table with cell colors cell colors are working 1`] = ` | ||
"βββββββββ¬ββββββββββ¬βββββββββ | ||
[37mβ[0m[37m [0m[01mindex[0m[37m β[0m[37m [0m[01m text[0m[37m β[0m[37m [0m[01m value[0m[37m β[0m | ||
βββββββββΌββββββββββΌβββββββββ€ | ||
[37mβ[0m[37m [0m[37m 1[0m[37m β[0m[37m [0m[37m [31mred[39m[0m[37m β[0m[37m [0m[37m10.212[0m[37m β[0m | ||
[37mβ[0m[37m [0m[37m 2[0m[37m β[0m[37m [0m[37m [32mgreen[39m[0m[37m β[0m[37m [0m[37m 20[0m[37m β[0m | ||
[37mβ[0m[37m [0m[37m 3[0m[37m β[0m[37m [0m[37m [33myellow[39m[0m[37m β[0m[37m [0m[37m 100[0m[37m β[0m | ||
[37mβ[0m[37m [0m[37m 4[0m[37m β[0m[37m [0m[37m[45mmagenta[49m[0m[37m β[0m[37m [0m[37m 300[0m[37m β[0m | ||
βββββββββ΄ββββββββββ΄βββββββββ" | ||
`; |
Oops, something went wrong.