cozy-client 57.6.0 → 57.7.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.
@@ -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.0";
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
 
@@ -105,5 +107,27 @@ var getAppDisplayName = function getAppDisplayName(app, lang) {
105
107
  var translatedPrefix = (0, _get.default)(app, ['locales', lang, 'name_prefix'], basePrefix);
106
108
  return translatedPrefix && translatedPrefix.toLowerCase() !== 'cozy' ? "".concat(translatedPrefix, " ").concat(translatedName) : translatedName;
107
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
+ });
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', () => {
@@ -129,4 +134,88 @@ describe('applications model', () => {
129
134
  })
130
135
  })
131
136
  })
137
+
138
+ describe('sort applications list', () => {
139
+ it('should sort apps according to the given order', () => {
140
+ const availableApps = [
141
+ { slug: 'drive', name: 'Drive' },
142
+ { slug: 'chat', name: 'Chat' },
143
+ { slug: 'mail', name: 'Mail' },
144
+ { slug: 'contacts', name: 'Contacts' },
145
+ { slug: 'password', name: 'Password' }
146
+ ]
147
+ const order = ['chat', 'drive', 'mail', 'password', 'contacts']
148
+
149
+ const expected = [
150
+ { slug: 'chat', name: 'Chat' },
151
+ { slug: 'drive', name: 'Drive' },
152
+ { slug: 'mail', name: 'Mail' },
153
+ { slug: 'password', name: 'Password' },
154
+ { slug: 'contacts', name: 'Contacts' }
155
+ ]
156
+
157
+ const result = sortApplicationsList(availableApps, order)
158
+ expect(result).toEqual(expected)
159
+ })
160
+
161
+ it('should handle apps not in the order array', () => {
162
+ const availableApps = [
163
+ { slug: 'drive', name: 'Drive' },
164
+ { slug: 'chat', name: 'Chat' },
165
+ { slug: 'store', name: 'Store' },
166
+ { slug: 'mail', name: 'Mail' },
167
+ { slug: 'contacts', name: 'Contacts' },
168
+ { slug: 'password', name: 'Password' },
169
+ { slug: 'calendar', name: 'Calendar' }
170
+ ]
171
+ const order = ['chat', 'drive', 'mail', 'password', 'contacts']
172
+
173
+ const expected = [
174
+ { slug: 'chat', name: 'Chat' },
175
+ { slug: 'drive', name: 'Drive' },
176
+ { slug: 'mail', name: 'Mail' },
177
+ { slug: 'password', name: 'Password' },
178
+ { slug: 'contacts', name: 'Contacts' },
179
+ { slug: 'store', name: 'Store' },
180
+ { slug: 'calendar', name: 'Calendar' }
181
+ ]
182
+
183
+ const result = sortApplicationsList(availableApps, order)
184
+ expect(result).toEqual(expected)
185
+ })
186
+
187
+ it('should handle an empty apps array', () => {
188
+ const availableApps = []
189
+ const order = ['chat', 'drive', 'mail', 'password', 'notes', 'contacts']
190
+
191
+ const expected = []
192
+
193
+ const result = sortApplicationsList(availableApps, order)
194
+ expect(result).toEqual(expected)
195
+ })
196
+
197
+ it('should handle an empty order array', () => {
198
+ const availableApps = [
199
+ { slug: 'drive', name: 'Drive' },
200
+ { slug: 'chat', name: 'Chat' },
201
+ { slug: 'store', name: 'Store' },
202
+ { slug: 'mail', name: 'Mail' },
203
+ { slug: 'contacts', name: 'Contacts' },
204
+ { slug: 'password', name: 'Password' }
205
+ ]
206
+ const order = []
207
+
208
+ const expected = [
209
+ { slug: 'drive', name: 'Drive' },
210
+ { slug: 'chat', name: 'Chat' },
211
+ { slug: 'store', name: 'Store' },
212
+ { slug: 'mail', name: 'Mail' },
213
+ { slug: 'contacts', name: 'Contacts' },
214
+ { slug: 'password', name: 'Password' }
215
+ ]
216
+
217
+ const result = sortApplicationsList(availableApps, order)
218
+ expect(result).toEqual(expected)
219
+ })
220
+ })
132
221
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-client",
3
- "version": "57.6.0",
3
+ "version": "57.7.0",
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": "4e22dfcf7f2549b631c9777126da3ffad690ca93"
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[];