@beinformed/ui 1.27.6 → 1.28.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 (56) hide show
  1. package/CHANGELOG.md +11 -1
  2. package/esm/constants/LayoutHintConfig.js +0 -9
  3. package/esm/constants/LayoutHintConfig.js.map +1 -1
  4. package/esm/constants/LayoutHints.js +0 -4
  5. package/esm/constants/LayoutHints.js.map +1 -1
  6. package/esm/constants/Settings.js +0 -4
  7. package/esm/constants/Settings.js.map +1 -1
  8. package/esm/models/attributes/DatetimeAttributeModel.js +3 -29
  9. package/esm/models/attributes/DatetimeAttributeModel.js.map +1 -1
  10. package/esm/react-client/Init.js +2 -2
  11. package/esm/react-client/Init.js.map +1 -1
  12. package/esm/react-client/client.js +80 -52
  13. package/esm/react-client/client.js.map +1 -1
  14. package/esm/redux/store/configureStore.js +4 -4
  15. package/esm/redux/store/configureStore.js.map +1 -1
  16. package/lib/constants/LayoutHintConfig.js +0 -9
  17. package/lib/constants/LayoutHintConfig.js.flow +0 -9
  18. package/lib/constants/LayoutHintConfig.js.map +1 -1
  19. package/lib/constants/LayoutHints.js +2 -7
  20. package/lib/constants/LayoutHints.js.flow +0 -4
  21. package/lib/constants/LayoutHints.js.map +1 -1
  22. package/lib/constants/Settings.js +0 -4
  23. package/lib/constants/Settings.js.flow +0 -6
  24. package/lib/constants/Settings.js.map +1 -1
  25. package/lib/models/attributes/DatetimeAttributeModel.js +3 -29
  26. package/lib/models/attributes/DatetimeAttributeModel.js.flow +7 -41
  27. package/lib/models/attributes/DatetimeAttributeModel.js.map +1 -1
  28. package/lib/models/attributes/__tests__/DateAttributeModel.spec.js.flow +1 -35
  29. package/lib/models/attributes/__tests__/DatetimeAttributeModel.spec.js.flow +158 -216
  30. package/lib/models/attributes/__tests__/TimestampModel.spec.js.flow +0 -5
  31. package/lib/react-client/Init.js +2 -2
  32. package/lib/react-client/Init.js.flow +3 -3
  33. package/lib/react-client/Init.js.map +1 -1
  34. package/lib/react-client/client.js +83 -53
  35. package/lib/react-client/client.js.flow +106 -67
  36. package/lib/react-client/client.js.map +1 -1
  37. package/lib/redux/store/configureStore.js +4 -4
  38. package/lib/redux/store/configureStore.js.flow +5 -5
  39. package/lib/redux/store/configureStore.js.map +1 -1
  40. package/package.json +17 -19
  41. package/src/constants/LayoutHintConfig.js +0 -9
  42. package/src/constants/LayoutHints.js +0 -4
  43. package/src/constants/Settings.js +0 -6
  44. package/src/models/attributes/DatetimeAttributeModel.js +7 -41
  45. package/src/models/attributes/__tests__/DateAttributeModel.spec.js +1 -35
  46. package/src/models/attributes/__tests__/DatetimeAttributeModel.spec.js +158 -216
  47. package/src/models/attributes/__tests__/TimestampModel.spec.js +0 -5
  48. package/src/react-client/Init.js +3 -3
  49. package/src/react-client/client.js +106 -67
  50. package/src/redux/store/configureStore.js +5 -5
  51. package/types/constants/LayoutHintConfig.d.ts +8 -23
  52. package/types/constants/LayoutHints.d.ts +0 -4
  53. package/types/models/actions/ActionCollection.d.ts +1 -1
  54. package/types/models/attributes/DatetimeAttributeModel.d.ts +8 -2
  55. package/types/redux/_modularui/types.d.ts +4 -0
  56. package/types/redux/types.d.ts +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"DatetimeAttributeModel.js","names":["PRODUCT_DEFAULT_DATE_FORMAT","DatetimeAttributeModel","StringAttributeModel","constructor","attribute","attributeContributions","updateInitValue","isApplicableModel","contributions","type","formatUtil","TimeUtil","TimestampUtil","DateTimeUtil","DateUtil","getInitValue","value","data","length","split","hasTime","getTimeValue","timeValue","timeInputFormat","toLowerCase","setHour","setMinute","setSecond","setMilliseconds","_initvalue","_inputvalue","getInitialInputValue","_value","initValue","toFormat","inputFormat","getContribution","getInputValue","toString","inputvalue","validate","toISO","format","convertFormat","operator","hasDate","formatLabel","dateInputFormat","ignoreFormatSetting","layouthint","has","IGNORE_FORMAT_SETTING","dateInputFormatSetting","getSetting","dateFormat","replace","dateReadonlyFormat","readonlyFormatSetting","placeholder","_placeholder","timeFormatParts","push","timeFormat","join","timeReadonlyFormat","dateInputValue","timeInputValue","formatValue","hasFormat","ISO_DATE_FORMAT","dateTimeReadonlyFormat","readonlyvalue","mindate","maxdate","addServerError","error","id","message","properties","_errorCollection","getFormatConstraint","DateTimeDateFormatConstraint","DateTimeTimeFormatConstraint","DatetimeFormatConstraint","addConstraints","constraints","ConstraintCollection","add","DateBoundaryConstraint","readonlyWidth","ATTRIBUTE_WIDTH","SMALL","MEDIUM"],"sources":["../../../src/models/attributes/DatetimeAttributeModel.js"],"sourcesContent":["// @flow\nimport { has } from \"../../utils/helpers/objects\";\n\nimport {\n DateUtil,\n DateTimeUtil,\n TimeUtil,\n TimestampUtil,\n} from \"../../utils/datetime/DateTimeUtil\";\n\nimport StringAttributeModel from \"./StringAttributeModel\";\n\nimport ConstraintCollection from \"./input-constraints/ConstraintCollection\";\nimport DateTimeDateFormatConstraint from \"./input-constraints/DateTimeDateFormatConstraint\";\nimport DateTimeTimeFormatConstraint from \"./input-constraints/DateTimeTimeFormatConstraint\";\nimport DatetimeFormatConstraint from \"./input-constraints/DatetimeFormatConstraint\";\nimport DateBoundaryConstraint from \"./input-constraints/DateBoundaryConstraint\";\n\nimport { ATTRIBUTE_WIDTH, ISO_DATE_FORMAT } from \"../../constants\";\nimport { getSetting } from \"../../constants/Settings\";\nimport { IGNORE_FORMAT_SETTING } from \"../../constants/LayoutHints\";\n\nimport type { FormErrorAnchor, IConstraintModel } from \"../types\";\n\n// date format of default\nconst PRODUCT_DEFAULT_DATE_FORMAT = \"dd-MM-yyyy\";\n\n/**\n */\nclass DatetimeAttributeModel extends StringAttributeModel {\n /**\n */\n constructor(attribute: Object, attributeContributions: Object) {\n super(attribute, attributeContributions);\n\n this.updateInitValue();\n }\n\n /**\n */\n static isApplicableModel(contributions: Object): boolean {\n return [\"date\", \"time\", \"datetime\", \"timestamp\"].includes(\n contributions.type\n );\n }\n\n /**\n */\n get formatUtil():\n | typeof TimeUtil\n | typeof TimestampUtil\n | typeof DateTimeUtil\n | typeof DateUtil {\n switch (this.type) {\n case \"time\":\n return TimeUtil;\n case \"timestamp\":\n return TimestampUtil;\n case \"datetime\":\n return DateTimeUtil;\n default:\n return DateUtil;\n }\n }\n\n /**\n */\n getInitValue(): string | null {\n let value = this.data.value;\n if (value != null) {\n if (this.type === \"time\" && value.length === 5) {\n value = `${value}:00`;\n }\n\n // handle old datetime values, which contained ms\n if (this.type === \"datetime\" && value.includes(\".\")) {\n value = value.split(\".\")[0];\n }\n\n if (this.hasTime) {\n value = this.getTimeValue(value);\n }\n }\n\n return value;\n }\n\n /**\n */\n getTimeValue(value: string): string {\n let timeValue = value;\n if (!this.timeInputFormat.toLowerCase().includes(\"h\")) {\n timeValue = this.formatUtil.setHour(value, 0);\n }\n if (!this.timeInputFormat.includes(\"m\")) {\n timeValue = this.formatUtil.setMinute(value, 0);\n }\n if (!this.timeInputFormat.includes(\"s\")) {\n timeValue = this.formatUtil.setSecond(value, 0);\n }\n if (this.type === \"timestamp\" && !this.timeInputFormat.includes(\"S\")) {\n timeValue = this.formatUtil.setMilliseconds(value, 0);\n }\n return timeValue;\n }\n\n /**\n * Set time in the correct value based on available elements in the time format\n */\n updateInitValue() {\n const value = this.getInitValue();\n if (value != null) {\n this._initvalue = value;\n this._inputvalue = this.getInitialInputValue(value);\n this._value = value;\n }\n }\n\n /**\n * Get initial user input value\n */\n getInitialInputValue(value?: string): string {\n if (!value) {\n return \"\";\n }\n\n let initValue = value;\n if (this.type === \"time\" && value.length === 5) {\n initValue = `${value}:00`;\n }\n\n return this.formatUtil.toFormat(initValue, this.inputFormat);\n }\n\n /**\n * Set type to date\n */\n get type(): string {\n return this.getContribution(\"type\", \"date\");\n }\n\n /**\n * Returns the value as entered by the user. This can differ from the internal iso value that is stored\n */\n getInputValue(): string {\n return this._inputvalue ? this._inputvalue.toString() : \"\";\n }\n\n /**\n * Get input value\n */\n get inputvalue(): string {\n return this.getInputValue();\n }\n\n /**\n * Sets the input value to the value entered by the user\n */\n set inputvalue(value: string) {\n this.validate(value);\n\n this._inputvalue = value;\n\n this.value =\n value !== null && value !== \"\"\n ? this.formatUtil.toISO(value, this.inputFormat)\n : null;\n }\n\n /**\n * Get date format\n */\n get format(): string {\n const format = this.getContribution(\"format\", \"\");\n return this.formatUtil.convertFormat(format);\n }\n\n /**\n */\n get operator(): string {\n return this.getContribution(\"operator\", \"\");\n }\n\n /**\n */\n get hasDate(): boolean {\n return (\n this.type === \"date\" ||\n this.type === \"datetime\" ||\n this.type === \"timestamp\"\n );\n }\n\n /**\n */\n get hasTime(): boolean {\n return (\n this.type === \"time\" ||\n this.type === \"datetime\" ||\n this.type === \"timestamp\"\n );\n }\n\n /**\n */\n get formatLabel(): string {\n switch (this.type) {\n case \"date\":\n return this.dateInputFormat.toLowerCase();\n case \"time\":\n return this.timeInputFormat.toLowerCase();\n default:\n return this.format.toLowerCase();\n }\n }\n\n /**\n */\n get inputFormat(): string {\n if (this.hasDate && this.hasTime) {\n return `${this.dateInputFormat} ${this.timeInputFormat}`.trim();\n }\n\n if (this.hasDate) {\n return this.dateInputFormat;\n }\n\n if (this.hasTime) {\n return this.timeInputFormat;\n }\n\n return \"\";\n }\n\n /**\n */\n get dateInputFormat(): string {\n if (!this.hasDate) {\n return \"\";\n }\n\n // setting for date input\n const ignoreFormatSetting = this.layouthint.has(IGNORE_FORMAT_SETTING);\n if (!ignoreFormatSetting) {\n const dateInputFormatSetting = getSetting(\"DATE_INPUT_FORMAT\", \"\");\n if (dateInputFormatSetting) {\n return dateInputFormatSetting;\n }\n }\n\n let format = this.format;\n\n let dateFormat = this.hasTime\n ? format.replace(this.timeInputFormat, \"\").trim()\n : format;\n\n return dateFormat;\n }\n\n /**\n */\n get dateReadonlyFormat(): string {\n if (!this.hasDate) {\n return \"\";\n }\n\n let format = this.format;\n\n let dateFormat = this.hasTime\n ? format.replace(this.timeInputFormat, \"\").trim()\n : format;\n\n const readonlyFormatSetting = getSetting(\"DATE_READONLY_FORMAT\", \"\");\n\n if (dateFormat === PRODUCT_DEFAULT_DATE_FORMAT && readonlyFormatSetting) {\n dateFormat = readonlyFormatSetting;\n }\n\n return dateFormat;\n }\n\n /**\n * return attribute placeholder or, if DATE_INPUT_FORMAT setting is used, lowercased setting, otherwise return formatlabel without time input format from contributions\n */\n get placeholder(): string {\n if (this._placeholder !== \"\") {\n return this._placeholder;\n }\n\n const dateInputFormatSetting = getSetting(\"DATE_INPUT_FORMAT\", \"\");\n\n if (dateInputFormatSetting) {\n return dateInputFormatSetting.toLowerCase();\n }\n\n const formatLabel = this.getContribution(\"formatlabel\", \"\");\n\n if (this.hasDate && this.hasTime && formatLabel.includes(\" \")) {\n // return first part of formatlabel to keep placeholder matching date input\n return formatLabel.split(\" \")[0];\n }\n\n return formatLabel;\n }\n\n /**\n * Set placeholder text\n */\n set placeholder(placeholder: string) {\n this._placeholder = placeholder;\n }\n\n /**\n */\n get timeInputFormat(): string {\n if (!this.hasTime) {\n return \"\";\n }\n\n const format = this.format;\n\n let timeFormatParts = [];\n if (format.includes(\"H\")) {\n timeFormatParts.push(\"HH\");\n } else if (format.includes(\"h\")) {\n timeFormatParts.push(\"hh\");\n }\n if (format.includes(\"m\")) {\n timeFormatParts.push(\"mm\");\n }\n if (format.includes(\"s\")) {\n timeFormatParts.push(\"ss\");\n }\n\n let timeFormat = timeFormatParts.join(\":\");\n if (format.includes(\"S\")) {\n timeFormat = `${timeFormat}.SSS`;\n }\n if (format.includes(\"a\")) {\n return `${timeFormat} a`;\n }\n return timeFormat;\n }\n\n /**\n */\n get timeReadonlyFormat(): string {\n if (!this.hasTime) {\n return \"\";\n }\n\n return this.timeInputFormat;\n }\n\n /**\n */\n get dateInputValue(): string {\n return typeof this.value === \"string\" && this.dateInputFormat !== \"\"\n ? this.formatUtil.toFormat(this.value, this.dateInputFormat)\n : \"\";\n }\n\n /**\n */\n get timeInputValue(): string {\n return typeof this.value === \"string\" && this.timeInputFormat !== \"\"\n ? this.formatUtil.toFormat(this.value, this.timeInputFormat)\n : \"\";\n }\n\n // format value in readonly rendering\n /**\n */\n formatValue(value: ?string): string {\n if (value == null || value.toString() === \"\") {\n return \"\";\n }\n\n // when the value is exactly an iso date, render as date\n if (\n (this.type === \"datetime\" || this.type === \"timestamp\") &&\n DateUtil.hasFormat(value, ISO_DATE_FORMAT)\n ) {\n return DateUtil.toFormat(value, this.dateReadonlyFormat);\n }\n\n if (this.hasDate && this.hasTime) {\n const dateTimeReadonlyFormat = `${this.dateReadonlyFormat} ${this.timeReadonlyFormat}`;\n return this.formatUtil.toFormat(value, dateTimeReadonlyFormat);\n }\n\n if (this.type === \"date\") {\n return this.formatUtil.toFormat(value, this.dateReadonlyFormat);\n }\n\n return this.formatUtil.toFormat(value, this.format);\n }\n\n /**\n * Retrieve readonly value, the date in the configurated format\n */\n get readonlyvalue(): string {\n if (typeof this.value === \"string\") {\n return this.formatValue(this.value.toString());\n }\n\n return \"\";\n }\n\n /**\n * Get minimum date\n */\n get mindate(): string | null {\n return this.getContribution(\"mindate\");\n }\n\n /**\n * Get maximum date\n */\n get maxdate(): string | null {\n return this.getContribution(\"maxdate\");\n }\n\n /**\n * Registers an error that was received from a server response\n */\n addServerError(error: FormErrorAnchor) {\n const { id, message, properties, layouthint } = error;\n if (properties && has(properties, \"format\") && this.formatLabel) {\n properties.format = this.formatLabel;\n }\n\n this._errorCollection.addServerError(id, message, properties, layouthint);\n }\n\n /**\n */\n getFormatConstraint(): IConstraintModel {\n switch (this.type) {\n case \"date\":\n return new DateTimeDateFormatConstraint(\n this.dateInputFormat,\n this.formatLabel\n );\n case \"time\":\n return new DateTimeTimeFormatConstraint(\n this.timeInputFormat,\n this.formatLabel\n );\n default:\n return new DatetimeFormatConstraint(\n this.type,\n this.inputFormat,\n this.formatLabel\n );\n }\n }\n\n /**\n * Add Date constraints for attribute\n */\n addConstraints(): ConstraintCollection {\n const constraints = new ConstraintCollection();\n\n constraints.add(this.getFormatConstraint());\n\n if (this.mindate || this.maxdate) {\n constraints.add(\n new DateBoundaryConstraint(\n this.type,\n this.mindate,\n this.maxdate,\n this.inputFormat\n )\n );\n }\n\n return constraints;\n }\n\n /**\n */\n get readonlyWidth(): $Keys<typeof ATTRIBUTE_WIDTH> {\n if (this.type === \"date\" || this.type === \"time\") {\n return ATTRIBUTE_WIDTH.SMALL;\n }\n\n return ATTRIBUTE_WIDTH.MEDIUM;\n }\n}\n\nexport default DatetimeAttributeModel;\n"],"mappings":";;;;;;;;;AACA;AAEA;AAOA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AAIA;AACA,MAAMA,2BAA2B,GAAG,YAAY;;AAEhD;AACA;AACA,MAAMC,sBAAsB,SAASC,6BAAoB,CAAC;EACxD;AACF;EACEC,WAAW,CAACC,SAAiB,EAAEC,sBAA8B,EAAE;IAC7D,KAAK,CAACD,SAAS,EAAEC,sBAAsB,CAAC;IAExC,IAAI,CAACC,eAAe,EAAE;EACxB;;EAEA;AACF;EACE,OAAOC,iBAAiB,CAACC,aAAqB,EAAW;IAAA;IACvD,OAAO,mCAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,CAAC,iBAC9CA,aAAa,CAACC,IAAI,CACnB;EACH;;EAEA;AACF;EACE,IAAIC,UAAU,GAIM;IAClB,QAAQ,IAAI,CAACD,IAAI;MACf,KAAK,MAAM;QACT,OAAOE,sBAAQ;MACjB,KAAK,WAAW;QACd,OAAOC,2BAAa;MACtB,KAAK,UAAU;QACb,OAAOC,0BAAY;MACrB;QACE,OAAOC,sBAAQ;IAAC;EAEtB;;EAEA;AACF;EACEC,YAAY,GAAkB;IAC5B,IAAIC,KAAK,GAAG,IAAI,CAACC,IAAI,CAACD,KAAK;IAC3B,IAAIA,KAAK,IAAI,IAAI,EAAE;MACjB,IAAI,IAAI,CAACP,IAAI,KAAK,MAAM,IAAIO,KAAK,CAACE,MAAM,KAAK,CAAC,EAAE;QAC9CF,KAAK,GAAI,GAAEA,KAAM,KAAI;MACvB;;MAEA;MACA,IAAI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E+B,mBAAmB,GAAqB;IACtC,QAAQ,IAAI,CAACvE,IAAI;MACf,KAAK,MAAM;QACT,OAAO,IAAIwE,qCAA4B,CACrC,IAAI,CAAClC,eAAe,EACpB,IAAI,CAACD,WAAW,CACjB;MACH,KAAK,MAAM;QACT,OAAO,IAAIoC,qCAA4B,CACrC,IAAI,CAAC3D,eAAe,EACpB,IAAI,CAACuB,WAAW,CACjB;MACH;QACE,OAAO,IAAIqC,iCAAwB,CACjC,IAAI,CAAC1E,IAAI,EACT,IAAI,CAAC0B,WAAW,EAChB,IAAI,CAACW,WAAW,CACjB;IAAC;EAER;;EAEA;AACF;AACA;EACEsC,cAAc,GAAyB;IACrC,MAAMC,WAAW,GAAG,IAAIC,6BAAoB,EAAE;IAE9CD,WAAW,CAACE,GAAG,CAAC,IAAI,CAACP,mBAAmB,EAAE,CAAC;IAE3C,IAAI,IAAI,CAACR,OAAO,IAAI,IAAI,CAACC,OAAO,EAAE;MAChCY,WAAW,CAACE,GAAG,CACb,IAAIC,+BAAsB,CACxB,IAAI,CAAC/E,IAAI,EACT,IAAI,CAAC+D,OAAO,EACZ,IAAI,CAACC,OAAO,EACZ,IAAI,CAACtC,WAAW,CACjB,CACF;IACH;IAEA,OAAOkD,WAAW;EACpB;;EAEA;AACF;EACE,IAAII,aAAa,GAAkC;IACjD,IAAI,IAAI,CAAChF,IAAI,KAAK,MAAM,IAAI,IAAI,CAACA,IAAI,KAAK,MAAM,EAAE;MAChD,OAAOiF,0BAAe,CAACC,KAAK;IAC9B;IAEA,OAAOD,0BAAe,CAACE,MAAM;EAC/B;AACF;AAAC,eAEc3F,sBAAsB;AAAA"}
