@kubex/zinc 1.1.65 → 1.1.66
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.
|
@@ -8132,6 +8132,15 @@
|
|
|
8132
8132
|
"privacy": "private",
|
|
8133
8133
|
"default": "false"
|
|
8134
8134
|
},
|
|
8135
|
+
{
|
|
8136
|
+
"kind": "field",
|
|
8137
|
+
"name": "_lastLoadHadRows",
|
|
8138
|
+
"type": {
|
|
8139
|
+
"text": "boolean"
|
|
8140
|
+
},
|
|
8141
|
+
"privacy": "private",
|
|
8142
|
+
"default": "false"
|
|
8143
|
+
},
|
|
8135
8144
|
{
|
|
8136
8145
|
"kind": "field",
|
|
8137
8146
|
"name": "_lastTableContent",
|
|
@@ -42301,7 +42310,7 @@
|
|
|
42301
42310
|
"package": {
|
|
42302
42311
|
"name": "@kubex/zinc",
|
|
42303
42312
|
"description": "A collection of web components for building web applications based off of @shoelace-style/Shoelace",
|
|
42304
|
-
"version": "1.1.
|
|
42313
|
+
"version": "1.1.66",
|
|
42305
42314
|
"author": "",
|
|
42306
42315
|
"license": "MIT"
|
|
42307
42316
|
}
|
package/dist/web-types.json
CHANGED
package/dist/zn.d.ts
CHANGED
|
@@ -3578,6 +3578,7 @@ declare module "components/data-table/data-table.component" {
|
|
|
3578
3578
|
selectAllButton: ZnButton;
|
|
3579
3579
|
private _initialLoad;
|
|
3580
3580
|
private _hasLoadedData;
|
|
3581
|
+
private _lastLoadHadRows;
|
|
3581
3582
|
private _lastTableContent;
|
|
3582
3583
|
private readonly resizeObserver;
|
|
3583
3584
|
private page;
|
package/dist/zn.min.js
CHANGED
|
@@ -653,16 +653,16 @@ import{a as Cn,b as i_,c as sr,d as c,e as F}from"./chunks/zn.UBLZO6CI.js";var Q
|
|
|
653
653
|
<div class="table__collum--datetime">
|
|
654
654
|
<span><strong>${o.slice(0,10)}</strong></span>
|
|
655
655
|
<zn-style size="s" muted>${o.slice(11)}</zn-style>
|
|
656
|
-
</div>`})},yt=class extends C{constructor(){super(...arguments);this.data=[];this.sortDirection="asc";this.localSort=!1;this.filter="";this.search="";this.key="id";this.headers={};this.displayTemplates={};this.hiddenHeaders="{}";this.hiddenColumns="{}";this.unsortableHeaders="{}";this.unsortable=!1;this.standalone=!1;this.emptyStateIcon="data_alert";this.filters=[];this.method="POST";this.noInitialLoad=!1;this.groupBy="";this.groups="";this.itemsPerPage=Hh;this._initialLoad=!0;this._hasLoadedData=!1;this._lastTableContent=u``;this.resizeObserver=new Jt(this,{target:null,callback:()=>{this.tableContainer&&this.tableContainer.scrollIntoView({behavior:"smooth",block:"nearest"})}});this.page=Xb;this._rows=[];this.numberOfRowsSelected=0;this.selectedRows=[];this.hasSlotController=new Q(this,"[default]","search".valueOf(),"delete-action".valueOf(),"modify-action".valueOf(),"create-action".valueOf(),"filter".valueOf(),"sort".valueOf(),"inputs".valueOf(),"empty-state");this._dataTask=new al(this,{task:async([t,r],{signal:n})=>{if(t===void 0||this.noInitialLoad&&this._initialLoad)return{rows:[],page:1,perPage:this.itemsPerPage,total:0};this.groupBy&&(this.itemsPerPage=1e3);let a={page:this.page,perPage:this.itemsPerPage,sortColumn:this.sortColumn,sortDirection:this.sortDirection,filter:this.filter,search:this.search},s=this.hasSlotController.getSlots("inputs".valueOf()),l={};s&&(s.forEach(h=>{if(["zn-input","zn-select","zn-query-builder","zn-multiselect","zn-params-select","zn-datepicker","input","select","textarea"].includes(h.tagName.toLowerCase())){let f=h.value||h.getAttribute("value"),b=h.name||h.getAttribute("name");b&&(l[b]=f)}}),Object.assign(a,l)),r&&typeof r=="object"&&Object.assign(a,r);let d=await fetch(t,{method:this.method,headers:{"x-kx-fetch-style":"zn-data-table"},signal:n,credentials:"same-origin",body:this.method==="POST"?JSON.stringify(a):void 0});if(!d.ok)throw new Error(d.statusText);return d.json()},args:()=>[this.dataUri,this.requestParams]});this.rowHasActions=!1;this._expandedRows=new Set;this._hiddenCells=new Map;this._formatTemplates=Qk;this.requestParams={};this.filterChangeListener=t=>{t.target instanceof Lh&&(this.filter=t.target.value,this._dataTask.run().then(r=>r))};this.searchChangeListener=t=>{let r=t.target;if(r&&r.tagName==="ZN-DATA-TABLE-SEARCH"){if(this.search=r.value,t.detail){let{formData:n,searchUri:a}=t.detail;if(n&&typeof n=="object"&&(this.requestParams={...this.requestParams,...n}),a){let s=this.dataUri;this.dataUri=a,this._dataTask.run().then(()=>{this.dataUri=s});return}}this._dataTask.run().then(n=>n)}}}refresh(){this._initialLoad=!1,this._dataTask.run().then(t=>t)}render(){let t=u``;if(this.noInitialLoad&&this._initialLoad)t=u`
|
|
657
|
-
<slot name="empty-state"></slot>`;else if(this.dataUri)t=this._dataTask.render({pending:()=>this._initialLoad||!this._hasLoadedData?u`
|
|
656
|
+
</div>`})},yt=class extends C{constructor(){super(...arguments);this.data=[];this.sortDirection="asc";this.localSort=!1;this.filter="";this.search="";this.key="id";this.headers={};this.displayTemplates={};this.hiddenHeaders="{}";this.hiddenColumns="{}";this.unsortableHeaders="{}";this.unsortable=!1;this.standalone=!1;this.emptyStateIcon="data_alert";this.filters=[];this.method="POST";this.noInitialLoad=!1;this.groupBy="";this.groups="";this.itemsPerPage=Hh;this._initialLoad=!0;this._hasLoadedData=!1;this._lastLoadHadRows=!1;this._lastTableContent=u``;this.resizeObserver=new Jt(this,{target:null,callback:()=>{this.tableContainer&&this.tableContainer.scrollIntoView({behavior:"smooth",block:"nearest"})}});this.page=Xb;this._rows=[];this.numberOfRowsSelected=0;this.selectedRows=[];this.hasSlotController=new Q(this,"[default]","search".valueOf(),"delete-action".valueOf(),"modify-action".valueOf(),"create-action".valueOf(),"filter".valueOf(),"sort".valueOf(),"inputs".valueOf(),"empty-state");this._dataTask=new al(this,{task:async([t,r],{signal:n})=>{if(t===void 0||this.noInitialLoad&&this._initialLoad)return{rows:[],page:1,perPage:this.itemsPerPage,total:0};this.groupBy&&(this.itemsPerPage=1e3);let a={page:this.page,perPage:this.itemsPerPage,sortColumn:this.sortColumn,sortDirection:this.sortDirection,filter:this.filter,search:this.search},s=this.hasSlotController.getSlots("inputs".valueOf()),l={};s&&(s.forEach(h=>{if(["zn-input","zn-select","zn-query-builder","zn-multiselect","zn-params-select","zn-datepicker","input","select","textarea"].includes(h.tagName.toLowerCase())){let f=h.value||h.getAttribute("value"),b=h.name||h.getAttribute("name");b&&(l[b]=f)}}),Object.assign(a,l)),r&&typeof r=="object"&&Object.assign(a,r);let d=await fetch(t,{method:this.method,headers:{"x-kx-fetch-style":"zn-data-table"},signal:n,credentials:"same-origin",body:this.method==="POST"?JSON.stringify(a):void 0});if(!d.ok)throw new Error(d.statusText);return d.json()},args:()=>[this.dataUri,this.requestParams]});this.rowHasActions=!1;this._expandedRows=new Set;this._hiddenCells=new Map;this._formatTemplates=Qk;this.requestParams={};this.filterChangeListener=t=>{t.target instanceof Lh&&(this.filter=t.target.value,this._dataTask.run().then(r=>r))};this.searchChangeListener=t=>{let r=t.target;if(r&&r.tagName==="ZN-DATA-TABLE-SEARCH"){if(this.search=r.value,t.detail){let{formData:n,searchUri:a}=t.detail;if(n&&typeof n=="object"&&(this.requestParams={...this.requestParams,...n}),a){let s=this.dataUri;this.dataUri=a,this._dataTask.run().then(()=>{this.dataUri=s});return}}this._dataTask.run().then(n=>n)}}}refresh(){this._initialLoad=!1,this._dataTask.run().then(t=>t)}render(){let t=u``;if(this.noInitialLoad&&this._initialLoad)t=u`
|
|
657
|
+
<slot name="empty-state"></slot>`;else if(this.dataUri)t=this._dataTask.render({pending:()=>this._initialLoad||!this._hasLoadedData||!this._lastLoadHadRows?u`
|
|
658
658
|
<div>${this.loadingTable()}</div>`:u`
|
|
659
|
-
<div class="reduced-opacity">${this._lastTableContent}</div>`,complete:a=>(this._initialLoad=!1,this._hasLoadedData=!0,this._lastTableContent=u`
|
|
659
|
+
<div class="reduced-opacity">${this._lastTableContent}</div>`,complete:a=>(this._initialLoad=!1,this._hasLoadedData=!0,this._lastLoadHadRows=(a?.rows?.length??0)>0,this._lastTableContent=u`
|
|
660
660
|
<div>${this.renderTable(a)}</div>`,this._lastTableContent),error:a=>{if(a instanceof Error){if(a.name==="SyntaxError")return console.debug(a.message),u`
|
|
661
661
|
<zn-sp>
|
|
662
662
|
<zn-alert level="error">Unable to load data</zn-alert>
|
|
663
663
|
</zn-sp>`;if(a.message==="Not Found")return this.emptyState()}return u`
|
|
664
|
-
<div>${a}</div>`}});else if(Array.isArray(this.data)?this.data.length>0:this.data){let a=Array.isArray(this.data)?this.data:[this.data],s={rows:a,perPage:a.length,total:a.length,page:1};this._initialLoad=!1,this._hasLoadedData=!0,this._lastTableContent=u`
|
|
665
|
-
|
|
664
|
+
<div>${a}</div>`}});else if(Array.isArray(this.data)?this.data.length>0:this.data){let a=Array.isArray(this.data)?this.data:[this.data],s={rows:a,perPage:a.length,total:a.length,page:1};this._initialLoad=!1,this._hasLoadedData=!0,this._lastLoadHadRows=a.length>0,this._lastTableContent=u`
|
|
665
|
+
<div>${this.renderTable(s)}</div>`,t=this._lastTableContent}let r=this.hasSlotController.test("delete-action".valueOf())||this.hasSlotController.test("modify-action".valueOf())||this.hasSlotController.test("create-action".valueOf())||this.hasSlotController.test("sort".valueOf())||this.hasSlotController.test("filter".valueOf())||this.hasSlotController.test("filter-top".valueOf())||this.hasSlotController.test("search".valueOf()),n=this.hasSlotController.test("inputs".valueOf());return u`
|
|
666
666
|
<div class="table-container" ${Fa(a=>this.tableContainer=a)}>
|
|
667
667
|
${n?u`
|
|
668
668
|
<slot name="${"inputs".valueOf()}" style="display: none"></slot>`:null}
|
|
@@ -691,7 +691,8 @@ import{a as Cn,b as i_,c as sr,d as c,e as F}from"./chunks/zn.UBLZO6CI.js";var Q
|
|
|
691
691
|
<zn-alert level="${t.level??"error"}"
|
|
692
692
|
icon="${H(t.icon)}"
|
|
693
693
|
size="small"
|
|
694
|
-
center>${t.text}
|
|
694
|
+
center>${t.text}
|
|
695
|
+
</zn-alert>`}humanize(t){return t.charAt(0).toUpperCase()+t.slice(1)}renderTableData(t,r){let n=Object.values(this.headers).filter(h=>h.hideHeader||h.hideColumn||Object.values(this.hiddenColumns).includes(h.key)?!1:!h.secondary);this._secondaryHeaders=Object.values(this.headers).filter(h=>h.hideColumn||Object.values(this.hiddenColumns).includes(h.key)?!1:h.secondary===!0),this.rowHasActions=this._rows.some(h=>h.actions&&h.actions.length>0);let a=new Set(this._secondaryHeaders.map(h=>h.key));this._hiddenCells.clear();let s=new Map;this._rows.forEach(h=>{let m=Array.isArray(h.cells)?h.cells:[],f=[],b=m.filter(g=>a.has(g.column));this._hiddenCells.set(h.id,b),n.forEach(g=>{let v=m.find(x=>x.column===g.key);v?f.push(v):f.push({text:"",column:g.key})}),s.set(h.id,f)});let l=this.hasHiddenColumns(),d=n.length+(this.rowHasActions?1:0)+(l?1:0);return u`
|
|
695
696
|
<div style="overflow-x: auto">
|
|
696
697
|
<table class="${D({table:!0,"table--standalone":this.standalone,"with-hover":!this.unsortable&&!this.hideCheckboxes})}">
|
|
697
698
|
<thead>
|
package/package.json
CHANGED
|
@@ -111,8 +111,8 @@ interface HeaderConfig {
|
|
|
111
111
|
hideColumn?: boolean;
|
|
112
112
|
secondary?: boolean;
|
|
113
113
|
type?: string;
|
|
114
|
-
cellTemplate
|
|
115
|
-
ifEmpty
|
|
114
|
+
cellTemplate?: Cell;
|
|
115
|
+
ifEmpty?: Cell;
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
type DisplayTemplate = (cell: Cell, row: Row, header: HeaderConfig) =>
|
|
@@ -250,12 +250,13 @@ export default class ZnDataTable extends ZincElement {
|
|
|
250
250
|
|
|
251
251
|
@property() groups = '';
|
|
252
252
|
|
|
253
|
-
@property({attribute: 'per-page-size', type:Number}) itemsPerPage:number = DEFAULT_PER_PAGE;
|
|
253
|
+
@property({attribute: 'per-page-size', type: Number}) itemsPerPage: number = DEFAULT_PER_PAGE;
|
|
254
254
|
@query('#select-all-rows') selectAllButton: ZnButton;
|
|
255
255
|
|
|
256
256
|
// Data Table Properties
|
|
257
257
|
private _initialLoad = true;
|
|
258
258
|
private _hasLoadedData = false;
|
|
259
|
+
private _lastLoadHadRows = false;
|
|
259
260
|
private _lastTableContent: TemplateResult = html``;
|
|
260
261
|
|
|
261
262
|
private readonly resizeObserver = new ResizeController(this, {
|
|
@@ -375,8 +376,10 @@ export default class ZnDataTable extends ZincElement {
|
|
|
375
376
|
tableBody = this._dataTask.render({
|
|
376
377
|
pending: () => {
|
|
377
378
|
// Show the skeleton until data has rendered at least once, so the
|
|
378
|
-
// first fetch on a no-initial-load table doesn't render blank space
|
|
379
|
-
|
|
379
|
+
// first fetch on a no-initial-load table doesn't render blank space.
|
|
380
|
+
// Also show it when the last load had no rows - a reduced-opacity
|
|
381
|
+
// empty state gives no visible indication that a search is running
|
|
382
|
+
if (this._initialLoad || !this._hasLoadedData || !this._lastLoadHadRows) {
|
|
380
383
|
return html`
|
|
381
384
|
<div>${this.loadingTable()}</div>`;
|
|
382
385
|
}
|
|
@@ -386,6 +389,7 @@ export default class ZnDataTable extends ZincElement {
|
|
|
386
389
|
complete: (data) => {
|
|
387
390
|
this._initialLoad = false;
|
|
388
391
|
this._hasLoadedData = true;
|
|
392
|
+
this._lastLoadHadRows = ((data as Response)?.rows?.length ?? 0) > 0;
|
|
389
393
|
this._lastTableContent = html`
|
|
390
394
|
<div>${this.renderTable(data as Response)}</div>`;
|
|
391
395
|
return this._lastTableContent;
|
|
@@ -416,8 +420,9 @@ export default class ZnDataTable extends ZincElement {
|
|
|
416
420
|
};
|
|
417
421
|
this._initialLoad = false;
|
|
418
422
|
this._hasLoadedData = true;
|
|
423
|
+
this._lastLoadHadRows = rows.length > 0;
|
|
419
424
|
this._lastTableContent = html`
|
|
420
|
-
|
|
425
|
+
<div>${this.renderTable(response)}</div>`;
|
|
421
426
|
tableBody = this._lastTableContent;
|
|
422
427
|
}
|
|
423
428
|
|
|
@@ -605,7 +610,8 @@ export default class ZnDataTable extends ZincElement {
|
|
|
605
610
|
<zn-alert level="${error.level ?? 'error'}"
|
|
606
611
|
icon="${ifDefined(error.icon)}"
|
|
607
612
|
size="small"
|
|
608
|
-
center>${error.text}
|
|
613
|
+
center>${error.text}
|
|
614
|
+
</zn-alert>`;
|
|
609
615
|
}
|
|
610
616
|
|
|
611
617
|
public humanize(str: string) {
|
|
@@ -996,7 +1002,7 @@ export default class ZnDataTable extends ZincElement {
|
|
|
996
1002
|
renderCell(data: Cell, row?: Row, header?: HeaderConfig): TemplateResult | ZincElement {
|
|
997
1003
|
const fn = (header?.type ? this.getTemplate(header.type) : undefined);
|
|
998
1004
|
|
|
999
|
-
if((!data.text && !data.iconSrc) && header?.ifEmpty !== undefined) {
|
|
1005
|
+
if ((!data.text && !data.iconSrc) && header?.ifEmpty !== undefined) {
|
|
1000
1006
|
const header2 = {...header, type: undefined, render: undefined, renderTemplate: undefined};
|
|
1001
1007
|
return this.renderCell({...data, ...header.ifEmpty}, row, header2)
|
|
1002
1008
|
}
|
|
@@ -1006,11 +1012,11 @@ export default class ZnDataTable extends ZincElement {
|
|
|
1006
1012
|
return typeof out === 'string' ? html`${unsafeHTML(out)}` : out;
|
|
1007
1013
|
}
|
|
1008
1014
|
|
|
1009
|
-
if(!data || typeof data !== 'object') {
|
|
1015
|
+
if (!data || typeof data !== 'object') {
|
|
1010
1016
|
return data;
|
|
1011
1017
|
}
|
|
1012
1018
|
|
|
1013
|
-
if(header?.cellTemplate !== undefined) {
|
|
1019
|
+
if (header?.cellTemplate !== undefined) {
|
|
1014
1020
|
data = {...header.cellTemplate, ...data}
|
|
1015
1021
|
}
|
|
1016
1022
|
|
|
@@ -49,6 +49,30 @@ describe('<zn-data-table>', () => {
|
|
|
49
49
|
}
|
|
50
50
|
});
|
|
51
51
|
|
|
52
|
+
it('shows the loading skeleton on reload when the previous load returned no rows', async () => {
|
|
53
|
+
const originalFetch = window.fetch;
|
|
54
|
+
const emptyResponse = () => new Response(JSON.stringify({rows: [], page: 1, perPage: 10, total: 0}),
|
|
55
|
+
{status: 200, headers: {'Content-Type': 'application/json'}});
|
|
56
|
+
window.fetch = () => Promise.resolve(emptyResponse());
|
|
57
|
+
|
|
58
|
+
try {
|
|
59
|
+
const el = await fixture<ZnDataTable>(html`
|
|
60
|
+
<zn-data-table data-uri="/test-data" headers='{"name": {"key": "name", "label": "Name"}}'></zn-data-table>`);
|
|
61
|
+
await waitUntil(() => el.shadowRoot?.querySelector('zn-empty-state'));
|
|
62
|
+
|
|
63
|
+
let release: (value: Response) => void;
|
|
64
|
+
window.fetch = () => new Promise<Response>(resolve => (release = resolve));
|
|
65
|
+
el.refresh();
|
|
66
|
+
await waitUntil(() => el.shadowRoot?.querySelector('zn-skeleton'));
|
|
67
|
+
expect(el.shadowRoot!.querySelector('zn-skeleton')).to.exist;
|
|
68
|
+
|
|
69
|
+
release!(emptyResponse());
|
|
70
|
+
await waitUntil(() => el.shadowRoot?.querySelector('zn-empty-state'));
|
|
71
|
+
} finally {
|
|
72
|
+
window.fetch = originalFetch;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
52
76
|
it('exposes displayTemplates as an object property', async () => {
|
|
53
77
|
const el = await fixture<ZnDataTable>(html` <zn-data-table></zn-data-table> `);
|
|
54
78
|
const templates = (el as unknown as {displayTemplates: Record<string, unknown>}).displayTemplates;
|