@atlaskit/link-datasource 1.12.4 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/cjs/analytics/constants.js +1 -1
- package/dist/cjs/ui/jira-issues-modal/basic-filters/utils/isClauseTooComplex.js +93 -0
- package/dist/cjs/ui/jira-issues-modal/basic-filters/utils/isQueryTooComplex.js +146 -0
- package/dist/cjs/ui/jira-issues-modal/jira-search-container/buildJQL.js +3 -2
- package/dist/cjs/ui/jira-issues-modal/jira-search-container/index.js +21 -8
- package/dist/cjs/ui/jira-issues-modal/jira-search-container/messages.js +5 -0
- package/dist/cjs/ui/jira-issues-modal/mode-switcher/index.js +28 -16
- package/dist/es2019/analytics/constants.js +1 -1
- package/dist/es2019/ui/jira-issues-modal/basic-filters/utils/isClauseTooComplex.js +77 -0
- package/dist/es2019/ui/jira-issues-modal/basic-filters/utils/isQueryTooComplex.js +105 -0
- package/dist/es2019/ui/jira-issues-modal/jira-search-container/buildJQL.js +2 -1
- package/dist/es2019/ui/jira-issues-modal/jira-search-container/index.js +13 -3
- package/dist/es2019/ui/jira-issues-modal/jira-search-container/messages.js +5 -0
- package/dist/es2019/ui/jira-issues-modal/mode-switcher/index.js +19 -9
- package/dist/esm/analytics/constants.js +1 -1
- package/dist/esm/ui/jira-issues-modal/basic-filters/utils/isClauseTooComplex.js +86 -0
- package/dist/esm/ui/jira-issues-modal/basic-filters/utils/isQueryTooComplex.js +140 -0
- package/dist/esm/ui/jira-issues-modal/jira-search-container/buildJQL.js +2 -1
- package/dist/esm/ui/jira-issues-modal/jira-search-container/index.js +21 -8
- package/dist/esm/ui/jira-issues-modal/jira-search-container/messages.js +5 -0
- package/dist/esm/ui/jira-issues-modal/mode-switcher/index.js +29 -17
- package/dist/types/ui/jira-issues-modal/basic-filters/utils/isClauseTooComplex.d.ts +2 -0
- package/dist/types/ui/jira-issues-modal/basic-filters/utils/isQueryTooComplex.d.ts +1 -0
- package/dist/types/ui/jira-issues-modal/jira-search-container/buildJQL.d.ts +1 -0
- package/dist/types/ui/jira-issues-modal/jira-search-container/index.d.ts +1 -0
- package/dist/types/ui/jira-issues-modal/jira-search-container/messages.d.ts +5 -0
- package/dist/types/ui/jira-issues-modal/mode-switcher/index.d.ts +2 -0
- package/dist/types-ts4.5/ui/jira-issues-modal/basic-filters/utils/isClauseTooComplex.d.ts +2 -0
- package/dist/types-ts4.5/ui/jira-issues-modal/basic-filters/utils/isQueryTooComplex.d.ts +1 -0
- package/dist/types-ts4.5/ui/jira-issues-modal/jira-search-container/buildJQL.d.ts +1 -0
- package/dist/types-ts4.5/ui/jira-issues-modal/jira-search-container/index.d.ts +1 -0
- package/dist/types-ts4.5/ui/jira-issues-modal/jira-search-container/messages.d.ts +5 -0
- package/dist/types-ts4.5/ui/jira-issues-modal/mode-switcher/index.d.ts +2 -0
- package/package.json +1 -2
- package/dist/cjs/ui/jira-issues-modal/basic-filters/hooks/useIsComplexQuery.js +0 -12
- package/dist/es2019/ui/jira-issues-modal/basic-filters/hooks/useIsComplexQuery.js +0 -6
- package/dist/esm/ui/jira-issues-modal/basic-filters/hooks/useIsComplexQuery.js +0 -6
- package/dist/types/ui/jira-issues-modal/basic-filters/hooks/useIsComplexQuery.d.ts +0 -3
- package/dist/types-ts4.5/ui/jira-issues-modal/basic-filters/hooks/useIsComplexQuery.d.ts +0 -3
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
|
-
import React, { useCallback, useMemo, useState } from 'react';
|
|
2
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
3
3
|
import { css, jsx } from '@emotion/react';
|
|
4
4
|
import { useIntl } from 'react-intl-next';
|
|
5
5
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
6
6
|
import { useDatasourceAnalyticsEvents } from '../../../analytics';
|
|
7
7
|
import { BasicFilters } from '../basic-filters';
|
|
8
|
+
import { isQueryTooComplex } from '../basic-filters/utils/isQueryTooComplex';
|
|
8
9
|
import { BasicSearchInput } from '../basic-search-input';
|
|
9
10
|
import { JiraJQLEditor } from '../jql-editor';
|
|
10
11
|
import { ModeSwitcher } from '../mode-switcher';
|
|
@@ -17,6 +18,7 @@ const inputContainerStyles = css({
|
|
|
17
18
|
minHeight: '60px'
|
|
18
19
|
});
|
|
19
20
|
const DEFAULT_JQL_QUERY = 'created >= -30d order by created DESC';
|
|
21
|
+
export const ALLOWED_ORDER_BY_KEYS = ['key', 'summary', 'assignee', 'status', 'created'];
|
|
20
22
|
const JiraSearchMethodSwitcher = ModeSwitcher;
|
|
21
23
|
export const JiraSearchContainer = props => {
|
|
22
24
|
const {
|
|
@@ -36,6 +38,7 @@ export const JiraSearchContainer = props => {
|
|
|
36
38
|
const [basicSearchTerm, setBasicSearchTerm] = useState('');
|
|
37
39
|
const [currentSearchMethod, setCurrentSearchMethod] = useState(initialSearchMethod);
|
|
38
40
|
const [jql, setJql] = useState(initialJql || DEFAULT_JQL_QUERY);
|
|
41
|
+
const [isComplexQuery, setIsComplexQuery] = useState(false);
|
|
39
42
|
const [orderKey, setOrderKey] = useState();
|
|
40
43
|
const [orderDirection, setOrderDirection] = useState();
|
|
41
44
|
const {
|
|
@@ -63,7 +66,7 @@ export const JiraSearchContainer = props => {
|
|
|
63
66
|
const order = hasOrder ? (_fragments$at3 = fragments.at(-1)) === null || _fragments$at3 === void 0 ? void 0 : _fragments$at3.split(' ').at(-1) : undefined;
|
|
64
67
|
|
|
65
68
|
// TODO: confirm if these are the only order keys we want to preserve - existing whiteboard logic
|
|
66
|
-
if (key &&
|
|
69
|
+
if (key && ALLOWED_ORDER_BY_KEYS.includes(key)) {
|
|
67
70
|
setOrderKey(key);
|
|
68
71
|
setOrderDirection(order);
|
|
69
72
|
}
|
|
@@ -73,6 +76,7 @@ export const JiraSearchContainer = props => {
|
|
|
73
76
|
onSearch({
|
|
74
77
|
jql
|
|
75
78
|
}, currentSearchMethod);
|
|
79
|
+
setIsComplexQuery(isQueryTooComplex(jql));
|
|
76
80
|
if (currentSearchMethod === 'basic') {
|
|
77
81
|
fireEvent('ui.form.submitted.basicSearch', {});
|
|
78
82
|
} else if (currentSearchMethod === 'jql') {
|
|
@@ -85,6 +89,10 @@ export const JiraSearchContainer = props => {
|
|
|
85
89
|
}
|
|
86
90
|
return false;
|
|
87
91
|
}, []);
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
setIsComplexQuery(isQueryTooComplex(jql));
|
|
94
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
95
|
+
}, []);
|
|
88
96
|
return jsx("div", {
|
|
89
97
|
css: inputContainerStyles
|
|
90
98
|
}, currentSearchMethod === 'basic' && jsx(React.Fragment, null, jsx(BasicSearchInput, {
|
|
@@ -109,7 +117,9 @@ export const JiraSearchContainer = props => {
|
|
|
109
117
|
value: 'jql'
|
|
110
118
|
}, {
|
|
111
119
|
label: formatMessage(modeSwitcherMessages.basicTextSearchLabel),
|
|
112
|
-
value: 'basic'
|
|
120
|
+
value: 'basic',
|
|
121
|
+
disabled: isComplexQuery,
|
|
122
|
+
tooltipText: isComplexQuery ? formatMessage(modeSwitcherMessages.basicModeSwitchDisabledTooltipText) : ''
|
|
113
123
|
}]
|
|
114
124
|
}));
|
|
115
125
|
};
|
|
@@ -4,5 +4,10 @@ export const modeSwitcherMessages = defineMessages({
|
|
|
4
4
|
id: 'linkDataSource.jira-issues.configmodal.basicModeText',
|
|
5
5
|
description: 'Display text for basic text search toggle button',
|
|
6
6
|
defaultMessage: 'Basic'
|
|
7
|
+
},
|
|
8
|
+
basicModeSwitchDisabledTooltipText: {
|
|
9
|
+
id: 'linkDataSource.jira-issues.configmodal.basicModeSwitchDisabledTooltipText',
|
|
10
|
+
description: 'Display tooltip text when basic mode switch is disabled',
|
|
11
|
+
defaultMessage: "You can't switch to basic for this query."
|
|
7
12
|
}
|
|
8
13
|
});
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
1
2
|
/** @jsx jsx */
|
|
2
3
|
import React from 'react';
|
|
3
4
|
import { css, jsx } from '@emotion/react';
|
|
4
|
-
import { N0, N20, N30A, N700 } from '@atlaskit/theme/colors';
|
|
5
|
+
import { N0, N20, N30A, N60, N700 } from '@atlaskit/theme/colors';
|
|
6
|
+
import Tooltip from '@atlaskit/tooltip';
|
|
5
7
|
const modeSwitcherStyles = css({
|
|
6
8
|
alignItems: 'center',
|
|
7
9
|
background: `var(--ds-background-neutral, ${N20})`,
|
|
@@ -44,8 +46,12 @@ const modeSwitcherLabelSelectedStyles = css({
|
|
|
44
46
|
}
|
|
45
47
|
});
|
|
46
48
|
const modeSwitcherLabelDisabledStyles = css({
|
|
49
|
+
color: `var(--ds-text-disabled, ${N60})`
|
|
50
|
+
});
|
|
51
|
+
const modeSwitcherDisabledStyles = css({
|
|
47
52
|
':hover': {
|
|
48
|
-
cursor: 'not-allowed'
|
|
53
|
+
cursor: 'not-allowed',
|
|
54
|
+
background: 'transparent'
|
|
49
55
|
}
|
|
50
56
|
});
|
|
51
57
|
const compactModeSwitcherLabelStyles = css({
|
|
@@ -69,22 +75,26 @@ export const ModeSwitcher = props => {
|
|
|
69
75
|
disabled: isDisabled
|
|
70
76
|
}, options.map(({
|
|
71
77
|
value,
|
|
72
|
-
label
|
|
78
|
+
label,
|
|
79
|
+
disabled: isOptionDisabled,
|
|
80
|
+
tooltipText
|
|
73
81
|
}) => {
|
|
74
82
|
const isSelected = value === selectedOptionValue;
|
|
75
|
-
return jsx(
|
|
83
|
+
return jsx(Tooltip, {
|
|
84
|
+
content: tooltipText
|
|
85
|
+
}, tooltipProps => jsx("label", _extends({}, tooltipProps, {
|
|
76
86
|
key: value,
|
|
77
|
-
css: [modeSwitcherLabelStyles, isCompact && compactModeSwitcherLabelStyles, isSelected && modeSwitcherLabelSelectedStyles, isDisabled && modeSwitcherLabelDisabledStyles],
|
|
87
|
+
css: [modeSwitcherLabelStyles, isCompact && compactModeSwitcherLabelStyles, isSelected && modeSwitcherLabelSelectedStyles, isDisabled && modeSwitcherDisabledStyles, isOptionDisabled && [modeSwitcherLabelDisabledStyles, modeSwitcherDisabledStyles]],
|
|
78
88
|
"data-testid": `mode-toggle-${value}`
|
|
79
|
-
}, label, jsx("input", {
|
|
89
|
+
}), label, jsx("input", {
|
|
80
90
|
"aria-checked": isSelected,
|
|
81
|
-
"aria-disabled":
|
|
91
|
+
"aria-disabled": isOptionDisabled,
|
|
82
92
|
checked: isSelected,
|
|
83
93
|
css: modeInputStyles,
|
|
84
|
-
disabled:
|
|
94
|
+
disabled: isOptionDisabled,
|
|
85
95
|
onChange: handleModeChange,
|
|
86
96
|
type: "radio",
|
|
87
97
|
value: value
|
|
88
|
-
}));
|
|
98
|
+
})));
|
|
89
99
|
})) : null;
|
|
90
100
|
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import { CLAUSE_TYPE_COMPOUND, CLAUSE_TYPE_TERMINAL, OPERAND_TYPE_VALUE } from '@atlaskit/jql-ast';
|
|
3
|
+
import { fuzzyCharacter } from '../../jira-search-container/buildJQL';
|
|
4
|
+
var removeFuzzyCharacter = function removeFuzzyCharacter(value) {
|
|
5
|
+
if (value !== null && value !== void 0 && value.endsWith(fuzzyCharacter)) {
|
|
6
|
+
return value.slice(0, -1);
|
|
7
|
+
}
|
|
8
|
+
return value;
|
|
9
|
+
};
|
|
10
|
+
var getValueFromTerminalClause = function getValueFromTerminalClause(clause) {
|
|
11
|
+
var operand = clause.operand;
|
|
12
|
+
return operand !== undefined && operand.operandType === OPERAND_TYPE_VALUE && removeFuzzyCharacter(operand.value) || undefined;
|
|
13
|
+
};
|
|
14
|
+
var areClauseFieldValuesEqual = function areClauseFieldValuesEqual(clauseA, clauseB, clauseC) {
|
|
15
|
+
var valueA = clauseA && getValueFromTerminalClause(clauseA);
|
|
16
|
+
var valueB = clauseB && getValueFromTerminalClause(clauseB);
|
|
17
|
+
var valueC = clauseC && getValueFromTerminalClause(clauseC);
|
|
18
|
+
var values = [valueA, valueB, valueC].filter(Boolean);
|
|
19
|
+
|
|
20
|
+
// checks if valid fields, text, summary and key have the same value, if not, its a complex query and cannnot be recreated in basic mode
|
|
21
|
+
return values.length > 1 && values.every(function (value) {
|
|
22
|
+
return value === values[0];
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
var areClauseFieldKeysAllowed = function areClauseFieldKeysAllowed(clauseA, clauseB, clauseC) {
|
|
26
|
+
var fieldA = clauseA.field.value;
|
|
27
|
+
var fieldB = clauseB.field.value;
|
|
28
|
+
var fieldC = clauseC === null || clauseC === void 0 ? void 0 : clauseC.field.value; // clauseC only if jql with 3 OR clauses, 'text ~ "EDM-6023*" or summary ~ "EDM-6023*" or key = EDM-6023 ORDER BY created DESC',
|
|
29
|
+
|
|
30
|
+
return [fieldA, fieldB, fieldC].filter(Boolean).every(function (field) {
|
|
31
|
+
return ['summary', 'text', 'key'].includes(field);
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var doesCompoundClauseContainAllTerminalClauses = function doesCompoundClauseContainAllTerminalClauses(clauses) {
|
|
35
|
+
return clauses.every(function (clauses) {
|
|
36
|
+
return clauses.clauseType === CLAUSE_TYPE_TERMINAL;
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
export var isClauseTooComplex = function isClauseTooComplex(clauses, key) {
|
|
40
|
+
if (key === 'text') {
|
|
41
|
+
var _clauses = _slicedToArray(clauses, 1),
|
|
42
|
+
clause = _clauses[0];
|
|
43
|
+
if (clause.clauseType === CLAUSE_TYPE_COMPOUND) {
|
|
44
|
+
var textClauses = clause.clauses;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* valid: text ~ "test*" or summary ~ "test*" ORDER BY created DESC
|
|
48
|
+
* valid: text ~ "EDM-6023*" or summary ~ "EDM-6023*" or key = EDM-6023 ORDER BY created DESC
|
|
49
|
+
* invalid: assignee = "me" or text ~ "EDM-6023*" or summary ~ "EDM-6023*" or key = EDM-6023 ORDER BY created DESC
|
|
50
|
+
*/
|
|
51
|
+
if (textClauses.length !== 2 && textClauses.length !== 3) {
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* valid: text ~ "test*" or summary ~ "test*"
|
|
57
|
+
* invalid: text ~ "test" or (summary ~ "test" or key = "test")
|
|
58
|
+
*/
|
|
59
|
+
if (!doesCompoundClauseContainAllTerminalClauses(textClauses)) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
var _textClauses = _slicedToArray(textClauses, 3),
|
|
63
|
+
clauseA = _textClauses[0],
|
|
64
|
+
clauseB = _textClauses[1],
|
|
65
|
+
clauseC = _textClauses[2];
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* valid: text ~ "EDM-6023*" or summary ~ "EDM-6023*" or key = EDM-6023 ORDER BY created DESC
|
|
69
|
+
* invalid: text ~ "EDM-6023*" or summary ~ "anotherValue" ORDER BY created DESC
|
|
70
|
+
* invalid: text ~ "EDM-6023*" or text ~ "anotherValue" ORDER BY created DESC
|
|
71
|
+
*/
|
|
72
|
+
if (!areClauseFieldValuesEqual(clauseA, clauseB, clauseC)) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* valid: text ~ "EDM-6023*" ORDER BY created DESC
|
|
78
|
+
* invalid: resolution = 40134 ORDER BY created DESC
|
|
79
|
+
*/
|
|
80
|
+
if (!areClauseFieldKeysAllowed(clauseA, clauseB, clauseC)) {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return clauses.length > 1;
|
|
86
|
+
};
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
5
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
6
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
7
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
8
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
9
|
+
import _wrapNativeSuper from "@babel/runtime/helpers/wrapNativeSuper";
|
|
10
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
11
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
12
|
+
import mergeWith from 'lodash/mergeWith';
|
|
13
|
+
import { AbstractJastVisitor, COMPOUND_OPERATOR_AND, COMPOUND_OPERATOR_OR, JastBuilder, OPERATOR_EQUALS, OPERATOR_GT_EQUALS, OPERATOR_IN, OPERATOR_LIKE } from '@atlaskit/jql-ast';
|
|
14
|
+
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
15
|
+
import { ALLOWED_ORDER_BY_KEYS } from '../../jira-search-container';
|
|
16
|
+
import { isClauseTooComplex } from './isClauseTooComplex';
|
|
17
|
+
import { isValidJql } from './index';
|
|
18
|
+
|
|
19
|
+
// Map of field keys to their respective clauses in the Jast
|
|
20
|
+
|
|
21
|
+
var allowedFields = [
|
|
22
|
+
// basic filter fields
|
|
23
|
+
'assignee', 'issuetype', 'project', 'status',
|
|
24
|
+
// search input fields
|
|
25
|
+
'text', 'summary', 'key',
|
|
26
|
+
// orderby field
|
|
27
|
+
'created'];
|
|
28
|
+
var fallbackOperators = [OPERATOR_IN];
|
|
29
|
+
var fieldSpecificOperators = {
|
|
30
|
+
text: [OPERATOR_LIKE, OPERATOR_EQUALS],
|
|
31
|
+
summary: [OPERATOR_LIKE, OPERATOR_EQUALS],
|
|
32
|
+
key: [OPERATOR_EQUALS],
|
|
33
|
+
created: [OPERATOR_GT_EQUALS],
|
|
34
|
+
project: [OPERATOR_IN, OPERATOR_EQUALS],
|
|
35
|
+
issuetype: [OPERATOR_IN, OPERATOR_EQUALS],
|
|
36
|
+
status: [OPERATOR_IN, OPERATOR_EQUALS],
|
|
37
|
+
assignee: [OPERATOR_IN, OPERATOR_EQUALS]
|
|
38
|
+
};
|
|
39
|
+
var JqlClauseCollectingVisitorError = /*#__PURE__*/function (_Error) {
|
|
40
|
+
_inherits(JqlClauseCollectingVisitorError, _Error);
|
|
41
|
+
var _super = _createSuper(JqlClauseCollectingVisitorError);
|
|
42
|
+
function JqlClauseCollectingVisitorError() {
|
|
43
|
+
_classCallCheck(this, JqlClauseCollectingVisitorError);
|
|
44
|
+
return _super.apply(this, arguments);
|
|
45
|
+
}
|
|
46
|
+
return _createClass(JqlClauseCollectingVisitorError);
|
|
47
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
48
|
+
/**
|
|
49
|
+
* Rather than having to navigate the entire tree structure ourself, we extend AbstractJastVisitor
|
|
50
|
+
* class and implement visitor functions for node types that we wish to process.
|
|
51
|
+
* A list of available visitor can be viewed in packages/jql/jql-ast/src/types/api/jast-visitor.ts
|
|
52
|
+
* more info - https://atlaskit.atlassian.com/packages/jql/jql-ast/docs/traversing-the-ast
|
|
53
|
+
* */
|
|
54
|
+
var JqlClauseCollectingVisitor = /*#__PURE__*/function (_AbstractJastVisitor) {
|
|
55
|
+
_inherits(JqlClauseCollectingVisitor, _AbstractJastVisitor);
|
|
56
|
+
var _super2 = _createSuper(JqlClauseCollectingVisitor);
|
|
57
|
+
function JqlClauseCollectingVisitor() {
|
|
58
|
+
var _this;
|
|
59
|
+
_classCallCheck(this, JqlClauseCollectingVisitor);
|
|
60
|
+
_this = _super2.call(this);
|
|
61
|
+
_defineProperty(_assertThisInitialized(_this), "visitNotClause", function () {
|
|
62
|
+
throw new JqlClauseCollectingVisitorError('Visited an unsupported node while traversing the AST');
|
|
63
|
+
});
|
|
64
|
+
_defineProperty(_assertThisInitialized(_this), "visitOrderByField", function (orderByField) {
|
|
65
|
+
var _orderByField$field$v;
|
|
66
|
+
var fieldValue = (_orderByField$field$v = orderByField.field.value) === null || _orderByField$field$v === void 0 ? void 0 : _orderByField$field$v.toLowerCase();
|
|
67
|
+
if (fieldValue && !ALLOWED_ORDER_BY_KEYS.includes(fieldValue)) {
|
|
68
|
+
throw new JqlClauseCollectingVisitorError("query with order by field '".concat(fieldValue, "' is not supported"));
|
|
69
|
+
}
|
|
70
|
+
return {};
|
|
71
|
+
});
|
|
72
|
+
_defineProperty(_assertThisInitialized(_this), "visitCompoundClause", function (compoundClause) {
|
|
73
|
+
var clauseMap = {};
|
|
74
|
+
var operator = compoundClause.operator.value;
|
|
75
|
+
if (operator === COMPOUND_OPERATOR_AND) {
|
|
76
|
+
return compoundClause.clauses.reduce(function (result, clause) {
|
|
77
|
+
return _this.aggregateResult(clause.accept(_assertThisInitialized(_this)), result);
|
|
78
|
+
}, clauseMap);
|
|
79
|
+
}
|
|
80
|
+
if (operator === COMPOUND_OPERATOR_OR) {
|
|
81
|
+
// this is delt with in isClauseTooComplex
|
|
82
|
+
return _this.aggregateResult({
|
|
83
|
+
text: [compoundClause]
|
|
84
|
+
}, clauseMap);
|
|
85
|
+
}
|
|
86
|
+
throw new JqlClauseCollectingVisitorError("Compound clauses using the operator '".concat(operator, "' is not supported"));
|
|
87
|
+
});
|
|
88
|
+
_defineProperty(_assertThisInitialized(_this), "visitTerminalClause", function (terminalClause) {
|
|
89
|
+
var _terminalClause$opera;
|
|
90
|
+
var fieldName = terminalClause.field.value.toLowerCase();
|
|
91
|
+
if (!allowedFields.includes(fieldName)) {
|
|
92
|
+
throw new JqlClauseCollectingVisitorError("Field with name '".concat(fieldName, "' of type ").concat(terminalClause.clauseType, " is not supported"));
|
|
93
|
+
}
|
|
94
|
+
var operator = (_terminalClause$opera = terminalClause.operator) === null || _terminalClause$opera === void 0 ? void 0 : _terminalClause$opera.value;
|
|
95
|
+
var allowedOperators = fieldSpecificOperators[fieldName] || fallbackOperators;
|
|
96
|
+
if (operator && !allowedOperators.includes(operator.toLowerCase())) {
|
|
97
|
+
throw new JqlClauseCollectingVisitorError("Field with name '".concat(fieldName, "' using operator ").concat(operator, " is not supported"));
|
|
98
|
+
}
|
|
99
|
+
return _defineProperty({}, terminalClause.field.value.toLowerCase(), [terminalClause]);
|
|
100
|
+
});
|
|
101
|
+
return _this;
|
|
102
|
+
}
|
|
103
|
+
_createClass(JqlClauseCollectingVisitor, [{
|
|
104
|
+
key: "aggregateResult",
|
|
105
|
+
value: function aggregateResult(aggregate, nextResult) {
|
|
106
|
+
return mergeWith(aggregate, nextResult, function (destValue, srcValue) {
|
|
107
|
+
return srcValue.concat(destValue !== null && destValue !== void 0 ? destValue : []);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}, {
|
|
111
|
+
key: "defaultResult",
|
|
112
|
+
value: function defaultResult() {
|
|
113
|
+
return {};
|
|
114
|
+
}
|
|
115
|
+
}]);
|
|
116
|
+
return JqlClauseCollectingVisitor;
|
|
117
|
+
}(AbstractJastVisitor);
|
|
118
|
+
export var isQueryTooComplex = function isQueryTooComplex(jql) {
|
|
119
|
+
if (!getBooleanFF('platform.linking-platform.datasource.show-jlol-basic-filters') || !jql) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
if (!isValidJql(jql)) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
var jast = new JastBuilder().build(jql);
|
|
126
|
+
try {
|
|
127
|
+
var jqlClauseCollectingVisitor = new JqlClauseCollectingVisitor();
|
|
128
|
+
var clauseMap = jast.query ? jast.query.accept(jqlClauseCollectingVisitor) : {}; // jast.query is defined as void | Query, hence the fallback
|
|
129
|
+
|
|
130
|
+
var hasAnyKeyWithComplexClause = Object.entries(clauseMap).some(function (_ref2) {
|
|
131
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
132
|
+
key = _ref3[0],
|
|
133
|
+
clauses = _ref3[1];
|
|
134
|
+
return isClauseTooComplex(clauses, key);
|
|
135
|
+
});
|
|
136
|
+
return hasAnyKeyWithComplexClause;
|
|
137
|
+
} catch (error) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
};
|
|
@@ -2,6 +2,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
2
2
|
import { COMPOUND_OPERATOR_AND, COMPOUND_OPERATOR_OR, creators, JastBuilder, OPERATOR_EQUALS, OPERATOR_GT_EQUALS, OPERATOR_IN, OPERATOR_LIKE, ORDER_BY_DIRECTION_ASC, ORDER_BY_DIRECTION_DESC, print } from '@atlaskit/jql-ast';
|
|
3
3
|
var fuzzySearchRegExp = /^"(.+)"$/;
|
|
4
4
|
var jiraIssueKeyRegExp = /[A-Z]+-\d+/;
|
|
5
|
+
export var fuzzyCharacter = '*';
|
|
5
6
|
var constructTerminalClause = function constructTerminalClause(field, operator, value) {
|
|
6
7
|
return creators.terminalClause(creators.field(field), creators.operator(operator), creators.valueOperand(value));
|
|
7
8
|
};
|
|
@@ -23,7 +24,7 @@ export var buildJQL = function buildJQL(input) {
|
|
|
23
24
|
return '';
|
|
24
25
|
}
|
|
25
26
|
if (trimmedRawSearch) {
|
|
26
|
-
var fuzzy = !trimmedRawSearch.match(fuzzySearchRegExp) ?
|
|
27
|
+
var fuzzy = !trimmedRawSearch.match(fuzzySearchRegExp) ? fuzzyCharacter : '';
|
|
27
28
|
var basicSearch = trimmedRawSearch.replace(/['"?*]+/g, '');
|
|
28
29
|
var text = constructTerminalClause('text', OPERATOR_LIKE, "".concat(basicSearch).concat(fuzzy));
|
|
29
30
|
var summary = constructTerminalClause('summary', OPERATOR_LIKE, "".concat(basicSearch).concat(fuzzy));
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
2
|
/** @jsx jsx */
|
|
3
|
-
import React, { useCallback, useMemo, useState } from 'react';
|
|
3
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
4
4
|
import { css, jsx } from '@emotion/react';
|
|
5
5
|
import { useIntl } from 'react-intl-next';
|
|
6
6
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
7
7
|
import { useDatasourceAnalyticsEvents } from '../../../analytics';
|
|
8
8
|
import { BasicFilters } from '../basic-filters';
|
|
9
|
+
import { isQueryTooComplex } from '../basic-filters/utils/isQueryTooComplex';
|
|
9
10
|
import { BasicSearchInput } from '../basic-search-input';
|
|
10
11
|
import { JiraJQLEditor } from '../jql-editor';
|
|
11
12
|
import { ModeSwitcher } from '../mode-switcher';
|
|
@@ -18,6 +19,7 @@ var inputContainerStyles = css({
|
|
|
18
19
|
minHeight: '60px'
|
|
19
20
|
});
|
|
20
21
|
var DEFAULT_JQL_QUERY = 'created >= -30d order by created DESC';
|
|
22
|
+
export var ALLOWED_ORDER_BY_KEYS = ['key', 'summary', 'assignee', 'status', 'created'];
|
|
21
23
|
var JiraSearchMethodSwitcher = ModeSwitcher;
|
|
22
24
|
export var JiraSearchContainer = function JiraSearchContainer(props) {
|
|
23
25
|
var isSearching = props.isSearching,
|
|
@@ -42,14 +44,18 @@ export var JiraSearchContainer = function JiraSearchContainer(props) {
|
|
|
42
44
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
43
45
|
jql = _useState6[0],
|
|
44
46
|
setJql = _useState6[1];
|
|
45
|
-
var _useState7 = useState(),
|
|
47
|
+
var _useState7 = useState(false),
|
|
46
48
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
isComplexQuery = _useState8[0],
|
|
50
|
+
setIsComplexQuery = _useState8[1];
|
|
49
51
|
var _useState9 = useState(),
|
|
50
52
|
_useState10 = _slicedToArray(_useState9, 2),
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
orderKey = _useState10[0],
|
|
54
|
+
setOrderKey = _useState10[1];
|
|
55
|
+
var _useState11 = useState(),
|
|
56
|
+
_useState12 = _slicedToArray(_useState11, 2),
|
|
57
|
+
orderDirection = _useState12[0],
|
|
58
|
+
setOrderDirection = _useState12[1];
|
|
53
59
|
var _useDatasourceAnalyti = useDatasourceAnalyticsEvents(),
|
|
54
60
|
fireEvent = _useDatasourceAnalyti.fireEvent;
|
|
55
61
|
var onSearchMethodChange = useCallback(function (searchMethod) {
|
|
@@ -76,7 +82,7 @@ export var JiraSearchContainer = function JiraSearchContainer(props) {
|
|
|
76
82
|
var order = hasOrder ? (_fragments$at3 = fragments.at(-1)) === null || _fragments$at3 === void 0 ? void 0 : _fragments$at3.split(' ').at(-1) : undefined;
|
|
77
83
|
|
|
78
84
|
// TODO: confirm if these are the only order keys we want to preserve - existing whiteboard logic
|
|
79
|
-
if (key &&
|
|
85
|
+
if (key && ALLOWED_ORDER_BY_KEYS.includes(key)) {
|
|
80
86
|
setOrderKey(key);
|
|
81
87
|
setOrderDirection(order);
|
|
82
88
|
}
|
|
@@ -86,6 +92,7 @@ export var JiraSearchContainer = function JiraSearchContainer(props) {
|
|
|
86
92
|
onSearch({
|
|
87
93
|
jql: jql
|
|
88
94
|
}, currentSearchMethod);
|
|
95
|
+
setIsComplexQuery(isQueryTooComplex(jql));
|
|
89
96
|
if (currentSearchMethod === 'basic') {
|
|
90
97
|
fireEvent('ui.form.submitted.basicSearch', {});
|
|
91
98
|
} else if (currentSearchMethod === 'jql') {
|
|
@@ -98,6 +105,10 @@ export var JiraSearchContainer = function JiraSearchContainer(props) {
|
|
|
98
105
|
}
|
|
99
106
|
return false;
|
|
100
107
|
}, []);
|
|
108
|
+
useEffect(function () {
|
|
109
|
+
setIsComplexQuery(isQueryTooComplex(jql));
|
|
110
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
111
|
+
}, []);
|
|
101
112
|
return jsx("div", {
|
|
102
113
|
css: inputContainerStyles
|
|
103
114
|
}, currentSearchMethod === 'basic' && jsx(React.Fragment, null, jsx(BasicSearchInput, {
|
|
@@ -122,7 +133,9 @@ export var JiraSearchContainer = function JiraSearchContainer(props) {
|
|
|
122
133
|
value: 'jql'
|
|
123
134
|
}, {
|
|
124
135
|
label: formatMessage(modeSwitcherMessages.basicTextSearchLabel),
|
|
125
|
-
value: 'basic'
|
|
136
|
+
value: 'basic',
|
|
137
|
+
disabled: isComplexQuery,
|
|
138
|
+
tooltipText: isComplexQuery ? formatMessage(modeSwitcherMessages.basicModeSwitchDisabledTooltipText) : ''
|
|
126
139
|
}]
|
|
127
140
|
}));
|
|
128
141
|
};
|
|
@@ -4,5 +4,10 @@ export var modeSwitcherMessages = defineMessages({
|
|
|
4
4
|
id: 'linkDataSource.jira-issues.configmodal.basicModeText',
|
|
5
5
|
description: 'Display text for basic text search toggle button',
|
|
6
6
|
defaultMessage: 'Basic'
|
|
7
|
+
},
|
|
8
|
+
basicModeSwitchDisabledTooltipText: {
|
|
9
|
+
id: 'linkDataSource.jira-issues.configmodal.basicModeSwitchDisabledTooltipText',
|
|
10
|
+
description: 'Display tooltip text when basic mode switch is disabled',
|
|
11
|
+
defaultMessage: "You can't switch to basic for this query."
|
|
7
12
|
}
|
|
8
13
|
});
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
1
2
|
/** @jsx jsx */
|
|
2
3
|
import React from 'react';
|
|
3
4
|
import { css, jsx } from '@emotion/react';
|
|
4
|
-
import { N0, N20, N30A, N700 } from '@atlaskit/theme/colors';
|
|
5
|
+
import { N0, N20, N30A, N60, N700 } from '@atlaskit/theme/colors';
|
|
6
|
+
import Tooltip from '@atlaskit/tooltip';
|
|
5
7
|
var modeSwitcherStyles = css({
|
|
6
8
|
alignItems: 'center',
|
|
7
9
|
background: "var(--ds-background-neutral, ".concat(N20, ")"),
|
|
@@ -44,8 +46,12 @@ var modeSwitcherLabelSelectedStyles = css({
|
|
|
44
46
|
}
|
|
45
47
|
});
|
|
46
48
|
var modeSwitcherLabelDisabledStyles = css({
|
|
49
|
+
color: "var(--ds-text-disabled, ".concat(N60, ")")
|
|
50
|
+
});
|
|
51
|
+
var modeSwitcherDisabledStyles = css({
|
|
47
52
|
':hover': {
|
|
48
|
-
cursor: 'not-allowed'
|
|
53
|
+
cursor: 'not-allowed',
|
|
54
|
+
background: 'transparent'
|
|
49
55
|
}
|
|
50
56
|
});
|
|
51
57
|
var compactModeSwitcherLabelStyles = css({
|
|
@@ -68,21 +74,27 @@ export var ModeSwitcher = function ModeSwitcher(props) {
|
|
|
68
74
|
disabled: isDisabled
|
|
69
75
|
}, options.map(function (_ref) {
|
|
70
76
|
var value = _ref.value,
|
|
71
|
-
label = _ref.label
|
|
77
|
+
label = _ref.label,
|
|
78
|
+
isOptionDisabled = _ref.disabled,
|
|
79
|
+
tooltipText = _ref.tooltipText;
|
|
72
80
|
var isSelected = value === selectedOptionValue;
|
|
73
|
-
return jsx(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
return jsx(Tooltip, {
|
|
82
|
+
content: tooltipText
|
|
83
|
+
}, function (tooltipProps) {
|
|
84
|
+
return jsx("label", _extends({}, tooltipProps, {
|
|
85
|
+
key: value,
|
|
86
|
+
css: [modeSwitcherLabelStyles, isCompact && compactModeSwitcherLabelStyles, isSelected && modeSwitcherLabelSelectedStyles, isDisabled && modeSwitcherDisabledStyles, isOptionDisabled && [modeSwitcherLabelDisabledStyles, modeSwitcherDisabledStyles]],
|
|
87
|
+
"data-testid": "mode-toggle-".concat(value)
|
|
88
|
+
}), label, jsx("input", {
|
|
89
|
+
"aria-checked": isSelected,
|
|
90
|
+
"aria-disabled": isOptionDisabled,
|
|
91
|
+
checked: isSelected,
|
|
92
|
+
css: modeInputStyles,
|
|
93
|
+
disabled: isOptionDisabled,
|
|
94
|
+
onChange: handleModeChange,
|
|
95
|
+
type: "radio",
|
|
96
|
+
value: value
|
|
97
|
+
}));
|
|
98
|
+
});
|
|
87
99
|
})) : null;
|
|
88
100
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isQueryTooComplex: (jql: string) => boolean;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx } from '@emotion/react';
|
|
2
2
|
import type { JiraSearchMethod } from '../../../common/types';
|
|
3
3
|
import { JiraIssueDatasourceParameters, JiraIssueDatasourceParametersQuery } from '../types';
|
|
4
|
+
export declare const ALLOWED_ORDER_BY_KEYS: string[];
|
|
4
5
|
export interface SearchContainerProps {
|
|
5
6
|
isSearching?: boolean;
|
|
6
7
|
onSearch: (query: JiraIssueDatasourceParametersQuery, searchMethod: JiraSearchMethod) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const isQueryTooComplex: (jql: string) => boolean;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx } from '@emotion/react';
|
|
2
2
|
import type { JiraSearchMethod } from '../../../common/types';
|
|
3
3
|
import { JiraIssueDatasourceParameters, JiraIssueDatasourceParametersQuery } from '../types';
|
|
4
|
+
export declare const ALLOWED_ORDER_BY_KEYS: string[];
|
|
4
5
|
export interface SearchContainerProps {
|
|
5
6
|
isSearching?: boolean;
|
|
6
7
|
onSearch: (query: JiraIssueDatasourceParametersQuery, searchMethod: JiraSearchMethod) => void;
|