@bigbinary/neeto-fields-frontend 1.1.7 → 1.1.9

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), {}, {
@@ -6605,7 +6634,22 @@ var renderFormFooter = function renderFormFooter(_ref3) {
6605
6634
  };
6606
6635
 
6607
6636
  var regexValidationSchema = yup.object().shape({
6608
- condition: yup.string().required(t$1("validations.regexConditionIsRequired")).matches(/^\/.*\/[igmsyu]*$/, t$1("validations.invalidRegexPattern")),
6637
+ condition: yup.string().required(t$1("validations.regexConditionIsRequired")).matches(/^\/.*\/[igmsyu]*$/, t$1("validations.invalidRegexPattern")).test({
6638
+ name: "regex",
6639
+ message: t$1("validations.invalidRegexPattern") || "",
6640
+ test: function test(value) {
6641
+ try {
6642
+ var lastIndex = value.lastIndexOf("/");
6643
+ var condition = value.substring(1, lastIndex);
6644
+ // Evaluating the regex to check if it is valid
6645
+ new RegExp(condition);
6646
+ "".search(condition);
6647
+ return true;
6648
+ } catch (_unused) {
6649
+ return false;
6650
+ }
6651
+ }
6652
+ }),
6609
6653
  helpMessage: yup.string().required(t$1("validations.regexHelpMessageIsRequired"))
6610
6654
  });
6611
6655
  var dropDownOptionsValidationSchema = yup.array().of(yup.object().shape({
@@ -7010,6 +7054,517 @@ var FieldsPane = function FieldsPane(_ref) {
7010
7054
  }, props)));
7011
7055
  };
7012
7056
 
