Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MWPW-34656: [Milo] Need the ability to reorder filter lists easily #1584

Merged
merged 10 commits into from
Dec 7, 2023
49 changes: 47 additions & 2 deletions libs/blocks/caas-config/caas-config.css
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ dd.content .sort-options > .field {
}

.multifield.filtersCustom > .multifield-set:nth-child(2) {
margin-top: -30px;
margin-top: -16px;
}

.multifield .multifield > .multifield-set:not(:nth-child(2)) {
Expand Down Expand Up @@ -97,6 +97,51 @@ dd.content .sort-options > .field {
margin-bottom: 20px;
}

.config-panel::-webkit-scrollbar {
.config-panel::-webkit-scrollbar {
display: none; /* Safari and Chrome */
}

/* Extends multifield */
[class^="multifield filters"] .multifield-header h3 {
display: flex;
justify-content: space-between;
}

[class^="multifield filters"] .multifield-set {
position: relative;
}

[class^="multifield filters"] .multifield-set .up-down {
display: flex;
font-weight: 300;
position: absolute;
top: 20px;
right: 10px;
flex-direction: column;
}

[class^="multifield filtersCustomItems"] .multifield-set .up-down {
top: 10px;
}

[class^="multifield"] + .multifield-header ~ .multifield-set .up-down .move-up {
display: none !important;
}

[class^="multifield"] .multifield-set .up-down button{
height: 17px !important;
margin: 0;
clip-path: none;
padding: 0 6px;
background-color: transparent !important;
color: #bbb !important;
}

[class^="multifield"] .multifield-set .up-down button:hover{
color: #fff !important;
}

[class^="multifield"] .move-down {
transform: rotate(180deg);
display: inline-block;
}
23 changes: 21 additions & 2 deletions libs/ui/controls/MultiField.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
const { miloLibs, codeRoot } = getConfig();
loadStyle(`${miloLibs || codeRoot}/ui/controls/multifield.css`);

const FieldSet = ({ fields, onDelete }) => html`
const FieldSet = ({ fields, onDelete, onMoveUp, onMoveDown }) => html`
<div class="multifield-set">
<div class="up-down">
<button class="move-up" title="Move Up" onClick=${onMoveUp}>▲</button>
<button class="move-down" title="Move Down" onClick=${onMoveDown}>▲</button>
</div>
<div class="multifield-fields">${fields}</div>
<button class="multifield-delete" onClick=${onDelete}></button>
</div>
Expand Down Expand Up @@ -75,13 +79,27 @@
onChange(newVals);
};

const moveFieldUp = (index) => () => {
if (index === 0) return;
const newVals = [...fieldValues];
[newVals[index], newVals[index - 1]] = [newVals[index - 1], newVals[index]];
onChange(newVals);
};

const moveFieldDown = (index) => () => {
if (index === fieldValues.length - 1) return;
const newVals = [...fieldValues];
[newVals[index], newVals[index + 1]] = [newVals[index + 1], newVals[index]];
onChange(newVals);
};

useEffect(() => {
if (parentValues) {
setFieldValues([...parentValues[parentIndex][name] ?? []]);
} else if (values) {
setFieldValues([...values]);
}
}, [values, parentValues]);

Check warning on line 102 in libs/ui/controls/MultiField.js

View workflow job for this annotation

GitHub Actions / Running eslint

[eslint] reported by reviewdog 🐶 React Hook useEffect has missing dependencies: 'name' and 'parentIndex'. Either include them or remove the dependency array. If 'setFieldValues' needs the current value of 'parentIndex', you can also switch to useReducer instead of useState and read 'parentIndex' in the reducer. Raw Output: {"ruleId":"react-hooks/exhaustive-deps","severity":1,"message":"React Hook useEffect has missing dependencies: 'name' and 'parentIndex'. Either include them or remove the dependency array. If 'setFieldValues' needs the current value of 'parentIndex', you can also switch to useReducer instead of useState and read 'parentIndex' in the reducer.","line":102,"column":6,"nodeType":"ArrayExpression","endLine":102,"endColumn":28,"suggestions":[{"desc":"Update the dependencies array to be: [values, parentValues, parentIndex, name]","fix":{"range":[3107,3129],"text":"[values, parentValues, parentIndex, name]"}}]}

useEffect(() => {
const newFieldSets = [];
Expand All @@ -92,7 +110,7 @@
});

setFieldSets(addMultifieldChangeListener(newFieldSets));
}, [fieldValues]);

