@01-edu/shared 1.2.2 → 1.2.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.
package/attrs-defs.js CHANGED
@@ -2665,11 +2665,122 @@ const sharedRanksDefinitions = {
2665
2665
  }
2666
2666
  },
2667
2667
  }
2668
+
2669
+ types.relatesToContent = Literal('', {
2670
+ label: 'Content',
2671
+ instruction:
2672
+ 'Select a child object to link this learning path status to. Each child can only be linked once.',
2673
+ editable: true,
2674
+ restrictive: true,
2675
+ options: (object, value) => {
2676
+ const learnPathStatus = object.attrs?.learnPathStatus
2677
+ ?.flatMap(({ relatesTo }) => relatesTo)
2678
+ .filter(v => v !== value)
2679
+
2680
+ const options = object.children ? Object.keys(object.children) : []
2681
+ return !learnPathStatus
2682
+ ? options
2683
+ : options.filter(k => !learnPathStatus.includes(k))
2684
+ },
2685
+ })
2686
+
2687
+ types.relatesToArray = TypeObject({
2688
+ label: 'Relates to',
2689
+ instruction:
2690
+ 'Link one or more child objects to this learning path status. You can add multiple links by clicking the add button. If student did at least one he will have that status',
2691
+ editable: true,
2692
+ required: true,
2693
+ restrictive: true,
2694
+ value: (...args) => [
2695
+ mapValues(types.relatesToArray.type, subDef =>
2696
+ getDefaultValue(subDef, ...args),
2697
+ ),
2698
+ ],
2699
+ type: [types.relatesToContent],
2700
+ })
2701
+
2702
+ types.learnerPathStatusName = Literal('', {
2703
+ label: 'Name',
2704
+ editable: true,
2705
+ required: true,
2706
+ primary: true,
2707
+ })
2708
+ types.definitionRelatesTo = TypeObject({
2709
+ label: 'Status Definition',
2710
+ type: {
2711
+ name: types.learnerPathStatusName,
2712
+ milestone: Literal('', {
2713
+ label: 'Hover description',
2714
+ instruction:
2715
+ 'Text that appears when users hover over this item. Use this to provide additional context or helpful information.',
2716
+ editable: true,
2717
+ }),
2718
+ relatesTo: types.relatesToArray,
2719
+ },
2720
+ check: (value, object) => {
2721
+ const { relatesTo: currentRelatesTo, name } = value
2722
+ const { learnPathStatus } = object.attrs
2723
+ const previousValue = learnPathStatus.find(
2724
+ ({ relatesTo }) =>
2725
+ !(
2726
+ currentRelatesTo.length !== relatesTo.length ||
2727
+ currentRelatesTo.some((val, i) => val !== relatesTo[i])
2728
+ ),
2729
+ )
2730
+ if (!previousValue) return
2731
+
2732
+ const isDifferent =
2733
+ previousValue.relatesTo.length !== currentRelatesTo.length ||
2734
+ previousValue.relatesTo.some((val, i) => val !== currentRelatesTo[i])
2735
+
2736
+ const hasSameKey = previousValue.name === name
2737
+ if (!isDifferent && hasSameKey) return
2738
+
2739
+ const definitionsWithSameName = object.attrs.learnPathStatus?.find(
2740
+ v => v.name === name,
2741
+ )
2742
+ if (definitionsWithSameName) {
2743
+ throw Error(
2744
+ `Name "${name}" is already set for a learner path status! A given name can only be attributed once.`,
2745
+ )
2746
+ }
2747
+ },
2748
+ })
2749
+
2750
+ const learnPathStatus = {
2751
+ label: 'Learner Path Status',
2752
+ instruction: 'List of Learner Status During Campus Steps',
2753
+ editable: true,
2754
+ restrictive: true,
2755
+ value: (...args) => [
2756
+ mapValues(types.learnPathStatus.type, subDef =>
2757
+ getDefaultValue(subDef, ...args),
2758
+ ),
2759
+ ],
2760
+ type: [types.definitionRelatesTo],
2761
+ check: (definition, object) => {
2762
+ if (!object.childrenRelation.length) {
2763
+ throw Error('Must contain at least one relation')
2764
+ }
2765
+ if (!definition?.length || !Array.isArray(definition)) {
2766
+ throw Error('Must be a non empty array')
2767
+ }
2768
+ },
2769
+ }
2770
+
2668
2771
  attrs.ranksDefinitions = {
2669
2772
  module: sharedRanksDefinitions,
2670
2773
  piscine: sharedRanksDefinitions,
2671
2774
  }
2672
2775
 
2776
+ attrs.learnPathStatus = {
2777
+ // the learn path status will define what the student is during the steps
2778
+ // - applicant (user that registered to the platform and passed the onboarding steps, up until being accepted to participate on the selection piscine/program)
2779
+ // - candidate (user that is participating on the selection piscine)
2780
+ // - learner (user that succeeded on the selection piscine and is participating on the module event)
2781
+ campus: learnPathStatus,
2782
+ }
2783
+
2673
2784
  const sharedRegistrationDuration = {
2674
2785
  label: 'Registration duration (to an event)',
2675
2786
  required: true,
package/attrs.js CHANGED
@@ -37,7 +37,8 @@ const typeChecker = (defs, value, object, key) => {
37
37
  check?.(value, object, key)
38
38
 
39
39
  if (options) {
40
- const opts = typeof options === 'function' ? options(object) : options
40
+ const opts =
41
+ typeof options === 'function' ? options(object, value) : options
41
42
  if (opts.length === 1) {
42
43
  if (opts[0] !== value) {
43
44
  throw Error(`${key} must be ${opts[0]} but was ${value}`)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@01-edu/shared",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "scripts": {
package/toolbox.js CHANGED
@@ -215,6 +215,16 @@ export const toDateFormatWithTime = (d, separator = 'T') => {
215
215
 
216
216
  return `${toDateFormat(date)}${separator}${hh}:${mm}`
217
217
  }
218
+
219
+ export const toPermanentDateFormatWithTime = (d, separator = 'T') => {
220
+ const date = toDate(d)
221
+ const hh = String(date.getHours()).padStart(2, '0')
222
+ const mm = String(date.getMinutes()).padStart(2, '0')
223
+ const month = (date.getMonth() + 1).toString().padStart(2, '0')
224
+ const day = date.getDate().toString().padStart(2, '0')
225
+
226
+ return `${date.getFullYear()}-${month}-${day}${separator}${hh}:${mm}`
227
+ }
218
228
  export const displayDateTime = dateTime => toDateFormatWithTime(dateTime, ' | ')
219
229
 
220
230
  export const getMonthName = month => monthNames[month]