@teselagen/ui 0.7.36 → 0.8.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.
- package/index.cjs.js +1 -2
- package/index.es.js +1 -2
- package/package.json +1 -1
- package/src/AdvancedOptions.spec.js +26 -0
- package/src/AsyncValidateFieldSpinner/index.js +12 -0
- package/src/BlueprintError/index.js +14 -0
- package/src/BounceLoader/index.js +16 -0
- package/src/BounceLoader/style.css +45 -0
- package/src/CollapsibleCard/index.js +68 -0
- package/src/CollapsibleCard/style.css +23 -0
- package/src/DNALoader/index.js +20 -0
- package/src/DNALoader/style.css +251 -0
- package/src/DataTable/index.js +3220 -0
- package/src/DataTable/style.css +608 -0
- package/src/DataTable/utils/index.js +55 -0
- package/{queryParams.js → src/DataTable/utils/queryParams.js} +0 -1
- package/src/DialogFooter/index.js +86 -0
- package/src/DialogFooter/style.css +9 -0
- package/src/FormComponents/index.js +1266 -0
- package/src/FormComponents/style.css +275 -0
- package/src/FormComponents/utils.js +6 -0
- package/src/HotkeysDialog/index.js +79 -0
- package/src/HotkeysDialog/style.css +54 -0
- package/src/InfoHelper/index.js +78 -0
- package/src/InfoHelper/style.css +7 -0
- package/src/IntentText/index.js +18 -0
- package/src/Loading/index.js +70 -0
- package/src/Loading/style.css +4 -0
- package/src/MenuBar/index.js +423 -0
- package/src/MenuBar/style.css +45 -0
- package/src/PromptUnsavedChanges/index.js +38 -0
- package/src/ResizableDraggableDialog/index.js +141 -0
- package/src/ResizableDraggableDialog/style.css +42 -0
- package/src/ScrollToTop/index.js +72 -0
- package/src/TagSelect/index.js +69 -0
- package/src/TagSelect/style.css +13 -0
- package/src/TgHtmlSelect/index.js +20 -0
- package/src/TgSelect/index.js +537 -0
- package/src/TgSelect/style.css +61 -0
- package/src/TgSuggest/index.js +124 -0
- package/src/Timeline/index.js +15 -0
- package/src/enhancers/withDialog/index.js +196 -0
- package/src/index.js +87 -0
- package/src/showConfirmationDialog/index.js +148 -0
- package/src/style.css +265 -0
- package/{isBeingCalledExcessively.js → src/utils/isBeingCalledExcessively.js} +0 -2
- /package/{AdvancedOptions.js → src/AdvancedOptions.js} +0 -0
- /package/{AssignDefaultsModeContext.js → src/AssignDefaultsModeContext.js} +0 -0
- /package/{CellDragHandle.js → src/DataTable/CellDragHandle.js} +0 -0
- /package/{ColumnFilterMenu.js → src/DataTable/ColumnFilterMenu.js} +0 -0
- /package/{Columns.js → src/DataTable/Columns.js} +0 -0
- /package/{DisabledLoadingComponent.js → src/DataTable/DisabledLoadingComponent.js} +0 -0
- /package/{DisplayOptions.js → src/DataTable/DisplayOptions.js} +0 -0
- /package/{DropdownCell.js → src/DataTable/DropdownCell.js} +0 -0
- /package/{EditableCell.js → src/DataTable/EditableCell.js} +0 -0
- /package/{FilterAndSortMenu.js → src/DataTable/FilterAndSortMenu.js} +0 -0
- /package/{PagingTool.js → src/DataTable/PagingTool.js} +0 -0
- /package/{RenderCell.js → src/DataTable/RenderCell.js} +0 -0
- /package/{SearchBar.js → src/DataTable/SearchBar.js} +0 -0
- /package/{SortableColumns.js → src/DataTable/SortableColumns.js} +0 -0
- /package/{TableFormTrackerContext.js → src/DataTable/TableFormTrackerContext.js} +0 -0
- /package/{ThComponent.js → src/DataTable/ThComponent.js} +0 -0
- /package/{dataTableEnhancer.js → src/DataTable/dataTableEnhancer.js} +0 -0
- /package/{defaultFormatters.js → src/DataTable/defaultFormatters.js} +0 -0
- /package/{defaultValidators.js → src/DataTable/defaultValidators.js} +0 -0
- /package/{editCellHelper.js → src/DataTable/editCellHelper.js} +0 -0
- /package/{getCellVal.js → src/DataTable/getCellVal.js} +0 -0
- /package/{getVals.js → src/DataTable/getVals.js} +0 -0
- /package/{isTruthy.js → src/DataTable/isTruthy.js} +0 -0
- /package/{isValueEmpty.js → src/DataTable/isValueEmpty.js} +0 -0
- /package/{convertSchema.js → src/DataTable/utils/convertSchema.js} +0 -0
- /package/{formatPasteData.js → src/DataTable/utils/formatPasteData.js} +0 -0
- /package/{getAllRows.js → src/DataTable/utils/getAllRows.js} +0 -0
- /package/{getCellCopyText.js → src/DataTable/utils/getCellCopyText.js} +0 -0
- /package/{getCellInfo.js → src/DataTable/utils/getCellInfo.js} +0 -0
- /package/{getFieldPathToField.js → src/DataTable/utils/getFieldPathToField.js} +0 -0
- /package/{getIdOrCodeOrIndex.js → src/DataTable/utils/getIdOrCodeOrIndex.js} +0 -0
- /package/{getLastSelectedEntity.js → src/DataTable/utils/getLastSelectedEntity.js} +0 -0
- /package/{getNewEntToSelect.js → src/DataTable/utils/getNewEntToSelect.js} +0 -0
- /package/{getRowCopyText.js → src/DataTable/utils/getRowCopyText.js} +0 -0
- /package/{getTableConfigFromStorage.js → src/DataTable/utils/getTableConfigFromStorage.js} +0 -0
- /package/{handleCopyColumn.js → src/DataTable/utils/handleCopyColumn.js} +0 -0
- /package/{handleCopyHelper.js → src/DataTable/utils/handleCopyHelper.js} +0 -0
- /package/{handleCopyRows.js → src/DataTable/utils/handleCopyRows.js} +0 -0
- /package/{handleCopyTable.js → src/DataTable/utils/handleCopyTable.js} +0 -0
- /package/{isBottomRightCornerOfRectangle.js → src/DataTable/utils/isBottomRightCornerOfRectangle.js} +0 -0
- /package/{isEntityClean.js → src/DataTable/utils/isEntityClean.js} +0 -0
- /package/{primarySelectedValue.js → src/DataTable/utils/primarySelectedValue.js} +0 -0
- /package/{removeCleanRows.js → src/DataTable/utils/removeCleanRows.js} +0 -0
- /package/{rowClick.js → src/DataTable/utils/rowClick.js} +0 -0
- /package/{selection.js → src/DataTable/utils/selection.js} +0 -0
- /package/{useTableEntities.js → src/DataTable/utils/useTableEntities.js} +0 -0
- /package/{utils.js → src/DataTable/utils/utils.js} +0 -0
- /package/{withSelectedEntities.js → src/DataTable/utils/withSelectedEntities.js} +0 -0
- /package/{withTableParams.js → src/DataTable/utils/withTableParams.js} +0 -0
- /package/{validateTableWideErrors.js → src/DataTable/validateTableWideErrors.js} +0 -0
- /package/{viewColumn.js → src/DataTable/viewColumn.js} +0 -0
- /package/{DropdownButton.js → src/DropdownButton.js} +0 -0
- /package/{FillWindow.css → src/FillWindow.css} +0 -0
- /package/{FillWindow.js → src/FillWindow.js} +0 -0
- /package/{FormSeparator.js → src/FormComponents/FormSeparator.js} +0 -0
- /package/{LoadingDots.js → src/FormComponents/LoadingDots.js} +0 -0
- /package/{Uploader.js → src/FormComponents/Uploader.js} +0 -0
- /package/{getNewName.js → src/FormComponents/getNewName.js} +0 -0
- /package/{itemUpload.js → src/FormComponents/itemUpload.js} +0 -0
- /package/{sortify.js → src/FormComponents/sortify.js} +0 -0
- /package/{tryToMatchSchemas.js → src/FormComponents/tryToMatchSchemas.js} +0 -0
- /package/{MatchHeaders.js → src/MatchHeaders.js} +0 -0
- /package/{SimpleStepViz.js → src/SimpleStepViz.js} +0 -0
- /package/{Tag.js → src/Tag.js} +0 -0
- /package/{TimelineEvent.js → src/Timeline/TimelineEvent.js} +0 -0
- /package/{style.css → src/Timeline/style.css} +0 -0
- /package/{UploadCsvWizard.css → src/UploadCsvWizard.css} +0 -0
- /package/{UploadCsvWizard.js → src/UploadCsvWizard.js} +0 -0
- /package/{autoTooltip.js → src/autoTooltip.js} +0 -0
- /package/{constants.js → src/constants.js} +0 -0
- /package/{customIcons.js → src/customIcons.js} +0 -0
- /package/{tg_modalState.js → src/enhancers/withDialog/tg_modalState.js} +0 -0
- /package/{withField.js → src/enhancers/withField.js} +0 -0
- /package/{withFields.js → src/enhancers/withFields.js} +0 -0
- /package/{withLocalStorage.js → src/enhancers/withLocalStorage.js} +0 -0
- /package/{rerenderOnWindowResize.js → src/rerenderOnWindowResize.js} +0 -0
- /package/{showAppSpinner.js → src/showAppSpinner.js} +0 -0
- /package/{showDialogOnDocBody.js → src/showDialogOnDocBody.js} +0 -0
- /package/{throwFormError.js → src/throwFormError.js} +0 -0
- /package/{toastr.js → src/toastr.js} +0 -0
- /package/{typeToCommonType.js → src/typeToCommonType.js} +0 -0
- /package/{useDialog.js → src/useDialog.js} +0 -0
- /package/{adHoc.js → src/utils/adHoc.js} +0 -0
- /package/{basicHandleActionsWithFullState.js → src/utils/basicHandleActionsWithFullState.js} +0 -0
- /package/{browserUtils.js → src/utils/browserUtils.js} +0 -0
- /package/{combineReducersWithFullState.js → src/utils/combineReducersWithFullState.js} +0 -0
- /package/{commandControls.js → src/utils/commandControls.js} +0 -0
- /package/{commandUtils.js → src/utils/commandUtils.js} +0 -0
- /package/{determineBlackOrWhiteTextColor.js → src/utils/determineBlackOrWhiteTextColor.js} +0 -0
- /package/{getDayjsFormatter.js → src/utils/getDayjsFormatter.js} +0 -0
- /package/{getTextFromEl.js → src/utils/getTextFromEl.js} +0 -0
- /package/{handlerHelpers.js → src/utils/handlerHelpers.js} +0 -0
- /package/{index.js → src/utils/hooks/index.js} +0 -0
- /package/{useDeepEqualMemo.js → src/utils/hooks/useDeepEqualMemo.js} +0 -0
- /package/{useStableReference.js → src/utils/hooks/useStableReference.js} +0 -0
- /package/{hotkeyUtils.js → src/utils/hotkeyUtils.js} +0 -0
- /package/{menuUtils.js → src/utils/menuUtils.js} +0 -0
- /package/{popoverOverflowModifiers.js → src/utils/popoverOverflowModifiers.js} +0 -0
- /package/{pureNoFunc.js → src/utils/pureNoFunc.js} +0 -0
- /package/{renderOnDoc.js → src/utils/renderOnDoc.js} +0 -0
- /package/{showProgressToast.js → src/utils/showProgressToast.js} +0 -0
- /package/{tagUtils.js → src/utils/tagUtils.js} +0 -0
- /package/{tgFormValues.js → src/utils/tgFormValues.js} +0 -0
- /package/{useTraceUpdate.js → src/utils/useTraceUpdate.js} +0 -0
- /package/{withSelectTableRecords.js → src/utils/withSelectTableRecords.js} +0 -0
- /package/{withStore.js → src/utils/withStore.js} +0 -0
- /package/{wrapDialog.js → src/wrapDialog.js} +0 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
import { Button } from "@blueprintjs/core";
|
|
3
|
+
import { Transition } from "react-transition-group";
|
|
4
|
+
|
|
5
|
+
const duration = 300;
|
|
6
|
+
|
|
7
|
+
const defaultStyle = {
|
|
8
|
+
transition: `opacity ${duration}ms ease-in-out`,
|
|
9
|
+
opacity: 0
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const transitionStyles = {
|
|
13
|
+
entering: { opacity: 1 },
|
|
14
|
+
entered: { opacity: 1 },
|
|
15
|
+
exiting: { opacity: 0 },
|
|
16
|
+
exited: { opacity: 0 }
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function ScrollToTop({
|
|
20
|
+
showAt = 150,
|
|
21
|
+
scrollContainer = document.scrollingElement
|
|
22
|
+
}) {
|
|
23
|
+
const [shouldShow, setShouldShow] = useState(
|
|
24
|
+
scrollContainer.scrollTop >= showAt
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const scrollListener = () => {
|
|
29
|
+
const newShouldShow = scrollContainer.scrollTop >= showAt;
|
|
30
|
+
if (newShouldShow !== shouldShow) setShouldShow(newShouldShow);
|
|
31
|
+
};
|
|
32
|
+
const listenerContainer =
|
|
33
|
+
scrollContainer === document.scrollingElement ? window : scrollContainer;
|
|
34
|
+
listenerContainer.addEventListener("scroll", scrollListener);
|
|
35
|
+
// Specify how to clean up after this effect:
|
|
36
|
+
return function cleanup() {
|
|
37
|
+
listenerContainer.removeEventListener("scroll", scrollListener);
|
|
38
|
+
};
|
|
39
|
+
}, [shouldShow, showAt, scrollContainer]);
|
|
40
|
+
|
|
41
|
+
const scrollToTop = () => {
|
|
42
|
+
const c = scrollContainer.scrollTop;
|
|
43
|
+
if (c > 0) {
|
|
44
|
+
window.requestAnimationFrame(scrollToTop);
|
|
45
|
+
scrollContainer.scrollTo(0, c - c / 8);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<Transition in={shouldShow} timeout={duration}>
|
|
51
|
+
{state =>
|
|
52
|
+
state === "exited" ? null : (
|
|
53
|
+
<div style={{ position: "fixed", bottom: 25, right: 25, zIndex: 10 }}>
|
|
54
|
+
<Button
|
|
55
|
+
style={{
|
|
56
|
+
borderRadius: "50%",
|
|
57
|
+
...defaultStyle,
|
|
58
|
+
...transitionStyles[state]
|
|
59
|
+
}}
|
|
60
|
+
intent="primary"
|
|
61
|
+
icon="arrow-up"
|
|
62
|
+
large
|
|
63
|
+
onClick={scrollToTop}
|
|
64
|
+
/>
|
|
65
|
+
</div>
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
</Transition>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export default ScrollToTop;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Button, InputGroup, Popover } from "@blueprintjs/core";
|
|
2
|
+
import React from "react";
|
|
3
|
+
|
|
4
|
+
import Tag from "../Tag";
|
|
5
|
+
import "./style.css";
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { itemListPredicate } from "../TgSelect";
|
|
8
|
+
|
|
9
|
+
export default ({ value = {}, options = [], onChange }) => {
|
|
10
|
+
const [open, setOpen] = useState(false);
|
|
11
|
+
const [searchTerm, setSearchTerm] = useState("");
|
|
12
|
+
|
|
13
|
+
const filteredOptions = itemListPredicate(searchTerm, options, false);
|
|
14
|
+
|
|
15
|
+
return (
|
|
16
|
+
<Popover
|
|
17
|
+
isOpen={open}
|
|
18
|
+
onInteraction={setOpen}
|
|
19
|
+
content={
|
|
20
|
+
<div className="tag-select-popover">
|
|
21
|
+
<InputGroup
|
|
22
|
+
rightElement={
|
|
23
|
+
// clear button
|
|
24
|
+
searchTerm ? (
|
|
25
|
+
<Button
|
|
26
|
+
icon="cross"
|
|
27
|
+
minimal
|
|
28
|
+
onClick={() => setSearchTerm("")}
|
|
29
|
+
/>
|
|
30
|
+
) : null
|
|
31
|
+
}
|
|
32
|
+
type="text"
|
|
33
|
+
placeholder="Search..."
|
|
34
|
+
autoFocus
|
|
35
|
+
value={searchTerm}
|
|
36
|
+
onChange={e => setSearchTerm(e.target.value)}
|
|
37
|
+
/>
|
|
38
|
+
<div className="tag-select-popover-inner">
|
|
39
|
+
{filteredOptions.map(option => {
|
|
40
|
+
return (
|
|
41
|
+
<Tag
|
|
42
|
+
key={option.name}
|
|
43
|
+
onClick={() => {
|
|
44
|
+
onChange(option);
|
|
45
|
+
setOpen(false);
|
|
46
|
+
}}
|
|
47
|
+
clickable
|
|
48
|
+
style={{ maxWidth: 150 }}
|
|
49
|
+
{...convertTagVals(option)}
|
|
50
|
+
doNotFillWidth
|
|
51
|
+
></Tag>
|
|
52
|
+
);
|
|
53
|
+
})}
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
56
|
+
}
|
|
57
|
+
>
|
|
58
|
+
<Tag style={{ maxWidth: 150 }} clickable {...convertTagVals(value)}></Tag>
|
|
59
|
+
</Popover>
|
|
60
|
+
);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
function convertTagVals(tagVals) {
|
|
64
|
+
return {
|
|
65
|
+
...tagVals,
|
|
66
|
+
|
|
67
|
+
name: tagVals.name || tagVals.label
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { HTMLSelect } from "@blueprintjs/core";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import classNames from "classnames";
|
|
4
|
+
|
|
5
|
+
// so far this component just makes the styling of the disabled html select
|
|
6
|
+
// look like a regular html select with the selected option displayed
|
|
7
|
+
// (instead of greyed out and without the ability to have tooltips working)
|
|
8
|
+
const TgHTMLSelect = ({ disabled, ...rest }) => {
|
|
9
|
+
if (disabled) {
|
|
10
|
+
const opt = rest.options.find(o => o.value === rest.value);
|
|
11
|
+
return (
|
|
12
|
+
<div {...rest} className={classNames("bp3-html-select", rest.className)}>
|
|
13
|
+
{opt.label}
|
|
14
|
+
</div>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
return <HTMLSelect {...rest}></HTMLSelect>;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export default TgHTMLSelect;
|
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
2
|
+
import { MultiSelect, getCreateNewItem } from "@blueprintjs/select";
|
|
3
|
+
import { Keys, Button, MenuItem, Tag } from "@blueprintjs/core";
|
|
4
|
+
import React, { useEffect, useState } from "react";
|
|
5
|
+
import { filter, isEqual } from "lodash-es";
|
|
6
|
+
import classNames from "classnames";
|
|
7
|
+
import "./style.css";
|
|
8
|
+
import { withProps } from "recompose";
|
|
9
|
+
import fuzzysearch from "fuzzysearch";
|
|
10
|
+
import getTextFromEl from "../utils/getTextFromEl";
|
|
11
|
+
import { getTagColorStyle, getTagProps } from "../utils/tagUtils";
|
|
12
|
+
import popoverOverflowModifiers from "../utils/popoverOverflowModifiers";
|
|
13
|
+
import { compose } from "redux";
|
|
14
|
+
|
|
15
|
+
class TgSelect extends React.Component {
|
|
16
|
+
constructor(props) {
|
|
17
|
+
super(props);
|
|
18
|
+
const { autoOpen = false } = this.props;
|
|
19
|
+
|
|
20
|
+
this.state = {
|
|
21
|
+
isOpen: autoOpen,
|
|
22
|
+
activeItem: null,
|
|
23
|
+
query: ""
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
setOpenState = isOpen => {
|
|
27
|
+
const { handleOpenChange } = this.props;
|
|
28
|
+
if (handleOpenChange) {
|
|
29
|
+
handleOpenChange(isOpen);
|
|
30
|
+
}
|
|
31
|
+
this.setState({ isOpen });
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
static defaultProps = {
|
|
35
|
+
onChange: () => {},
|
|
36
|
+
options: [],
|
|
37
|
+
unfilteredOptions: [],
|
|
38
|
+
value: undefined
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
itemRenderer = (i, { index, handleClick, modifiers }) => {
|
|
42
|
+
const optionRenderer = this.getOptionRenderer();
|
|
43
|
+
const onClick = i.onClick || handleClick;
|
|
44
|
+
return (
|
|
45
|
+
<div //we specifically don't use a BP MenuItem component here because the menu item is too slow when 100s are loaded and will cause the component to lag
|
|
46
|
+
onClick={modifiers.disabled ? undefined : onClick}
|
|
47
|
+
key={index}
|
|
48
|
+
className={classNames(
|
|
49
|
+
"tg-select-option bp3-menu-item bp3-fill bp3-text-overflow-ellipsis",
|
|
50
|
+
{
|
|
51
|
+
"bp3-active": modifiers.active,
|
|
52
|
+
"bp3-disabled": modifiers.disabled
|
|
53
|
+
}
|
|
54
|
+
)}
|
|
55
|
+
>
|
|
56
|
+
{optionRenderer ? optionRenderer(i, this.props) : i.label}
|
|
57
|
+
</div>
|
|
58
|
+
);
|
|
59
|
+
};
|
|
60
|
+
tagRenderer = i => {
|
|
61
|
+
if (!i || (!this.props.multi && this.state.query)) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
// return i
|
|
65
|
+
return i.label;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
handleItemSelect = (item, e) => {
|
|
69
|
+
e.stopPropagation();
|
|
70
|
+
const { onChange, value, multi, closeOnSelect, isTagSelect } = this.props;
|
|
71
|
+
this.setState({ activeItem: null });
|
|
72
|
+
if (multi) {
|
|
73
|
+
let valArray = getValueArray(value);
|
|
74
|
+
|
|
75
|
+
if (closeOnSelect || item.closeOnSelect) {
|
|
76
|
+
this.setOpenState(false);
|
|
77
|
+
this.input && this.input.blur();
|
|
78
|
+
}
|
|
79
|
+
if (
|
|
80
|
+
isTagSelect &&
|
|
81
|
+
item.value &&
|
|
82
|
+
item.value.includes &&
|
|
83
|
+
item.value.includes(":")
|
|
84
|
+
) {
|
|
85
|
+
const topLevelId = item.value.split(":")[0];
|
|
86
|
+
valArray = valArray.filter(val => {
|
|
87
|
+
if (val?.value && val.value.includes && val.value.includes(":")) {
|
|
88
|
+
const valId = val.value.split(":")[0];
|
|
89
|
+
if (valId === topLevelId) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
return onChange([...valArray, item], e);
|
|
97
|
+
} else {
|
|
98
|
+
this.setOpenState(false);
|
|
99
|
+
this.input && this.input.blur();
|
|
100
|
+
return onChange(item, e);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
handleTagRemove = (e, tagProps) => {
|
|
105
|
+
const { onChange, value } = this.props;
|
|
106
|
+
const filteredVals = filter(
|
|
107
|
+
value,
|
|
108
|
+
(obj, i) => !isEqual(i, tagProps["data-tag-index"])
|
|
109
|
+
);
|
|
110
|
+
e.stopPropagation();
|
|
111
|
+
onChange(filteredVals);
|
|
112
|
+
this.setOpenState(false);
|
|
113
|
+
this.input.focus();
|
|
114
|
+
};
|
|
115
|
+
handleTagInputRemove = (val, index) => {
|
|
116
|
+
const { onChange, value } = this.props;
|
|
117
|
+
const filteredVals = filter(value, (obj, i) => !isEqual(i, index));
|
|
118
|
+
// e.stopPropagation();
|
|
119
|
+
return onChange(filteredVals);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
handleClear = e => {
|
|
123
|
+
const { multi, value } = this.props;
|
|
124
|
+
|
|
125
|
+
e.stopPropagation();
|
|
126
|
+
e.preventDefault();
|
|
127
|
+
let newValue = null;
|
|
128
|
+
if (multi) {
|
|
129
|
+
newValue = filter(value, obj => obj?.disabled) || [];
|
|
130
|
+
} else if (value && value.disabled) {
|
|
131
|
+
newValue = value;
|
|
132
|
+
}
|
|
133
|
+
const { onChange } = this.props;
|
|
134
|
+
this.setState({ query: "" });
|
|
135
|
+
onChange(newValue);
|
|
136
|
+
this.setOpenState(false);
|
|
137
|
+
this.input.focus();
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
itemListPredicate = (queryString, item) => {
|
|
141
|
+
// this will hide an option if it returns false
|
|
142
|
+
// each item is an individual option item
|
|
143
|
+
const { isSimpleSearch } = this.props;
|
|
144
|
+
|
|
145
|
+
return itemListPredicate(queryString, item, isSimpleSearch);
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
onQueryChange = query => {
|
|
149
|
+
const { onInputChange = () => {} } = this.props;
|
|
150
|
+
this.setState({
|
|
151
|
+
query
|
|
152
|
+
});
|
|
153
|
+
onInputChange(query);
|
|
154
|
+
};
|
|
155
|
+
handleActiveItemChange = (item, isCreateNewItem) => {
|
|
156
|
+
this.setState({
|
|
157
|
+
activeItem:
|
|
158
|
+
item ||
|
|
159
|
+
//if there's no item and we're in creatable mode, auto-select the create-new option
|
|
160
|
+
(isCreateNewItem || this.props.creatable ? getCreateNewItem() : null)
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
onInteraction = () => {
|
|
164
|
+
if (this.input != null && this.input !== document.activeElement) {
|
|
165
|
+
// the input is no longer focused so we can close the popover
|
|
166
|
+
this.setOpenState(false);
|
|
167
|
+
this.setState({
|
|
168
|
+
query: ""
|
|
169
|
+
});
|
|
170
|
+
} else if (!this.props.openOnKeyDown) {
|
|
171
|
+
// open the popover when focusing the tag input
|
|
172
|
+
this.setOpenState(true);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
queryHasExactOptionMatch = () => {
|
|
177
|
+
//we don't want to show the creatable if the thing being created already exactly matches the label
|
|
178
|
+
return (
|
|
179
|
+
[
|
|
180
|
+
...(this.props.options || []),
|
|
181
|
+
...(Array.isArray(this.props.value)
|
|
182
|
+
? this.props.value
|
|
183
|
+
: [this.props.value])
|
|
184
|
+
].filter(o => {
|
|
185
|
+
const { label, value } = o || {};
|
|
186
|
+
const lowerQuery = (this.state.query || "").toLowerCase();
|
|
187
|
+
const lowerLabelOrVal =
|
|
188
|
+
label && label.toLowerCase
|
|
189
|
+
? label.toLowerCase()
|
|
190
|
+
: value && value.toLowerCase && value.toLowerCase();
|
|
191
|
+
const textFromEl = getTextFromEl(label);
|
|
192
|
+
|
|
193
|
+
return lowerQuery === lowerLabelOrVal || lowerQuery === textFromEl;
|
|
194
|
+
}).length > 0
|
|
195
|
+
);
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
getTagProps = label => {
|
|
199
|
+
const { multi, value = [], disabled: _disabled } = this.props;
|
|
200
|
+
const val = Array.isArray(value) ? value : [value];
|
|
201
|
+
const matchingVal = val.find(op => op?.label === label);
|
|
202
|
+
const disabled = _disabled || (matchingVal && matchingVal.disabled);
|
|
203
|
+
const className = matchingVal && matchingVal.className;
|
|
204
|
+
|
|
205
|
+
return {
|
|
206
|
+
...getTagColorStyle(multi && matchingVal && matchingVal.color),
|
|
207
|
+
intent: disabled ? "" : "primary",
|
|
208
|
+
minimal: true,
|
|
209
|
+
className: classNames(className, "tg-select-value", {
|
|
210
|
+
disabled
|
|
211
|
+
}),
|
|
212
|
+
onRemove: multi && !disabled ? this.handleTagRemove : null
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
getOptionRenderer = () => {
|
|
217
|
+
const { isTagSelect, optionRenderer, multi } = this.props;
|
|
218
|
+
|
|
219
|
+
if (isTagSelect && multi) {
|
|
220
|
+
return tagOptionRender;
|
|
221
|
+
}
|
|
222
|
+
return optionRenderer;
|
|
223
|
+
};
|
|
224
|
+
renderCreateNewOption = (query, active, handleClick) => {
|
|
225
|
+
if (this.props.renderCreateNewOption) {
|
|
226
|
+
return this.props.renderCreateNewOption(query, active, handleClick);
|
|
227
|
+
}
|
|
228
|
+
return (
|
|
229
|
+
<MenuItem
|
|
230
|
+
icon="add"
|
|
231
|
+
text={`Create "${query}"`}
|
|
232
|
+
active={active}
|
|
233
|
+
onClick={(...args) => {
|
|
234
|
+
const shouldStopEarly = this.props.onCreateNewOption?.(query);
|
|
235
|
+
if (shouldStopEarly) {
|
|
236
|
+
this.setOpenState(false);
|
|
237
|
+
} else {
|
|
238
|
+
handleClick(...args);
|
|
239
|
+
}
|
|
240
|
+
}}
|
|
241
|
+
shouldDismissPopover={false}
|
|
242
|
+
/>
|
|
243
|
+
);
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
render() {
|
|
247
|
+
let {
|
|
248
|
+
multi,
|
|
249
|
+
asTag,
|
|
250
|
+
options,
|
|
251
|
+
unfilteredOptions,
|
|
252
|
+
value,
|
|
253
|
+
creatable,
|
|
254
|
+
optionRenderer, //pull this one out here so it doesn't get passsed along
|
|
255
|
+
tagInputProps,
|
|
256
|
+
autoFocus,
|
|
257
|
+
autoOpen,
|
|
258
|
+
mustHaveQueryToOpen,
|
|
259
|
+
noResultsText,
|
|
260
|
+
noResults: _noResults,
|
|
261
|
+
inputProps,
|
|
262
|
+
backgroundColor,
|
|
263
|
+
doNotFillWidth,
|
|
264
|
+
noToggle,
|
|
265
|
+
small,
|
|
266
|
+
placeholder,
|
|
267
|
+
isLoading,
|
|
268
|
+
disallowClear,
|
|
269
|
+
onBlur,
|
|
270
|
+
disabled,
|
|
271
|
+
popoverProps,
|
|
272
|
+
additionalRightEl,
|
|
273
|
+
resetOnSelect = true,
|
|
274
|
+
...rest
|
|
275
|
+
} = this.props;
|
|
276
|
+
if (asTag) {
|
|
277
|
+
small = true;
|
|
278
|
+
placeholder = " ";
|
|
279
|
+
backgroundColor = "red";
|
|
280
|
+
disallowClear = true;
|
|
281
|
+
doNotFillWidth = true;
|
|
282
|
+
noToggle = true;
|
|
283
|
+
}
|
|
284
|
+
let noResults = _noResults;
|
|
285
|
+
|
|
286
|
+
// Null is also a valid value for a React Component, noResultsDefault should only be appplied when noResults is undefined
|
|
287
|
+
if (noResults === undefined) noResults = noResultsDefault;
|
|
288
|
+
const hasQuery = this.state.query?.length > 0;
|
|
289
|
+
const hasValue = Array.isArray(value)
|
|
290
|
+
? value.length > 0
|
|
291
|
+
: !!value || value === 0;
|
|
292
|
+
|
|
293
|
+
const rightElement = isLoading ? (
|
|
294
|
+
<Button loading minimal />
|
|
295
|
+
) : (
|
|
296
|
+
<span>
|
|
297
|
+
{additionalRightEl}
|
|
298
|
+
{hasValue && !disallowClear && !disabled && (
|
|
299
|
+
<Button
|
|
300
|
+
className="tg-select-clear-all"
|
|
301
|
+
icon="cross"
|
|
302
|
+
minimal
|
|
303
|
+
onClick={this.handleClear}
|
|
304
|
+
/>
|
|
305
|
+
)}
|
|
306
|
+
{noResults !== null && !noToggle && (
|
|
307
|
+
<Button
|
|
308
|
+
onClick={e => {
|
|
309
|
+
if (this.state.isOpen) {
|
|
310
|
+
e.stopPropagation();
|
|
311
|
+
|
|
312
|
+
this.setOpenState(false);
|
|
313
|
+
}
|
|
314
|
+
}}
|
|
315
|
+
disabled={disabled}
|
|
316
|
+
className="tg-select-toggle"
|
|
317
|
+
minimal
|
|
318
|
+
icon={this.state.isOpen ? "caret-up" : "caret-down"}
|
|
319
|
+
/>
|
|
320
|
+
)}
|
|
321
|
+
</span>
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
const maybeCreateNewItemFromQuery = creatable ? createNewOption : undefined;
|
|
325
|
+
const maybeCreateNewItemRenderer =
|
|
326
|
+
creatable && !this.queryHasExactOptionMatch()
|
|
327
|
+
? this.renderCreateNewOption
|
|
328
|
+
: null;
|
|
329
|
+
const selectedItems = getValueArray(value).map(value => {
|
|
330
|
+
if (value && value.label) return value; //if the value has a label, just use that
|
|
331
|
+
//if not, look for an existing option to use that value
|
|
332
|
+
// unfilteredOptions will have every option included selected ones
|
|
333
|
+
return unfilteredOptions.find(
|
|
334
|
+
opt => opt && opt.value === ((value && value.value) || value)
|
|
335
|
+
);
|
|
336
|
+
});
|
|
337
|
+
const toRet = (
|
|
338
|
+
<MultiSelect
|
|
339
|
+
onActiveItemChange={this.handleActiveItemChange}
|
|
340
|
+
closeOnSelect={!multi}
|
|
341
|
+
resetOnSelect={resetOnSelect}
|
|
342
|
+
items={options || []}
|
|
343
|
+
activeItem={
|
|
344
|
+
this.state.activeItem ||
|
|
345
|
+
(options && options.filter(opt => !selectedItems.includes(opt))[0]) ||
|
|
346
|
+
null //it's important we pass null here instead of undefined if no active item is found
|
|
347
|
+
}
|
|
348
|
+
itemDisabled={itemDisabled}
|
|
349
|
+
query={this.state.query}
|
|
350
|
+
popoverProps={{
|
|
351
|
+
captureDismiss: true,
|
|
352
|
+
minimal: true,
|
|
353
|
+
className: classNames("tg-select", "tg-stop-dialog-form-enter", {
|
|
354
|
+
"tg-single-select": !multi,
|
|
355
|
+
"tg-select-as-tag": asTag,
|
|
356
|
+
"do-not-fill-width": doNotFillWidth,
|
|
357
|
+
"tg-small": small
|
|
358
|
+
}),
|
|
359
|
+
wrapperTagName: "div",
|
|
360
|
+
canEscapeKeyClose: true,
|
|
361
|
+
onInteraction: this.onInteraction,
|
|
362
|
+
isOpen: mustHaveQueryToOpen
|
|
363
|
+
? hasQuery && this.state.isOpen
|
|
364
|
+
: this.state.isOpen,
|
|
365
|
+
modifiers: popoverOverflowModifiers,
|
|
366
|
+
...popoverProps
|
|
367
|
+
}}
|
|
368
|
+
onItemSelect={this.handleItemSelect}
|
|
369
|
+
createNewItemFromQuery={maybeCreateNewItemFromQuery}
|
|
370
|
+
createNewItemRenderer={maybeCreateNewItemRenderer}
|
|
371
|
+
noResults={noResultsText || noResults}
|
|
372
|
+
onQueryChange={this.onQueryChange}
|
|
373
|
+
itemRenderer={this.itemRenderer}
|
|
374
|
+
itemListPredicate={this.itemListPredicate}
|
|
375
|
+
{...{
|
|
376
|
+
selectedItems,
|
|
377
|
+
tagRenderer: this.tagRenderer,
|
|
378
|
+
tagInputProps: {
|
|
379
|
+
inputRef: n => {
|
|
380
|
+
if (n) this.input = n;
|
|
381
|
+
},
|
|
382
|
+
placeholder:
|
|
383
|
+
placeholder || (creatable ? "Select/Create..." : "Select..."),
|
|
384
|
+
tagProps: this.getTagProps,
|
|
385
|
+
onRemove: multi ? this.handleTagInputRemove : null,
|
|
386
|
+
rightElement: rightElement,
|
|
387
|
+
disabled: disabled, // tg: adding isLoading will cause the input to be blurred when using generic select asReactSelect (don't do it),
|
|
388
|
+
...tagInputProps, //spread additional tag input props here
|
|
389
|
+
intent: this.props.intent,
|
|
390
|
+
onKeyDown: e => {
|
|
391
|
+
const { which } = e;
|
|
392
|
+
e.persist();
|
|
393
|
+
if (which === Keys.ENTER) {
|
|
394
|
+
e.preventDefault();
|
|
395
|
+
// e.stopPropagation();
|
|
396
|
+
}
|
|
397
|
+
if (which === Keys.ESCAPE || which === Keys.TAB) {
|
|
398
|
+
// By default the escape key will not trigger a blur on the
|
|
399
|
+
// input element. It must be done explicitly.
|
|
400
|
+
if (this.input != null) {
|
|
401
|
+
this.input.blur();
|
|
402
|
+
}
|
|
403
|
+
this.setOpenState(false);
|
|
404
|
+
e.preventDefault();
|
|
405
|
+
e.stopPropagation(); //this prevents dialog's it is in from closing
|
|
406
|
+
} else if (
|
|
407
|
+
!(
|
|
408
|
+
which === Keys.BACKSPACE ||
|
|
409
|
+
which === Keys.ARROW_LEFT ||
|
|
410
|
+
which === Keys.ARROW_RIGHT
|
|
411
|
+
)
|
|
412
|
+
) {
|
|
413
|
+
this.setOpenState(true);
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
inputProps: {
|
|
417
|
+
autoFocus: autoFocus || autoOpen,
|
|
418
|
+
onBlur,
|
|
419
|
+
...(tagInputProps && tagInputProps.inputProps)
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
}}
|
|
423
|
+
{...rest}
|
|
424
|
+
/>
|
|
425
|
+
);
|
|
426
|
+
return toRet;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
const withAsyncOptions = Component => props => {
|
|
431
|
+
const { loadOptions, options, ...rest } = props;
|
|
432
|
+
const [asyncOptions, setAsyncOptions] = useState([]);
|
|
433
|
+
const [isLoading, setLoading] = useState(false);
|
|
434
|
+
useEffect(() => {
|
|
435
|
+
if (loadOptions) {
|
|
436
|
+
setLoading(true);
|
|
437
|
+
loadOptions().then(options => {
|
|
438
|
+
setAsyncOptions(options);
|
|
439
|
+
setLoading(false);
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
}, [loadOptions]);
|
|
443
|
+
|
|
444
|
+
return (
|
|
445
|
+
<Component
|
|
446
|
+
{...rest}
|
|
447
|
+
isLoading={isLoading || rest.isLoading}
|
|
448
|
+
options={loadOptions ? asyncOptions : options}
|
|
449
|
+
/>
|
|
450
|
+
);
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
export default compose(
|
|
454
|
+
withAsyncOptions,
|
|
455
|
+
withProps(props => {
|
|
456
|
+
const { multi, value, options = [] } = props;
|
|
457
|
+
let optionsToRet = options;
|
|
458
|
+
// based on incoming value hide those selected options from the option list
|
|
459
|
+
if (multi && value) {
|
|
460
|
+
const valArray = getValueArray(value);
|
|
461
|
+
optionsToRet = options.filter(op => {
|
|
462
|
+
const isOptionSelected = valArray.some(val => {
|
|
463
|
+
if (!val) return false;
|
|
464
|
+
const matching = isEqual(val.value, op.value);
|
|
465
|
+
return matching;
|
|
466
|
+
});
|
|
467
|
+
return !isOptionSelected;
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
return {
|
|
471
|
+
// unfilteredOptions is needed for finding selected items
|
|
472
|
+
unfilteredOptions: options,
|
|
473
|
+
options: optionsToRet
|
|
474
|
+
};
|
|
475
|
+
})
|
|
476
|
+
)(TgSelect);
|
|
477
|
+
|
|
478
|
+
const itemDisabled = i => i.disabled;
|
|
479
|
+
const noResultsDefault = <div>No Results...</div>;
|
|
480
|
+
|
|
481
|
+
export function createNewOption(newValString) {
|
|
482
|
+
if (!newValString) return;
|
|
483
|
+
return {
|
|
484
|
+
userCreated: true,
|
|
485
|
+
label: newValString,
|
|
486
|
+
value: newValString
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
function getValueArray(value) {
|
|
491
|
+
return value || value === 0 ? (Array.isArray(value) ? value : [value]) : [];
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
//we export this here for use in createGenericSelect
|
|
495
|
+
export const itemListPredicate = (_queryString = "", items, isSimpleSearch) => {
|
|
496
|
+
const queryString = _queryString.toLowerCase();
|
|
497
|
+
const toSearchArr = (items || []).map(item => {
|
|
498
|
+
return {
|
|
499
|
+
item,
|
|
500
|
+
text: item.toLowerCase
|
|
501
|
+
? item.toLowerCase()
|
|
502
|
+
: item.label
|
|
503
|
+
? item.label.toLowerCase
|
|
504
|
+
? item.label.toLowerCase()
|
|
505
|
+
: getTextFromEl(item.label).toLowerCase()
|
|
506
|
+
: (item.value &&
|
|
507
|
+
item.value.toLowerCase &&
|
|
508
|
+
item.value.toLowerCase()) ||
|
|
509
|
+
""
|
|
510
|
+
};
|
|
511
|
+
});
|
|
512
|
+
let toRet = toSearchArr.filter(({ text }) =>
|
|
513
|
+
(isSimpleSearch ? simplesearch : fuzzysearch)(queryString, text)
|
|
514
|
+
);
|
|
515
|
+
toRet = toRet.sort(({ text }, { text: text2 }) => {
|
|
516
|
+
return getSort(text, queryString) - getSort(text2, queryString);
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
toRet = toRet.map(({ item }) => item);
|
|
520
|
+
return toRet;
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
export function simplesearch(needle, haystack) {
|
|
524
|
+
return (haystack || "").indexOf(needle) !== -1;
|
|
525
|
+
}
|
|
526
|
+
function tagOptionRender(vals) {
|
|
527
|
+
if (vals.noTagStyle) return vals.label;
|
|
528
|
+
return <Tag {...getTagProps(vals)}></Tag>;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
function getSort(text, queryString) {
|
|
532
|
+
let ret;
|
|
533
|
+
if (text === queryString) ret = -1;
|
|
534
|
+
else if (text.includes(queryString)) ret = text.indexOf(queryString);
|
|
535
|
+
else ret = text.length;
|
|
536
|
+
return ret;
|
|
537
|
+
}
|