-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #139
- Loading branch information
Showing
9 changed files
with
261 additions
and
31 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
type: add | ||
issue: 139 | ||
audience: user | ||
components: | ||
- ui | ||
- cli | ||
- api | ||
--- | ||
# Add groupBy field name to export | ||
|
||
## CLI | ||
|
||
Via `--group-by` option: | ||
|
||
``` | ||
$ snage export --group-by type | ||
``` | ||
|
||
## API | ||
|
||
Via `groupBy` query parameter: | ||
|
||
`/export?groupBy=type&query=` | ||
|
||
## UI | ||
|
||
Inside the export dialog. |
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,36 @@ | ||
import {Config} from '../config/type'; | ||
import {Note} from './note'; | ||
import * as E from 'fp-ts/lib/Either'; | ||
import {pipe} from 'fp-ts/lib/pipeable'; | ||
import * as A from 'fp-ts/lib/Array'; | ||
import {encodeStringValue} from './convert'; | ||
|
||
export const groupByFieldNameMaybe = ( | ||
config: Config, | ||
fieldName?: string | ||
): ((notes: Note[]) => E.Either<string, Record<string, Note[]> | Note[]>) => { | ||
if (fieldName === undefined) { | ||
return E.right; | ||
} | ||
return groupByFieldName(config, fieldName); | ||
}; | ||
|
||
export const groupByFieldName = (config: Config, fieldName: string) => ( | ||
notes: Note[] | ||
): E.Either<string, Record<string, Note[]>> => | ||
pipe( | ||
config.fields, | ||
A.findFirst(({name}) => name === fieldName), | ||
E.fromOption(() => `field ${fieldName} does not exist`), | ||
E.filterOrElse( | ||
(field) => !field.list, | ||
() => `field ${fieldName} cannot be grouped because it is type list` | ||
), | ||
E.map((field) => | ||
notes.reduce((grouped, note) => { | ||
const value = note.values[field.name]; | ||
const key = value ? encodeStringValue(field.type, field, value).toString() : 'no value'; | ||
return {...grouped, [key]: [...(grouped[key] ?? []), note]}; | ||
}, {}) | ||
) | ||
); |
Oops, something went wrong.