From 2436da1d295d1125d65a415413cebd5743a51f9a Mon Sep 17 00:00:00 2001 From: Iury Nogueira Date: Mon, 18 Sep 2023 13:53:29 -0300 Subject: [PATCH] fix: order table asc/desc :ambulance: --- .../smart-table/smart-table.component.spec.ts | 6 +-- .../lib/smart-table/smart-table.component.ts | 5 ++- .../src/lib/use-table/use-table.component.ts | 38 +++++++++++++++++-- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/projects/ion/src/lib/smart-table/smart-table.component.spec.ts b/projects/ion/src/lib/smart-table/smart-table.component.spec.ts index cf8221544..b34c7d640 100644 --- a/projects/ion/src/lib/smart-table/smart-table.component.spec.ts +++ b/projects/ion/src/lib/smart-table/smart-table.component.spec.ts @@ -168,7 +168,7 @@ describe('IonSmartTableComponent', () => { ); }); - it('should emit event sort with desc false when click in sort icon', async () => { + it('should emit event sort with desc true when click in sort icon', async () => { const orderBy = columns[0].key; fireEvent.click(screen.getByTestId('sort-by-' + orderBy)); expect(events).toHaveBeenCalledWith({ @@ -176,7 +176,7 @@ describe('IonSmartTableComponent', () => { event: EventTable.SORT, order: { column: orderBy, - desc: false, + desc: true, }, }); }); @@ -186,7 +186,7 @@ describe('IonSmartTableComponent', () => { fireEvent.click(screen.getByTestId('sort-by-' + orderBy)); expect(defaultProps.config.order).toStrictEqual({ column: orderBy, - desc: true, + desc: false, }); }); diff --git a/projects/ion/src/lib/smart-table/smart-table.component.ts b/projects/ion/src/lib/smart-table/smart-table.component.ts index cc57bdab0..d78947d94 100644 --- a/projects/ion/src/lib/smart-table/smart-table.component.ts +++ b/projects/ion/src/lib/smart-table/smart-table.component.ts @@ -103,6 +103,8 @@ export class IonSmartTableComponent implements OnInit, AfterViewChecked { } public sort(column: Column): void { + column.desc = !column.desc; + this.config.order = { column: column.key, desc: column.desc, @@ -112,7 +114,7 @@ export class IonSmartTableComponent implements OnInit, AfterViewChecked { change_page: this.pagination, order: { column: column.key, - desc: !!column.desc, + desc: column.desc, }, }); @@ -121,7 +123,6 @@ export class IonSmartTableComponent implements OnInit, AfterViewChecked { columnEach.desc = null; } }); - column.desc = !column.desc; } public handleEvent(row: SafeAny, action: ActionTable): void { diff --git a/projects/ion/src/lib/use-table/use-table.component.ts b/projects/ion/src/lib/use-table/use-table.component.ts index 27c095eda..5583cda51 100644 --- a/projects/ion/src/lib/use-table/use-table.component.ts +++ b/projects/ion/src/lib/use-table/use-table.component.ts @@ -8,6 +8,39 @@ interface User { data_criacao: string; } +const columns = [ + { + key: 'data_monitoramento', + label: 'Data do monitoramento', + sort: true, + }, + { + key: 'http_code', + label: 'HTTP code', + sort: true, + }, + { + key: 'dns', + label: 'DNS', + sort: true, + }, + { + key: 'latencia', + label: 'Conexão', + sort: true, + }, + { + key: 'processamento', + label: 'Processamento', + sort: true, + }, + { + key: 'problemas', + label: 'Problemas', + sort: true, + }, +]; + @Component({ selector: 'ion-use-table', templateUrl: './use-table.component.html', @@ -17,10 +50,7 @@ export class IonUseTableComponent extends BnTable { super({ service, tableConfig: { - columns: [ - { label: 'Nome', sort: true, key: 'nome', desc: true }, - { label: 'Url', sort: true, key: 'url' }, - ], + columns, actions: [ { icon: 'trash',