fix: fix the linkage between search items and quick search
Quick search becomes selected when the search criteria are consistent with quick search Change-Id: I517c7f9b74a53a9aaf4facb9b1fd013e115b36b6
This commit is contained in:
parent
0775c02b67
commit
6ab6af82ad
@ -39,6 +39,19 @@ const filterParam = PropTypes.shape({
|
|||||||
isTime: PropTypes.bool,
|
isTime: PropTypes.bool,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const getCheckOptionValue = (name, key) => {
|
||||||
|
return `${name}--${key}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const getCheckValueInfo = (value = '') => {
|
||||||
|
const name = value.split('--')[0];
|
||||||
|
const key = value.split('--')[1];
|
||||||
|
return {
|
||||||
|
name,
|
||||||
|
key,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export const getTags = (initValue, filterParams) => {
|
export const getTags = (initValue, filterParams) => {
|
||||||
if (!initValue || isEmpty(initValue)) {
|
if (!initValue || isEmpty(initValue)) {
|
||||||
return {};
|
return {};
|
||||||
@ -56,7 +69,7 @@ export const getTags = (initValue, filterParams) => {
|
|||||||
if (options.length) {
|
if (options.length) {
|
||||||
const optionItem = options.find((op) => op.key === value);
|
const optionItem = options.find((op) => op.key === value);
|
||||||
if (optionItem && optionItem.isQuick) {
|
if (optionItem && optionItem.isQuick) {
|
||||||
checkValues.push(`${item.name}--${value}`);
|
checkValues.push(getCheckOptionValue(item.name, value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tags.push({
|
tags.push({
|
||||||
@ -188,7 +201,7 @@ class MagicInput extends PureComponent {
|
|||||||
const { tags, checkValues } = this.state;
|
const { tags, checkValues } = this.state;
|
||||||
const newTags = tags.filter((it) => it.filter.name !== name);
|
const newTags = tags.filter((it) => it.filter.name !== name);
|
||||||
const leftCheckValues = checkValues.filter(
|
const leftCheckValues = checkValues.filter(
|
||||||
(it) => it.split('--')[0] !== name
|
(it) => getCheckValueInfo(it).name !== name
|
||||||
);
|
);
|
||||||
this.setState(
|
this.setState(
|
||||||
{
|
{
|
||||||
@ -406,11 +419,20 @@ class MagicInput extends PureComponent {
|
|||||||
this.clearInputValue();
|
this.clearInputValue();
|
||||||
const newTags = tags.filter((it) => it.filter.name !== newTag.filter.name);
|
const newTags = tags.filter((it) => it.filter.name !== newTag.filter.name);
|
||||||
newTags.push(newTag);
|
newTags.push(newTag);
|
||||||
|
const quickTags = newTags.filter((it) => {
|
||||||
|
const { value: tagValue, filter: { options = [] } = {} } = it;
|
||||||
|
const quickOption = options.find((o) => o.key === tagValue && o.isQuick);
|
||||||
|
return !!quickOption;
|
||||||
|
});
|
||||||
|
const checkValues = quickTags.map((it) => {
|
||||||
|
return getCheckOptionValue(it.filter.name, it.value);
|
||||||
|
});
|
||||||
this.setState(
|
this.setState(
|
||||||
{
|
{
|
||||||
tags: newTags,
|
tags: newTags,
|
||||||
currentFilter: null,
|
currentFilter: null,
|
||||||
inputValue: '',
|
inputValue: '',
|
||||||
|
checkValues,
|
||||||
},
|
},
|
||||||
() => {
|
() => {
|
||||||
this.onTagsChange();
|
this.onTagsChange();
|
||||||
@ -464,7 +486,7 @@ class MagicInput extends PureComponent {
|
|||||||
});
|
});
|
||||||
const checkValuesNames = Array.from(
|
const checkValuesNames = Array.from(
|
||||||
new Set([...checkValues, ...values])
|
new Set([...checkValues, ...values])
|
||||||
).map((it) => it.split('--')[0]);
|
).map((it) => getCheckValueInfo(it).name);
|
||||||
const { filterParams } = this.props;
|
const { filterParams } = this.props;
|
||||||
const { tags } = this.state;
|
const { tags } = this.state;
|
||||||
const otherTags = tags.filter(
|
const otherTags = tags.filter(
|
||||||
@ -474,8 +496,7 @@ class MagicInput extends PureComponent {
|
|||||||
changedValues.forEach((it) => {
|
changedValues.forEach((it) => {
|
||||||
const { key, value } = it;
|
const { key, value } = it;
|
||||||
if (value) {
|
if (value) {
|
||||||
const name = key.split('--')[0];
|
const { name, key: realValue } = getCheckValueInfo(key);
|
||||||
const realValue = key.split('--')[1];
|
|
||||||
const filter = filterParams.find((tt) => tt.name === name);
|
const filter = filterParams.find((tt) => tt.name === name);
|
||||||
newTags.push({
|
newTags.push({
|
||||||
value: realValue,
|
value: realValue,
|
||||||
@ -504,7 +525,7 @@ class MagicInput extends PureComponent {
|
|||||||
const { checkLabel, key, father } = it;
|
const { checkLabel, key, father } = it;
|
||||||
return {
|
return {
|
||||||
label: checkLabel,
|
label: checkLabel,
|
||||||
value: `${father.name}--${key}`,
|
value: getCheckOptionValue(father.name, key),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
return (
|
return (
|
||||||
|
Loading…
Reference in New Issue
Block a user