Skip to content

Commit ba15673

Browse files
authored
Query builder updates (#23)
* Add default value to comparator select * Cleanup re-rendering of elements * Remove need for `lodash` imports * Move delete button to `query-builder__wrapper` * Split switch statement logic into method calls * Add `ZnButton` type hint * Remove unused date logic * Refactor comparator option text * Add `ZnButton` and `ZnInput` dependencies * Create `litToHTML` utility * Use lit for element rendering * Add query builder example doc * Use lit for element rendering comparator * Use lit for element rendering rows * Remove unused method * Fix `showPopover` being run on deleted elements * Add live query string example doc * Rename example to use a generic filter * Reformat query-builder docs * Add comparators table * Add types table * Fix query builder row widths * Update query builder docs * Add `in` operator example to docs * Add string IDs to query builder filters in docs * Tidy data-table component * Split out duplicate page logic * Shorten if statement * Increase key and comparator flex-basis values * Add optional query builder to data table component * Remove unused styling * Disable confirm dialog for disabled buttons * Disable data table action buttons by default * Add filter query to data-table * Replace pagination defaults values with constants * Refactor to only re-render table body & footer with new data * Refactor click event for `show` method * Move styles onto separate line * Add actions to `HasSlotController`
1 parent 90c0aea commit ba15673

File tree

8 files changed

+545
-434
lines changed

8 files changed

+545
-434
lines changed

docs/assets/scripts/docs.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,28 @@
347347

348348
document.addEventListener('turbo:load', updateVersion);
349349
})();
350+
351+
//
352+
// Show query on query builder example
353+
//
354+
(() =>
355+
{
356+
['click', 'keyup'].forEach(function (evt)
357+
{
358+
document.addEventListener(evt, function (e)
359+
{
360+
if(!document.getElementById('query-string-example'))
361+
{
362+
return;
363+
}
364+
const target = e.target;
365+
366+
if(target.id === 'query-string-example')
367+
{
368+
document.querySelector('.query-string').innerText = target.value;
369+
}
370+
});
371+
});
372+
})();
373+
374+

docs/pages/components/query-builder.md

Lines changed: 123 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,135 @@ layout: component
66
---
77

88
```html:preview
9-
<zn-query-builder></zn-query-builder>
9+
10+
<zn-query-builder
11+
filters="[
12+
{
13+
&quot;id&quot;:&quot;title&quot;,
14+
&quot;name&quot;:&quot;Title&quot;,
15+
&quot;operators&quot;:[
16+
&quot;eq&quot;
17+
]
18+
},
19+
{
20+
&quot;id&quot;:&quot;author&quot;,
21+
&quot;name&quot;:&quot;Author&quot;,
22+
&quot;operators&quot;:[
23+
&quot;eq&quot;,
24+
&quot;fuzzy&quot;
25+
]
26+
}
27+
]">
28+
</zn-query-builder>
1029
```
1130

1231
## Examples
1332