Check warning on line 113 in libs/ui/controls/MultiField.js

View workflow job for this annotation

GitHub Actions / Running eslint

[eslint] reported by reviewdog 🐶 React Hook useEffect has missing dependencies: 'addMultifieldChangeListener' and 'children'. Either include them or remove the dependency array. Raw Output: {"ruleId":"react-hooks/exhaustive-deps","severity":1,"message":"React Hook useEffect has missing dependencies: 'addMultifieldChangeListener' and 'children'. Either include them or remove the dependency array.","line":113,"column":6,"nodeType":"ArrayExpression","endLine":113,"endColumn":19,"suggestions":[{"desc":"Update the dependencies array to be: [addMultifieldChangeListener, children, fieldValues]","fix":{"range":[3437,3450],"text":"[addMultifieldChangeListener, children, fieldValues]"}}]}

return html`
<div class=${`multifield ${className}`}>
Expand All @@ -104,7 +122,8 @@
${fieldSets.map(
(fields, idx) => {
fields.forEach((field) => (field.props.parentIndex = idx));
return html`<${FieldSet} key=${idx} fields=${fields} onDelete=${deleteFields(idx)} />`;
return html`<${FieldSet} key=${idx} fields=${fields} onDelete=${deleteFields(idx)}
onMoveUp=${moveFieldUp(idx)} onMoveDown=${moveFieldDown(idx)} />`;
},
)}
</div>
Expand Down
4 changes: 4 additions & 0 deletions libs/ui/controls/multifield.css
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@

background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='18' viewBox='0 0 18 18' width='18'%3E%3Cdefs%3E%3Cstyle%3E .fill %7B fill: %23464646; %7D %3C/style%3E%3C/defs%3E%3Ctitle%3ES DeleteOutline 18 N%3C/title%3E%3Crect id='Canvas' fill='%23ff13dc' opacity='0' width='18' height='18' /%3E%3Cpath class='fill' d='M13.7455,4l-1.154,12H4.4085L3.2545,4ZM11,1H6A1,1,0,0,0,5,2V3H1.25A.25.25,0,0,0,1,3.25v.5A.25.25,0,0,0,1.25,4h1L3.4565,16.55a.5.5,0,0,0,.5.45H13.046a.5.5,0,0,0,.5-.45L14.75,4h1A.25.25,0,0,0,16,3.75v-.5A.25.25,0,0,0,15.75,3H12V2A1,1,0,0,0,11,1ZM6,3V2h5V3Z' /%3E%3Cpath class='fill' d='M8.5,14.5A.5.5,0,0,1,8,14V6A.5.5,0,0,1,9,6v8A.5.5,0,0,1,8.5,14.5Z' /%3E%3Cpath class='fill' d='M10.467,14.5a.5.5,0,0,1-.46718-.5308L10,13.9665l.5355-7.9975a.50112.50112,0,1,1,1,.067L11,14.034a.5.5,0,0,1-.53176.46608Z' /%3E%3Cpath class='fill' d='M6.533,14.5a.5.5,0,0,0,.46718-.5308L7,13.9665,6.4625,5.969a.50112.50112,0,1,0-1,.067l.5355,8a.5.5,0,0,0,.53348.46411Z' /%3E%3C/svg%3E");
}

.multifield-set .up-down {
display: none;
}
Loading