cozy-ui 92.0.0 → 92.0.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,10 @@
1
+ ## [92.0.1](https://github.com/cozy/cozy-ui/compare/v92.0.0...v92.0.1) (2023-08-31)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **Viewer:** Remove filename on path ending with slash ([ad8b88c](https://github.com/cozy/cozy-ui/commit/ad8b88c))
7
+
1
8
  # [92.0.0](https://github.com/cozy/cozy-ui/compare/v91.2.0...v92.0.0) (2023-08-28)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "92.0.0",
3
+ "version": "92.0.1",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -7,7 +7,11 @@ import AppLinker from '../../AppLinker'
7
7
  import FilePath from '../../FilePath'
8
8
  import useBreakpoints from '../../hooks/useBreakpoints'
9
9
 
10
- import { makeWebLink, normalizeAndSpreadAttributes } from '../helpers'
10
+ import {
11
+ makeWebLink,
12
+ normalizeAndSpreadAttributes,
13
+ removeFilenameFromPath
14
+ } from '../helpers'
11
15
  import { buildFileByIdQuery } from '../queries'
12
16
 
13
17
  const { ensureFilePath } = models.file
@@ -35,7 +39,7 @@ const ToolbarFilePath = ({ file }) => {
35
39
  if (fileWithPath) {
36
40
  const appSlug = 'drive'
37
41
  const nativePath = `/folder/${fileWithPath.dir_id}`
38
- const path = fileWithPath.path.replace(fileWithPath.name, '')
42
+ const path = removeFilenameFromPath(fileWithPath.path)
39
43
  const link = makeWebLink({ client, path: nativePath, slug: appSlug })
40
44
 
41
45
  if (isDesktop && link) {
@@ -203,3 +203,13 @@ export const makeWebLink = ({ client, slug, path }) => {
203
203
  return null
204
204
  }
205
205
  }
206
+
207
+ /**
208
+ * Remove the file name at the end of a path
209
+ * @param {string} path
210
+ * @returns {string} new path
211
+ */
212
+ export const removeFilenameFromPath = path => {
213
+ const newPath = path.substring(0, path.lastIndexOf('/'))
214
+ return newPath === '' ? '/' : newPath
215
+ }
@@ -7,7 +7,8 @@ import {
7
7
  buildEditAttributePath,
8
8
  knownDateMetadataNames,
9
9
  knownInformationMetadataNames,
10
- isEditableAttribute
10
+ isEditableAttribute,
11
+ removeFilenameFromPath
11
12
  } from './helpers'
12
13
 
13
14
  const fakeMetadata = {
@@ -155,4 +156,19 @@ describe('helpers', () => {
155
156
  })
156
157
  })
157
158
  })
159
+ describe('removeFilenameFromPath', () => {
160
+ it('should handle all types of path', () => {
161
+ expect(removeFilenameFromPath('/folder/7IsD.gif', '7IsD.gif')).toBe(
162
+ '/folder'
163
+ )
164
+
165
+ expect(removeFilenameFromPath('/7IsD.gif', '7IsD.gif')).toBe('/')
166
+
167
+ expect(removeFilenameFromPath('//7IsD.gif', '7IsD.gif')).toBe('/')
168
+
169
+ expect(removeFilenameFromPath('/7IsD.gif/7IsD.gif', '7IsD.gif')).toBe(
170
+ '/7IsD.gif'
171
+ )
172
+ })
173
+ })
158
174
  })
@@ -10,7 +10,7 @@ import Link from "cozy-ui/transpiled/react/Link";
10
10
  import AppLinker from "cozy-ui/transpiled/react/AppLinker";
11
11
  import FilePath from "cozy-ui/transpiled/react/FilePath";
12
12
  import useBreakpoints from "cozy-ui/transpiled/react/hooks/useBreakpoints";
13
- import { makeWebLink, normalizeAndSpreadAttributes } from "cozy-ui/transpiled/react/Viewer/helpers";
13
+ import { makeWebLink, normalizeAndSpreadAttributes, removeFilenameFromPath } from "cozy-ui/transpiled/react/Viewer/helpers";
14
14
  import { buildFileByIdQuery } from "cozy-ui/transpiled/react/Viewer/queries";
15
15
  var ensureFilePath = models.file.ensureFilePath;
16
16
 
@@ -33,7 +33,7 @@ var ToolbarFilePath = function ToolbarFilePath(_ref) {
33
33
  if (fileWithPath) {
34
34
  var appSlug = 'drive';
35
35
  var nativePath = "/folder/".concat(fileWithPath.dir_id);
36
- var path = fileWithPath.path.replace(fileWithPath.name, '');
36
+ var path = removeFilenameFromPath(fileWithPath.path);
37
37
  var link = makeWebLink({
38
38
  client: client,
39
39
  path: nativePath,
@@ -193,4 +193,14 @@ export var makeWebLink = function makeWebLink(_ref6) {
193
193
  } catch (e) {
194
194
  return null;
195
195
  }
196
+ };
197
+ /**
198
+ * Remove the file name at the end of a path
199
+ * @param {string} path
200
+ * @returns {string} new path
201
+ */
202
+
203
+ export var removeFilenameFromPath = function removeFilenameFromPath(path) {
204
+ var newPath = path.substring(0, path.lastIndexOf('/'));
205
+ return newPath === '' ? '/' : newPath;
196
206
  };