Skip to content

Commit bb6ca62

Browse files
authored
simplify properties filter ui (#2713)
* simplify properties filter ui * format
1 parent bd67803 commit bb6ca62

4 files changed

Lines changed: 226 additions & 156 deletions

File tree

src/components/TaskPropertyQueryBuilder/Messages.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,31 @@ export default defineMessages({
1919
defaultMessage: "Add Value",
2020
},
2121

22+
addRuleButton: {
23+
id: "TaskPropertyQueryBuilder.controls.addRule",
24+
defaultMessage: "Add Rule",
25+
},
26+
27+
removeRuleButton: {
28+
id: "TaskPropertyQueryBuilder.controls.removeRule",
29+
defaultMessage: "Remove Rule",
30+
},
31+
32+
conditionLabel: {
33+
id: "TaskPropertyQueryBuilder.controls.conditionLabel",
34+
defaultMessage: "Match rules using",
35+
},
36+
37+
addFilterButton: {
38+
id: "TaskPropertyQueryBuilder.controls.addFilter",
39+
defaultMessage: "Add Filter",
40+
},
41+
42+
removeFilterButton: {
43+
id: "TaskPropertyQueryBuilder.controls.removeFilter",
44+
defaultMessage: "Remove Filter",
45+
},
46+
2247
noneOption: {
2348
id: "Challenge.basemap.none",
2449
defaultMessage: "None",
@@ -78,9 +103,4 @@ export default defineMessages({
78103
id: "TaskPropertyQueryBuilder.error.missingStyleName",
79104
defaultMessage: "You must choose a style name.",
80105
},
81-
82-
commaSeparateValues: {
83-
id: "TaskPropertyQueryBuilder.commaSeparateValues.label",
84-
defaultMessage: "Comma separate values",
85-
},
86106
});

src/components/TaskPropertyQueryBuilder/TaskPropertiesSchema.jsx

Lines changed: 56 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -50,37 +50,19 @@ export const jsSchema = (intl, taskPropertyKeys) => {
5050
type: "object",
5151
properties: {
5252
valueType: {
53-
title: "Property Type ",
53+
title: "",
5454
type: "string",
55-
enum: ["string", "number", "compound rule"],
55+
enum: ["string", "number"],
5656
enumNames: [
5757
intl.formatMessage(messages.stringType),
5858
intl.formatMessage(messages.numberType),
59-
intl.formatMessage(messages.compoundRuleType),
6059
],
6160
},
6261
},
6362
dependencies: {
6463
// Show operators appropriate to value type
6564
valueType: {
6665
oneOf: [
67-
{
68-
// nested rules
69-
properties: {
70-
valueType: {
71-
enum: ["compound rule"],
72-
},
73-
left: { $ref: "#/definitions/tagRule" },
74-
condition: {
75-
title: " ", // empty title
76-
type: "string",
77-
enum: _values(TaskPropertyOperationType),
78-
enumNames: operationTypeMessages,
79-
default: _values(TaskPropertyOperationType)[0],
80-
},
81-
right: { $ref: "#/definitions/tagRule" },
82-
},
83-
},
8466
{
8567
// string values
8668
properties: {
@@ -152,28 +134,23 @@ export const jsSchema = (intl, taskPropertyKeys) => {
152134
},
153135
],
154136
},
155-
value: {
156-
oneOf: [
157-
{
158-
properties: {
159-
value: {
160-
minItems: 2,
161-
},
162-
},
163-
},
164-
{
165-
properties: {
166-
value: {
167-
maxItems: 1,
168-
},
169-
commaSeparate: {
170-
title: intl.formatMessage(messages.commaSeparateValues),
171-
type: "boolean",
172-
default: false,
173-
},
174-
},
175-
},
176-
],
137+
},
138+
},
139+
ruleGroup: {
140+
title: " ", // empty title for compact UI
141+
type: "object",
142+
properties: {
143+
condition: {
144+
title: intl.formatMessage(messages.conditionLabel),
145+
type: "string",
146+
enum: _values(TaskPropertyOperationType),
147+
enumNames: operationTypeMessages,
148+
default: _values(TaskPropertyOperationType)[0],
149+
},
150+
rules: {
151+
title: "",
152+
type: "array",
153+
items: { $ref: "#/definitions/tagRule" },
177154
},
178155
},
179156
},
@@ -183,7 +160,7 @@ export const jsSchema = (intl, taskPropertyKeys) => {
183160
title: "",
184161
type: "object",
185162
properties: {
186-
rootRule: { $ref: "#/definitions/tagRule" },
163+
rootRule: { $ref: "#/definitions/ruleGroup" },
187164
},
188165
},
189166
},
@@ -198,11 +175,7 @@ export const jsSchema = (intl, taskPropertyKeys) => {
198175
*
199176
* @private
200177
*/
201-
function buildUISchema(deepness, taskPropertyKeys) {
202-
if (deepness === 0) {
203-
return {};
204-
}
205-
178+
function buildUISchema(taskPropertyKeys) {
206179
let keyType = {
207180
classNames: "inline-selector mr-inline",
208181
"ui:widget": "select",
@@ -218,15 +191,9 @@ function buildUISchema(deepness, taskPropertyKeys) {
218191
}
219192

220193
return {
221-
classNames:
222-
"property-rule mr-border-2 mr-border-white-10 mr-pt-2 mr-pb-3 mr-m-1 mr-pl-4 mr-flex",
194+
classNames: "property-rule-content mr-pt-1 mr-pb-0 mr-pl-1 mr-flex",
223195
valueType: {
224-
classNames: "mr-text-green mr-w-48",
225-
"ui:widget": "select",
226-
"ui:options": { inline: true, label: true },
227-
},
228-
condition: {
229-
classNames: "mr-ml-4 mr-w-24",
196+
classNames: "mr-text-green mr-w-40",
230197
"ui:widget": "select",
231198
"ui:options": { inline: true, label: false },
232199
},
@@ -240,12 +207,6 @@ function buildUISchema(deepness, taskPropertyKeys) {
240207
classNames: "inline-selector mr-inline",
241208
"ui:options": { inline: true, label: false, orderable: false },
242209
},
243-
commaSeparate: {
244-
classNames: "inline-selector mr-inline",
245-
"ui:options": { inline: true },
246-
},
247-
left: buildUISchema(deepness - 1),
248-
right: buildUISchema(deepness - 1),
249210
};
250211
}
251212

@@ -259,11 +220,11 @@ export function ArrayFieldTemplate(props) {
259220
<div key={index}>
260221
<div className="mr-flex">
261222
{element.children}
262-
{props.items.length > 1 && (
223+
{props.items.length > 1 && props.schema?.title === "Value" && (
263224
<Fragment>
264225
<button
265226
type="button"
266-
className="mr-text-red-light mr-pb-4 mr-pl-2"
227+
className="mr-text-red-light mr-pb-4"
267228
onClick={(event) => element.onDropIndexClick(index)(event)}
268229
>
269230
<SvgSymbol
@@ -278,7 +239,18 @@ export function ArrayFieldTemplate(props) {
278239
</Fragment>
279240
)}
280241
</div>
281-
{props.canAdd && props.items.length === index + 1 && (
242+
{props.schema?.title !== "Value" && element.hasRemove && (
243+
<div className="mr-border-b mr-border-grey mr-pb-2">
244+
<button
245+
type="button"
246+
className="mr-text-red-light"
247+
onClick={(event) => element.onDropIndexClick(index)(event)}
248+
>
249+
<FormattedMessage {...messages.removeRuleButton} />
250+
</button>
251+
</div>
252+
)}
253+
{props.schema?.title === "Value" && props.canAdd && props.items.length === index + 1 && (
282254
<button
283255
type="button"
284256
className="mr-text-green-lighter mr-mt-1"
@@ -289,6 +261,13 @@ export function ArrayFieldTemplate(props) {
289261
)}
290262
</div>
291263
))}
264+
{props.schema?.title !== "Value" && props.canAdd && (
265+
<div className="mr-mt-2">
266+
<button type="button" className="mr-text-green-lighter" onClick={props.onAddClick}>
267+
<FormattedMessage {...messages.addRuleButton} />
268+
</button>
269+
</div>
270+
)}
292271
</div>
293272
);
294273
}
@@ -305,6 +284,17 @@ export function ArrayFieldTemplate(props) {
305284
*/
306285
export const uiSchema = (intl, taskPropertyKeys) => ({
307286
propertyRules: {
308-
rootRule: buildUISchema(7, taskPropertyKeys),
287+
rootRule: {
288+
classNames: "property-rule-group mr-m-1 ",
289+
condition: {
290+
classNames: "mr-ml-1 mr-w-48",
291+
"ui:widget": "select",
292+
"ui:options": { inline: true, label: true, labelText: "__conditionLabel__" },
293+
},
294+
rules: {
295+
classNames: "mr-mt-2",
296+
items: buildUISchema(taskPropertyKeys),
297+
},
298+
},
309299
},
310300
});

src/components/TaskPropertyQueryBuilder/TaskPropertiesSchema.scss

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
1+
.property-rule {
2+
border: 1px solid rgba(255, 255, 255, 0.1);
3+
margin: 0.25rem;
4+
border-radius: 0.25rem;
5+
background-color: rgba(22, 34, 46, 0.75);
6+
}
7+
.property-rule-content {
8+
padding: 0.5rem 0.75rem 0.25rem 0.75rem;
9+
}
10+
11+
.property-rule .rule-body {
12+
display: grid;
13+
grid-template-columns: 180px 1fr 1fr 1fr;
14+
grid-column-gap: 0.75rem;
15+
align-items: center;
16+
}
17+
18+
.property-rule .rule-footer {
19+
display: flex;
20+
justify-content: flex-start;
21+
margin-top: 0.25rem;
22+
}
23+
24+
.property-rule .remove-rule-link {
25+
color: #ff6b6b; /* red-light */
26+
font-size: 0.875rem;
27+
}
128
.task-properties-form {
229
label.control-label {
330
margin-right: 5px;

0 commit comments

Comments
 (0)