@bigbinary/neeto-fields-frontend 1.1.7 → 1.1.8

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/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import React, { useContext, useState, useRef, useEffect, useMemo, useLayoutEffect, useCallback, createContext, memo, useReducer } from 'react';
2
- import { Checkbox as Checkbox$1, TimePicker, DatePicker, Select, Input, Textarea, Typography, Pane, Label, Button as Button$1, Dropdown, NoData, Table, Spinner, Alert } from '@bigbinary/neetoui';
2
+ import { Checkbox as Checkbox$1, TimePicker, DatePicker, Select, Input, Textarea, Typography, Pane, Label, Button as Button$1, Dropdown, Alert, NoData, Table, Spinner } from '@bigbinary/neetoui';
3
3
  import { toLabelAndValue, isNotEmpty, capitalize as capitalize$1, filterBy, findBy, slugify, humanize, countBy, existsBy, noop as noop$2 } from '@bigbinary/neeto-commons-frontend/pure';
4
4
  import { values, map, isNotNil, isEmpty, isNil, pluck, clone as clone$1, pipe, mergeAll, omit, prop, pick, assoc, any, not, head } from 'ramda';
5
5
  import { useFormikContext, useField, FieldArray } from 'formik';
@@ -5250,7 +5250,7 @@ var titles = {
5250
5250
  field_other: "Fields",
5251
5251
  addField: "Add new field",
5252
5252
  editField: "Edit field",
5253
- deleteField: "Delete field ?",
5253
+ deleteField: "Delete field?",
5254
5254
  fieldName: "Field name",
5255
5255
  fieldKind: "Field type",
5256
5256
  required: "Required",
@@ -5307,7 +5307,8 @@ var fields = {
5307
5307
  };
5308
5308
  var messages = {
5309
5309
  noFields: "There are no {{title}} to show",
5310
- confirmDelete: "Are you sure want to delete the field? This action cannot be undone.",
5310
+ confirmDelete: "You are permanently deleting the field <strong>{{name}}</strong>. This action can't be undone.",
5311
+ confirmDeleteWithCount: "You are permanently deleting the field <strong>{{name}}</strong> which holds values for <strong>{{count}} {{resource}}</strong>. The values will be lost on deleting the field. This action can't be undone.",
5311
5312
  manageFieldFor: "Manage fields for {{resource}}",
5312
5313
  manageTitleForResource: "Manage {{title}} for {{resource}}",
5313
5314
  titleForResource: "{{title}} for {{resource}}",
@@ -6367,6 +6368,7 @@ var FIELDS_URL = "".concat(NEETO_FIELDS_URL, "/fields");
6367
6368
  var FIELD_VALUES_URL = "".concat(NEETO_FIELDS_URL, "/field_values");
6368
6369
  var FIELD_VALUE_URL = "".concat(NEETO_FIELDS_URL, "/field_values/:fieldValueId");
6369
6370
  var FIELD_URL = "".concat(NEETO_FIELDS_URL, "/fields/:fieldId");
6371
+ var DEPENDENCIES_URL = "".concat(NEETO_FIELDS_URL, "/fields/:fieldId/dependencies");
6370
6372
  var FIELDS_REORDER_URL = "".concat(FIELDS_URL, "/reorder");
6371
6373
  var CONFIGS_URL = "".concat(NEETO_FIELDS_URL, "/configs");
6372
6374
  var SINGULAR = {
@@ -6396,6 +6398,11 @@ var fieldUrl = function fieldUrl(fieldId) {
6396
6398
  fieldId: fieldId
6397
6399
  });
6398
6400
  };
6401
+ var dependenciesUrl = function dependenciesUrl(fieldId) {
6402
+ return buildUrl(DEPENDENCIES_URL, {
6403
+ fieldId: fieldId
6404
+ });
6405
+ };
6399
6406
  var fetch$1 = function fetch(_ref) {
6400
6407
  var resourceType = _ref.resourceType,
6401
6408
  ownerId = _ref.ownerId,
@@ -6439,25 +6446,37 @@ var update$1 = function update(_ref4) {
6439
6446
  var reorder = function reorder(payload) {
6440
6447
  return axios.patch(FIELDS_REORDER_URL, payload);
6441
6448
  };
6449
+ var dependencies = function dependencies(_ref5) {
6450
+ var fieldId = _ref5.fieldId,
6451
+ ownerId = _ref5.ownerId;
6452
+ return axios.get(dependenciesUrl(fieldId), {
6453
+ params: {
6454
+ ownerId: ownerId
6455
+ }
6456
+ });
6457
+ };
6442
6458
  var fieldsApi = {
6443
6459
  fetch: fetch$1,
6444
6460
  create: create$1,
6445
6461
  show: show,
6446
6462
  destroy: destroy$1,
6447
6463
  update: update$1,
6448
- reorder: reorder
6464
+ reorder: reorder,
6465
+ dependencies: dependencies
6449
6466
  };
6450
6467
 
6451
6468
  var QUERY_KEYS = {
6452
6469
  FIELDS: "fields",
6453
6470
  FIELD_VALUES: "field_values",
6454
- CONFIGS: "configurations"
6471
+ CONFIGS: "configurations",
6472
+ DEPENDENCIES: "dependencies"
6455
6473
  };
6456
6474
  var DEFAULT_STALE_TIME = 3600000; // 1 hour
6457
6475
 
6458
6476
  function ownKeys$8(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
6459
6477
  function _objectSpread$8(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$8(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$8(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6460
- var FIELDS = QUERY_KEYS.FIELDS;
6478
+ var FIELDS = QUERY_KEYS.FIELDS,
6479
+ DEPENDENCIES = QUERY_KEYS.DEPENDENCIES;
6461
6480
  var useFetchFields = function useFetchFields(_ref, options) {
6462
6481
  var resourceType = _ref.resourceType,
6463
6482
  ownerId = _ref.ownerId,
@@ -6500,6 +6519,16 @@ var useShowField = function useShowField(_ref2, options) {
6500
6519
  });
6501
6520
  }, options);
6502
6521
  };
6522
+ var useFetchDependencies = function useFetchDependencies(_ref3, options) {
6523
+ var fieldId = _ref3.fieldId,
6524
+ ownerId = _ref3.ownerId;
6525
+ return useQuery([DEPENDENCIES, fieldId], function () {
6526
+ return fieldsApi.dependencies({
6527
+ fieldId: fieldId,
6528
+ ownerId: ownerId
6529
+ });
6530
+ }, options);
6531
+ };
6503
6532
  var useUpdateField = function useUpdateField(options) {
6504
6533
  var queryClient = useQueryClient();
6505
6534
  return useMutation(fieldsApi.update, _objectSpread$8(_objectSpread$8({}, options), {}, {
@@ -7010,6 +7039,517 @@ var FieldsPane = function FieldsPane(_ref) {
7010
7039
  }, props)));
7011
7040
  };
7012
7041
 
7042
+ function commonjsRequire(path) {
7043
+ throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
7044
+ }
7045
+
7046
+ var pluralize$1 = {exports: {}};
7047
+
7048
+ /* global define */
7049
+ pluralize$1.exports;
7050
+
7051
+ (function (module, exports) {
7052
+ (function (root, pluralize) {
7053
+ /* istanbul ignore else */
7054
+ if (typeof commonjsRequire === 'function' && 'object' === 'object' && 'object' === 'object') {
7055
+ // Node.
7056
+ module.exports = pluralize();
7057
+ } else {
7058
+ // Browser global.
7059
+ root.pluralize = pluralize();
7060
+ }
7061
+ })(commonjsGlobal, function () {
7062
+ // Rule storage - pluralize and singularize need to be run sequentially,
7063
+ // while other rules can be optimized using an object for instant lookups.
7064
+ var pluralRules = [];
7065
+ var singularRules = [];
7066
+ var uncountables = {};
7067
+ var irregularPlurals = {};
7068
+ var irregularSingles = {};
7069
+
7070
+ /**
7071
+ * Sanitize a pluralization rule to a usable regular expression.
7072
+ *
7073
+ * @param {(RegExp|string)} rule
7074
+ * @return {RegExp}
7075
+ */
7076
+ function sanitizeRule (rule) {
7077
+ if (typeof rule === 'string') {
7078
+ return new RegExp('^' + rule + '$', 'i');
7079
+ }
7080
+
7081
+ return rule;
7082
+ }
7083
+
7084
+ /**
7085
+ * Pass in a word token to produce a function that can replicate the case on
7086
+ * another word.
7087
+ *
7088
+ * @param {string} word
7089
+ * @param {string} token
7090
+ * @return {Function}
7091
+ */
7092
+ function restoreCase (word, token) {
7093
+ // Tokens are an exact match.
7094
+ if (word === token) return token;
7095
+
7096
+ // Lower cased words. E.g. "hello".
7097
+ if (word === word.toLowerCase()) return token.toLowerCase();
7098
+
7099
+ // Upper cased words. E.g. "WHISKY".
7100
+ if (word === word.toUpperCase()) return token.toUpperCase();
7101
+
7102
+ // Title cased words. E.g. "Title".
7103
+ if (word[0] === word[0].toUpperCase()) {
7104
+ return token.charAt(0).toUpperCase() + token.substr(1).toLowerCase();
7105
+ }
7106
+
7107
+ // Lower cased words. E.g. "test".
7108
+ return token.toLowerCase();
7109
+ }
7110
+
7111
+ /**
7112
+ * Interpolate a regexp string.
7113
+ *
7114
+ * @param {string} str
7115
+ * @param {Array} args
7116
+ * @return {string}
7117
+ */
7118
+ function interpolate (str, args) {
7119
+ return str.replace(/\$(\d{1,2})/g, function (match, index) {
7120
+ return args[index] || '';
7121
+ });
7122
+ }
7123
+
7124
+ /**
7125
+ * Replace a word using a rule.
7126
+ *
7127
+ * @param {string} word
7128
+ * @param {Array} rule
7129
+ * @return {string}
7130
+ */
7131
+ function replace (word, rule) {
7132
+ return word.replace(rule[0], function (match, index) {
7133
+ var result = interpolate(rule[1], arguments);
7134
+
7135
+ if (match === '') {
7136
+ return restoreCase(word[index - 1], result);
7137
+ }
7138
+
7139
+ return restoreCase(match, result);
7140
+ });
7141
+ }
7142
+
7143
+ /**
7144
+ * Sanitize a word by passing in the word and sanitization rules.
7145
+ *
7146
+ * @param {string} token
7147
+ * @param {string} word
7148
+ * @param {Array} rules
7149
+ * @return {string}
7150
+ */
7151
+ function sanitizeWord (token, word, rules) {
7152
+ // Empty string or doesn't need fixing.
7153
+ if (!token.length || uncountables.hasOwnProperty(token)) {
7154
+ return word;
7155
+ }
7156
+
7157
+ var len = rules.length;
7158
+
7159
+ // Iterate over the sanitization rules and use the first one to match.
7160
+ while (len--) {
7161
+ var rule = rules[len];
7162
+
7163
+ if (rule[0].test(word)) return replace(word, rule);
7164
+ }
7165
+
7166
+ return word;
7167
+ }
7168
+
7169
+ /**
7170
+ * Replace a word with the updated word.
7171
+ *
7172
+ * @param {Object} replaceMap
7173
+ * @param {Object} keepMap
7174
+ * @param {Array} rules
7175
+ * @return {Function}
7176
+ */
7177
+ function replaceWord (replaceMap, keepMap, rules) {
7178
+ return function (word) {
7179
+ // Get the correct token and case restoration functions.
7180
+ var token = word.toLowerCase();
7181
+
7182
+ // Check against the keep object map.
7183
+ if (keepMap.hasOwnProperty(token)) {
7184
+ return restoreCase(word, token);
7185
+ }
7186
+
7187
+ // Check against the replacement map for a direct word replacement.
7188
+ if (replaceMap.hasOwnProperty(token)) {
7189
+ return restoreCase(word, replaceMap[token]);
7190
+ }
7191
+
7192
+ // Run all the rules against the word.
7193
+ return sanitizeWord(token, word, rules);
7194
+ };
7195
+ }
7196
+
7197
+ /**
7198
+ * Check if a word is part of the map.
7199
+ */
7200
+ function checkWord (replaceMap, keepMap, rules, bool) {
7201
+ return function (word) {
7202
+ var token = word.toLowerCase();
7203
+
7204
+ if (keepMap.hasOwnProperty(token)) return true;
7205
+ if (replaceMap.hasOwnProperty(token)) return false;
7206
+
7207
+ return sanitizeWord(token, token, rules) === token;
7208
+ };
7209
+ }
7210
+
7211
+ /**
7212
+ * Pluralize or singularize a word based on the passed in count.
7213
+ *
7214
+ * @param {string} word The word to pluralize
7215
+ * @param {number} count How many of the word exist
7216
+ * @param {boolean} inclusive Whether to prefix with the number (e.g. 3 ducks)
7217
+ * @return {string}
7218
+ */
7219
+ function pluralize (word, count, inclusive) {
7220
+ var pluralized = count === 1
7221
+ ? pluralize.singular(word) : pluralize.plural(word);
7222
+
7223
+ return (inclusive ? count + ' ' : '') + pluralized;
7224
+ }
7225
+
7226
+ /**
7227
+ * Pluralize a word.
7228
+ *
7229
+ * @type {Function}
7230
+ */
7231
+ pluralize.plural = replaceWord(
7232
+ irregularSingles, irregularPlurals, pluralRules
7233
+ );
7234
+
7235
+ /**
7236
+ * Check if a word is plural.
7237
+ *
7238
+ * @type {Function}
7239
+ */
7240
+ pluralize.isPlural = checkWord(
7241
+ irregularSingles, irregularPlurals, pluralRules
7242
+ );
7243
+
7244
+ /**
7245
+ * Singularize a word.
7246
+ *
7247
+ * @type {Function}
7248
+ */
7249
+ pluralize.singular = replaceWord(
7250
+ irregularPlurals, irregularSingles, singularRules
7251
+ );
7252
+
7253
+ /**
7254
+ * Check if a word is singular.
7255
+ *
7256
+ * @type {Function}
7257
+ */
7258
+ pluralize.isSingular = checkWord(
7259
+ irregularPlurals, irregularSingles, singularRules
7260
+ );
7261
+
7262
+ /**
7263
+ * Add a pluralization rule to the collection.
7264
+ *
7265
+ * @param {(string|RegExp)} rule
7266
+ * @param {string} replacement
7267
+ */
7268
+ pluralize.addPluralRule = function (rule, replacement) {
7269
+ pluralRules.push([sanitizeRule(rule), replacement]);
7270
+ };
7271
+
7272
+ /**
7273
+ * Add a singularization rule to the collection.
7274
+ *
7275
+ * @param {(string|RegExp)} rule
7276
+ * @param {string} replacement
7277
+ */
7278
+ pluralize.addSingularRule = function (rule, replacement) {
7279
+ singularRules.push([sanitizeRule(rule), replacement]);
7280
+ };
7281
+
7282
+ /**
7283
+ * Add an uncountable word rule.
7284
+ *
7285
+ * @param {(string|RegExp)} word
7286
+ */
7287
+ pluralize.addUncountableRule = function (word) {
7288
+ if (typeof word === 'string') {
7289
+ uncountables[word.toLowerCase()] = true;
7290
+ return;
7291
+ }
7292
+
7293
+ // Set singular and plural references for the word.
7294
+ pluralize.addPluralRule(word, '$0');
7295
+ pluralize.addSingularRule(word, '$0');
7296
+ };
7297
+
7298
+ /**
7299
+ * Add an irregular word definition.
7300
+ *
7301
+ * @param {string} single
7302
+ * @param {string} plural
7303
+ */
7304
+ pluralize.addIrregularRule = function (single, plural) {
7305
+ plural = plural.toLowerCase();
7306
+ single = single.toLowerCase();
7307
+
7308
+ irregularSingles[single] = plural;
7309
+ irregularPlurals[plural] = single;
7310
+ };
7311
+
7312
+ /**
7313
+ * Irregular rules.
7314
+ */
7315
+ [
7316
+ // Pronouns.
7317
+ ['I', 'we'],
7318
+ ['me', 'us'],
7319
+ ['he', 'they'],
7320
+ ['she', 'they'],
7321
+ ['them', 'them'],
7322
+ ['myself', 'ourselves'],
7323
+ ['yourself', 'yourselves'],
7324
+ ['itself', 'themselves'],
7325
+ ['herself', 'themselves'],
7326
+ ['himself', 'themselves'],
7327
+ ['themself', 'themselves'],
7328
+ ['is', 'are'],
7329
+ ['was', 'were'],
7330
+ ['has', 'have'],
7331
+ ['this', 'these'],
7332
+ ['that', 'those'],
7333
+ // Words ending in with a consonant and `o`.
7334
+ ['echo', 'echoes'],
7335
+ ['dingo', 'dingoes'],
7336
+ ['volcano', 'volcanoes'],
7337
+ ['tornado', 'tornadoes'],
7338
+ ['torpedo', 'torpedoes'],
7339
+ // Ends with `us`.
7340
+ ['genus', 'genera'],
7341
+ ['viscus', 'viscera'],
7342
+ // Ends with `ma`.
7343
+ ['stigma', 'stigmata'],
7344
+ ['stoma', 'stomata'],
7345
+ ['dogma', 'dogmata'],
7346
+ ['lemma', 'lemmata'],
7347
+ ['schema', 'schemata'],
7348
+ ['anathema', 'anathemata'],
7349
+ // Other irregular rules.
7350
+ ['ox', 'oxen'],
7351
+ ['axe', 'axes'],
7352
+ ['die', 'dice'],
7353
+ ['yes', 'yeses'],
7354
+ ['foot', 'feet'],
7355
+ ['eave', 'eaves'],
7356
+ ['goose', 'geese'],
7357
+ ['tooth', 'teeth'],
7358
+ ['quiz', 'quizzes'],
7359
+ ['human', 'humans'],
7360
+ ['proof', 'proofs'],
7361
+ ['carve', 'carves'],
7362
+ ['valve', 'valves'],
7363
+ ['looey', 'looies'],
7364
+ ['thief', 'thieves'],
7365
+ ['groove', 'grooves'],
7366
+ ['pickaxe', 'pickaxes'],
7367
+ ['passerby', 'passersby']
7368
+ ].forEach(function (rule) {
7369
+ return pluralize.addIrregularRule(rule[0], rule[1]);
7370
+ });
7371
+
7372
+ /**
7373
+ * Pluralization rules.
7374
+ */
7375
+ [
7376
+ [/s?$/i, 's'],
7377
+ [/[^\u0000-\u007F]$/i, '$0'],
7378
+ [/([^aeiou]ese)$/i, '$1'],
7379
+ [/(ax|test)is$/i, '$1es'],
7380
+ [/(alias|[^aou]us|t[lm]as|gas|ris)$/i, '$1es'],
7381
+ [/(e[mn]u)s?$/i, '$1s'],
7382
+ [/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i, '$1'],
7383
+ [/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, '$1i'],
7384
+ [/(alumn|alg|vertebr)(?:a|ae)$/i, '$1ae'],
7385
+ [/(seraph|cherub)(?:im)?$/i, '$1im'],
7386
+ [/(her|at|gr)o$/i, '$1oes'],
7387
+ [/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i, '$1a'],
7388
+ [/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i, '$1a'],
7389
+ [/sis$/i, 'ses'],
7390
+ [/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i, '$1$2ves'],
7391
+ [/([^aeiouy]|qu)y$/i, '$1ies'],
7392
+ [/([^ch][ieo][ln])ey$/i, '$1ies'],
7393
+ [/(x|ch|ss|sh|zz)$/i, '$1es'],
7394
+ [/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i, '$1ices'],
7395
+ [/\b((?:tit)?m|l)(?:ice|ouse)$/i, '$1ice'],
7396
+ [/(pe)(?:rson|ople)$/i, '$1ople'],
7397
+ [/(child)(?:ren)?$/i, '$1ren'],
7398
+ [/eaux$/i, '$0'],
7399
+ [/m[ae]n$/i, 'men'],
7400
+ ['thou', 'you']
7401
+ ].forEach(function (rule) {
7402
+ return pluralize.addPluralRule(rule[0], rule[1]);
7403
+ });
7404
+
7405
+ /**
7406
+ * Singularization rules.
7407
+ */
7408
+ [
7409
+ [/s$/i, ''],
7410
+ [/(ss)$/i, '$1'],
7411
+ [/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i, '$1fe'],
7412
+ [/(ar|(?:wo|[ae])l|[eo][ao])ves$/i, '$1f'],
7413
+ [/ies$/i, 'y'],
7414
+ [/\b([pl]|zomb|(?:neck|cross)?t|coll|faer|food|gen|goon|group|lass|talk|goal|cut)ies$/i, '$1ie'],
7415
+ [/\b(mon|smil)ies$/i, '$1ey'],
7416
+ [/\b((?:tit)?m|l)ice$/i, '$1ouse'],
7417
+ [/(seraph|cherub)im$/i, '$1'],
7418
+ [/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i, '$1'],
7419
+ [/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i, '$1sis'],
7420
+ [/(movie|twelve|abuse|e[mn]u)s$/i, '$1'],
7421
+ [/(test)(?:is|es)$/i, '$1is'],
7422
+ [/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, '$1us'],
7423
+ [/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i, '$1um'],
7424
+ [/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i, '$1on'],
7425
+ [/(alumn|alg|vertebr)ae$/i, '$1a'],
7426
+ [/(cod|mur|sil|vert|ind)ices$/i, '$1ex'],
7427
+ [/(matr|append)ices$/i, '$1ix'],
7428
+ [/(pe)(rson|ople)$/i, '$1rson'],
7429
+ [/(child)ren$/i, '$1'],
7430
+ [/(eau)x?$/i, '$1'],
7431
+ [/men$/i, 'man']
7432
+ ].forEach(function (rule) {
7433
+ return pluralize.addSingularRule(rule[0], rule[1]);
7434
+ });
7435
+
7436
+ /**
7437
+ * Uncountable rules.
7438
+ */
7439
+ [
7440
+ // Singular words with no plurals.
7441
+ 'adulthood',
7442
+ 'advice',
7443
+ 'agenda',
7444
+ 'aid',
7445
+ 'aircraft',
7446
+ 'alcohol',
7447
+ 'ammo',
7448
+ 'analytics',
7449
+ 'anime',
7450
+ 'athletics',
7451
+ 'audio',
7452
+ 'bison',
7453
+ 'blood',
7454
+ 'bream',
7455
+ 'buffalo',
7456
+ 'butter',
7457
+ 'carp',
7458
+ 'cash',
7459
+ 'chassis',
7460
+ 'chess',
7461
+ 'clothing',
7462
+ 'cod',
7463
+ 'commerce',
7464
+ 'cooperation',
7465
+ 'corps',
7466
+ 'debris',
7467
+ 'diabetes',
7468
+ 'digestion',
7469
+ 'elk',
7470
+ 'energy',
7471
+ 'equipment',
7472
+ 'excretion',
7473
+ 'expertise',
7474
+ 'firmware',
7475
+ 'flounder',
7476
+ 'fun',
7477
+ 'gallows',
7478
+ 'garbage',
7479
+ 'graffiti',
7480
+ 'hardware',
7481
+ 'headquarters',
7482
+ 'health',
7483
+ 'herpes',
7484
+ 'highjinks',
7485
+ 'homework',
7486
+ 'housework',
7487
+ 'information',
7488
+ 'jeans',
7489
+ 'justice',
7490
+ 'kudos',
7491
+ 'labour',
7492
+ 'literature',
7493
+ 'machinery',
7494
+ 'mackerel',
7495
+ 'mail',
7496
+ 'media',
7497
+ 'mews',
7498
+ 'moose',
7499
+ 'music',
7500
+ 'mud',
7501
+ 'manga',
7502
+ 'news',
7503
+ 'only',
7504
+ 'personnel',
7505
+ 'pike',
7506
+ 'plankton',
7507
+ 'pliers',
7508
+ 'police',
7509
+ 'pollution',
7510
+ 'premises',
7511
+ 'rain',
7512
+ 'research',
7513
+ 'rice',
7514
+ 'salmon',
7515
+ 'scissors',
7516
+ 'series',
7517
+ 'sewage',
7518
+ 'shambles',
7519
+ 'shrimp',
7520
+ 'software',
7521
+ 'species',
7522
+ 'staff',
7523
+ 'swine',
7524
+ 'tennis',
7525
+ 'traffic',
7526
+ 'transportation',
7527
+ 'trout',
7528
+ 'tuna',
7529
+ 'wealth',
7530
+ 'welfare',
7531
+ 'whiting',
7532
+ 'wildebeest',
7533
+ 'wildlife',
7534
+ 'you',
7535
+ /pok[eé]mon$/i,
7536
+ // Regexes.
7537
+ /[^aeiou]ese$/i, // "chinese", "japanese"
7538
+ /deer$/i, // "deer", "reindeer"
7539
+ /fish$/i, // "fish", "blowfish", "angelfish"
7540
+ /measles$/i,
7541
+ /o[iu]s$/i, // "carnivorous"
7542
+ /pox$/i, // "chickpox", "smallpox"
7543
+ /sheep$/i
7544
+ ].forEach(pluralize.addUncountableRule);
7545
+
7546
+ return pluralize;
7547
+ });
7548
+ } (pluralize$1, pluralize$1.exports));
7549
+
7550
+ var pluralizeExports = pluralize$1.exports;
7551
+ var pluralize = /*@__PURE__*/getDefaultExportFromCjs(pluralizeExports);
7552
+
7013
7553
  var Menu = Dropdown.Menu,
7014
7554
  MenuItem = Dropdown.MenuItem;
7015
7555
  var buildDefaultColumns = function buildDefaultColumns(_ref) {
@@ -7131,32 +7671,38 @@ var renderMenuBarFilters = function renderMenuBarFilters(_ref3) {
7131
7671
  })
7132
7672
  }));
7133
7673
  };
