@teselagen/ui 0.7.33-beta.1 → 0.7.33-beta.2

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.
Files changed (114) hide show
  1. package/package.json +1 -1
  2. package/src/AdvancedOptions.js +33 -0
  3. package/src/AssignDefaultsModeContext.js +22 -0
  4. package/src/CellDragHandle.js +132 -0
  5. package/src/ColumnFilterMenu.js +62 -0
  6. package/src/Columns.js +979 -0
  7. package/src/DisabledLoadingComponent.js +15 -0
  8. package/src/DisplayOptions.js +199 -0
  9. package/src/DropdownButton.js +36 -0
  10. package/src/DropdownCell.js +61 -0
  11. package/src/EditableCell.js +44 -0
  12. package/src/FillWindow.css +6 -0
  13. package/src/FillWindow.js +69 -0
  14. package/src/FilterAndSortMenu.js +388 -0
  15. package/src/FormSeparator.js +9 -0
  16. package/src/LoadingDots.js +14 -0
  17. package/src/MatchHeaders.js +234 -0
  18. package/src/PagingTool.js +225 -0
  19. package/src/RenderCell.js +191 -0
  20. package/src/SearchBar.js +69 -0
  21. package/src/SimpleStepViz.js +22 -0
  22. package/src/SortableColumns.js +100 -0
  23. package/src/TableFormTrackerContext.js +10 -0
  24. package/src/Tag.js +112 -0
  25. package/src/ThComponent.js +44 -0
  26. package/src/TimelineEvent.js +31 -0
  27. package/src/UploadCsvWizard.css +4 -0
  28. package/src/UploadCsvWizard.js +719 -0
  29. package/src/Uploader.js +1278 -0
  30. package/src/adHoc.js +10 -0
  31. package/src/autoTooltip.js +201 -0
  32. package/src/basicHandleActionsWithFullState.js +14 -0
  33. package/src/browserUtils.js +3 -0
  34. package/src/combineReducersWithFullState.js +14 -0
  35. package/src/commandControls.js +82 -0
  36. package/src/commandUtils.js +112 -0
  37. package/src/constants.js +1 -0
  38. package/src/convertSchema.js +69 -0
  39. package/src/customIcons.js +361 -0
  40. package/src/dataTableEnhancer.js +41 -0
  41. package/src/defaultFormatters.js +32 -0
  42. package/src/defaultValidators.js +40 -0
  43. package/src/determineBlackOrWhiteTextColor.js +4 -0
  44. package/src/editCellHelper.js +44 -0
  45. package/src/filterLocalEntitiesToHasura.js +216 -0
  46. package/src/formatPasteData.js +16 -0
  47. package/src/getAllRows.js +11 -0
  48. package/src/getCellCopyText.js +7 -0
  49. package/src/getCellInfo.js +36 -0
  50. package/src/getCellVal.js +20 -0
  51. package/src/getDayjsFormatter.js +35 -0
  52. package/src/getFieldPathToField.js +7 -0
  53. package/src/getIdOrCodeOrIndex.js +9 -0
  54. package/src/getLastSelectedEntity.js +11 -0
  55. package/src/getNewEntToSelect.js +25 -0
  56. package/src/getNewName.js +31 -0
  57. package/src/getRowCopyText.js +28 -0
  58. package/src/getTableConfigFromStorage.js +5 -0
  59. package/src/getTextFromEl.js +28 -0
  60. package/src/getVals.js +8 -0
  61. package/src/handleCopyColumn.js +21 -0
  62. package/src/handleCopyHelper.js +15 -0
  63. package/src/handleCopyRows.js +23 -0
  64. package/src/handleCopyTable.js +16 -0
  65. package/src/handlerHelpers.js +24 -0
  66. package/src/hotkeyUtils.js +131 -0
  67. package/src/index.js +1 -0
  68. package/src/initializeHasuraWhereAndFilter.js +27 -0
  69. package/src/isBeingCalledExcessively.js +24 -0
  70. package/src/isBottomRightCornerOfRectangle.js +20 -0
  71. package/src/isEntityClean.js +15 -0
  72. package/src/isTruthy.js +12 -0
  73. package/src/isValueEmpty.js +3 -0
  74. package/src/itemUpload.js +84 -0
  75. package/src/menuUtils.js +433 -0
  76. package/src/popoverOverflowModifiers.js +11 -0
  77. package/src/primarySelectedValue.js +1 -0
  78. package/src/pureNoFunc.js +31 -0
  79. package/src/queryParams.js +336 -0
  80. package/src/removeCleanRows.js +22 -0
  81. package/src/renderOnDoc.js +32 -0
  82. package/src/rerenderOnWindowResize.js +26 -0
  83. package/src/rowClick.js +181 -0
  84. package/src/selection.js +8 -0
  85. package/src/showAppSpinner.js +12 -0
  86. package/src/showDialogOnDocBody.js +33 -0
  87. package/src/showProgressToast.js +22 -0
  88. package/src/simplifyHasuraWhere.js +80 -0
  89. package/src/sortify.js +73 -0
  90. package/src/style.css +29 -0
  91. package/src/tableQueryParamsToHasuraClauses.js +113 -0
  92. package/src/tagUtils.js +45 -0
  93. package/src/tgFormValues.js +35 -0
  94. package/src/tg_modalState.js +47 -0
  95. package/src/throwFormError.js +16 -0
  96. package/src/toastr.js +148 -0
  97. package/src/tryToMatchSchemas.js +264 -0
  98. package/src/typeToCommonType.js +6 -0
  99. package/src/useDeepEqualMemo.js +15 -0
  100. package/src/useDialog.js +63 -0
  101. package/src/useStableReference.js +9 -0
  102. package/src/useTableEntities.js +38 -0
  103. package/src/useTraceUpdate.js +19 -0
  104. package/src/utils.js +37 -0
  105. package/src/validateTableWideErrors.js +160 -0
  106. package/src/viewColumn.js +97 -0
  107. package/src/withField.js +20 -0
  108. package/src/withFields.js +11 -0
  109. package/src/withLocalStorage.js +11 -0
  110. package/src/withSelectTableRecords.js +43 -0
  111. package/src/withSelectedEntities.js +65 -0
  112. package/src/withStore.js +10 -0
  113. package/src/withTableParams.js +288 -0
  114. package/src/wrapDialog.js +116 -0
