cozy-ui 95.10.0 → 95.11.1

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/CHANGELOG.md CHANGED
@@ -1,3 +1,20 @@
1
+ ## [95.11.1](https://github.com/cozy/cozy-ui/compare/v95.11.0...v95.11.1) (2023-11-20)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **BottomSheet:** Did not compare peek heights correctly ([600c430](https://github.com/cozy/cozy-ui/commit/600c430))
7
+ * **BottomSheet:** Did not set default currentIndex correctly ([e22c482](https://github.com/cozy/cozy-ui/commit/e22c482))
8
+ * **BottomSheet:** Did not set topPosition and snapIndex correctly ([c23ee5a](https://github.com/cozy/cozy-ui/commit/c23ee5a))
9
+
10
+ # [95.11.0](https://github.com/cozy/cozy-ui/compare/v95.10.0...v95.11.0) (2023-11-20)
11
+
12
+
13
+ ### Features
14
+
15
+ * Add missing `bicNumber` attribute ([ed37277](https://github.com/cozy/cozy-ui/commit/ed37277))
16
+ * Remove last occurence of `mespapiers.migrated.metadata` flag ([11c3147](https://github.com/cozy/cozy-ui/commit/11c3147))
17
+
1
18
  # [95.10.0](https://github.com/cozy/cozy-ui/compare/v95.9.0...v95.10.0) (2023-11-14)
2
19
 
3
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "95.10.0",
3
+ "version": "95.11.1",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -155,7 +155,7 @@ const BottomSheet = memo(
155
155
  const [isHidden, setIsHidden] = useState(false)
156
156
  const [showBackdrop, setShowBackdrop] = useState(backdrop)
157
157
  const [peekHeights, setPeekHeights] = useState(null)
158
- const [currentIndex, setCurrentIndex] = useState()
158
+ const [currentIndex, setCurrentIndex] = useState(1) // as setInitPos use computedMediumHeight
159
159
  const [bottomSpacerHeight, setBottomSpacerHeight] = useState(0)
160
160
  const [initPos, setInitPos] = useState(0)
161
161
  const prevInitPos = useRef()
@@ -189,12 +189,10 @@ const BottomSheet = memo(
189
189
  }, [onClose])
190
190
 
191
191
  const handleOnIndexChange = snapIndex => {
192
- const maxHeightSnapIndex = peekHeights.length - 1
193
-
194
192
  setCurrentIndex(snapIndex)
195
193
  setTopPosition({
196
194
  snapIndex,
197
- maxHeightSnapIndex,
195
+ peekHeights,
198
196
  isTopPosition,
199
197
  setIsTopPosition
200
198
  })
@@ -251,25 +249,29 @@ const BottomSheet = memo(
251
249
  actionButtonsBottomMargin
252
250
  })
253
251
 
254
- if (computedMediumHeight >= maxHeight) {
255
- setIsTopPosition(true)
256
- } else {
257
- setIsTopPosition(false)
258
- }
259
-
260
252
  const newPeekHeights = [
261
253
  ...new Set([minHeight, computedMediumHeight, maxHeight])
262
254
  ]
263
255
 
264
- const hasPeekHeightsChanged = peekHeights !== newPeekHeights
256
+ const hasPeekHeightsChanged =
257
+ peekHeights?.toString() !== newPeekHeights?.toString()
265
258
 
266
- if (hasPeekHeightsChanged && isTopPosition) {
267
- setCurrentIndex(v => v - 1)
268
- }
259
+ // lower the BottomSheet after a refresh if it was as top position and peek changed
260
+ const snapIndex =
261
+ hasPeekHeightsChanged && isTopPosition
262
+ ? currentIndex - 1 - (currentIndex - (newPeekHeights.length - 1))
263
+ : currentIndex
269
264
 
265
+ setCurrentIndex(snapIndex)
270
266
  setPeekHeights(newPeekHeights)
271
267
  prevInitPos.current = initPos
272
268
  setInitPos(computedMediumHeight)
269
+ setTopPosition({
270
+ snapIndex,
271
+ peekHeights: newPeekHeights,
272
+ isTopPosition,
273
+ setIsTopPosition
274
+ })
273
275
  // Used so that the BottomSheet can be opened to the top without stopping at the content height
274
276
  setBottomSpacerHeight(bottomSpacerHeight)
275
277
 
@@ -84,10 +84,12 @@ export const makeOverridenChildren = (children, headerContentRef) => {
84
84
 
85
85
  export const setTopPosition = ({
86
86
  snapIndex,
87
- maxHeightSnapIndex,
87
+ peekHeights,
88
88
  isTopPosition,
89
89
  setIsTopPosition
90
90
  }) => {
91
+ const maxHeightSnapIndex = peekHeights.length - 1
92
+
91
93
  if (snapIndex > maxHeightSnapIndex) {
92
94
  setIsTopPosition(true)
93
95
  }
@@ -161,7 +161,7 @@ describe('setTopPosition', () => {
161
161
 
162
162
  setTopPosition({
163
163
  snapIndex: 3,
164
- maxHeightSnapIndex: 2,
164
+ peekHeights: [0, 100, 200],
165
165
  setIsTopPosition
166
166
  })
167
167
 
@@ -173,7 +173,7 @@ describe('setTopPosition', () => {
173
173
 
174
174
  setTopPosition({
175
175
  snapIndex: 2,
176
- maxHeightSnapIndex: 2,
176
+ peekHeights: [0, 100, 200],
177
177
  isTopPosition: false,
178
178
  setIsTopPosition
179
179
  })
@@ -186,7 +186,7 @@ describe('setTopPosition', () => {
186
186
 
187
187
  setTopPosition({
188
188
  snapIndex: 1,
189
- maxHeightSnapIndex: 2,
189
+ peekHeights: [0, 100, 200],
190
190
  isTopPosition: true,
191
191
  setIsTopPosition
192
192
  })
@@ -201,7 +201,7 @@ describe('setTopPosition', () => {
201
201
 
202
202
  setTopPosition({
203
203
  snapIndex: 2,
204
- maxHeightSnapIndex: 2,
204
+ peekHeights: [0, 100, 200],
205
205
  isTopPosition: true,
206
206
  setIsTopPosition
207
207
  })
@@ -214,7 +214,7 @@ describe('setTopPosition', () => {
214
214
 
215
215
  setTopPosition({
216
216
  snapIndex: 1,
217
- maxHeightSnapIndex: 2,
217
+ peekHeights: [0, 100, 200],
218
218
  isTopPosition: false,
219
219
  setIsTopPosition
220
220
  })
@@ -1,5 +1,4 @@
1
1
  import { models, generateWebLink } from 'cozy-client'
2
- import flag from 'cozy-flags'
3
2
 
4
3
  const {
5
4
  isEncrypted,
@@ -22,23 +21,14 @@ export const knownDateMetadataNames = [
22
21
  'date',
23
22
  'datetime'
24
23
  ]
25
- export const knownInformationMetadataNames = flag(
26
- 'mespapiers.migrated.metadata'
27
- )
28
- ? ['number', 'country', 'refTaxIncome', 'contractType', 'noticePeriod']
29
- : [
30
- 'number',
31
- 'cafFileNumber',
32
- 'cardNumber',
33
- 'vinNumber',
34
- 'ibanNumber',
35
- 'bicNumber',
36
- 'country',
37
- 'passportNumber',
38
- 'refTaxIncome',
39
- 'contractType',
40
- 'noticePeriod'
41
- ]
24
+ export const knownInformationMetadataNames = [
25
+ 'number',
26
+ 'bicNumber',
27
+ 'country',
28
+ 'refTaxIncome',
29
+ 'contractType',
30
+ 'noticePeriod'
31
+ ]
42
32
  export const knownOtherMetadataNames = ['contact', 'page', 'qualification']
43
33
 
44
34
  export const getCurrentModel = metadataName => {
@@ -171,10 +171,11 @@ var BottomSheet = /*#__PURE__*/memo(function (_ref3) {
171
171
  peekHeights = _useState10[0],
172
172
  setPeekHeights = _useState10[1];
173
173
 
174
- var _useState11 = useState(),
174
+ var _useState11 = useState(1),
175
175
  _useState12 = _slicedToArray(_useState11, 2),
176
176
  currentIndex = _useState12[0],
177
- setCurrentIndex = _useState12[1];
177
+ setCurrentIndex = _useState12[1]; // as setInitPos use computedMediumHeight
178
+
178
179
 
179
180
  var _useState13 = useState(0),
180
181
  _useState14 = _slicedToArray(_useState13, 2),
@@ -212,11 +213,10 @@ var BottomSheet = /*#__PURE__*/memo(function (_ref3) {
212
213
  }, [onClose]);
213
214
 
214
215
  var handleOnIndexChange = function handleOnIndexChange(snapIndex) {
215
- var maxHeightSnapIndex = peekHeights.length - 1;
216
216
  setCurrentIndex(snapIndex);
217
217
  setTopPosition({
218
218
  snapIndex: snapIndex,
219
- maxHeightSnapIndex: maxHeightSnapIndex,
219
+ peekHeights: peekHeights,
220
220
  isTopPosition: isTopPosition,
221
221
  setIsTopPosition: setIsTopPosition
222
222
  });
@@ -268,25 +268,21 @@ var BottomSheet = /*#__PURE__*/memo(function (_ref3) {
268
268
  actionButtonsBottomMargin: actionButtonsBottomMargin
269
269
  });
270
270
 
271
- if (computedMediumHeight >= maxHeight) {
272
- setIsTopPosition(true);
273
- } else {
274
- setIsTopPosition(false);
275
- }
276
-
277
271
  var newPeekHeights = _toConsumableArray(new Set([minHeight, computedMediumHeight, maxHeight]));
278
272
 
279
- var hasPeekHeightsChanged = peekHeights !== newPeekHeights;
280
-
281
- if (hasPeekHeightsChanged && isTopPosition) {
282
- setCurrentIndex(function (v) {
283
- return v - 1;
284
- });
285
- }
273
+ var hasPeekHeightsChanged = (peekHeights === null || peekHeights === void 0 ? void 0 : peekHeights.toString()) !== (newPeekHeights === null || newPeekHeights === void 0 ? void 0 : newPeekHeights.toString()); // lower the BottomSheet after a refresh if it was as top position and peek changed
286
274
 
275
+ var snapIndex = hasPeekHeightsChanged && isTopPosition ? currentIndex - 1 - (currentIndex - (newPeekHeights.length - 1)) : currentIndex;
276
+ setCurrentIndex(snapIndex);
287
277
  setPeekHeights(newPeekHeights);
288
278
  prevInitPos.current = initPos;
289
- setInitPos(computedMediumHeight); // Used so that the BottomSheet can be opened to the top without stopping at the content height
279
+ setInitPos(computedMediumHeight);
280
+ setTopPosition({
281
+ snapIndex: snapIndex,
282
+ peekHeights: newPeekHeights,
283
+ isTopPosition: isTopPosition,
284
+ setIsTopPosition: setIsTopPosition
285
+ }); // Used so that the BottomSheet can be opened to the top without stopping at the content height
290
286
 
291
287
  setBottomSpacerHeight(bottomSpacerHeight); // eslint-disable-next-line react-hooks/exhaustive-deps
292
288
  }, [// initPos is missing, because we need the previous value
@@ -64,9 +64,10 @@ export var makeOverridenChildren = function makeOverridenChildren(children, head
64
64
  };
65
65
  export var setTopPosition = function setTopPosition(_ref3) {
66
66
  var snapIndex = _ref3.snapIndex,
67
- maxHeightSnapIndex = _ref3.maxHeightSnapIndex,
67
+ peekHeights = _ref3.peekHeights,
68
68
  isTopPosition = _ref3.isTopPosition,
69
69
  setIsTopPosition = _ref3.setIsTopPosition;
70
+ var maxHeightSnapIndex = peekHeights.length - 1;
70
71
 
71
72
  if (snapIndex > maxHeightSnapIndex) {
72
73
  setIsTopPosition(true);
@@ -8,7 +8,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
8
8
 
9
9
  import _regeneratorRuntime from "@babel/runtime/regenerator";
10
10
  import { models, generateWebLink } from 'cozy-client';
11
- import flag from 'cozy-flags';
12
11
  var _models$file = models.file,
13
12
  isEncrypted = _models$file.isEncrypted,
14
13
  isFromKonnector = _models$file.isFromKonnector,
@@ -16,7 +15,7 @@ var _models$file = models.file,
16
15
  hasCertifications = _models$file.hasCertifications,
17
16
  normalize = _models$file.normalize;
18
17
  export var knownDateMetadataNames = ['AObtentionDate', 'BObtentionDate', 'CObtentionDate', 'DObtentionDate', 'obtentionDate', 'expirationDate', 'referencedDate', 'issueDate', 'shootingDate', 'date', 'datetime'];
19
- export var knownInformationMetadataNames = flag('mespapiers.migrated.metadata') ? ['number', 'country', 'refTaxIncome', 'contractType', 'noticePeriod'] : ['number', 'cafFileNumber', 'cardNumber', 'vinNumber', 'ibanNumber', 'bicNumber', 'country', 'passportNumber', 'refTaxIncome', 'contractType', 'noticePeriod'];
18
+ export var knownInformationMetadataNames = ['number', 'bicNumber', 'country', 'refTaxIncome', 'contractType', 'noticePeriod'];
20
19
  export var knownOtherMetadataNames = ['contact', 'page', 'qualification'];
21
20
  export var getCurrentModel = function getCurrentModel(metadataName) {
22
21
  if (knownDateMetadataNames.includes(metadataName) || knownInformationMetadataNames.includes(metadataName)) {