7057
+ function commonjsRequire(path) {
7058
+ 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.');
7059
+ }
7060
+
7061
+ var pluralize$1 = {exports: {}};
7062
+
7063
+ /* global define */
7064
+ pluralize$1.exports;
7065
+
7066
+ (function (module, exports) {
7067
+ (function (root, pluralize) {
7068
+ /* istanbul ignore else */
7069
+ if (typeof commonjsRequire === 'function' && 'object' === 'object' && 'object' === 'object') {
7070
+ // Node.
7071
+ module.exports = pluralize();
7072
+ } else {
7073
+ // Browser global.
7074
+ root.pluralize = pluralize();
7075
+ }
7076
+ })(commonjsGlobal, function () {
7077
+ // Rule storage - pluralize and singularize need to be run sequentially,
7078
+ // while other rules can be optimized using an object for instant lookups.
7079
+ var pluralRules = [];
7080
+ var singularRules = [];
7081
+ var uncountables = {};
7082
+ var irregularPlurals = {};
7083
+ var irregularSingles = {};
7084
+
7085
+ /**
7086
+ * Sanitize a pluralization rule to a usable regular expression.
7087
+ *
7088
+ * @param {(RegExp|string)} rule
7089
+ * @return {RegExp}
7090
+ */
7091
+ function sanitizeRule (rule) {
7092
+ if (typeof rule === 'string') {
7093
+ return new RegExp('^' + rule + '$', 'i');
7094
+ }
7095
+
7096
+ return rule;
7097
+ }
7098
+
7099
+ /**
7100
+ * Pass in a word token to produce a function that can replicate the case on
7101
+ * another word.
7102
+ *
7103
+ * @param {string} word
7104
+ * @param {string} token
7105
+ * @return {Function}
7106
+ */
7107
+ function restoreCase (word, token) {
7108
+ // Tokens are an exact match.
7109
+ if (word === token) return token;
7110
+
7111
+ // Lower cased words. E.g. "hello".
7112
+ if (word === word.toLowerCase()) return token.toLowerCase();
7113
+
7114
+ // Upper cased words. E.g. "WHISKY".
7115
+ if (word === word.toUpperCase()) return token.toUpperCase();
7116
+
7117
+ // Title cased words. E.g. "Title".
7118
+ if (word[0] === word[0].toUpperCase()) {
7119
+ return token.charAt(0).toUpperCase() + token.substr(1).toLowerCase();
7120
+ }
7121
+
7122
+ // Lower cased words. E.g. "test".
7123
+ return token.toLowerCase();
7124
+ }
7125
+
7126
+ /**
7127
+ * Interpolate a regexp string.
7128
+ *
7129
+ * @param {string} str
7130
+ * @param {Array} args
7131
+ * @return {string}
7132
+ */
7133
+ function interpolate (str, args) {
7134
+ return str.replace(/\$(\d{1,2})/g, function (match, index) {
7135
+ return args[index] || '';
7136
+ });
7137
+ }
7138
+
7139
+ /**
7140
+ * Replace a word using a rule.
7141
+ *
7142
+ * @param {string} word
7143
+ * @param {Array} rule
7144
+ * @return {string}
7145
+ */
7146
+ function replace (word, rule) {
7147
+ return word.replace(rule[0], function (match, index) {
7148
+ var result = interpolate(rule[1], arguments);
7149
+
7150
+ if (match === '') {
7151
+ return restoreCase(word[index - 1], result);
7152
+ }
7153
+
7154
+ return restoreCase(match, result);
7155
+ });
7156
+ }
7157
+
7158
+ /**
7159
+ * Sanitize a word by passing in the word and sanitization rules.
7160
+ *
7161
+ * @param {string} token
7162
+ * @param {string} word
7163
+ * @param {Array} rules
7164
+ * @return {string}
7165
+ */
7166
+ function sanitizeWord (token, word, rules) {
7167
+ // Empty string or doesn't need fixing.
7168
+ if (!token.length || uncountables.hasOwnProperty(token)) {
7169
+ return word;
7170
+ }
7171
+
7172
+ var len = rules.length;
7173
+
7174
+ // Iterate over the sanitization rules and use the first one to match.
7175
+ while (len--) {
7176
+ var rule = rules[len];
7177
+
7178
+ if (rule[0].test(word)) return replace(word, rule);
7179
+ }
7180
+
7181
+ return word;
7182
+ }
7183
+
7184
+ /**
7185
+ * Replace a word with the updated word.
7186
+ *
7187
+ * @param {Object} replaceMap
7188
+ * @param {Object} keepMap
7189
+ * @param {Array} rules
7190
+ * @return {Function}
7191
+ */
7192
+ function replaceWord (replaceMap, keepMap, rules) {
7193
+ return function (word) {
7194
+ // Get the correct token and case restoration functions.
7195
+ var token = word.toLowerCase();
7196
+
7197
+ // Check against the keep object map.
7198
+ if (keepMap.hasOwnProperty(token)) {
7199
+ return restoreCase(word, token);
7200
+ }
7201
+
7202
+ // Check against the replacement map for a direct word replacement.
7203
+ if (replaceMap.hasOwnProperty(token)) {
7204
+ return restoreCase(word, replaceMap[token]);
7205
+ }
7206
+
7207
+ // Run all the rules against the word.
7208
+ return sanitizeWord(token, word, rules);
7209
+ };
7210
+ }
7211
+
7212
+ /**
7213
+ * Check if a word is part of the map.
7214
+ */
7215
+ function checkWord (replaceMap, keepMap, rules, bool) {
7216
+ return function (word) {
7217
+ var token = word.toLowerCase();
7218
+
7219
+ if (keepMap.hasOwnProperty(token)) return true;
7220
+ if (replaceMap.hasOwnProperty(token)) return false;
7221
+
7222
+ return sanitizeWord(token, token, rules) === token;
7223
+ };
7224
+ }
7225
+
7226
+ /**
7227
+ * Pluralize or singularize a word based on the passed in count.
7228
+ *
7229
+ * @param {string} word The word to pluralize
7230
+ * @param {number} count How many of the word exist
7231
+ * @param {boolean} inclusive Whether to prefix with the number (e.g. 3 ducks)
7232
+ * @return {string}
7233
+ */
7234
+ function pluralize (word, count, inclusive) {
7235
+ var pluralized = count === 1
7236
+ ? pluralize.singular(word) : pluralize.plural(word);
7237
+
7238
+ return (inclusive ? count + ' ' : '') + pluralized;
7239
+ }
7240
+
7241
+ /**
7242
+ * Pluralize a word.
7243
+ *
7244
+ * @type {Function}
7245
+ */
7246
+ pluralize.plural = replaceWord(
7247
+ irregularSingles, irregularPlurals, pluralRules
7248
+ );
7249
+
7250
+ /**
7251
+ * Check if a word is plural.
7252
+ *
7253
+ * @type {Function}
7254
+ */
7255
+ pluralize.isPlural = checkWord(
7256
+ irregularSingles, irregularPlurals, pluralRules
7257
+ );
7258
+
7259
+ /**
7260
+ * Singularize a word.
7261
+ *
7262
+ * @type {Function}
7263
+ */
7264
+ pluralize.singular = replaceWord(
7265
+ irregularPlurals, irregularSingles, singularRules
7266
+ );
7267
+
7268
+ /**
7269
+ * Check if a word is singular.
7270
+ *
7271
+ * @type {Function}
7272
+ */
7273
+ pluralize.isSingular = checkWord(
7274
+ irregularPlurals, irregularSingles, singularRules
7275
+ );
7276
+
7277
+ /**
7278
+ * Add a pluralization rule to the collection.
7279
+ *
7280
+ * @param {(string|RegExp)} rule
7281
+ * @param {string} replacement
7282
+ */
7283
+ pluralize.addPluralRule = function (rule, replacement) {
7284
+ pluralRules.push([sanitizeRule(rule), replacement]);
7285
+ };
7286
+
7287
+ /**
7288
+ * Add a singularization rule to the collection.
7289
+ *
7290
+ * @param {(string|RegExp)} rule
7291
+ * @param {string} replacement
7292
+ */
7293
+ pluralize.addSingularRule = function (rule, replacement) {
7294
+ singularRules.push([sanitizeRule(rule), replacement]);
7295
+ };
7296
+
7297
+ /**
7298
+ * Add an uncountable word rule.
7299
+ *
7300
+ * @param {(string|RegExp)} word
7301
+ */
7302
+ pluralize.addUncountableRule = function (word) {
7303
+ if (typeof word === 'string') {
7304
+ uncountables[word.toLowerCase()] = true;
7305
+ return;
7306
+ }
7307
+
7308
+ // Set singular and plural references for the word.
7309
+ pluralize.addPluralRule(word, '$0');
7310
+ pluralize.addSingularRule(word, '$0');
7311
+ };
7312
+
7313
+ /**
7314
+ * Add an irregular word definition.
7315
+ *
7316
+ * @param {string} single
7317
+ * @param {string} plural
7318
+ */
7319
+ pluralize.addIrregularRule = function (single, plural) {
7320
+ plural = plural.toLowerCase();
7321
+ single = single.toLowerCase();
7322
+
7323
+ irregularSingles[single] = plural;
7324
+ irregularPlurals[plural] = single;
7325
+ };
7326
+
7327
+ /**
7328
+ * Irregular rules.
7329
+ */
7330
+ [
7331
+ // Pronouns.
7332
+ ['I', 'we'],
7333
+ ['me', 'us'],
7334
+ ['he', 'they'],
7335
+ ['she', 'they'],
7336
+ ['them', 'them'],
7337
+ ['myself', 'ourselves'],
7338
+ ['yourself', 'yourselves'],
7339
+ ['itself', 'themselves'],
7340
+ ['herself', 'themselves'],
7341
+ ['himself', 'themselves'],
7342
+ ['themself', 'themselves'],
7343
+ ['is', 'are'],
7344
+ ['was', 'were'],
7345
+ ['has', 'have'],
7346
+ ['this', 'these'],
7347
+ ['that', 'those'],
7348
+ // Words ending in with a consonant and `o`.
7349
+ ['echo', 'echoes'],
7350
+ ['dingo', 'dingoes'],
7351
+ ['volcano', 'volcanoes'],
7352
+ ['tornado', 'tornadoes'],
7353
+ ['torpedo', 'torpedoes'],
7354
+ // Ends with `us`.
7355
+ ['genus', 'genera'],
7356
+ ['viscus', 'viscera'],
7357
+ // Ends with `ma`.
7358
+ ['stigma', 'stigmata'],
7359
+ ['stoma', 'stomata'],
7360
+ ['dogma', 'dogmata'],
7361
+ ['lemma', 'lemmata'],
7362
+ ['schema', 'schemata'],
7363
+ ['anathema', 'anathemata'],
7364
+ // Other irregular rules.
7365
+ ['ox', 'oxen'],
7366
+ ['axe', 'axes'],
7367
+ ['die', 'dice'],
7368
+ ['yes', 'yeses'],
7369
+ ['foot', 'feet'],
7370
+ ['eave', 'eaves'],
7371
+ ['goose', 'geese'],
7372
+ ['tooth', 'teeth'],
7373
+ ['quiz', 'quizzes'],
7374
+ ['human', 'humans'],
7375
+ ['proof', 'proofs'],
7376
+ ['carve', 'carves'],
7377
+ ['valve', 'valves'],
7378
+ ['looey', 'looies'],
7379
+ ['thief', 'thieves'],
7380
+ ['groove', 'grooves'],
7381
+ ['pickaxe', 'pickaxes'],
7382
+ ['passerby', 'passersby']
7383
+ ].forEach(function (rule) {
7384
+ return pluralize.addIrregularRule(rule[0], rule[1]);
7385
+ });
7386
+
7387
+ /**
7388
+ * Pluralization rules.
7389
+ */
7390
+ [
7391
+ [/s?$/i, 's'],
7392
+ [/[^\u0000-\u007F]$/i, '$0'],
7393
+ [/([^aeiou]ese)$/i, '$1'],
7394
+ [/(ax|test)is$/i, '$1es'],
7395
+ [/(alias|[^aou]us|t[lm]as|gas|ris)$/i, '$1es'],
7396
+ [/(e[mn]u)s?$/i, '$1s'],
7397
+ [/([^l]ias|[aeiou]las|[ejzr]as|[iu]am)$/i, '$1'],
7398
+ [/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, '$1i'],
7399
+ [/(alumn|alg|vertebr)(?:a|ae)$/i, '$1ae'],
7400
+ [/(seraph|cherub)(?:im)?$/i, '$1im'],
7401
+ [/(her|at|gr)o$/i, '$1oes'],
7402
+ [/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|automat|quor)(?:a|um)$/i, '$1a'],
7403
+ [/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)(?:a|on)$/i, '$1a'],
7404
+ [/sis$/i, 'ses'],
7405
+ [/(?:(kni|wi|li)fe|(ar|l|ea|eo|oa|hoo)f)$/i, '$1$2ves'],
7406
+ [/([^aeiouy]|qu)y$/i, '$1ies'],
7407
+ [/([^ch][ieo][ln])ey$/i, '$1ies'],
7408
+ [/(x|ch|ss|sh|zz)$/i, '$1es'],
7409
+ [/(matr|cod|mur|sil|vert|ind|append)(?:ix|ex)$/i, '$1ices'],
7410
+ [/\b((?:tit)?m|l)(?:ice|ouse)$/i, '$1ice'],
7411
+ [/(pe)(?:rson|ople)$/i, '$1ople'],
7412
+ [/(child)(?:ren)?$/i, '$1ren'],
7413
+ [/eaux$/i, '$0'],
7414
+ [/m[ae]n$/i, 'men'],
7415
+ ['thou', 'you']
7416
+ ].forEach(function (rule) {
7417
+ return pluralize.addPluralRule(rule[0], rule[1]);
7418
+ });
7419
+
7420
+ /**
7421
+ * Singularization rules.
7422
+ */
7423
+ [
7424
+ [/s$/i, ''],
7425
+ [/(ss)$/i, '$1'],
7426
+ [/(wi|kni|(?:after|half|high|low|mid|non|night|[^\w]|^)li)ves$/i, '$1fe'],
7427
+ [/(ar|(?:wo|[ae])l|[eo][ao])ves$/i, '$1f'],
7428
+ [/ies$/i, 'y'],
7429
+ [/\b([pl]|zomb|(?:neck|cross)?t|coll|faer|food|gen|goon|group|lass|talk|goal|cut)ies$/i, '$1ie'],
7430
+ [/\b(mon|smil)ies$/i, '$1ey'],
7431
+ [/\b((?:tit)?m|l)ice$/i, '$1ouse'],
7432
+ [/(seraph|cherub)im$/i, '$1'],
7433
+ [/(x|ch|ss|sh|zz|tto|go|cho|alias|[^aou]us|t[lm]as|gas|(?:her|at|gr)o|[aeiou]ris)(?:es)?$/i, '$1'],
7434
+ [/(analy|diagno|parenthe|progno|synop|the|empha|cri|ne)(?:sis|ses)$/i, '$1sis'],
7435
+ [/(movie|twelve|abuse|e[mn]u)s$/i, '$1'],
7436
+ [/(test)(?:is|es)$/i, '$1is'],
7437
+ [/(alumn|syllab|vir|radi|nucle|fung|cact|stimul|termin|bacill|foc|uter|loc|strat)(?:us|i)$/i, '$1us'],
7438
+ [/(agend|addend|millenni|dat|extrem|bacteri|desiderat|strat|candelabr|errat|ov|symposi|curricul|quor)a$/i, '$1um'],
7439
+ [/(apheli|hyperbat|periheli|asyndet|noumen|phenomen|criteri|organ|prolegomen|hedr|automat)a$/i, '$1on'],
7440
+ [/(alumn|alg|vertebr)ae$/i, '$1a'],
7441
+ [/(cod|mur|sil|vert|ind)ices$/i, '$1ex'],
7442
+ [/(matr|append)ices$/i, '$1ix'],
7443
+ [/(pe)(rson|ople)$/i, '$1rson'],
7444
+ [/(child)ren$/i, '$1'],
7445
+ [/(eau)x?$/i, '$1'],
7446
+ [/men$/i, 'man']
7447
+ ].forEach(function (rule) {
7448
+ return pluralize.addSingularRule(rule[0], rule[1]);
7449
+ });
7450
+
7451
+ /**
7452
+ * Uncountable rules.
7453
+ */
7454
+ [
7455
+ // Singular words with no plurals.
7456
+ 'adulthood',
7457
+ 'advice',
7458
+ 'agenda',
7459
+ 'aid',
7460
+ 'aircraft',
7461
+ 'alcohol',
7462
+ 'ammo',
7463
+ 'analytics',
7464
+ 'anime',
7465
+ 'athletics',
7466
+ 'audio',
7467
+ 'bison',
7468
+ 'blood',
7469
+ 'bream',
7470
+ 'buffalo',
7471
+ 'butter',
7472
+ 'carp',
7473
+ 'cash',
7474
+ 'chassis',
7475
+ 'chess',
7476
+ 'clothing',
7477
+ 'cod',
7478
+ 'commerce',
7479
+ 'cooperation',
7480
+ 'corps',
7481
+ 'debris',
7482
+ 'diabetes',
7483
+ 'digestion',
7484
+ 'elk',
7485
+ 'energy',
7486
+ 'equipment',
7487
+ 'excretion',
7488
+ 'expertise',
7489
+ 'firmware',
7490
+ 'flounder',
7491
+ 'fun',
7492
+ 'gallows',
7493
+ 'garbage',
7494
+ 'graffiti',
7495
+ 'hardware',
7496
+ 'headquarters',
7497
+ 'health',
7498
+ 'herpes',
7499
+ 'highjinks',
7500
+ 'homework',
7501
+ 'housework',
7502
+ 'information',
7503
+ 'jeans',
7504
+ 'justice',
7505
+ 'kudos',
7506
+ 'labour',
7507
+ 'literature',
7508
+ 'machinery',
7509
+ 'mackerel',
7510
+ 'mail',
7511
+ 'media',
7512
+ 'mews',
7513
+ 'moose',
7514
+ 'music',
7515
+ 'mud',
7516
+ 'manga',
7517
+ 'news',
7518
+ 'only',
7519
+ 'personnel',
7520
+ 'pike',
7521
+ 'plankton',
7522
+ 'pliers',
7523
+ 'police',
7524
+ 'pollution',
7525
+ 'premises',
7526
+ 'rain',
7527
+ 'research',
7528
+ 'rice',
7529
+ 'salmon',
7530
+ 'scissors',
7531
+ 'series',
7532
+ 'sewage',
7533
+ 'shambles',
7534
+ 'shrimp',
7535
+ 'software',
7536
+ 'species',
7537
+ 'staff',
7538
+ 'swine',
7539
+ 'tennis',
7540
+ 'traffic',
7541
+ 'transportation',
7542
+ 'trout',
7543
+ 'tuna',
7544
+ 'wealth',
7545
+ 'welfare',
7546
+ 'whiting',
7547
+ 'wildebeest',
7548
+ 'wildlife',
7549
+ 'you',
7550
+ /pok[eé]mon$/i,
7551
+ // Regexes.
7552
+ /[^aeiou]ese$/i, // "chinese", "japanese"
7553
+ /deer$/i, // "deer", "reindeer"
7554
+ /fish$/i, // "fish", "blowfish", "angelfish"
7555
+ /measles$/i,
7556
+ /o[iu]s$/i, // "carnivorous"
7557
+ /pox$/i, // "chickpox", "smallpox"
7558
+ /sheep$/i
7559
+ ].forEach(pluralize.addUncountableRule);
7560
+
7561
+ return pluralize;
7562
+ });
7563
+ } (pluralize$1, pluralize$1.exports));
7564
+
7565
+ var pluralizeExports = pluralize$1.exports;
7566
+ var pluralize = /*@__PURE__*/getDefaultExportFromCjs(pluralizeExports);
7567
+
7013
7568
  var Menu = Dropdown.Menu,
