cozy-client 57.6.0 → 57.7.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.
@@ -3112,7 +3112,7 @@ var CozyClient = /*#__PURE__*/function () {
3112
3112
  CozyClient.hooks = CozyClient.hooks || {};
3113
3113
  CozyClient.fetchPolicies = _policies.default; //COZY_CLIENT_VERSION_PACKAGE in replaced by babel. See babel config
3114
3114
 
3115
- CozyClient.version = "57.6.0";
3115
+ CozyClient.version = "57.7.1";
3116
3116
 
3117
3117
  _microee.default.mixin(CozyClient);
3118
3118
 
@@ -5,7 +5,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.getAppDisplayName = exports.getUrl = exports.isInstalled = exports.getStoreInstallationURL = exports.getStoreURL = void 0;
8
+ exports.sortApplicationsList = exports.getAppDisplayName = exports.getUrl = exports.isInstalled = exports.getStoreInstallationURL = exports.getStoreURL = void 0;
9
+
10
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
11
 
10
12
  var _get = _interopRequireDefault(require("lodash/get"));
11
13
 
@@ -103,7 +105,29 @@ var getAppDisplayName = function getAppDisplayName(app, lang) {
103
105
  var baseName = (0, _get.default)(app, 'name');
104
106
  var translatedName = (0, _get.default)(app, ['locales', lang, 'name'], baseName);
105
107
  var translatedPrefix = (0, _get.default)(app, ['locales', lang, 'name_prefix'], basePrefix);
106
- return translatedPrefix && translatedPrefix.toLowerCase() !== 'cozy' ? "".concat(translatedPrefix, " ").concat(translatedName) : translatedName;
108
+ return translatedPrefix && translatedPrefix.toLowerCase() !== 'cozy' && translatedPrefix.toLowerCase() !== 'twake' ? "".concat(translatedPrefix, " ").concat(translatedName) : translatedName;
109
+ };
110
+ /**
111
+ * sortApplicationsList - Sort the apps based on the slugs in parameters. Apps listed in the slugsOrder array will be added first
112
+ * and will respect the order defined by slugsOrder and other apps will be added after.
113
+ *
114
+ * @param {object[]} apps io.cozy.apps array
115
+ * @param {string[]} slugsOrder slugs array
116
+ *
117
+ * @returns {object[]} io.cozy.apps array
118
+ */
119
+
120
+
121
+ exports.getAppDisplayName = getAppDisplayName;
122
+
123
+ var sortApplicationsList = function sortApplicationsList(apps, slugsOrder) {
124
+ return (0, _toConsumableArray2.default)(apps).sort(function (a, b) {
125
+ var indexA = slugsOrder.indexOf(a.slug);
126
+ if (indexA === -1) indexA = 1000;
127
+ var indexB = slugsOrder.indexOf(b.slug);
128
+ if (indexB === -1) indexB = 1000;
129
+ return indexA - indexB;
130
+ });
107
131
  };
108
132
 
109
- exports.getAppDisplayName = getAppDisplayName;
133
+ exports.sortApplicationsList = sortApplicationsList;
@@ -1,5 +1,10 @@
1
1
  import { applications } from './'
2
- const { getAppDisplayName, getStoreURL, getStoreInstallationURL } = applications
2
+ const {
3
+ getAppDisplayName,
4
+ getStoreURL,
5
+ getStoreInstallationURL,
6
+ sortApplicationsList
7
+ } = applications
3
8
 
4
9
  describe('applications model', () => {
5
10
  describe('application name', () => {
@@ -18,6 +23,12 @@ describe('applications model', () => {
18
23
  expect(getAppDisplayName({ name_prefix: 'Cozy', name: 'Cozy' })).toBe(
19
24
  'Cozy'
20
25
  )
26
+ expect(getAppDisplayName({ name_prefix: 'Twake', name: 'Cloud' })).toBe(
27
+ 'Cloud'
28
+ )
29
+ expect(getAppDisplayName({ name_prefix: 'Twake', name: 'Twake' })).toBe(
30
+ 'Twake'
31
+ )
21
32
  })
22
33
 
23
34
  it('should support translations', () => {
@@ -129,4 +140,88 @@ describe('applications model', () => {
129
140
  })
130
141
  })
131
142
  })
143
+
144
+ describe('sort applications list', () => {
145
+ it('should sort apps according to the given order', () => {
146
+ const availableApps = [
147
+ { slug: 'drive', name: 'Drive' },
148
+ { slug: 'chat', name: 'Chat' },
149
+ { slug: 'mail', name: 'Mail' },
150
+ { slug: 'contacts', name: 'Contacts' },
151
+ { slug: 'password', name: 'Password' }
152
+ ]
153
+ const order = ['chat', 'drive', 'mail', 'password', 'contacts']
154
+
155
+ const expected = [
156
+ { slug: 'chat', name: 'Chat' },
157
+ { slug: 'drive', name: 'Drive' },
158
+ { slug: 'mail', name: 'Mail' },
159
+ { slug: 'password', name: 'Password' },
160
+ { slug: 'contacts', name: 'Contacts' }
161
+ ]
162
+
163
+ const result = sortApplicationsList(availableApps, order)
164
+ expect(result).toEqual(expected)
165
+ })
166
+
167
+ it('should handle apps not in the order array', () => {
168
+ const availableApps = [
169
+ { slug: 'drive', name: 'Drive' },
170
+ { slug: 'chat', name: 'Chat' },
171
+ { slug: 'store', name: 'Store' },
172
+ { slug: 'mail', name: 'Mail' },
173
+ { slug: 'contacts', name: 'Contacts' },
174
+ { slug: 'password', name: 'Password' },
175
+ { slug: 'calendar', name: 'Calendar' }
176
+ ]
177
+ const order = ['chat', 'drive', 'mail', 'password', 'contacts']
178
+
179
+ const expected = [
180
+ { slug: 'chat', name: 'Chat' },
181
+ { slug: 'drive', name: 'Drive' },
182
+ { slug: 'mail', name: 'Mail' },
183
+ { slug: 'password', name: 'Password' },
184
+ { slug: 'contacts', name: 'Contacts' },
185
+ { slug: 'store', name: 'Store' },
186
+ { slug: 'calendar', name: 'Calendar' }
187
+ ]
188
+
189
+ const result = sortApplicationsList(availableApps, order)
190
+ expect(result).toEqual(expected)
191
+ })
192
+
193
+ it('should handle an empty apps array', () => {
194
+ const availableApps = []
195
+ const order = ['chat', 'drive', 'mail', 'password', 'notes', 'contacts']
196
+
197
+ const expected = []
198
+
199
+ const result = sortApplicationsList(availableApps, order)
200
+ expect(result).toEqual(expected)
201
+ })
202
+
203
+ it('should handle an empty order array', () => {
204
+ const availableApps = [
205
+ { slug: 'drive', name: 'Drive' },
206
+ { slug: 'chat', name: 'Chat' },
207
+ { slug: 'store', name: 'Store' },
208
+ { slug: 'mail', name: 'Mail' },
209
+ { slug: 'contacts', name: 'Contacts' },
210
+ { slug: 'password', name: 'Password' }
211
+ ]
212
+ const order = []
213
+
214
+ const expected = [
215
+ { slug: 'drive', name: 'Drive' },
216
+ { slug: 'chat', name: 'Chat' },
217
+ { slug: 'store', name: 'Store' },
218
+ { slug: 'mail', name: 'Mail' },
219
+ { slug: 'contacts', name: 'Contacts' },
220
+ { slug: 'password', name: 'Password' }
221
+ ]
222
+
223
+ const result = sortApplicationsList(availableApps, order)
224
+ expect(result).toEqual(expected)
225
+ })
226
+ })
132
227
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "57.6.0",
3
+ "version": "57.7.1",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.node.js",
6
6
  "browser": "dist/index.js",
@@ -74,5 +74,5 @@
74
74
  "react-native-ios11-devicecheck": "^0.0.3"
75
75
  },
76
76
  "sideEffects": false,
77
- "gitHead": "5a646c30c51b7a93ea7e65d309425799487b1968"
77
+ "gitHead": "6be3e7f973341b52f8394ba6e5adbba672e32dd6"
78
78
  }
@@ -3,3 +3,4 @@ export function getStoreInstallationURL(appData?: any[], app?: object): string;
3
3
  export function isInstalled(apps?: any[], wantedApp?: object): object;
4
4
  export function getUrl(app: object): string;
5
5
  export function getAppDisplayName(app: object, lang: string): string;
6
+ export function sortApplicationsList(apps: object[], slugsOrder: string[]): object[];