7134
- var getDashBoardTitle = function getDashBoardTitle(_ref4) {
7135
- var _findBy;
7674
+ var getResourceName = function getResourceName(_ref4) {
7136
7675
  var isOwnerBased = _ref4.isOwnerBased,
7137
7676
  owners = _ref4.owners,
7138
7677
  selectedVal = _ref4.selectedVal,
7139
- nameAliases = _ref4.nameAliases,
7140
- isSingleResource = _ref4.isSingleResource,
7141
- showStateFilter = _ref4.showStateFilter,
7142
- selectedState = _ref4.selectedState,
7143
- title = _ref4.title;
7144
- var resource = isOwnerBased ? (_findBy = findBy({
7145
- id: selectedVal
7146
- }, owners)) === null || _findBy === void 0 ? void 0 : _findBy.name : nameAliases[selectedVal] || selectedVal;
7678
+ nameAliases = _ref4.nameAliases;
7679
+ if (isOwnerBased) {
7680
+ var _findBy;
7681
+ return (_findBy = findBy({
7682
+ id: selectedVal
7683
+ }, owners)) === null || _findBy === void 0 ? void 0 : _findBy.name;
7684
+ }
7685
+ return nameAliases[selectedVal] || selectedVal;
7686
+ };
7687
+ var getDashBoardTitle = function getDashBoardTitle(_ref5) {
7688
+ var resourceName = _ref5.resourceName,
7689
+ isSingleResource = _ref5.isSingleResource,
7690
+ showStateFilter = _ref5.showStateFilter,
7691
+ selectedState = _ref5.selectedState,
7692
+ title = _ref5.title;
7147
7693
  var displayTitle = title;
7148
7694
  if (showStateFilter && !isSingleResource) {
7149
7695
  displayTitle = t$1("messages.stateTitleForResource", {
7150
7696
  state: selectedState,
7151
7697
  title: title,
7152
- resource: resource
7698
+ resource: resourceName
7153
7699
  });
7154
7700
  } else if (showStateFilter && isSingleResource) {
7155
7701
  displayTitle = "".concat(selectedState, " ").concat(title);
7156
7702
  } else if (!showStateFilter && !isSingleResource) {
7157
7703
  displayTitle = t$1("messages.titleForResource", {
7158
7704
  title: title,
7159
- resource: resource
7705
+ resource: resourceName
7160
7706
  });
7161
7707
  }
7162
7708
  return humanize(displayTitle);
@@ -7179,6 +7725,24 @@ var renderNoDataHelpText = function renderNoDataHelpText(title, url) {
7179
7725
  }
7180
7726
  });