7014
7569
  MenuItem = Dropdown.MenuItem;
7015
7570
  var buildDefaultColumns = function buildDefaultColumns(_ref) {
@@ -7131,32 +7686,38 @@ var renderMenuBarFilters = function renderMenuBarFilters(_ref3) {
7131
7686
  })
7132
7687
  }));
7133
7688
  };
7134
- var getDashBoardTitle = function getDashBoardTitle(_ref4) {
7135
- var _findBy;
7689
+ var getResourceName = function getResourceName(_ref4) {
7136
7690
  var isOwnerBased = _ref4.isOwnerBased,
7137
7691
  owners = _ref4.owners,
7138
7692
  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;
7693
+ nameAliases = _ref4.nameAliases;
7694
+ if (isOwnerBased) {
7695
+ var _findBy;
7696
+ return (_findBy = findBy({
7697
+ id: selectedVal
7698
+ }, owners)) === null || _findBy === void 0 ? void 0 : _findBy.name;
7699
+ }
7700
+ return nameAliases[selectedVal] || selectedVal;
7701
+ };
7702
+ var getDashBoardTitle = function getDashBoardTitle(_ref5) {
7703
+ var resourceName = _ref5.resourceName,
7704
+ isSingleResource = _ref5.isSingleResource,
7705
+ showStateFilter = _ref5.showStateFilter,
7706
+ selectedState = _ref5.selectedState,
7707
+ title = _ref5.title;
7147
7708
  var displayTitle = title;
7148
7709
  if (showStateFilter && !isSingleResource) {
7149
7710
  displayTitle = t$1("messages.stateTitleForResource", {
7150
7711
  state: selectedState,
7151
7712
  title: title,
7152
- resource: resource
7713
+ resource: resourceName
7153
7714
  });
7154
7715
  } else if (showStateFilter && isSingleResource) {
7155
7716
  displayTitle = "".concat(selectedState, " ").concat(title);
7156
7717
  } else if (!showStateFilter && !isSingleResource) {
7157
7718
  displayTitle = t$1("messages.titleForResource", {
7158
7719
  title: title,
7159
- resource: resource
7720
+ resource: resourceName
7160
7721
  });
7161
7722
  }
7162
7723
  return humanize(displayTitle);
@@ -7179,6 +7740,24 @@ var renderNoDataHelpText = function renderNoDataHelpText(title, url) {
7179
7740
  }
7180
7741
  });
