@dev-crew-berlin/enter-js-utils 0.45.0 → 0.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,15 @@
1
1
  import { components } from '../generated/api-schema';
2
+ import { Field } from './field';
2
3
  export declare type Dictionary<T> = Record<string, T>;
3
4
  export declare type FieldGroup = components['schemas']['FieldGroup'];
4
5
  export declare type FieldLabels = Record<string, FieldTitle | undefined>;
5
6
  declare type FieldTitle = string | Dictionary<string>;
6
7
  export declare class FieldGroups {
7
8
  groups: FieldGroup[];
9
+ get groupNames(): string[];
10
+ get fields(): Map<string, Field & {
11
+ group: string;
12
+ }>;
8
13
  constructor(json: FieldGroup[]);
9
14
  toJSON(): FieldGroup[];
10
15
  getFieldLabels(): FieldLabels;
@@ -1,4 +1,19 @@
1
1
  export class FieldGroups {
2
+ get groupNames() {
3
+ return this.groups.map((_, index) => index.toString());
4
+ }
5
+ get fields() {
6
+ const fields = new Map();
7
+ for (const [groupIndex, group] of this.groups.entries()) {
8
+ for (const field of group.questions) {
9
+ fields.set(field.name, {
10
+ ...field,
11
+ group: groupIndex.toString()
12
+ });
13
+ }
14
+ }
15
+ return fields;
16
+ }
2
17
  constructor(json) {
3
18
  this.groups = json;
4
19
  }
@@ -6,12 +21,11 @@ export class FieldGroups {
6
21
  return this.groups;
7
22
  }
8
23
  getFieldLabels() {
9
- return this.groups.reduce((labels, group) => {
10
- return group.questions.reduce((labels, question) => {
11
- labels[question.name] = question.title ?? question.name;
12
- return labels;
13
- }, labels);
14
- }, {});
24
+ const labels = {};
25
+ for (const [fieldKey, field] of this.fields.entries()) {
26
+ labels[fieldKey] = field.title ?? field.name;
27
+ }
28
+ return labels;
15
29
  }
16
30
  getLabelForField(fieldKey, language) {
17
31
  const fieldLabel = this.getFieldLabels()[fieldKey];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev-crew-berlin/enter-js-utils",
3
- "version": "0.45.0",
3
+ "version": "0.46.0",
4
4
  "description": "utils such as vaildation and other helpers to work with data from the enter app",
5
5
  "files": [
6
6
  "dist",