@neovici/cosmoz-omnitable 8.2.1 → 8.3.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.
@@ -27,6 +27,7 @@ export const
27
27
  title: { type: String },
28
28
  valuePath: { type: String, notify: true },
29
29
  values: { type: Array, notify: true },
30
+ filter: { type: Object },
30
31
  /**
31
32
  * If the column should be disabled until enabled with enabledColumns
32
33
  */
@@ -61,6 +62,21 @@ export const
61
62
  };
62
63
  }
63
64
 
65
+ static get observers() {
66
+ return ['notifyFilterChange(filter)'];
67
+ }
68
+
69
+ notifyFilterChange(filter) {
70
+ if (this.__ownChange) {
71
+ return;
72
+ }
73
+ this.dispatchEvent(new CustomEvent('legacy-filter-changed', { detail: { name: this.name, state: this.legacyFilterToState(filter) }, bubbles: true }));
74
+ }
75
+
76
+ legacyFilterToState(filter) {
77
+ return { filter };
78
+ }
79
+
64
80
  /**
65
81
  * Override this in column elements if you need a different default width
66
82
  */
@@ -85,6 +101,13 @@ export const
85
101
  }
86
102
 
87
103
  deserializeFilter(column, filter) {
104
+ if (filter == null) {
105
+ return null;
106
+ }
107
+
108
+ if (typeof filter === 'string') {
109
+ return window.decodeURIComponent(filter);
110
+ }
88
111
  return filter;
89
112
  }
90
113
 
@@ -75,5 +75,9 @@ class OmnitableColumn extends columnMixin(PolymerElement) {
75
75
  <cosmoz-clear-button suffix slot="suffix" ?visible=${ hasFilter(filter) } light @click=${ resetFilter(setState) }></cosmoz-clear-button>
76
76
  </paper-input>`;
77
77
  }
78
+
79
+ legacyFilterToState(filter) {
80
+ return { filter, inputValue: filter };
81
+ }
78
82
  }
79
83
  customElements.define('cosmoz-omnitable-column', OmnitableColumn);
@@ -298,7 +298,7 @@ export default `<style>
298
298
  align-items: center;
299
299
  }
300
300
  .footer-control + .footer-control {
301
- margin-left: 34px;
301
+ margin-left: 16px;
302
302
  }
303
303
  .footer-control::part(input-label) {
304
304
  opacity: 0.7;
@@ -318,6 +318,7 @@ export default `<style>
318
318
  display: flex;
319
319
  flex-direction: column;
320
320
  align-items: flex-end;
321
+ white-space: nowrap;
321
322
  }
322
323
 
323
324
  .footer-tableStats :first-child {
@@ -146,6 +146,7 @@ class Omnitable extends hauntedPolymer(useOmnitable)(mixin({ isEmpty }, translat
146
146
  >
147
147
  <svg slot="suffix" viewBox="0 0 24 24" preserveAspectRatio="xMidYMid meet" focusable="false" width="24" fill="currentColor"><path d="M7 10l5 5 5-5z"></path></svg>
148
148
  </cosmoz-autocomplete>
149
+ <slot id="controlsSlot" name="controls"></slot>
149
150
  </div>
150
151
  <div class="footer-tableStats">
151
152
  <span>[[ ngettext('{0} group', '{0} groups', groupsCount, t) ]]</span>
@@ -223,7 +224,7 @@ class Omnitable extends hauntedPolymer(useOmnitable)(mixin({ isEmpty }, translat
223
224
  /**
224
225
  * Specific columns to enable
225
226
  */
226
- enabledColumns: { type: Array },
227
+ enabledColumns: { type: Array, notify: true },
227
228
 
228
229
  /**
229
230
  * Whether bottom-bar has actions.
@@ -38,7 +38,7 @@ const
38
38
  }
39
39
 
40
40
  const columns = Array.isArray(enabledColumns)
41
- ? domColumns.filter(column => enabledColumns.includes(column.name))
41
+ ? domColumns.filter(column => enabledColumns.includes(column.name))
42
42
  : domColumns.filter(column => !column.disabled);
43
43
 
44
44
  // eslint-disable-next-line max-lines-per-function
@@ -133,6 +133,8 @@ const
133
133
  };
134
134
  }, []);
135
135
 
136
+ useEffect(() => setColumns(domColumnsToConfig(host, { enabledColumns })), [enabledColumns]);
137
+
136
138
  return columns;
137
139
  };
138
140
 
@@ -21,6 +21,7 @@ const
21
21
  url = hashUrl(),
22
22
  searchParams = new URLSearchParams(url.hash.replace('#', ''));
23
23
 
24
+ // TODO: make parameterize pure
24
25
  parameterize(hashParam, value, codec, searchParams);
25
26
 
26
27
  return '#!' + Object.assign(url, { hash: searchParams }).href.replace(location.origin, '');
@@ -1,4 +1,4 @@
1
- import { useCallback, useMemo, useState } from 'haunted';
1
+ import { useCallback, useMemo, useState, useEffect } from 'haunted';
2
2
  import { normalizeSettings } from './normalize-settings';
3
3
  import { useProcessedItems } from './use-processed-items';
4
4
  import { useFastLayout } from './use-fast-layout';
@@ -74,6 +74,12 @@ export const useOmnitable = host => {
74
74
  [filterFunctions, normalizedSettings, collapsedColumns]
75
75
  );
76
76
 
77
+ useEffect(() => {
78
+ const handler = ev => setFilterState(ev.detail.name, state => ({ ...state, ...ev.detail.state }));
79
+ host.addEventListener('legacy-filter-changed', handler);
80
+ return () => host.removeEventListener('legacy-filter-changed', handler);
81
+ }, []);
82
+
77
83
  return {
78
84
  columns,
79
85
 
@@ -13,7 +13,9 @@ const
13
13
  }
14
14
 
15
15
  Object.entries(changes).forEach(([key, value]) => {
16
+ column[columnSymbol].__ownChange = true;
16
17
  column[columnSymbol][key] = value;
18
+ column[columnSymbol].__ownChange = false;
17
19
  column[columnSymbol].dispatchEvent(new CustomEvent(`${ kebab(key) }-changed`, { bubbles: true, detail: { value }}));
18
20
  });
19
21
  };
@@ -34,7 +36,7 @@ export const useProcessedItems = ({ data, columns, groupOnColumn, groupOnDescend
34
36
  if (column == null) {
35
37
  return [filter, undefined];
36
38
  }
37
- // TODO: add try-catch
39
+
38
40
  const state = { filter: column.deserializeFilter(column, value) };
39
41
  notifyChanges(column, state);
40
42
  return [filter, state];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-omnitable",
3
- "version": "8.2.1",
3
+ "version": "8.3.0",
4
4
  "description": "[![Build Status](https://travis-ci.org/Neovici/cosmoz-omnitable.svg?branch=master)](https://travis-ci.org/Neovici/cosmoz-omnitable)",
5
5
  "keywords": [
6
6
  "web-components"