7181
7742
  };
7743
+ var getDeletionConfirmationMessage = function getDeletionConfirmationMessage(_ref6) {
7744
+ var resource = _ref6.resource,
7745
+ fieldName = _ref6.fieldName,
7746
+ affectedResourcesCount = _ref6.affectedResourcesCount;
7747
+ return affectedResourcesCount > 0 ? /*#__PURE__*/React.createElement(Trans, {
7748
+ i18nKey: "messages.confirmDeleteWithCount",
7749
+ values: {
7750
+ resource: pluralize(resource, affectedResourcesCount),
7751
+ name: fieldName,
7752
+ count: affectedResourcesCount
7753
+ }
7754
+ }) : /*#__PURE__*/React.createElement(Trans, {
7755
+ i18nKey: "messages.confirmDelete",
7756
+ values: {
7757
+ name: fieldName
7758
+ }
7759
+ });
7760
+ };
7182
7761
 
7183
7762
  var fetchConfigs = function fetchConfigs() {
7184
7763
  return axios.get(CONFIGS_URL);
@@ -7353,18 +7932,23 @@ var useFieldsDashboard = function useFieldsDashboard(_ref) {
7353
7932
  };
7354
7933
  var isSingleResource = menuItems.length === 1;
7355
7934
  var isMenuBarNeeded = showStateFilter || !isSingleResource;
7356
- var headerDisplayTitle = useMemo(function () {
7357
- return getDashBoardTitle({
7935
+ var resourceName = useMemo(function () {
7936
+ return getResourceName({
7358
7937
  isOwnerBased: isOwnerBased,
7359
- owners: menuItems,
7360
- selectedVal: resource,
7361
7938
  nameAliases: nameAliases,
7939
+ owners: menuItems,
7940
+ selectedVal: resource
7941
+ });
7942
+ }, [menuItems, resource]);
7943
+ var headerDisplayTitle = useMemo(function () {
7944
+ return getDashBoardTitle({
7945
+ resourceName: resourceName,
7362
7946
  showStateFilter: showStateFilter,
7363
7947
  selectedState: state,
7364
7948
  isSingleResource: isSingleResource,
7365
7949
  title: title
7366
7950
  });
7367
- }, [resource, state, isSingleResource, menuItems]);
7951
+ }, [state, isSingleResource, resourceName]);
7368
7952
  var menuBarFilters = useMemo(function () {
7369
7953
  return renderMenuBarFilters({
7370
7954
  selectedState: state,
@@ -7402,6 +7986,7 @@ var useFieldsDashboard = function useFieldsDashboard(_ref) {
7402
7986
  selectedState: state,
7403
7987
  selectedMenu: resource,
7404
7988
  // resource will be ownerId if showOwnersInMenu is true, else it will be resourceType
7989
+ ownerId: ownerId,
7405
7990
  isFieldsFetching: isFieldsFetching,
7406
7991
  isFieldsLoading: isFieldsLoading,
7407
7992
  isDeleting: isDeleting,
@@ -7421,6 +8006,41 @@ var useFieldsDashboard = function useFieldsDashboard(_ref) {
7421
8006
  };
7422
8007
  };
7423
8008
 
8009
+ var DeleteAlert = function DeleteAlert(_ref) {
8010
+ var selectedField = _ref.selectedField,
8011
+ ownerId = _ref.ownerId,
8012
+ isDeleteAlertOpen = _ref.isDeleteAlertOpen,
8013
+ isDeleting = _ref.isDeleting,
8014
+ resourceTypeName = _ref.resourceTypeName,
8015
+ handleAlertClose = _ref.handleAlertClose,
8016
+ handleDelete = _ref.handleDelete;
8017
+ var _useTranslation = useTranslation(),
8018
+ t = _useTranslation.t;
8019
+ var _useFetchDependencies = useFetchDependencies({
8020
+ fieldId: selectedField.id,
8021
+ ownerId: ownerId
8022
+ }, {
8023
+ enabled: isDeleteAlertOpen && isNotEmpty(selectedField)
8024
+ }),
8025
+ _useFetchDependencies2 = _useFetchDependencies.data,
8026
+ _useFetchDependencies3 = _useFetchDependencies2 === void 0 ? {} : _useFetchDependencies2,
8027
+ affectedResourcesCount = _useFetchDependencies3.affectedResourcesCount;
8028
+ return /*#__PURE__*/React.createElement(Alert, {
8029
+ affectedResourcesCount: affectedResourcesCount,
8030
+ isOpen: isDeleteAlertOpen,
8031
+ isSubmitting: isDeleting,
8032
+ submitButtonLabel: t("labels.delete"),
8033
+ title: t("titles.deleteField"),
8034
+ message: getDeletionConfirmationMessage({
8035
+ resource: resourceTypeName,
8036
+ affectedResourcesCount: affectedResourcesCount,
8037
+ fieldName: selectedField === null || selectedField === void 0 ? void 0 : selectedField.name
8038
+ }),
8039
+ onClose: handleAlertClose,
8040
+ onSubmit: handleDelete
8041
+ });
8042
+ };
8043
+
7424
8044
  var FieldsTable = function FieldsTable(_ref) {
7425
8045
  var totalCount = _ref.totalCount,
7426
8046
  isLoading = _ref.isLoading,
@@ -11870,6 +12490,7 @@ var FieldsDashboard = function FieldsDashboard(_ref) {
11870
12490
  selectedField = _useFieldsDashboard.selectedField,
11871
12491
  selectedState = _useFieldsDashboard.selectedState,
11872
12492
  selectedMenu = _useFieldsDashboard.selectedMenu,
12493
+ ownerId = _useFieldsDashboard.ownerId,
11873
12494
  isFieldsFetching = _useFieldsDashboard.isFieldsFetching,
11874
12495
  isFieldsLoading = _useFieldsDashboard.isFieldsLoading,
11875
12496
  isDeleting = _useFieldsDashboard.isDeleting,
@@ -11954,13 +12575,14 @@ var FieldsDashboard = function FieldsDashboard(_ref) {
11954
12575
  ownerId: isOwnerBased ? selectedMenu : "",
11955
12576
  onClose: handleReorderPaneClose,
11956
12577
  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
12578
+ }), /*#__PURE__*/React.createElement(DeleteAlert, {
12579
+ handleAlertClose: handleAlertClose,
12580
+ handleDelete: handleDelete,
12581
+ isDeleteAlertOpen: isDeleteAlertOpen,
12582
+ isDeleting: isDeleting,
12583
+ ownerId: ownerId,
12584
+ selectedField: selectedField,
12585
+ resourceTypeName: isOwnerBased ? resourceType : selectedMenu
11964
12586
  }));
11965
12587
  };
11966
12588