-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
doc-app/tests/integration/components/ember-ui/prefabs/tpk-table-generic-prefab-test.gts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { module, test } from 'qunit'; | ||
import { setupRenderingTest } from 'ember-qunit'; | ||
import { setupIntl } from 'ember-intl/test-support'; | ||
import { render } from '@ember/test-helpers'; | ||
import { TableGenericUserWorker } from 'doc-app/tests/workers/table-generic'; | ||
import { worker } from 'doc-app/tests/worker'; | ||
import TpkTableGenericPrefab from '@triptyk/ember-ui/components/prefabs/tpk-table-generic-prefab'; | ||
|
||
module('Integration | Component | Prefabs | Tpk-table-generic-prefab', function(hooks) { | ||
setupRenderingTest(hooks); | ||
setupIntl(hooks, 'fr-fr'); | ||
|
||
hooks.beforeEach(async function () { | ||
await TableGenericUserWorker(worker); | ||
}); | ||
|
||
async function renderComponent(){ | ||
const columns = [ | ||
{ | ||
field: 'lastName', | ||
headerName: 'Nom', | ||
sortable: true, | ||
}, | ||
{ | ||
field: 'fisrtName', | ||
headerName: 'Prénom', | ||
sortable: true, | ||
}]; | ||
|
||
await render( | ||
<template> | ||
<TpkTableGenericPrefab @entity="user" @columns={{columns}}/> | ||
</template> | ||
) | ||
} | ||
|
||
test('Render prefab table generic', async function(assert) { | ||
await renderComponent() | ||
await this.pauseTest(); | ||
assert.dom('[data-test-table-generic-container]').exists(); | ||
}); | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
packages/ember-ui/src/components/prefabs/tpk-table-generic-prefab.gts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import Component from '@glimmer/component'; | ||
import type { TableGenericComponentSignature } from "../tpk-table-generic.gts"; | ||
import TableGenericComponent from "../tpk-table-generic.gts"; | ||
import TpkTableGeneric from "../tpk-table-generic.gts"; | ||
import type { WithBoundArgs } from '@glint/template'; | ||
import t from 'ember-intl/helpers/t'; | ||
|
||
export interface TableGenericPrefabComponentSignature { | ||
Args: TableGenericComponentSignature["Args"] & { | ||
columns: { | ||
field: string; | ||
headerName: string; | ||
sortable: boolean; | ||
}[] | ||
}; | ||
Blocks: { | ||
default: [ | ||
WithBoundArgs<typeof TableGenericComponent, 'rowClick' | 'filterText' | 'relationships' | 'registerApi' | 'entity' | 'pageSizes' | 'additionalFilters' | 'defaultSortColumn'> | ||
]; | ||
}; | ||
Element: HTMLElement; | ||
} | ||
|
||
export default class TableGenericPrefabComponent extends Component<TableGenericPrefabComponentSignature>{ | ||
|
||
get pageSizes(){ | ||
if(this.args.pageSizes){ | ||
return this.args.pageSizes; | ||
} | ||
return [5, 10, 25]; | ||
} | ||
|
||
get filterText(): string | undefined { | ||
if(this.args.filterText){ | ||
return this.args.filterText; | ||
} | ||
return this.filterText; | ||
} | ||
|
||
get columns() { | ||
console.log(this.args.columns); | ||
if(!this.args.columns){ | ||
throw new Error("entityKeys is required"); | ||
|
||
} | ||
return this.args.columns | ||
} | ||
|
||
<template> | ||
<TpkTableGeneric | ||
@pageSizes={{this.pageSizes}} | ||
@additionalFilters={{@additionalFilters}} | ||
@defaultSortColumn={{@defaultSortColumn}} | ||
@entity={{@entity}} | ||
@relationships={{@relationships}} | ||
@filterText={{this.filterText}} | ||
as | TG |> | ||
<TG.SearchBar /> | ||
<TG.Table as | Table |> | ||
<Table.Header as |Header|> | ||
{{#each this.columns as |column|}} | ||
<Header.Cell @sortable={{column.sortable}} @prop={{column.field}} data-test-table={{column.field}}> | ||
{{column.headerName}} | ||
</Header.Cell> | ||
{{/each}} | ||
</Table.Header> | ||
<Table.Body as |Body element|> | ||
{{!-- {{#each this.columns as |column|}} | ||
<Body.Cell > | ||
{{element[column.field}]}} | ||
</Body.Cell> | ||
{{/each}} --}} | ||
</Table.Body> | ||
<Table.Footer /> | ||
</TG.Table> | ||
</TpkTableGeneric> | ||
</template> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters