@ndla/ui 46.0.1 → 46.1.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.
Files changed (37) hide show
  1. package/es/Article/Article.js +12 -4
  2. package/es/Embed/AudioEmbed.js +3 -1
  3. package/es/RadioButtonGroup/RadioButtonGroup.js +99 -80
  4. package/es/index.js +0 -1
  5. package/lib/Article/Article.d.ts +6 -3
  6. package/lib/Article/Article.js +12 -4
  7. package/lib/Embed/AudioEmbed.d.ts +2 -1
  8. package/lib/Embed/AudioEmbed.js +3 -1
  9. package/lib/Figure/Figure.d.ts +1 -0
  10. package/lib/RadioButtonGroup/RadioButtonGroup.d.ts +16 -8
  11. package/lib/RadioButtonGroup/RadioButtonGroup.js +108 -84
  12. package/lib/index.d.ts +0 -2
  13. package/lib/index.js +0 -7
  14. package/package.json +3 -2
  15. package/src/Article/Article.tsx +21 -7
  16. package/src/Embed/AudioEmbed.tsx +3 -2
  17. package/src/Figure/Figure.tsx +1 -0
  18. package/src/RadioButtonGroup/RadioButtonGroup.stories.tsx +126 -0
  19. package/src/RadioButtonGroup/RadioButtonGroup.tsx +137 -104
  20. package/src/index.ts +0 -10
  21. package/es/User/UserInfo.js +0 -114
  22. package/es/User/apiTypes.js +0 -1
  23. package/es/User/index.js +0 -10
  24. package/es/User/parseUserObject.js +0 -101
  25. package/lib/User/UserInfo.d.ts +0 -12
  26. package/lib/User/UserInfo.js +0 -119
  27. package/lib/User/apiTypes.d.ts +0 -70
  28. package/lib/User/apiTypes.js +0 -5
  29. package/lib/User/index.d.ts +0 -11
  30. package/lib/User/index.js +0 -12
  31. package/lib/User/parseUserObject.d.ts +0 -33
  32. package/lib/User/parseUserObject.js +0 -107
  33. package/src/User/UserInfo.tsx +0 -101
  34. package/src/User/__tests__/parseUserObject-test.ts +0 -316
  35. package/src/User/apiTypes.ts +0 -84
  36. package/src/User/index.ts +0 -21
  37. package/src/User/parseUserObject.ts +0 -89
@@ -1,316 +0,0 @@
1
- /**
2
- * Copyright (c) 2022-present, NDLA.
3
- *
4
- * This source code is licensed under the GPLv3 license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
-
9
- import { FeideUserApiType } from '../apiTypes';
10
- import { parseUserObject } from '../parseUserObject';
11
-
12
- const feideUserLaerer: FeideUserApiType = {
13
- cn: ['David LærerVGS Jonsen'],
14
- displayName: 'David LærerVGS Jonsen',
15
- eduPersonAffiliation: ['member', 'employee', 'faculty'],
16
- eduPersonPrimaryAffiliation: 'employee',
17
- eduPersonPrincipalName: 'david_laerervgs@spusers.feide.no',
18
- givenName: ['David LærerVGS'],
19
- mail: ['david_laerervgs@feide.no'],
20
- sn: ['Jonsen'],
21
- uid: ['david_laerervgs'],
22
- groups: [
23
- {
24
- id: 'fc:org:spusers.feide.no',
25
- displayName: 'Rogn fylkeskommune',
26
- type: 'fc:org',
27
- public: false,
28
- membership: {
29
- basic: 'admin',
30
- affiliation: ['member', 'employee', 'faculty'],
31
- primaryAffiliation: 'employee',
32
- displayName: 'Akademisk ansatt',
33
- },
34
- orgType: ['higher_education', 'upper_secondary_owner', 'primary_and_lower_secondary_owner'],
35
- norEduOrgNIN: 'NO956326503',
36
- eduOrgLegalName: 'Rogn fylkeskommune',
37
- mail: 'support@feide.no',
38
- },
39
- {
40
- id: 'fc:org:spusers.feide.no:unit:NO956326504',
41
- parent: 'fc:org:spusers.feide.no',
42
- displayName: 'Lind VGS',
43
- type: 'fc:org',
44
- public: false,
45
- membership: {
46
- basic: 'member',
47
- primarySchool: true,
48
- },
49
- orgType: ['primary_and_lower_secondary'],
50
- },
51
- {
52
- id: 'fc:org:spusers.feide.no:unit:NO856326501',
53
- parent: 'fc:org:spusers.feide.no',
54
- displayName: 'Lerk VGS',
55
- type: 'fc:org',
56
- public: false,
57
- membership: {
58
- basic: 'member',
59
- primarySchool: false,
60
- },
61
- orgType: ['primary_and_lower_secondary'],
62
- },
63
- {
64
- id: 'fc:gogroup:spusers.feide.no:b:NO856326501:1sta:2000-07-01:2100-06-30',
65
- displayName: 'Klasse 1STA',
66
- type: 'fc:gogroup',
67
- notBefore: '2000-06-30T22:00:00Z',
68
- notAfter: '2100-06-30T23:00:00Z',
69
- go_type: 'b',
70
- parent: 'fc:org:spusers.feide.no:unit:NO856326501',
71
- membership: {
72
- basic: 'member',
73
- affiliation: ['employee'],
74
- displayName: 'Ansatt',
75
- },
76
- go_type_displayName: 'basisgruppe',
77
- },
78
- {
79
- id: 'fc:gogroup:spusers.feide.no:a:NO856326501:1sta-lab1:2000-07-01:2100-06-30',
80
- displayName: 'Laboratoriegruppe 1',
81
- type: 'fc:gogroup',
82
- notBefore: '2000-06-30T22:00:00Z',
83
- notAfter: '2100-06-30T23:00:00Z',
84
- go_type: 'a',
85
- parent: 'fc:org:spusers.feide.no:unit:NO856326501',
86
- membership: {
87
- basic: 'member',
88
- affiliation: ['employee'],
89
- displayName: 'Ansatt',
90
- },
91
- go_type_displayName: 'other groups',
92
- },
93
- {
94
- id: 'fc:gogroup:spusers.feide.no:a:NO856326501:1sta-lab2:2000-07-01:2100-06-30',
95
- displayName: 'Laboratoriegruppe 2',
96
- type: 'fc:gogroup',
97
- notBefore: '2000-06-30T22:00:00Z',
98
- notAfter: '2100-06-30T23:00:00Z',
99
- go_type: 'a',
100
- parent: 'fc:org:spusers.feide.no:unit:NO856326501',
101
- membership: {
102
- basic: 'member',
103
- affiliation: ['employee'],
104
- displayName: 'Ansatt',
105
- },
106
- go_type_displayName: 'other groups',
107
- },
108
- {
109
- id: 'fc:gogroup:spusers.feide.no:u:NO856326501:1mat11-1map1:2000-07-01:2100-06-30',
110
- displayName: 'Matematikk 1P',
111
- type: 'fc:gogroup',
112
- notBefore: '2000-06-30T22:00:00Z',
113
- notAfter: '2100-06-30T23:00:00Z',
114
- go_type: 'u',
115
- parent: 'fc:org:spusers.feide.no:unit:NO856326501',
116
- membership: {
117
- basic: 'member',
118
- affiliation: ['employee'],
119
- displayName: 'Ansatt',
120
- },
121
- go_type_displayName: 'undervisningsgruppe',
122
- grep: {
123
- displayName: 'Mathematics 1P',
124
- code: 'MAT1011',
125
- },
126
- },
127
- {
128
- id: 'fc:gogroup:spusers.feide.no:u:NO856326501:1mat13-1mat1:2000-07-01:2100-06-30',
129
- displayName: 'Matematikk 1T',
130
- type: 'fc:gogroup',
131
- notBefore: '2000-06-30T22:00:00Z',
132
- notAfter: '2100-06-30T23:00:00Z',
133
- go_type: 'u',
134
- parent: 'fc:org:spusers.feide.no:unit:NO856326501',
135
- membership: {
136
- basic: 'member',
137
- affiliation: ['employee'],
138
- displayName: 'Ansatt',
139
- },
140
- go_type_displayName: 'undervisningsgruppe',
141
- grep: {
142
- displayName: 'Mathematics 1T',
143
- code: 'MAT1013',
144
- },
145
- },
146
- ],
147
- primarySchool: {
148
- id: 'fc:org:spusers.feide.no:unit:NO956326504',
149
- parent: 'fc:org:spusers.feide.no',
150
- displayName: 'Lind VGS',
151
- type: 'fc:org',
152
- public: false,
153
- membership: {
154
- basic: 'member',
155
- primarySchool: true,
156
- },
157
- orgType: ['primary_and_lower_secondary'],
158
- },
159
- };
160
-
161
- describe('parseUserObject', () => {
162
- it('Correctly parses Feide user', () => {
163
- const expected = {
164
- uid: ['david_laerervgs'],
165
- displayName: 'David LærerVGS Jonsen',
166
- mail: ['david_laerervgs@feide.no'],
167
- eduPersonAffiliation: ['member', 'employee', 'faculty'],
168
- grepCodes: [],
169
- organizations: [
170
- {
171
- id: 'fc:org:spusers.feide.no',
172
- displayName: 'Rogn fylkeskommune',
173
- type: 'fc:org',
174
- public: false,
175
- membership: {
176
- basic: 'admin',
177
- affiliation: ['member', 'employee', 'faculty'],
178
- primaryAffiliation: 'employee',
179
- displayName: 'Akademisk ansatt',
180
- },
181
- orgType: ['higher_education', 'upper_secondary_owner', 'primary_and_lower_secondary_owner'],
182
- norEduOrgNIN: 'NO956326503',
183
- eduOrgLegalName: 'Rogn fylkeskommune',
184
- mail: 'support@feide.no',
185
- children: {
186
- basic: [],
187
- teaching: [],
188
- other: [],
189
- },
190
- },
191
- {
192
- id: 'fc:org:spusers.feide.no:unit:NO956326504',
193
- parent: 'fc:org:spusers.feide.no',
194
- displayName: 'Lind VGS',
195
- type: 'fc:org',
196
- public: false,
197
- membership: {
198
- basic: 'member',
199
- primarySchool: true,
200
- },
201
- orgType: ['primary_and_lower_secondary'],
202
- children: {
203
- basic: [],
204
- teaching: [],
205
- other: [],
206
- },
207
- },
208
- {
209
- id: 'fc:org:spusers.feide.no:unit:NO856326501',
210
- parent: 'fc:org:spusers.feide.no',
211
- displayName: 'Lerk VGS',
212
- type: 'fc:org',
213
- public: false,
214
- membership: {
215
- basic: 'member',
216
- primarySchool: false,
217
- },
218
- orgType: ['primary_and_lower_secondary'],
219
- children: {
220
- basic: [
221
- {
222
- id: 'fc:gogroup:spusers.feide.no:b:NO856326501:1sta:2000-07-01:2100-06-30',
223
- displayName: 'Klasse 1STA',
224
- type: 'fc:gogroup',
225
- notBefore: '2000-06-30T22:00:00Z',
226
- notAfter: '2100-06-30T23:00:00Z',
227
- go_type: 'b',
228
- parent: 'fc:org:spusers.feide.no:unit:NO856326501',
229
- membership: {
230
- basic: 'member',
231
- affiliation: ['employee'],
232
- displayName: 'Ansatt',
233
- },
234
- go_type_displayName: 'basisgruppe',
235
- },
236
- ],
237
- teaching: [
238
- {
239
- id: 'fc:gogroup:spusers.feide.no:u:NO856326501:1mat11-1map1:2000-07-01:2100-06-30',
240
- displayName: 'Matematikk 1P',
241
- type: 'fc:gogroup',
242
- notBefore: '2000-06-30T22:00:00Z',
243
- notAfter: '2100-06-30T23:00:00Z',
244
- go_type: 'u',
245
- parent: 'fc:org:spusers.feide.no:unit:NO856326501',
246
- membership: {
247
- basic: 'member',
248
- affiliation: ['employee'],
249
- displayName: 'Ansatt',
250
- },
251
- go_type_displayName: 'undervisningsgruppe',
252
- grep: {
253
- displayName: 'Mathematics 1P',
254
- code: 'MAT1011',
255
- },
256
- },
257
- {
258
- id: 'fc:gogroup:spusers.feide.no:u:NO856326501:1mat13-1mat1:2000-07-01:2100-06-30',
259
- displayName: 'Matematikk 1T',
260
- type: 'fc:gogroup',
261
- notBefore: '2000-06-30T22:00:00Z',
262
- notAfter: '2100-06-30T23:00:00Z',
263
- go_type: 'u',
264
- parent: 'fc:org:spusers.feide.no:unit:NO856326501',
265
- membership: {
266
- basic: 'member',
267
- affiliation: ['employee'],
268
- displayName: 'Ansatt',
269
- },
270
- go_type_displayName: 'undervisningsgruppe',
271
- grep: {
272
- displayName: 'Mathematics 1T',
273
- code: 'MAT1013',
274
- },
275
- },
276
- ],
277
- other: [
278
- {
279
- id: 'fc:gogroup:spusers.feide.no:a:NO856326501:1sta-lab1:2000-07-01:2100-06-30',
280
- displayName: 'Laboratoriegruppe 1',
281
- type: 'fc:gogroup',
282
- notBefore: '2000-06-30T22:00:00Z',
283
- notAfter: '2100-06-30T23:00:00Z',
284
- go_type: 'a',
285
- parent: 'fc:org:spusers.feide.no:unit:NO856326501',
286
- membership: {
287
- basic: 'member',
288
- affiliation: ['employee'],
289
- displayName: 'Ansatt',
290
- },
291
- go_type_displayName: 'other groups',
292
- },
293
- {
294
- id: 'fc:gogroup:spusers.feide.no:a:NO856326501:1sta-lab2:2000-07-01:2100-06-30',
295
- displayName: 'Laboratoriegruppe 2',
296
- type: 'fc:gogroup',
297
- notBefore: '2000-06-30T22:00:00Z',
298
- notAfter: '2100-06-30T23:00:00Z',
299
- go_type: 'a',
300
- parent: 'fc:org:spusers.feide.no:unit:NO856326501',
301
- membership: {
302
- basic: 'member',
303
- affiliation: ['employee'],
304
- displayName: 'Ansatt',
305
- },
306
- go_type_displayName: 'other groups',
307
- },
308
- ],
309
- },
310
- },
311
- ],
312
- };
313
- const actual = parseUserObject(feideUserLaerer);
314
- expect(actual).toEqual(expected);
315
- });
316
- });
@@ -1,84 +0,0 @@
1
- /**
2
- * Copyright (c) 2022-present, NDLA.
3
- *
4
- * This source code is licensed under the GPLv3 license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
-
9
- type OrgType =
10
- | 'higher_education'
11
- | 'primary_and_lower_secondary'
12
- | 'primary_and_lower_secondary_owner'
13
- | 'upper_secondary'
14
- | 'upper_secondary_owner';
15
-
16
- export type AffiliationType = 'member' | 'student' | 'faculty' | 'staff' | 'affiliate' | 'employee';
17
-
18
- export interface FeideMembershipType {
19
- basic: 'member' | 'admin' | 'owner'; // Basic membership role of user.
20
- affiliation?: AffiliationType[];
21
- primarySchool?: boolean;
22
- primaryAffiliation?: AffiliationType;
23
- displayName?: string;
24
- }
25
-
26
- interface FeideBaseGroup {
27
- id: string;
28
- type: 'fc:org' | 'fc:gogroup' | 'fc:grep';
29
- displayName: string;
30
- membership: FeideMembershipType;
31
- }
32
-
33
- export interface FeideOrg extends FeideBaseGroup {
34
- type: 'fc:org';
35
- orgType: OrgType[];
36
- norEduOrgNIN?: string;
37
- eduOrgLegalName?: string;
38
- mail?: string;
39
- parent?: string;
40
- public: boolean;
41
- }
42
-
43
- export interface FeideGoGroup extends FeideBaseGroup {
44
- type: 'fc:gogroup';
45
- notBefore: string;
46
- notAfter: string;
47
- go_type: 'b' | 'u' | 'a';
48
- parent: string;
49
- go_type_displayName: string;
50
- grep?: {
51
- displayName: string;
52
- code: string;
53
- };
54
- }
55
-
56
- export interface FeideGrep extends FeideBaseGroup {
57
- type: 'fc:grep';
58
- code: string;
59
- grep_type: 'aarstrinn' | 'fagkoder';
60
- public: boolean;
61
- }
62
-
63
- export type FeideGroup = FeideOrg | FeideGoGroup | FeideGrep;
64
-
65
- export interface FeideUser {
66
- cn: string[];
67
- displayName: string;
68
- eduPersonAffiliation: AffiliationType[];
69
- eduPersonPrimaryAffiliation: AffiliationType;
70
- eduPersonPrincipalName: string;
71
- givenName: string[];
72
- mail?: string[];
73
- schacHomeOrganization?: string;
74
- sn: string[];
75
- uid: string[];
76
- preferredLanguage?: string;
77
- mobile?: string;
78
- }
79
-
80
- export interface FeideUserApiType extends FeideUser {
81
- groups: FeideGroup[];
82
- primarySchool?: FeideGroup;
83
- baseOrg?: FeideGroup;
84
- }
package/src/User/index.ts DELETED
@@ -1,21 +0,0 @@
1
- /**
2
- * Copyright (c) 2021-present, NDLA.
3
- *
4
- * This source code is licensed under the GPLv3 license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
-
9
- import { UserInfo } from './UserInfo';
10
- import type {
11
- AffiliationType,
12
- FeideGoGroup,
13
- FeideGroup,
14
- FeideOrg,
15
- FeideUserApiType,
16
- FeideMembershipType,
17
- FeideUser,
18
- } from './apiTypes';
19
-
20
- export { UserInfo };
21
- export type { AffiliationType, FeideGoGroup, FeideGroup, FeideOrg, FeideUserApiType, FeideMembershipType, FeideUser };
@@ -1,89 +0,0 @@
1
- /**
2
- * Copyright (c) 2022-present, NDLA.
3
- *
4
- * This source code is licensed under the GPLv3 license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- */
7
-
8
- import groupBy from 'lodash/groupBy';
9
- import { FeideGoGroup, FeideGrep, FeideGroup, FeideOrg, FeideUserApiType } from './apiTypes';
10
-
11
- type GoGroupType = 'basic' | 'teaching' | 'other';
12
-
13
- /**
14
- * The keys come from:
15
- * https://docs.feide.no/reference/apis/groups_api/groups_data_model/primary_and_secondary_education_groups.html?highlight=gogroup#specific-attributes-for-fc-gogroup
16
- */
17
- const goGroupTypeMap: Record<'a' | 'b' | 'u', GoGroupType> = {
18
- a: 'other',
19
- b: 'basic',
20
- u: 'teaching',
21
- };
22
-
23
- /**
24
- * @param groups GoGroups to be mapped to specific GoGroupType
25
- * @returns GoGroups mapped to GoGroupType. basic, teaching and other..
26
- */
27
- const createGroupings = (groups: FeideGoGroup[]) => {
28
- return groups.reduce<Record<GoGroupType, FeideGoGroup[]>>(
29
- (acc, curr) => {
30
- const type = goGroupTypeMap[curr.go_type];
31
- if (!acc[type]) return acc;
32
-
33
- acc[type] = acc[type].concat(curr);
34
- return acc;
35
- },
36
- {
37
- basic: [],
38
- teaching: [],
39
- other: [],
40
- },
41
- );
42
- };
43
-
44
- /**
45
- * @param groups GoGroups to be mapped to root/child relations.
46
- * @returns An object containing root groups mapped with children.
47
- */
48
- const parseOrgs = (groups: FeideGroup[]) => {
49
- const [roots, children, grep] = groups.reduce<[FeideOrg[], FeideGoGroup[], FeideGrep[]]>(
50
- (acc, curr) => {
51
- if (curr.type === 'fc:org') {
52
- return [acc[0].concat(curr), acc[1], acc[2]];
53
- } else if (curr.type === 'fc:gogroup') {
54
- return [acc[0], acc[1].concat(curr), acc[2]];
55
- } else {
56
- return [acc[0], acc[1], acc[2].concat(curr)];
57
- }
58
- },
59
- [[], [], []],
60
- );
61
-
62
- const childrenByParentId = groupBy(children, (c) => c.parent);
63
- const rootsWithChildren = roots.map((root) => ({ ...root, children: childrenByParentId[root.id] ?? [] }));
64
-
65
- return {
66
- grepCodes: grep,
67
- roots: rootsWithChildren.map((root) => ({
68
- ...root,
69
- children: createGroupings(root.children),
70
- })),
71
- };
72
- };
73
-
74
- /**
75
- * @param user A user object coming from the API
76
- * @returns A user object parsed in a presentable way to be handled by i.e UserInfo component.
77
- */
78
- export const parseUserObject = (user: FeideUserApiType) => {
79
- const { roots, grepCodes } = parseOrgs(user.groups);
80
-
81
- return {
82
- uid: user.uid,
83
- eduPersonAffiliation: user.eduPersonAffiliation,
84
- displayName: user.displayName,
85
- mail: user.mail,
86
- organizations: roots,
87
- grepCodes,
88
- };
89
- };