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

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,12 +1,14 @@
1
1
  import { components } from '../generated/api-schema';
2
2
  import { Field } from './field';
3
3
  export declare type Dictionary<T> = Record<string, T>;
4
- export declare type FieldGroup = components['schemas']['FieldGroup'];
4
+ export declare type _FieldGroup = components['schemas']['FieldGroup'];
5
+ export declare type FieldGroup = Omit<_FieldGroup, 'questions'>;
5
6
  export declare class FieldGroups {
6
7
  private _groups;
7
8
  get groups(): Map<string, FieldGroup>;
8
9
  get fields(): Map<string, Field>;
9
- constructor(json: FieldGroup[]);
10
- toJSON(): FieldGroup[];
10
+ constructor(json: _FieldGroup[]);
11
+ toJSON(): _FieldGroup[];
12
+ withoutMetaFields(): FieldGroups;
11
13
  getLabelForField(fieldKey: string, language: string): string;
12
14
  }
@@ -8,9 +8,12 @@ export class FieldGroups {
8
8
  }
9
9
  get fields() {
10
10
  const fields = new Map();
11
- for (const group of this._groups) {
11
+ for (const [groupIndex, group] of this._groups.entries()) {
12
12
  for (const field of group.questions) {
13
- fields.set(field.name, field);
13
+ fields.set(field.name, {
14
+ ...field,
15
+ group: groupIndex.toString()
16
+ });
14
17
  }
15
18
  }
16
19
  return fields;
@@ -21,6 +24,22 @@ export class FieldGroups {
21
24
  toJSON() {
22
25
  return this._groups;
23
26
  }
27
+ withoutMetaFields() {
28
+ const fieldGroupList = [];
29
+ for (const group of this._groups) {
30
+ if (group.isMetaGroup) continue;
31
+ const fields = [];
32
+ for (const field of group.questions) {
33
+ if (field.isMetaField) continue;
34
+ fields.push(field);
35
+ }
36
+ fieldGroupList.push({
37
+ ...group,
38
+ questions: fields
39
+ });
40
+ }
41
+ return new FieldGroups(fieldGroupList);
42
+ }
24
43
  getLabelForField(fieldKey, language) {
25
44
  const field = this.fields.get(fieldKey);
26
45
  const fieldLabel = field?.title ?? field?.name ?? fieldKey;
@@ -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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dev-crew-berlin/enter-js-utils",
3
- "version": "0.47.1",
3
+ "version": "0.47.3",
4
4
  "description": "utils such as vaildation and other helpers to work with data from the enter app",
5
5
  "files": [
6
6
  "dist",