14-
### First Example
33+
### Query String
34+
35+
This example will show the produced query string from the selected parameters.
36+
37+
```html:preview
1538
16-
TODO
39+
<zn-query-builder
40+
id="query-string-example"
41+
filters="[
42+
{
43+
&quot;id&quot;:&quot;title&quot;,
44+
&quot;name&quot;:&quot;Title&quot;,
45+
&quot;operators&quot;:[
46+
&quot;eq&quot;
47+
]
48+
},
49+
{
50+
&quot;id&quot;:&quot;author&quot;,
51+
&quot;name&quot;:&quot;Author&quot;,
52+
&quot;operators&quot;:[
53+
&quot;eq&quot;,
54+
&quot;fuzzy&quot;
55+
]
56+
},
57+
{
58+
&quot;id&quot;:&quot;genre&quot;,
59+
&quot;name&quot;:&quot;Genre&quot;,
60+
&quot;options&quot;:{
61+
&quot;action&quot;:&quot;Action&quot;,
62+
&quot;comedy&quot;:&quot;Comedy&quot;,
63+
&quot;drama&quot;:&quot;Drama&quot;,
64+
&quot;fantasy&quot;:&quot;Fantasy&quot;,
65+
&quot;horror&quot;:&quot;Horror&quot;,
66+
&quot;mystery&quot;:&quot;Mystery&quot;,
67+
&quot;romance&quot;:&quot;Romance&quot;,
68+
&quot;thriller&quot;:&quot;Thriller&quot;,
69+
&quot;sci-fi&quot;:&quot;Science Fiction&quot;
70+
},
71+
&quot;maxOptionsVisible&quot;: &quot;3&quot;,
72+
&quot;operators&quot;:[
73+
&quot;eq&quot;,
74+
&quot;in&quot;
75+
]
76+
},
77+
{
78+
&quot;id&quot;:&quot;rating&quot;,
79+
&quot;name&quot;:&quot;Rating&quot;,
80+
&quot;type&quot;:&quot;number&quot;,
81+
&quot;operators&quot;:[
82+
&quot;eq&quot;,
83+
&quot;gt&quot;,
84+
&quot;gte&quot;,
85+
&quot;lt&quot;,
86+
&quot;lte&quot;
87+
]
88+
},
89+
{
90+
&quot;id&quot;:&quot;created&quot;,
91+
&quot;name&quot;:&quot;Created&quot;,
92+
&quot;type&quot;:&quot;date&quot;,
93+
&quot;operators&quot;:[
94+
&quot;eq&quot;,
95+
&quot;before&quot;,
96+
&quot;after&quot;
97+
]
98+
}
99+
]">
100+
</zn-query-builder>
101+
102+
<br>
103+
104+
<div style="word-wrap: break-word;"><b>Query String:</b> </span><span class="query-string"></span></div>
105+
```
17106

18-
### Second Example
107+
## Types
19108

20-
TODO
109+
| Name |
110+
|-----------|
111+
| `bool` |
112+
| `boolean` |
113+
| `date` |
114+
| `number` |
21115

116+
## Comparators
22117

118+
| Name | Description |
119+
|-------------------|------------------------------|
120+
| `Eq` | Equals |
121+
| `Neq` | Not Equals |
122+
| `Before` | Was Before |
123+
| `After` | Was After |
124+
| `In` | In |
125+
| `MatchPhrasePre` | Match Phrase Prefix |
126+
| `NMatchPhrasePre` | Does Not Match Phrase Prefix |
127+
| `MatchPhrase` | Match Phrase |
128+
| `NMatchPhrase` | Does Not Match Phrase |
129+
| `Match` | Match |
130+
| `NMatch` | Does Not Match |
131+
| `Starts` | Starts With |
132+
| `NStarts` | Does Not Start With |
133+
| `Wild` | Wildcard Match |
134+
| `NWild` | Does Not Match Wildcard |
135+
| `Fuzzy` | Fuzzy Match With |
136+
| `NFuzzy` | Does Not Match Fuzzy With |
137+
| `Gte` | Greater Than or Equals |
138+
| `Gt` | Greater Than |
139+
| `Lt` | Less Than |
140+
| `Lte` | Less Than or Equals |

src/components/confirm/confirm.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ export default class ZnConfirm extends ZincElement {
8787
if (this.trigger) {
8888
const trigger = this.parentElement?.querySelector('#' + this.trigger);
8989
if (trigger) {
90-
trigger.addEventListener('click', () => this.show());
90+
trigger.addEventListener('click', this.show);
9191
}
9292
}
9393
}
9494

95-
show() {
95+
show = (event: Event | undefined = undefined) =>{
96+
const trigger = event?.target as HTMLButtonElement
97+
if (trigger?.disabled) return;
9698
this.dialog.show();
9799
}
98100

0 commit comments

Comments
 (0)