@dev-crew-berlin/enter-js-utils 0.46.1 → 0.47.2

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,18 +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
- export declare type FieldMap = Map<string, Field & {
7
- group: string;
8
- }>;
9
- declare type FieldTitle = string | Dictionary<string>;
10
5
  export declare class FieldGroups {
11
- groups: FieldGroup[];
12
- get groupNames(): string[];
13
- get fields(): FieldMap;
6
+ private _groups;
7
+ get groups(): Map<string, FieldGroup>;
8
+ get fields(): Map<string, Field>;
14
9
  constructor(json: FieldGroup[]);
15
10
  toJSON(): FieldGroup[];
16
- getFieldLabels(): FieldLabels;
17
11
  getLabelForField(fieldKey: string, language: string): string;
18
12
  }
19
- export {};
@@ -1,10 +1,14 @@
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 [groupIndex, group] of this._groups.entries()) {
8
12
  for (const field of group.questions) {
9
13
  fields.set(field.name, {
10
14
  ...field,
@@ -15,20 +19,14 @@ export class FieldGroups {
15
19
  return fields;
16
20
  }
17
21
  constructor(json) {
18
- this.groups = json;
22
+ this._groups = json;
19
23
  }
20
24
  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;
25
+ return this._groups;
29
26
  }
30
27
  getLabelForField(fieldKey, language) {
31
- const fieldLabel = this.getFieldLabels()[fieldKey];
28
+ const field = this.fields.get(fieldKey);
29
+ const fieldLabel = field?.title ?? field?.name ?? fieldKey;
32
30
  const translatedLabel = fieldLabel === undefined || typeof fieldLabel === 'string' ? fieldLabel : fieldLabel[language];
33
31
  return translatedLabel ?? fieldKey;
34
32
  }
@@ -1,11 +1,31 @@
1
1
  import { components } from '../generated/api-schema';
2
- export declare type StaticField = components['schemas']['StaticField'];
3
- export declare type TextField = components['schemas']['TextField'];
4
- export declare type EmailField = components['schemas']['EmailField'];
5
- export declare type NumberField = components['schemas']['NumberField'];
6
- export declare type CheckboxField = components['schemas']['CheckboxGroupField'];
7
- export declare type SingleCheckboxField = components['schemas']['CheckboxField'];
8
- export declare type RadioField = components['schemas']['RadioButtonGroupField'];
9
- export declare type SingleRadioField = components['schemas']['RadioButtonField'];
10
- export declare type SelectField = components['schemas']['DropdownField'];
11
- export declare type Field = components['schemas']['FieldGroup']['questions'][number];
2
+ export declare type StaticField = components['schemas']['StaticField'] & {
3
+ group: string;
4
+ };
5
+ export declare type TextField = components['schemas']['TextField'] & {
6
+ group: string;
7
+ };
8
+ export declare type EmailField = components['schemas']['EmailField'] & {
9
+ group: string;
10
+ };
11
+ export declare type NumberField = components['schemas']['NumberField'] & {
12
+ group: string;
13
+ };
14
+ export declare type CheckboxField = components['schemas']['CheckboxGroupField'] & {
15
+ group: string;
16
+ };
17
+ export declare type SingleCheckboxField = components['schemas']['CheckboxField'] & {
18
+ group: string;
19
+ };
20
+ export declare type RadioField = components['schemas']['RadioButtonGroupField'] & {
21
+ group: string;
22
+ };
23
+ export declare type SingleRadioField = components['schemas']['RadioButtonField'] & {
24
+ group: string;
25
+ };
26
+ export declare type SelectField = components['schemas']['DropdownField'] & {
27
+ group: string;
28
+ };
29
+ export declare type Field = components['schemas']['FieldGroup']['questions'][number] & {
30
+ group: string;
31
+ };
@@ -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, FieldMap } 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.1",
3
+ "version": "0.47.2",
4
4
  "description": "utils such as vaildation and other helpers to work with data from the enter app",
5
5
  "files": [
6
6
  "dist",