1
+ {"version":3,"file":"DatetimeAttributeModel.js","names":["DatetimeAttributeModel","StringAttributeModel","constructor","attribute","attributeContributions","updateInitValue","isApplicableModel","contributions","type","formatUtil","TimeUtil","TimestampUtil","DateTimeUtil","DateUtil","getInitValue","value","data","length","split","hasTime","getTimeValue","timeValue","timeInputFormat","toLowerCase","setHour","setMinute","setSecond","setMilliseconds","_initvalue","_inputvalue","getInitialInputValue","_value","initValue","toFormat","inputFormat","getContribution","getInputValue","toString","inputvalue","validate","toISO","format","convertFormat","operator","hasDate","formatLabel","dateInputFormat","replace","dateReadonlyFormat","placeholder","_placeholder","timeFormatParts","push","timeFormat","join","timeReadonlyFormat","dateInputValue","timeInputValue","formatValue","hasFormat","ISO_DATE_FORMAT","dateTimeReadonlyFormat","readonlyvalue","mindate","maxdate","addServerError","error","id","message","properties","layouthint","has","_errorCollection","getFormatConstraint","DateTimeDateFormatConstraint","DateTimeTimeFormatConstraint","DatetimeFormatConstraint","addConstraints","constraints","ConstraintCollection","add","DateBoundaryConstraint","readonlyWidth","ATTRIBUTE_WIDTH","SMALL","MEDIUM"],"sources":["../../../src/models/attributes/DatetimeAttributeModel.js"],"sourcesContent":["// @flow\nimport { has } from \"../../utils/helpers/objects\";\n\nimport {\n DateUtil,\n DateTimeUtil,\n TimeUtil,\n TimestampUtil,\n} from \"../../utils/datetime/DateTimeUtil\";\n\nimport StringAttributeModel from \"./StringAttributeModel\";\n\nimport ConstraintCollection from \"./input-constraints/ConstraintCollection\";\nimport DateTimeDateFormatConstraint from \"./input-constraints/DateTimeDateFormatConstraint\";\nimport DateTimeTimeFormatConstraint from \"./input-constraints/DateTimeTimeFormatConstraint\";\nimport DatetimeFormatConstraint from \"./input-constraints/DatetimeFormatConstraint\";\nimport DateBoundaryConstraint from \"./input-constraints/DateBoundaryConstraint\";\n\nimport { ATTRIBUTE_WIDTH, ISO_DATE_FORMAT } from \"../../constants\";\n\nimport type { FormErrorAnchor, IConstraintModel } from \"../types\";\n\n/**\n */\nclass DatetimeAttributeModel extends StringAttributeModel {\n /**\n */\n constructor(attribute: Object, attributeContributions: Object) {\n super(attribute, attributeContributions);\n\n this.updateInitValue();\n }\n\n /**\n */\n static isApplicableModel(contributions: Object): boolean {\n return [\"date\", \"time\", \"datetime\", \"timestamp\"].includes(\n contributions.type\n );\n }\n\n /**\n */\n get formatUtil():\n | typeof TimeUtil\n | typeof TimestampUtil\n | typeof DateTimeUtil\n | typeof DateUtil {\n switch (this.type) {\n case \"time\":\n return TimeUtil;\n case \"timestamp\":\n return TimestampUtil;\n case \"datetime\":\n return DateTimeUtil;\n default:\n return DateUtil;\n }\n }\n\n /**\n */\n getInitValue(): string | null {\n let value = this.data.value;\n if (value != null) {\n if (this.type === \"time\" && value.length === 5) {\n value = `${value}:00`;\n }\n\n // handle old datetime values, which contained ms\n if (this.type === \"datetime\" && value.includes(\".\")) {\n value = value.split(\".\")[0];\n }\n\n if (this.hasTime) {\n value = this.getTimeValue(value);\n }\n }\n\n return value;\n }\n\n /**\n */\n getTimeValue(value: string): string {\n let timeValue = value;\n if (!this.timeInputFormat.toLowerCase().includes(\"h\")) {\n timeValue = this.formatUtil.setHour(value, 0);\n }\n if (!this.timeInputFormat.includes(\"m\")) {\n timeValue = this.formatUtil.setMinute(value, 0);\n }\n if (!this.timeInputFormat.includes(\"s\")) {\n timeValue = this.formatUtil.setSecond(value, 0);\n }\n if (this.type === \"timestamp\" && !this.timeInputFormat.includes(\"S\")) {\n timeValue = this.formatUtil.setMilliseconds(value, 0);\n }\n return timeValue;\n }\n\n /**\n * Set time in the correct value based on available elements in the time format\n */\n updateInitValue() {\n const value = this.getInitValue();\n if (value != null) {\n this._initvalue = value;\n this._inputvalue = this.getInitialInputValue(value);\n this._value = value;\n }\n }\n\n /**\n * Get initial user input value\n */\n getInitialInputValue(value?: string): string {\n if (!value) {\n return \"\";\n }\n\n let initValue = value;\n if (this.type === \"time\" && value.length === 5) {\n initValue = `${value}:00`;\n }\n\n return this.formatUtil.toFormat(initValue, this.inputFormat);\n }\n\n /**\n * Set type to date\n */\n get type(): string {\n return this.getContribution(\"type\", \"date\");\n }\n\n /**\n * Returns the value as entered by the user. This can differ from the internal iso value that is stored\n */\n getInputValue(): string {\n return this._inputvalue ? this._inputvalue.toString() : \"\";\n }\n\n /**\n * Get input value\n */\n get inputvalue(): string {\n return this.getInputValue();\n }\n\n /**\n * Sets the input value to the value entered by the user\n */\n set inputvalue(value: string) {\n this.validate(value);\n\n this._inputvalue = value;\n\n this.value =\n value !== null && value !== \"\"\n ? this.formatUtil.toISO(value, this.inputFormat)\n : null;\n }\n\n /**\n * Get date format\n */\n get format(): string {\n const format = this.getContribution(\"format\", \"\");\n return this.formatUtil.convertFormat(format);\n }\n\n /**\n */\n get operator(): string {\n return this.getContribution(\"operator\", \"\");\n }\n\n /**\n */\n get hasDate(): boolean {\n return (\n this.type === \"date\" ||\n this.type === \"datetime\" ||\n this.type === \"timestamp\"\n );\n }\n\n /**\n */\n get hasTime(): boolean {\n return (\n this.type === \"time\" ||\n this.type === \"datetime\" ||\n this.type === \"timestamp\"\n );\n }\n\n /**\n */\n get formatLabel(): string {\n switch (this.type) {\n case \"date\":\n return this.dateInputFormat.toLowerCase();\n case \"time\":\n return this.timeInputFormat.toLowerCase();\n default:\n return this.format.toLowerCase();\n }\n }\n\n /**\n */\n get inputFormat(): string {\n if (this.hasDate && this.hasTime) {\n return `${this.dateInputFormat} ${this.timeInputFormat}`.trim();\n }\n\n if (this.hasDate) {\n return this.dateInputFormat;\n }\n\n if (this.hasTime) {\n return this.timeInputFormat;\n }\n\n return \"\";\n }\n\n /**\n */\n get dateInputFormat(): string {\n if (!this.hasDate) {\n return \"\";\n }\n\n return this.hasTime\n ? this.format.replace(this.timeInputFormat, \"\").trim()\n : this.format;\n }\n\n /**\n */\n get dateReadonlyFormat(): string {\n if (!this.hasDate) {\n return \"\";\n }\n\n return this.hasTime\n ? this.format.replace(this.timeInputFormat, \"\").trim()\n : this.format;\n }\n\n /**\n * return attribute placeholder or return formatlabel without time input format from contributions\n */\n get placeholder(): string {\n if (this._placeholder !== \"\") {\n return this._placeholder;\n }\n\n const formatLabel = this.getContribution(\"formatlabel\", \"\");\n\n if (this.hasDate && this.hasTime && formatLabel.includes(\" \")) {\n // return first part of formatlabel to keep placeholder matching date input\n return formatLabel.split(\" \")[0];\n }\n\n return formatLabel;\n }\n\n /**\n * Set placeholder text\n */\n set placeholder(placeholder: string) {\n this._placeholder = placeholder;\n }\n\n /**\n */\n get timeInputFormat(): string {\n if (!this.hasTime) {\n return \"\";\n }\n\n const format = this.format;\n\n let timeFormatParts = [];\n if (format.includes(\"H\")) {\n timeFormatParts.push(\"HH\");\n } else if (format.includes(\"h\")) {\n timeFormatParts.push(\"hh\");\n }\n if (format.includes(\"m\")) {\n timeFormatParts.push(\"mm\");\n }\n if (format.includes(\"s\")) {\n timeFormatParts.push(\"ss\");\n }\n\n let timeFormat = timeFormatParts.join(\":\");\n if (format.includes(\"S\")) {\n timeFormat = `${timeFormat}.SSS`;\n }\n if (format.includes(\"a\")) {\n return `${timeFormat} a`;\n }\n return timeFormat;\n }\n\n /**\n */\n get timeReadonlyFormat(): string {\n if (!this.hasTime) {\n return \"\";\n }\n\n return this.timeInputFormat;\n }\n\n /**\n */\n get dateInputValue(): string {\n return typeof this.value === \"string\" && this.dateInputFormat !== \"\"\n ? this.formatUtil.toFormat(this.value, this.dateInputFormat)\n : \"\";\n }\n\n /**\n */\n get timeInputValue(): string {\n return typeof this.value === \"string\" && this.timeInputFormat !== \"\"\n ? this.formatUtil.toFormat(this.value, this.timeInputFormat)\n : \"\";\n }\n\n // format value in readonly rendering\n /**\n */\n formatValue(value: ?string): string {\n if (value == null || value.toString() === \"\") {\n return \"\";\n }\n\n // when the value is exactly an iso date, render as date\n if (\n (this.type === \"datetime\" || this.type === \"timestamp\") &&\n DateUtil.hasFormat(value, ISO_DATE_FORMAT)\n ) {\n return DateUtil.toFormat(value, this.dateReadonlyFormat);\n }\n\n if (this.hasDate && this.hasTime) {\n const dateTimeReadonlyFormat = `${this.dateReadonlyFormat} ${this.timeReadonlyFormat}`;\n return this.formatUtil.toFormat(value, dateTimeReadonlyFormat);\n }\n\n if (this.type === \"date\") {\n return this.formatUtil.toFormat(value, this.dateReadonlyFormat);\n }\n\n return this.formatUtil.toFormat(value, this.format);\n }\n\n /**\n * Retrieve readonly value, the date in the configurated format\n */\n get readonlyvalue(): string {\n if (typeof this.value === \"string\") {\n return this.formatValue(this.value.toString());\n }\n\n return \"\";\n }\n\n /**\n * Get minimum date\n */\n get mindate(): string | null {\n return this.getContribution(\"mindate\");\n }\n\n /**\n * Get maximum date\n */\n get maxdate(): string | null {\n return this.getContribution(\"maxdate\");\n }\n\n /**\n * Registers an error that was received from a server response\n */\n addServerError(error: FormErrorAnchor) {\n const { id, message, properties, layouthint } = error;\n if (properties && has(properties, \"format\") && this.formatLabel) {\n properties.format = this.formatLabel;\n }\n\n this._errorCollection.addServerError(id, message, properties, layouthint);\n }\n\n /**\n */\n getFormatConstraint(): IConstraintModel {\n switch (this.type) {\n case \"date\":\n return new DateTimeDateFormatConstraint(\n this.dateInputFormat,\n this.formatLabel\n );\n case \"time\":\n return new DateTimeTimeFormatConstraint(\n this.timeInputFormat,\n this.formatLabel\n );\n default:\n return new DatetimeFormatConstraint(\n this.type,\n this.inputFormat,\n this.formatLabel\n );\n }\n }\n\n /**\n * Add Date constraints for attribute\n */\n addConstraints(): ConstraintCollection {\n const constraints = new ConstraintCollection();\n\n constraints.add(this.getFormatConstraint());\n\n if (this.mindate || this.maxdate) {\n constraints.add(\n new DateBoundaryConstraint(\n this.type,\n this.mindate,\n this.maxdate,\n this.inputFormat\n )\n );\n }\n\n return constraints;\n }\n\n /**\n */\n get readonlyWidth(): $Keys<typeof ATTRIBUTE_WIDTH> {\n if (this.type === \"date\" || this.type === \"time\") {\n return ATTRIBUTE_WIDTH.SMALL;\n }\n\n return ATTRIBUTE_WIDTH.MEDIUM;\n }\n}\n\nexport default DatetimeAttributeModel;\n"],"mappings":";;;;;;;;;AACA;AAEA;AAOA;AAEA;AACA;AACA;AACA;AACA;AAEA;AAIA;AACA;AACA,MAAMA,sBAAsB,SAASC,6BAAoB,CAAC;EACxD;AACF;EACEC,WAAW,CAACC,SAAiB,EAAEC,sBAA8B,EAAE;IAC7D,KAAK,CAACD,SAAS,EAAEC,sBAAsB,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AmB,GAAqB;IACtC,QAAQ,IAAI,CAACjE,IAAI;MACf,KAAK,MAAM;QACT,OAAO,IAAIkE,qCAA4B,CACrC,IAAI,CAAC5B,eAAe,EACpB,IAAI,CAACD,WAAW,CACjB;MACH,KAAK,MAAM;QACT,OAAO,IAAI8B,qCAA4B,CACrC,IAAI,CAACrD,eAAe,EACpB,IAAI,CAACuB,WAAW,CACjB;MACH;QACE,OAAO,IAAI+B,iCAAwB,CACjC,IAAI,CAACpE,IAAI,EACT,IAAI,CAAC0B,WAAW,EAChB,IAAI,CAACW,WAAW,CACjB;IAAC;EAER;;EAEA;AACF;AACA;EACEgC,cAAc,GAAyB;IACrC,MAAMC,WAAW,GAAG,IAAIC,6BAAoB,EAAE;IAE9CD,WAAW,CAACE,GAAG,CAAC,IAAI,CAACP,mBAAmB,EAAE,CAAC;IAE3C,IAAI,IAAI,CAACV,OAAO,IAAI,IAAI,CAACC,OAAO,EAAE;MAChCc,WAAW,CAACE,GAAG,CACb,IAAIC,+BAAsB,CACxB,IAAI,CAACzE,IAAI,EACT,IAAI,CAACuD,OAAO,EACZ,IAAI,CAACC,OAAO,EACZ,IAAI,CAAC9B,WAAW,CACjB,CACF;IACH;IAEA,OAAO4C,WAAW;EACpB;;EAEA;AACF;EACE,IAAII,aAAa,GAAkC;IACjD,IAAI,IAAI,CAAC1E,IAAI,KAAK,MAAM,IAAI,IAAI,CAACA,IAAI,KAAK,MAAM,EAAE;MAChD,OAAO2E,0BAAe,CAACC,KAAK;IAC9B;IAEA,OAAOD,0BAAe,CAACE,MAAM;EAC/B;AACF;AAAC,eAEcrF,sBAAsB;AAAA"}
@@ -1,12 +1,7 @@
1
1
  import DatetimeAttributeModel from "../DatetimeAttributeModel";
