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

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.
@@ -2,17 +2,11 @@ import { components } from '../generated/api-schema';
2
2
  import { Field } from './field';
3
3
  export declare type Dictionary<T> = Record<string, T>;
4
4
  export declare type FieldGroup = components['schemas']['FieldGroup'];
5
- export declare type FieldLabels = Record<string, FieldTitle | undefined>;
6
- declare type FieldTitle = string | Dictionary<string>;
7
5
  export declare class FieldGroups {
8
- groups: FieldGroup[];
9
- get groupNames(): string[];
10
- get fields(): Map<string, Field & {
11
- group: string;
12
- }>;
6
+ private _groups;
7
+ get groups(): Map<string, FieldGroup>;
8
+ get fields(): Map<string, Field>;
13
9
  constructor(json: FieldGroup[]);
14
10
  toJSON(): FieldGroup[];
15
- getFieldLabels(): FieldLabels;
16
11
  getLabelForField(fieldKey: string, language: string): string;
17
12
  }
18
- export {};
@@ -1,34 +1,29 @@
1
1
  export class FieldGroups {
2
- get groupNames() {
3
- return this.groups.map((_, index) => index.toString());
2
+ get groups() {
3
+ const groups = new Map();
4
+ for (const [index, group] of this._groups.entries()) {
5
+ groups.set(index.toString(), group);
6
+ }
7
+ return groups;
4
8
  }
5
9
  get fields() {
6
10
  const fields = new Map();
7
- for (const [groupIndex, group] of this.groups.entries()) {
11
+ for (const group of this._groups) {
8
12
  for (const field of group.questions) {
9
- fields.set(field.name, {
10
- ...field,
11
- group: groupIndex.toString()
12
- });
13
+ fields.set(field.name, field);
13
14
  }
14
15
  }
15
16
  return fields;
16
17
  }
17
18
  constructor(json) {
18
- this.groups = json;
19
+ this._groups = json;
19
20
  }
20
21
  toJSON() {
21
- return this.groups;
22
- }
23
- getFieldLabels() {
24
- const labels = {};
25
- for (const [fieldKey, field] of this.fields.entries()) {
26
- labels[fieldKey] = field.title ?? field.name;
27
- }
28
- return labels;
22
+ return this._groups;
29
23
  }
30
24
  getLabelForField(fieldKey, language) {
31
- const fieldLabel = this.getFieldLabels()[fieldKey];
25
+ const field = this.fields.get(fieldKey);
26
+ const fieldLabel = field?.title ?? field?.name ?? fieldKey;
32
27
  const translatedLabel = fieldLabel === undefined || typeof fieldLabel === 'string' ? fieldLabel : fieldLabel[language];
33
28
  return translatedLabel ?? fieldKey;
34
29
  }
@@ -6,7 +6,7 @@ export type { CheckinJSON } from './checkin';
6
6
  export { Checkins } from './checkins';
7
7
  export type { CheckinsJSON } from './checkins';
8
8
  export type { Event, AttendeeUpdatedEvent, AttendeeCreatedEvent, AttendeeRespondedEvent, AttendeeDeletedEvent, CheckinCreatedEvent, CheckinDeletedEvent, PaymentPaidEvent, } from './event';
9
- export type { FieldGroup, FieldLabels } from './field-group';
9
+ export type { FieldGroup } from './field-group';
10
10
  export { FieldGroups } from './field-group';
11
11
  export type { FieldValue } from './field-value';
12
12
  export type { StaticField, TextField, EmailField, NumberField, CheckboxField, SingleCheckboxField, RadioField, SingleRadioField, SelectField, Field, } from './field';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev-crew-berlin/enter-js-utils",
3
- "version": "0.46.0",
3
+ "version": "0.47.1",
4
4
  "description": "utils such as vaildation and other helpers to work with data from the enter app",
5
5
  "files": [
6
6
  "dist",