@@ -0,0 +1,80 @@
1
+ export function simplifyHasuraWhere(whereClause) {
2
+ const simplifiedWhere = {};
3
+
4
+ for (const key in whereClause) {
5
+ // eslint-disable-next-line no-prototype-builtins
6
+ if (whereClause.hasOwnProperty(key)) {
7
+ const value = whereClause[key];
8
+
9
+ if (
10
+ typeof value === "object" &&
11
+ value !== null &&
12
+ !Array.isArray(value)
13
+ ) {
14
+ if (key.includes(".")) {
15
+ // Handle dot-nested where clauses
16
+ const keys = key.split(".");
17
+ let currentObj = simplifiedWhere;
18
+ for (let i = 0; i < keys.length - 1; i++) {
19
+ const nestedKey = keys[i];
20
+ if (!currentObj[nestedKey]) {
21
+ currentObj[nestedKey] = {};
22
+ }
23
+ currentObj = currentObj[nestedKey];
24
+ }
25
+ if (typeof value === "object" && value !== null && "_eq" in value) {
26
+ currentObj[keys[keys.length - 1]] = value;
27
+ } else {
28
+ currentObj[keys[keys.length - 1]] = { _eq: value };
29
+ }
30
+ } else {
31
+ // Handle regular Hasura operators or already nested objects.
32
+ if (
33
+ typeof value === "object" &&
34
+ value !== null &&
35
+ !("_eq" in value) &&
36
+ !("_gt" in value) &&
37
+ !("_lt" in value) &&
38
+ !("_gte" in value) &&
39
+ !("_lte" in value) &&
40
+ !("_in" in value) &&
41
+ !("_nin" in value) &&
42
+ !("_neq" in value) &&
43
+ !("_like" in value) &&
44
+ !("_nlike" in value) &&
45
+ !("_ilike" in value) &&
46
+ !("_nilike" in value) &&
47
+ !("_similar" in value) &&
48
+ !("_nsimilar" in value) &&
49
+ !("_regex" in value) &&
50
+ !("_nregex" in value) &&
51
+ !("_iregex" in value) &&
52
+ !("_niregex" in value)
53
+ ) {
54
+ simplifiedWhere[key] = simplifyHasuraWhere(value);
55
+ } else {
56
+ simplifiedWhere[key] = value;
57
+ }
58
+ }
59
+ } else {
60
+ // Handle simplified _eq where clauses
61
+ if (key.includes(".")) {
62
+ const keys = key.split(".");
63
+ let currentObj = simplifiedWhere;
64
+ for (let i = 0; i < keys.length - 1; i++) {
65
+ const nestedKey = keys[i];
66
+ if (!currentObj[nestedKey]) {
67
+ currentObj[nestedKey] = {};
68
+ }
69
+ currentObj = currentObj[nestedKey];
70
+ }
71
+ currentObj[keys[keys.length - 1]] = { _eq: value };
72
+ } else {
73
+ simplifiedWhere[key] = { _eq: value };
74
+ }
75
+ }
76
+ }
77
+ }
78
+
79
+ return simplifiedWhere;
80
+ }
package/src/sortify.js ADDED
@@ -0,0 +1,73 @@
1
+ /*!
2
+ * Copyright 2015-2016 Thomas Rosenau
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ /**
18
+ * Create a “sorted” version of an object.
19
+ *
20
+ * JS engines internally keep track of an object's keys in the order of
21
+ * creation time, i.e. {a:1,b:2} is treated differently from {b:2,a:1}.
22
+ * That difference can be seen when JSON.stringify is called on that object.
23
+ * This function normalizes any kind of object by rearranging the keys in
24
+ * alphabetical order (numerical keys first, since v8 does so, and there's
25
+ * nothing we can do about it).
26
+ * @param {*} o The object to be sorted
27
+ */
28
+
29
+ /* eslint-disable */
30
+ const sortKeys = o => {
31
+ if (Array.isArray(o)) {
32
+ return o.map(sortKeys);
33
+ } else if (o instanceof Object) {
34
+ // put numeric keys first
35
+ let numeric = [];
36
+ let nonNumeric = [];
37
+ Object.keys(o).forEach(key => {
38
+ if (/^(0|[1-9][0-9]*)$/.test(key)) {
39
+ numeric.push(+key);
40
+ } else {
41
+ nonNumeric.push(key);
42
+ }
43
+ });
44
+ // do the rearrangement
45
+ return numeric
46
+ .sort(function (a, b) {
47
+ return a - b;
48
+ })
49
+ .concat(nonNumeric.sort())
50
+ .reduce((result, key) => {
51
+ result[key] = sortKeys(o[key]); // recurse!
52
+ return result;
53
+ }, {});
54
+ }
55
+ return o;
56
+ };
57
+
58
+ const jsonStringify = JSON.stringify.bind(JSON);
59
+
60
+ const sortify = (value, replacer, space) => {
61
+ // replacer, toJSON(), cyclic references and other stuff is better handled by native stringifier.
62
+ // So we do JSON.stringify(sortKeys( JSON.parse(JSON.stringify()) )).
63
+ // This approach is slightly slower but much safer than a manual stringification.
64
+ let nativeJson = jsonStringify(value, replacer, 0);
65
+ if (!nativeJson || (nativeJson[0] !== "{" && nativeJson[0] !== "[")) {
66
+ // if value is not an Object or Array
67
+ return nativeJson;
68
+ }
69
+ let cleanObj = JSON.parse(nativeJson);
70
+ return jsonStringify(sortKeys(cleanObj), null, space);
71
+ };
72
+
73
+ export default sortify;
package/src/style.css ADDED
@@ -0,0 +1,29 @@
1
+ /* Copyright (C) 2018 TeselaGen Biotechnology, Inc. */
2
+ .tg-timeline {
3
+ position: relative;
4
+ white-space: nowrap;
5
+ }
6
+
7
+ .tg-timeline-line {
8
+ position: absolute;
9
+ height: 90%;
10
+ border-left: 2px solid #bfccd6;
11
+ top: 3px;
12
+ left: 5px;
13
+ }
14
+
15
+ .tg-timeline-event {
16
+ margin-bottom: 15px;
17
+ }
18
+
19
+ .tg-timeline-circle {
20
+ width: 12px;
21
+ min-width: 12px;
22
+ height: 12px;
23
+ min-height: 12px;
24
+ z-index: 1;
25
+ margin-right: 10px;
26
+ border-radius: 100px;
27
+ background: #e1e8ed;
28
+ border: 2px solid #137cbd;
29
+ }
@@ -0,0 +1,113 @@
1
+ export function tableQueryParamsToHasuraClauses({
2
+ page,
3
+ pageSize,
4
+ searchTerm,
5
+ filters,
6
+ order,
7
+ schema, // Add schema as a parameter
8
+ additionalFilter
9
+ }) {
10
+ let where = {};
11
+ const order_by = {};
12
+ const limit = pageSize || 25;
13
+ const offset = page && pageSize ? (page - 1) * pageSize : 0;
14
+
15
+ if (searchTerm) {
16
+ const searchTermFilters = [];
17
+ schema.fields.forEach(field => {
18
+ const { type, path, searchDisabled } = field;
19
+ if (searchDisabled || field.filterDisabled || type === "color") return;
20
+ const filterValue = searchTerm; // No cleaning needed here, we're using _ilike
21
+
22
+ if (type === "string" || type === "lookup") {
23
+ searchTermFilters.push({
24
+ [path]: { _ilike: `%${filterValue}%` }
25
+ });
26
+ } else if (type === "boolean") {
27
+ let regex;
28
+ try {
29
+ regex = new RegExp("^" + searchTerm, "ig");
30
+ } catch (error) {
31
+ //ignore
32
+ }
33
+ if (regex) {
34
+ if ("true".replace(regex, "") !== "true") {
35
+ searchTermFilters.push({
36
+ [path]: { _eq: true }
37
+ });
38
+ } else if ("false".replace(regex, "") !== "false") {
39
+ searchTermFilters.push({
40
+ [path]: { _eq: false }
41
+ });
42
+ }
43
+ }
44
+ } else if (
45
+ (type === "number" || type === "integer") &&
46
+ !isNaN(filterValue)
47
+ ) {
48
+ searchTermFilters.push({
49
+ [path]: { _eq: parseFloat(filterValue) }
50
+ });
51
+ }
52
+ });
53
+ if (searchTermFilters.length > 0) {
54
+ if (Object.keys(where).length > 0) {
55
+ where = { _and: [where, { _or: searchTermFilters }] };
56
+ } else {
57
+ where = { _or: searchTermFilters };
58
+ }
59
+ }
60
+ }
61
+
62
+ if (filters && filters.length > 0) {
63
+ const filterClauses = filters.map(filter => {
64
+ const { selectedFilter, filterOn, filterValue } = filter;
65
+ switch (selectedFilter) {
66
+ case "textContains":
67
+ return { [filterOn]: { _ilike: `%${filterValue}%` } };
68
+ case "textEquals":
69
+ return { [filterOn]: { _eq: filterValue } };
70
+ case "textNotEquals":
71
+ return { [filterOn]: { _neq: filterValue } };
72
+ case "numberEquals":
73
+ return { [filterOn]: { _eq: parseFloat(filterValue) } };
74
+ case "numberGreaterThan":
75
+ return { [filterOn]: { _gt: parseFloat(filterValue) } };
76
+ case "numberLessThan":
77
+ return { [filterOn]: { _lt: parseFloat(filterValue) } };
78
+ case "numberGreaterThanEquals":
79
+ return { [filterOn]: { _gte: parseFloat(filterValue) } };
80
+ case "numberLessThanEquals":
81
+ return { [filterOn]: { _lte: parseFloat(filterValue) } };
82
+ case "isNull":
83
+ return { [filterOn]: { _is_null: true } };
84
+ case "isNotNull":
85
+ return { [filterOn]: { _is_null: false } };
86
+ default:
87
+ console.warn(`Unsupported filter type: ${selectedFilter}`);
88
+ return {};
89
+ }
90
+ });
91
+
92
+ if (filterClauses.length > 0) {
93
+ if (Object.keys(where).length > 0) {
94
+ where = { _and: [where, ...filterClauses] };
95
+ } else {
96
+ where = { _and: filterClauses };
97
+ }
98
+ }
99
+ }
100
+
101
+ if (order && order.length > 0) {
102
+ order.forEach(item => {
103
+ const field = item.startsWith("-") ? item.substring(1) : item;
104
+ const direction = item.startsWith("-") ? "desc" : "asc";
105
+ order_by[field] = direction;
106
+ });
107
+ }
108
+
109
+ if (additionalFilter) {
110
+ where = { _and: [where, additionalFilter] };
111
+ }
112
+ return { where, order_by, limit, offset };
113
+ }
@@ -0,0 +1,45 @@
1
+ import { flatMap, keyBy } from "lodash-es";
2
+ import determineBlackOrWhiteTextColor from "./determineBlackOrWhiteTextColor";
3
+
4
+ export function getTagsAndTagOptions(allTags) {
5
+ return flatMap(allTags, tag => {
6
+ if (tag.tagOptions && tag.tagOptions.length) {
7
+ return tag.tagOptions.map(tagO => {
8
+ const fullname = `${tag.name}: ${tagO.name}`;
9
+ const value = `${tag.id}:${tagO.id}`;
10
+ return {
11
+ ...tagO,
12
+ label: fullname,
13
+ value,
14
+ id: tagO.id
15
+ };
16
+ });
17
+ }
18
+ return {
19
+ ...tag,
20
+ label: tag.name,
21
+ value: tag.id
22
+ };
23
+ });
24
+ }
25
+
26
+ export function getKeyedTagsAndTagOptions(tags) {
27
+ return keyBy(getTagsAndTagOptions(tags), "value");
28
+ }
29
+
30
+ export function getTagColorStyle(color) {
31
+ return color
32
+ ? {
33
+ style: {
34
+ backgroundColor: color,
35
+ color: determineBlackOrWhiteTextColor(color)
36
+ }
37
+ }
38
+ : {};
39
+ }
40
+ export function getTagProps({ color, label, name }) {
41
+ return {
42
+ ...getTagColorStyle(color),
43
+ children: label || name
44
+ };
45
+ }
@@ -0,0 +1,35 @@
1
+ import React, { useMemo } from "react";
2
+ import { connect } from "react-redux";
3
+ import { FormName, formValueSelector } from "redux-form";
4
+
5
+ const tgFormValues =
6
+ (...fieldNames) =>
7
+ Component =>
8
+ props => {
9
+ return (
10
+ <FormName>
11
+ {formName => {
12
+ const name = formName.form;
13
+ const Wrapped = useMemo(() => {
14
+ const selector = formValueSelector(name || "");
15
+ const wrapper = connect(state => {
16
+ const vals = {};
17
+ fieldNames.forEach(name => {
18
+ vals[name] = selector(state, name);
19
+ });
20
+ return vals;
21
+ });
22
+ return wrapper(Component);
23
+ }, [name]);
24
+ return <Wrapped {...props} />;
25
+ }}
26
+ </FormName>
27
+ );
28
+ };
29
+ export default tgFormValues;
30
+
31
+ export const tgFormValueSelector = (formName, ...fields) => {
32
+ return connect(state => {
33
+ return formValueSelector(formName)(state, ...fields);
34
+ });
35
+ };
@@ -0,0 +1,47 @@
1
+ import { omit } from "lodash-es";
2
+
3
+ export default function tg_modalState(
4
+ state = {},
5
+ { type, name, uniqueName, props = {} }
6
+ ) {
7
+ const existingModalState = state[name] || {};
8
+ const { __registeredAs = {} } = existingModalState;
9
+ if (type === "TG_REGISTER_MODAL") {
10
+ return {
11
+ ...state,
12
+ [name]: {
13
+ ...existingModalState,
14
+ __registeredAs: { ...__registeredAs, [uniqueName]: true }
15
+ }
16
+ };
17
+ }
18
+ if (type === "TG_UNREGISTER_MODAL") {
19
+ return {
20
+ ...state,
21
+ [name]: {
22
+ ...existingModalState,
23
+ __registeredAs: omit(__registeredAs, uniqueName)
24
+ }
25
+ };
26
+ }
27
+ if (type === "TG_SHOW_MODAL") {
28
+ return {
29
+ ...state,
30
+ [name]: {
31
+ ...existingModalState,
32
+ ...props,
33
+ open: true
34
+ }
35
+ };
36
+ }
37
+ if (type === "TG_HIDE_MODAL") {
38
+ return {
39
+ ...state,
40
+ [name]: {
41
+ __registeredAs: existingModalState.__registeredAs,
42
+ open: false
43
+ }
44
+ };
45
+ }
46
+ return state;
47
+ }
@@ -0,0 +1,16 @@
1
+ import { SubmissionError } from "redux-form";
2
+
3
+ export const throwFormError = error => {
4
+ if (error.message) {
5
+ console.error("error:", error);
6
+ }
7
+ const errorToUse = error.message
8
+ ? { _error: error.message }
9
+ : typeof error === "string"
10
+ ? { _error: error }
11
+ : error;
12
+ if (!errorToUse._error) {
13
+ errorToUse._error = "Error Submitting Form";
14
+ }
15
+ throw new SubmissionError(errorToUse);
16
+ };
package/src/toastr.js ADDED
@@ -0,0 +1,148 @@
1
+ import { Position, Toaster, Intent, Classes } from "@blueprintjs/core";
2
+ import classNames from "classnames";
3
+
4
+ const TopToaster = Toaster.create({
5
+ className: "top-toaster",
6
+ position: Position.TOP
7
+ });
8
+
9
+ const BottomToaster = Toaster.create({
10
+ className: "bottom-toaster",
11
+ position: Position.BOTTOM
12
+ });
13
+
14
+ window.__tgClearAllToasts = () => {
15
+ TopToaster.clear();
16
+ BottomToaster.clear();
17
+ };
18
+
19
+ let counter = 5000;
20
+ const generateToast = intent => (message, options) => {
21
+ options = options || {};
22
+ const toastToUse = options.bottom ? BottomToaster : TopToaster;
23
+ let updatedTimeout;
24
+ if (options.updateTimeout) {
25
+ //generate a slightly different than default timeout to make the update stay on the page for a full 5 seconds
26
+ if (counter > 5500) {
27
+ updatedTimeout = --counter;
28
+ } else {
29
+ updatedTimeout = ++counter;
30
+ }
31
+ }
32
+ if (intent === Intent.DANGER) {
33
+ console.error("Toastr error message: ", message);
34
+ }
35
+ if (intent === Intent.WARNING) {
36
+ console.error("Toastr warning message: ", message);
37
+ }
38
+
39
+ const maybeAddClearAll = () => {
40
+ // wipe any existing clear all buttons
41
+ const existingClearAllButtons =
42
+ document.querySelectorAll(`.tg-clear-all-toasts`);
43
+ existingClearAllButtons.forEach(button => {
44
+ button.remove();
45
+ });
46
+ const activeToasts = document.querySelectorAll(
47
+ `.bp3-toast:not(.bp3-toast-exit)`
48
+ );
49
+ if (activeToasts.length > 1) {
50
+ // add custom clear all button
51
+
52
+ const topToaster = document.querySelector(`.bp3-toast`);
53
+ if (!topToaster) return;
54
+ const closeButton = document.createElement("div");
55
+ closeButton.classList.add(
56
+ Classes.BUTTON,
57
+ Classes.LARGE,
58
+ Classes.INTENT_PRIMARY,
59
+ "tg-clear-all-toasts"
60
+ );
61
+ closeButton.innerText = "Clear all";
62
+ closeButton.onclick = window.__tgClearAllToasts;
63
+ // position the button to the right of the message
64
+ closeButton.style.position = "absolute";
65
+ closeButton.style.right = "-100px";
66
+
67
+ topToaster.appendChild(closeButton);
68
+ }
69
+ };
70
+ const uniqKey = toastToUse.show(
71
+ {
72
+ intent,
73
+ message,
74
+ onDismiss: () => {
75
+ if (options.onDismiss) {
76
+ options.onDismiss();
77
+ }
78
+ setTimeout(() => {
79
+ maybeAddClearAll();
80
+ }, 0);
81
+ },
82
+ timeout:
83
+ options.timeout ||
84
+ updatedTimeout ||
85
+ (!window.Cypress &&
86
+ (intent === Intent.DANGER || intent === Intent.WARNING)
87
+ ? 60000
88
+ : undefined),
89
+ action: options.action,
90
+ icon: options.icon,
91
+ className: classNames("preserve-newline", options.className)
92
+ },
93
+ options.key
94
+ );
95
+ setTimeout(() => {
96
+ maybeAddClearAll();
97
+ }, 0);
98
+ function clear() {
99
+ toastToUse.dismiss(uniqKey);
100
+ setTimeout(() => {
101
+ maybeAddClearAll();
102
+ }, 0);
103
+ }
104
+ clear.key = uniqKey;
105
+ return clear;
106
+ };
107
+
108
+ function preventDuplicates(func) {
109
+ const previousToasts = {};
110
+ return (message, options = {}) => {
111
+ const clearToast = func(message, options);
112
+ // no duplicate check for toasts with updates
113
+
114
+ if (!options.key) {
115
+ if (!options.key && previousToasts[message]) {
116
+ previousToasts[message](); //clear it!
117
+ }
118
+
119
+ setTimeout(() => {
120
+ delete previousToasts[message];
121
+ }, options.timeout || 5000);
122
+
123
+ previousToasts[message] = clearToast;
124
+ }
125
+ return clearToast;
126
+ };
127
+ }
128
+
129
+ if (!window.toastr) window.toastr = {};
130
+ if (!window.toastr.success) {
131
+ window.toastr.success = preventDuplicates(generateToast(Intent.SUCCESS));
132
+ }
133
+
134
+ if (!window.toastr.error) {
135
+ window.toastr.error = preventDuplicates(generateToast(Intent.DANGER));
136
+ }
137
+
138
+ if (!window.toastr.warning) {
139
+ window.toastr.warning = preventDuplicates(generateToast(Intent.WARNING));
140
+ }
141
+
142
+ if (!window.toastr.info) {
143
+ window.toastr.info = preventDuplicates(generateToast(Intent.PRIMARY));
144
+ }
145
+
146
+ if (!window.toastr.default) {
147
+ window.toastr.default = preventDuplicates(generateToast(Intent.NONE));
148
+ }