2
- import { setSettings } from "../../../constants/Settings";
3
2
 
4
3
  describe("dateAttributeModel", () => {
5
4
  describe("with date related settings set", () => {
6
- beforeAll(() => {
7
- setSettings({ DATE_INPUT_FORMAT: "dd-MM-yyyy" });
8
- setSettings({ DATE_READONLY_FORMAT: "dd-MM-yyyy" });
9
- });
10
5
  it("should be able to create an empty Attribute object", () => {
11
6
  const attribute = new DatetimeAttributeModel();
12
7
 
@@ -51,7 +46,7 @@ describe("dateAttributeModel", () => {
51
46
 
52
47
  it("can set input", () => {
53
48
  const attribute = new DatetimeAttributeModel({});
54
- attribute.inputvalue = "10-12-2010";
49
+ attribute.inputvalue = "2010-12-10";
55
50
 
56
51
  expect(attribute.readonlyvalue).toBe("2010-12-10");
57
52
 
@@ -65,36 +60,7 @@ describe("dateAttributeModel", () => {
65
60
  });
66
61
  });
67
62
 
68
- describe("with non default date related settings configured", () => {
69
- beforeAll(() => {
70
- setSettings({ DATE_INPUT_FORMAT: "MM/dd/yyyy" });
71
- setSettings({ DATE_READONLY_FORMAT: "mm/dd/yyyy" });
72
- });
73
-
74
- it("returns the right date formats", () => {
75
- const attribute = new DatetimeAttributeModel(
76
- {},
77
- {
78
- label: "Date of birth",
79
- type: "date",
80
- format: "dd-MM-yyyy",
81
- formatlabel: "dd-mm-yyyy",
82
- }
83
- );
84
-
85
- // expect date input and readonly format to match the settings
86
- expect(attribute.format).toBe("dd-MM-yyyy");
87
- expect(attribute.dateInputFormat).toBe("MM/dd/yyyy");
88
- expect(attribute.dateReadonlyFormat).toBe("mm/dd/yyyy");
89
- });
90
- });
91
-
92
63
  describe("without date input and date readonly settings defined", () => {
93
- beforeAll(() => {
94
- // explicitly clear setting
95
- setSettings({ DATE_INPUT_FORMAT: "" });
96
- setSettings({ DATE_READONLY_FORMAT: "" });
97
- });
98
64
  it("should be able to return contributions format as date input format", () => {
99
65
  const attribute = new DatetimeAttributeModel(
100
66
  {},
@@ -1,226 +1,168 @@
1
1
  import DatetimeAttributeModel from "../DatetimeAttributeModel";
2
- import { setSettings } from "../../../constants/Settings";
3
2
  import { ATTRIBUTE_WIDTH } from "../../../constants";
4
3
 
5
4
  describe("datetimeAttributeModel", () => {
6
- describe("with date readonly format in product default format", () => {
7
- beforeAll(() => {
8
- // using product default format
9
- setSettings({ DATE_READONLY_FORMAT: "dd-MM-yyyy" });
10
- setSettings({ DATE_INPUT_FORMAT: "dd-MM-yyyy" });
11
- });
12
-
13
- it("should be able to create an empty DatetimeAttribute object", () => {
14
- const attribute = new DatetimeAttributeModel({}, { type: "datetime" });
15
-
16
- expect(attribute).toBeInstanceOf(DatetimeAttributeModel);
17
-
18
- expect(attribute.type).toBe("datetime");
19
- expect(attribute.format).toBe("yyyy-MM-dd'T'HH:mm:ss");
20
- expect(attribute.getInputValue()).toBe("");
21
- expect(attribute.inputvalue).toBe("");
22
- expect(attribute.readonlyvalue).toBe("");
23
-
24
- attribute.addConstraints();
25
- expect(attribute.constraintCollection).toHaveLength(1);
26
- });
27
-
28
- it("should be able to update", () => {
29
- const attribute = new DatetimeAttributeModel(
30
- {},
31
- {
32
- type: "datetime",
33
- format: "dd-MM-yyyy HH:mm",
34
- }
35
- );
36
-
37
- attribute.update("18-08-2016 13:45");
38
- expect(attribute.getInputValue()).toBe("18-08-2016 13:45");
39
- expect(attribute.getInitialInputValue("2016-08-18T13:45:23")).toBe(
40
- "18-08-2016 13:45"
41
- );
42
-
43
- expect(attribute.readonlyvalue).toBe("18-08-2016 13:45");
44
-
45
- attribute.update(null);
46
- expect(attribute.getInputValue()).toBe("");
47
-
48
- attribute.update("");
49
- expect(attribute.value).toBeNull();
50
-
51
- attribute.update("aaaa");
52
- expect(attribute.value).toBe("Invalid Date");
53
- });
54
-
55
- it("should be able to handle min and max date in only date format and renders in format", () => {
56
- const attribute = new DatetimeAttributeModel(
57
- {},
58
- {
59
- type: "datetime",
60
- format: "dd-MM-yyyy HH:mm",
61
- mindate: "2010-10-01T00:00:00",
62
- maxdate: "2010-10-31T23:59:59",
63
- }
64
- );
65
-
66
- attribute.update("18-08-2016 13:45");
67
-
68
- expect(attribute.isValid).toBe(false);
69
- expect(attribute.formatValue(attribute.mindate)).toBe("01-10-2010 00:00");
70
- expect(attribute.formatValue(attribute.maxdate)).toBe("31-10-2010 23:59");
71
- });
5
+ it("should be able to create an empty DatetimeAttribute object", () => {
6
+ const attribute = new DatetimeAttributeModel({}, { type: "datetime" });
7
+
8
+ expect(attribute).toBeInstanceOf(DatetimeAttributeModel);
9
+
10
+ expect(attribute.type).toBe("datetime");
11
+ expect(attribute.format).toBe("yyyy-MM-dd'T'HH:mm:ss");
12
+ expect(attribute.getInputValue()).toBe("");
13
+ expect(attribute.inputvalue).toBe("");
14
+ expect(attribute.readonlyvalue).toBe("");
15
+
16
+ attribute.addConstraints();
17
+ expect(attribute.constraintCollection).toHaveLength(1);
72
18
  });
73
19
 
74
- describe("with customized readonly format for dates", () => {
75
- beforeAll(() => {
76
- // readonly format in non product default format
77
- setSettings({ DATE_READONLY_FORMAT: "MM-dd-yyyy" });
78
- });
79
-
80
- it("should show datetime readonly value in custom date format", () => {
81
- const attribute = new DatetimeAttributeModel(
82
- {},
83
- {
84
- type: "datetime",
85
- format: "dd-MM-yyyy HH:mm",
86
- }
87
- );
88
-
89
- attribute.update("18-08-2016 13:45");
90
- expect(attribute.readonlyvalue).toBe("08-18-2016 13:45");
91
- });
92
-
93
- it("should show date only value according in custom date format", () => {
94
- const attribute = new DatetimeAttributeModel(
95
- { value: "2017-07-29" },
96
- {
97
- type: "date",
98
- format: "dd-MM-yyyy",
99
- }
100
- );
101
-
102
- expect(attribute.readonlyvalue).toBe("07-29-2017");
103
- });
104
-
105
- it("should show custom format with am/pm in custom date format", () => {
106
- const attribute = new DatetimeAttributeModel(
107
- { value: "2031-12-21T17:41:21" },
108
- { type: "datetime", format: "dd-MM-yyyy hh:mm:ss a" }
109
- );
110
-
111
- expect(attribute.readonlyvalue).toBe("12-21-2031 05:41:21 PM");
112
- });
113
-
114
- it("should return AttributeWidth for dates", () => {
115
- const attribute = new DatetimeAttributeModel(
116
- {},
117
- {
118
- type: "date",
119
- }
120
- );
121
- expect(attribute.readonlyWidth).toBe(ATTRIBUTE_WIDTH.SMALL);
122
- });
123
-
124
- it("should return AttributeWidth for times", () => {
125
- const attribute = new DatetimeAttributeModel(
126
- {},
127
- {
128
- type: "time",
129
- }
130
- );
131
- expect(attribute.readonlyWidth).toBe(ATTRIBUTE_WIDTH.SMALL);
132
- });
133
-
134
- it("should return AttributeWidth for datetime", () => {
135
- const attribute = new DatetimeAttributeModel(
136
- {},
137
- {
138
- type: "datetime",
139
- }
140
- );
141
- expect(attribute.readonlyWidth).toBe(ATTRIBUTE_WIDTH.MEDIUM);
142
- });
143
-
144
- it("can validate datetime with datetime format", () => {
145
- const datetimeFormat = new DatetimeAttributeModel(
146
- {},
147
- {
148
- type: "datetime",
149
- format: "dd-MM-yyyy HH:mm",
150
- }
151
- );
152
-
153
- expect(datetimeFormat.validate("19-10-2010 1:45")).toBe(true);
154
- expect(datetimeFormat.validate("19-10-2010 13:45")).toBe(true);
155
-
156
- expect(datetimeFormat.validate("19-10-2010")).toBe(false);
157
- expect(datetimeFormat.validate("13:45")).toBe(false);
158
- expect(datetimeFormat.validate("19-10-2010 1:45 am")).toBe(false);
159
- });
160
-
161
- it("can validate datetime with only date format", () => {
162
- const dateFormat = new DatetimeAttributeModel(
163
- {},
164
- {
165
- type: "datetime",
166
- format: "dd-MM-yyyy",
167
- }
168
- );
169
-
170
- expect(dateFormat.validate("19-10-2010")).toBe(true);
171
-
172
- expect(dateFormat.validate("19-10-2010 1:45")).toBe(false);
173
- expect(dateFormat.validate("13:45")).toBe(false);
174
- expect(dateFormat.validate("19-10-2010 1:45 am")).toBe(false);
175
- });
176
-
177
- it("can validate datetime with datetime am/pm format", () => {
178
- const datetimeAmPmFormat = new DatetimeAttributeModel(
179
- {},
180
- {
181
- type: "datetime",
182
- format: "dd-MM-yyyy hh:mm a",
183
- }
184
- );
185
-
186
- expect(datetimeAmPmFormat.validate("19-10-2010 1:45 am")).toBe(true);
187
- expect(datetimeAmPmFormat.validate("19-10-2010 1:45 pm")).toBe(true);
188
-
189
- expect(datetimeAmPmFormat.validate("19-10-2010 1:45")).toBe(false);
190
- expect(datetimeAmPmFormat.validate("19-10-2010 13:45")).toBe(false);
191
- });
192
-
193
- it("can handle old datetime format with ms", () => {
194
- const attribute = new DatetimeAttributeModel(
195
- { value: "2031-12-21T17:41:21.000" },
196
- {
197
- type: "datetime",
198
- format: "dd-MM-yyyy HH:mm",
199
- }
200
- );
201
-
202
- expect(attribute.readonlyvalue).toBe("12-21-2031 17:41");
203
- });
20
+ it("should be able to update", () => {
21
+ const attribute = new DatetimeAttributeModel(
22
+ {},
23
+ {
24
+ type: "datetime",
25
+ format: "dd-MM-yyyy HH:mm",
26
+ }
27
+ );
28
+
29
+ attribute.update("18-08-2016 13:45");
30
+ expect(attribute.getInputValue()).toBe("18-08-2016 13:45");
31
+ expect(attribute.getInitialInputValue("2016-08-18T13:45:23")).toBe(
32
+ "18-08-2016 13:45"
33
+ );
34
+
35
+ expect(attribute.readonlyvalue).toBe("18-08-2016 13:45");
36
+
37
+ attribute.update(null);
38
+ expect(attribute.getInputValue()).toBe("");
39
+
40
+ attribute.update("");
41
+ expect(attribute.value).toBeNull();
42
+
43
+ attribute.update("aaaa");
44
+ expect(attribute.value).toBe("Invalid Date");
45
+ });
46
+
47
+ it("should be able to handle min and max date in only date format and renders in format", () => {
48
+ const attribute = new DatetimeAttributeModel(
49
+ {},
50
+ {
51
+ type: "datetime",
52
+ format: "dd-MM-yyyy HH:mm",
53
+ mindate: "2010-10-01T00:00:00",
54
+ maxdate: "2010-10-31T23:59:59",
55
+ }
56
+ );
57
+
58
+ attribute.update("18-08-2016 13:45");
59
+
60
+ expect(attribute.isValid).toBe(false);
61
+ expect(attribute.formatValue(attribute.mindate)).toBe("01-10-2010 00:00");
62
+ expect(attribute.formatValue(attribute.maxdate)).toBe("31-10-2010 23:59");
63
+ });
64
+
65
+ it("should return AttributeWidth for dates", () => {
66
+ const attribute = new DatetimeAttributeModel(
67
+ {},
68
+ {
69
+ type: "date",
70
+ }
71
+ );
72
+ expect(attribute.readonlyWidth).toBe(ATTRIBUTE_WIDTH.SMALL);
73
+ });
74
+
75
+ it("should return AttributeWidth for times", () => {
76
+ const attribute = new DatetimeAttributeModel(
77
+ {},
78
+ {
79
+ type: "time",
80
+ }
81
+ );
82
+ expect(attribute.readonlyWidth).toBe(ATTRIBUTE_WIDTH.SMALL);
83
+ });
84
+
85
+ it("should return AttributeWidth for datetime", () => {
86
+ const attribute = new DatetimeAttributeModel(
87
+ {},
88
+ {
89
+ type: "datetime",
90
+ }
91
+ );
92
+ expect(attribute.readonlyWidth).toBe(ATTRIBUTE_WIDTH.MEDIUM);
93
+ });
94
+
95
+ it("can validate datetime with datetime format", () => {
96
+ const datetimeFormat = new DatetimeAttributeModel(
97
+ {},
98
+ {
99
+ type: "datetime",
100
+ format: "dd-MM-yyyy HH:mm",
101
+ }
102
+ );
103
+
104
+ expect(datetimeFormat.validate("19-10-2010 1:45")).toBe(true);
105
+ expect(datetimeFormat.validate("19-10-2010 13:45")).toBe(true);
106
+
107
+ expect(datetimeFormat.validate("19-10-2010")).toBe(false);
108
+ expect(datetimeFormat.validate("13:45")).toBe(false);
109
+ expect(datetimeFormat.validate("19-10-2010 1:45 am")).toBe(false);
110
+ });
111
+
112
+ it("can validate datetime with only date format", () => {
113
+ const dateFormat = new DatetimeAttributeModel(
114
+ {},
115
+ {
116
+ type: "datetime",
117
+ format: "dd-MM-yyyy",
118
+ }
119
+ );
120
+
121
+ expect(dateFormat.validate("19-10-2010")).toBe(true);
122
+
123
+ expect(dateFormat.validate("19-10-2010 1:45")).toBe(false);
124
+ expect(dateFormat.validate("13:45")).toBe(false);
125
+ expect(dateFormat.validate("19-10-2010 1:45 am")).toBe(false);
126
+ });
127
+
128
+ it("can validate datetime with datetime am/pm format", () => {
129
+ const datetimeAmPmFormat = new DatetimeAttributeModel(
130
+ {},
131
+ {
132
+ type: "datetime",
133
+ format: "dd-MM-yyyy hh:mm a",
134
+ }
135
+ );
136
+
137
+ expect(datetimeAmPmFormat.validate("19-10-2010 1:45 am")).toBe(true);
138
+ expect(datetimeAmPmFormat.validate("19-10-2010 1:45 pm")).toBe(true);
139
+
140
+ expect(datetimeAmPmFormat.validate("19-10-2010 1:45")).toBe(false);
141
+ expect(datetimeAmPmFormat.validate("19-10-2010 13:45")).toBe(false);
142
+ });
143
+
144
+ it("can handle old datetime format with ms", () => {
145
+ const attribute = new DatetimeAttributeModel(
146
+ { value: "2031-12-21T17:41:21.000" },
147
+ {
148
+ type: "datetime",
149
+ format: "dd-MM-yyyy HH:mm",
150
+ }
151
+ );
152
+
153
+ expect(attribute.readonlyvalue).toBe("21-12-2031 17:41");
204
154
  });
205
155
 
206
- describe("without date input and date readonly settings defined", () => {
207
- beforeAll(() => {
208
- // explicitly clear setting
209
- setSettings({ DATE_INPUT_FORMAT: "" });
210
- setSettings({ DATE_READONLY_FORMAT: "" });
211
- });
212
-
213
- it("returns date part of formatlabel as placeholder if attribute has date and time", () => {
214
- const attribute = new DatetimeAttributeModel(
215
- {},
216
- {
217
- type: "datetime",
218
- format: "dd-MM-yyyy HH:mm",
219
- formatlabel: "dd-MM-yyyy HH:mm",
220
- }
221
- );
222
-
223
- expect(attribute.placeholder).toBe("dd-MM-yyyy");
224
- });
156
+ it("returns date part of formatlabel as placeholder if attribute has date and time", () => {
157
+ const attribute = new DatetimeAttributeModel(
158
+ {},
159
+ {
160
+ type: "datetime",
161
+ format: "dd-MM-yyyy HH:mm",
162
+ formatlabel: "dd-MM-yyyy HH:mm",
163
+ }
164
+ );
165
+
166
+ expect(attribute.placeholder).toBe("dd-MM-yyyy");
225
167
  });
226
168
  });
@@ -1,10 +1,5 @@
1
1
  import DatetimeAttributeModel from "../DatetimeAttributeModel";
2
- import { setSettings } from "../../../constants/Settings";
3
-
4
2
  describe("timestampAttributeModel", () => {
5
- beforeAll(() => {
6
- setSettings({ DATE_INPUT_FORMAT: "dd-MM-yyyy" });
7
- });
8
3
  it("should be able to create an empty TimestampAttribute object", () => {
9
4
  const attribute = new DatetimeAttributeModel({}, { type: "timestamp" });
10
5
 
@@ -16,7 +16,7 @@ var _jsxRuntime = require("react/jsx-runtime");
16
16
  const Init = _ref => {
17
17
  let {
18
18
  store,
19
- history,
19
+ routerHistory,
20
20
  contextPath,
21
21
  theme,
22
22
  children,
@@ -30,7 +30,7 @@ const Init = _ref => {
30
30
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ErrorBoundary.default, {
31
31
  FallbackComponent: ErrorFallbackComponent,
32
32
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactRouter.Router, {
33
- history: history,
33
+ history: routerHistory,
34
34
  basename: contextPath,
35
35
  children: children
36
36
  })
@@ -14,7 +14,7 @@ import type { Props as FallbackProps } from "../react/ErrorBoundaryFallback";
14
14
 
15
15
  export type Props = {
16
16
  +store: ReduxStore,
17
- +history: RouterHistory,
17
+ +routerHistory: RouterHistory,
18
18
  +contextPath: string,
19
19
  +theme?: Theme | Array<Theme>,
20
20
  +children: ?Node,
@@ -25,7 +25,7 @@ export type Props = {
25
25
  */
26
26
  const Init = ({
27
27
  store,
28
- history,
28
+ routerHistory,
29
29
  contextPath,
30
30
  theme,
31
31
  children,
@@ -35,7 +35,7 @@ const Init = ({
35
35
  <ThemeProvider theme={theme}>
36
36
  <HelmetProvider>
37
37
  <ErrorBoundary FallbackComponent={ErrorFallbackComponent}>
38
- <Router history={history} basename={contextPath}>
38
+ <Router history={routerHistory} basename={contextPath}>
39
39
  {children}
40
40
  </Router>
41
41
  </ErrorBoundary>
@@ -1 +1 @@
1
- {"version":3,"file":"Init.js","names":["Init","store","history","contextPath","theme","children","ErrorFallbackComponent","displayName"],"sources":["../../src/react-client/Init.js"],"sourcesContent":["// @flow\nimport { Provider } from \"react-redux\";\nimport { HelmetProvider } from \"react-helmet-async\";\nimport { Router } from \"react-router\";\n\nimport ThemeProvider from \"../react-theme/ThemeProvider\";\nimport ErrorBoundary from \"../react/ErrorBoundary\";\n\nimport type { ComponentType, Node } from \"react\";\nimport type { RouterHistory } from \"react-router\";\nimport type { Theme } from \"../react-theme/types\";\nimport type { ReduxStore } from \"../redux/types\";\nimport type { Props as FallbackProps } from \"../react/ErrorBoundaryFallback\";\n\nexport type Props = {\n +store: ReduxStore,\n +history: RouterHistory,\n +contextPath: string,\n +theme?: Theme | Array<Theme>,\n +children: ?Node,\n +ErrorFallbackComponent?: ComponentType<FallbackProps>,\n};\n\n/**\n */\nconst Init = ({\n store,\n history,\n contextPath,\n theme,\n children,\n ErrorFallbackComponent,\n}: Props): Node => (\n <Provider store={store}>\n <ThemeProvider theme={theme}>\n <HelmetProvider>\n <ErrorBoundary FallbackComponent={ErrorFallbackComponent}>\n <Router history={history} basename={contextPath}>\n {children}\n </Router>\n </ErrorBoundary>\n </HelmetProvider>\n </ThemeProvider>\n </Provider>\n);\n\nInit.displayName = \"BI.Init\";\n\nexport default Init;\n"],"mappings":";;;;;;;AACA;AACA;AACA;AAEA;AACA;AAAmD;AAiBnD;AACA;AACA,MAAMA,IAAI,GAAG;EAAA,IAAC;IACZC,KAAK;IACLC,OAAO;IACPC,WAAW;IACXC,KAAK;IACLC,QAAQ;IACRC;EACK,CAAC;EAAA,oBACN,qBAAC,oBAAQ;IAAC,KAAK,EAAEL,KAAM;IAAA,uBACrB,qBAAC,sBAAa;MAAC,KAAK,EAAEG,KAAM;MAAA,uBAC1B,qBAAC,gCAAc;QAAA,uBACb,qBAAC,sBAAa;UAAC,iBAAiB,EAAEE,sBAAuB;UAAA,uBACvD,qBAAC,mBAAM;YAAC,OAAO,EAAEJ,OAAQ;YAAC,QAAQ,EAAEC,WAAY;YAAA,UAC7CE;UAAQ;QACF;MACK;IACD;EACH,EACP;AAAA,CACZ;AAEDL,IAAI,CAACO,WAAW,GAAG,SAAS;AAAC,eAEdP,IAAI;AAAA"}
1
+ {"version":3,"file":"Init.js","names":["Init","store","routerHistory","contextPath","theme","children","ErrorFallbackComponent","displayName"],"sources":["../../src/react-client/Init.js"],"sourcesContent":["// @flow\nimport { Provider } from \"react-redux\";\nimport { HelmetProvider } from \"react-helmet-async\";\nimport { Router } from \"react-router\";\n\nimport ThemeProvider from \"../react-theme/ThemeProvider\";\nimport ErrorBoundary from \"../react/ErrorBoundary\";\n\nimport type { ComponentType, Node } from \"react\";\nimport type { RouterHistory } from \"react-router\";\nimport type { Theme } from \"../react-theme/types\";\nimport type { ReduxStore } from \"../redux/types\";\nimport type { Props as FallbackProps } from \"../react/ErrorBoundaryFallback\";\n\nexport type Props = {\n +store: ReduxStore,\n +routerHistory: RouterHistory,\n +contextPath: string,\n +theme?: Theme | Array<Theme>,\n +children: ?Node,\n +ErrorFallbackComponent?: ComponentType<FallbackProps>,\n};\n\n/**\n */\nconst Init = ({\n store,\n routerHistory,\n contextPath,\n theme,\n children,\n ErrorFallbackComponent,\n}: Props): Node => (\n <Provider store={store}>\n <ThemeProvider theme={theme}>\n <HelmetProvider>\n <ErrorBoundary FallbackComponent={ErrorFallbackComponent}>\n <Router history={routerHistory} basename={contextPath}>\n {children}\n </Router>\n </ErrorBoundary>\n </HelmetProvider>\n </ThemeProvider>\n </Provider>\n);\n\nInit.displayName = \"BI.Init\";\n\nexport default Init;\n"],"mappings":";;;;;;;AACA;AACA;AACA;AAEA;AACA;AAAmD;AAiBnD;AACA;AACA,MAAMA,IAAI,GAAG;EAAA,IAAC;IACZC,KAAK;IACLC,aAAa;IACbC,WAAW;IACXC,KAAK;IACLC,QAAQ;IACRC;EACK,CAAC;EAAA,oBACN,qBAAC,oBAAQ;IAAC,KAAK,EAAEL,KAAM;IAAA,uBACrB,qBAAC,sBAAa;MAAC,KAAK,EAAEG,KAAM;MAAA,uBAC1B,qBAAC,gCAAc;QAAA,uBACb,qBAAC,sBAAa;UAAC,iBAAiB,EAAEE,sBAAuB;UAAA,uBACvD,qBAAC,mBAAM;YAAC,OAAO,EAAEJ,aAAc;YAAC,QAAQ,EAAEC,WAAY;YAAA,UACnDE;UAAQ;QACF;MACK;IACD;EACH,EACP;AAAA,CACZ;AAEDL,IAAI,CAACO,WAAW,GAAG,SAAS;AAAC,eAEdP,IAAI;AAAA"}