7181
7727
  };
7728
+ var getDeletionConfirmationMessage = function getDeletionConfirmationMessage(_ref6) {
7729
+ var resource = _ref6.resource,
7730
+ fieldName = _ref6.fieldName,
7731
+ affectedResourcesCount = _ref6.affectedResourcesCount;
7732
+ return affectedResourcesCount > 0 ? /*#__PURE__*/React.createElement(Trans, {
7733
+ i18nKey: "messages.confirmDeleteWithCount",
7734
+ values: {
7735
+ resource: pluralize(resource, affectedResourcesCount),
7736
+ name: fieldName,
7737
+ count: affectedResourcesCount
7738
+ }
7739
+ }) : /*#__PURE__*/React.createElement(Trans, {
7740
+ i18nKey: "messages.confirmDelete",
7741
+ values: {
7742
+ name: fieldName
7743
+ }
7744
+ });
7745
+ };
7182
7746
 
7183
7747
  var fetchConfigs = function fetchConfigs() {
7184
7748
  return axios.get(CONFIGS_URL);
@@ -7353,18 +7917,23 @@ var useFieldsDashboard = function useFieldsDashboard(_ref) {
7353
7917
  };
7354
7918
  var isSingleResource = menuItems.length === 1;
7355
7919
  var isMenuBarNeeded = showStateFilter || !isSingleResource;
7356
- var headerDisplayTitle = useMemo(function () {
7357
- return getDashBoardTitle({
7920
+ var resourceName = useMemo(function () {
7921
+ return getResourceName({
7358
7922
  isOwnerBased: isOwnerBased,
7359
- owners: menuItems,
7360
- selectedVal: resource,
7361
7923
  nameAliases: nameAliases,
7924
+ owners: menuItems,
7925
+ selectedVal: resource
7926
+ });
7927
+ }, [menuItems, resource]);
7928
+ var headerDisplayTitle = useMemo(function () {
7929
+ return getDashBoardTitle({
7930
+ resourceName: resourceName,
7362
7931
  showStateFilter: showStateFilter,
7363
7932
  selectedState: state,
7364
7933
  isSingleResource: isSingleResource,
7365
7934
  title: title
7366
7935
  });
7367
- }, [resource, state, isSingleResource, menuItems]);
7936
+ }, [state, isSingleResource, resourceName]);
7368
7937
  var menuBarFilters = useMemo(function () {
7369
7938
  return renderMenuBarFilters({
7370
7939
  selectedState: state,
@@ -7402,6 +7971,7 @@ var useFieldsDashboard = function useFieldsDashboard(_ref) {
7402
7971
  selectedState: state,
7403
7972
  selectedMenu: resource,
7404
7973
  // resource will be ownerId if showOwnersInMenu is true, else it will be resourceType
7974
+ ownerId: ownerId,
7405
7975
  isFieldsFetching: isFieldsFetching,
7406
7976
  isFieldsLoading: isFieldsLoading,
7407
7977
  isDeleting: isDeleting,
@@ -7421,6 +7991,41 @@ var useFieldsDashboard = function useFieldsDashboard(_ref) {
7421
7991
  };
7422
7992
  };
7423
7993
 
7994
+ var DeleteAlert = function DeleteAlert(_ref) {
7995
+ var selectedField = _ref.selectedField,
7996
+ ownerId = _ref.ownerId,
7997
+ isDeleteAlertOpen = _ref.isDeleteAlertOpen,
7998
+ isDeleting = _ref.isDeleting,
7999
+ resourceTypeName = _ref.resourceTypeName,
8000
+ handleAlertClose = _ref.handleAlertClose,
8001
+ handleDelete = _ref.handleDelete;
8002
+ var _useTranslation = useTranslation(),
8003
+ t = _useTranslation.t;
8004
+ var _useFetchDependencies = useFetchDependencies({
8005
+ fieldId: selectedField.id,
8006
+ ownerId: ownerId
8007
+ }, {
8008
+ enabled: isDeleteAlertOpen && isNotEmpty(selectedField)
8009
+ }),
8010
+ _useFetchDependencies2 = _useFetchDependencies.data,
8011
+ _useFetchDependencies3 = _useFetchDependencies2 === void 0 ? {} : _useFetchDependencies2,
8012
+ affectedResourcesCount = _useFetchDependencies3.affectedResourcesCount;
8013
+ return /*#__PURE__*/React.createElement(Alert, {
8014
+ affectedResourcesCount: affectedResourcesCount,
8015
+ isOpen: isDeleteAlertOpen,
8016
+ isSubmitting: isDeleting,
8017
+ submitButtonLabel: t("labels.delete"),
8018
+ title: t("titles.deleteField"),
8019
+ message: getDeletionConfirmationMessage({
8020
+ resource: resourceTypeName,
8021
+ affectedResourcesCount: affectedResourcesCount,
8022
+ fieldName: selectedField === null || selectedField === void 0 ? void 0 : selectedField.name
8023
+ }),
8024
+ onClose: handleAlertClose,
8025
+ onSubmit: handleDelete
8026
+ });
8027
+ };
8028
+
7424
8029
  var FieldsTable = function FieldsTable(_ref) {
7425
8030
  var totalCount = _ref.totalCount,
7426
8031
  isLoading = _ref.isLoading,
@@ -11870,6 +12475,7 @@ var FieldsDashboard = function FieldsDashboard(_ref) {
11870
12475
  selectedField = _useFieldsDashboard.selectedField,
11871
12476
  selectedState = _useFieldsDashboard.selectedState,
11872
12477
  selectedMenu = _useFieldsDashboard.selectedMenu,
12478
+ ownerId = _useFieldsDashboard.ownerId,
11873
12479
  isFieldsFetching = _useFieldsDashboard.isFieldsFetching,
11874
12480
  isFieldsLoading = _useFieldsDashboard.isFieldsLoading,
11875
12481
  isDeleting = _useFieldsDashboard.isDeleting,
@@ -11954,13 +12560,14 @@ var FieldsDashboard = function FieldsDashboard(_ref) {
11954
12560
  ownerId: isOwnerBased ? selectedMenu : "",
11955
12561
  onClose: handleReorderPaneClose,
11956
12562
  allFields: allFields
11957
- }), /*#__PURE__*/React.createElement(Alert, {
11958
- isOpen: isDeleteAlertOpen,
11959
- isSubmitting: isDeleting,
11960
- message: t("messages.confirmDelete"),
11961
- title: t("titles.deleteField"),
11962
- onClose: handleAlertClose,
11963
- onSubmit: handleDelete
12563
+ }), /*#__PURE__*/React.createElement(DeleteAlert, {
12564
+ handleAlertClose: handleAlertClose,
12565
+ handleDelete: handleDelete,
12566
+ isDeleteAlertOpen: isDeleteAlertOpen,
12567
+ isDeleting: isDeleting,
12568
+ ownerId: ownerId,
12569
+ selectedField: selectedField,
12570
+ resourceTypeName: isOwnerBased ? resourceType : selectedMenu
11964
12571
  }));
11965
12572
  };
11966
12573