Skip to content

Commit

Permalink
feat: on work
Browse files Browse the repository at this point in the history
  • Loading branch information
Brenion committed Jan 3, 2025
1 parent 8505fbc commit 6501c4b
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 0 deletions.
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();
});

})
1 change: 1 addition & 0 deletions packages/ember-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
},
"app-js": {
"./components/prefabs/tpk-confirm-modal-prefab.js": "./dist/_app_/components/prefabs/tpk-confirm-modal-prefab.js",
"./components/prefabs/tpk-table-generic-prefab.js": "./dist/_app_/components/prefabs/tpk-table-generic-prefab.js",
"./components/tpk-actions-menu.js": "./dist/_app_/components/tpk-actions-menu.js",
"./components/tpk-actions-menu/element.js": "./dist/_app_/components/tpk-actions-menu/element.js",
"./components/tpk-confirm-modal.js": "./dist/_app_/components/tpk-confirm-modal.js",
Expand Down
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>
}
2 changes: 2 additions & 0 deletions packages/ember-ui/src/template-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type TpkActionsMenuElementComponent from './components/tpk-actions-menu/e
import type TpkStackListTitleComponent from './components/tpk-stack-list/title.gts';
import type TpkLazyImageComponent from './components/tpk-lazy-image.gts';
import type TpkConfirmModalPrefabComponent from './components/prefabs/tpk-confirm-modal-prefab.gts';
import type TableGenericPrefabComponent from './components/prefabs/tpk-table-generic-prefab';

export default interface Registry {
'tpk-actions-menu/element': typeof TpkActionsMenuElementComponent;
Expand Down Expand Up @@ -59,4 +60,5 @@ export default interface Registry {
'table-generic/header/cell': typeof TableGenericHeaderCellComponent;
'tpk-confirm-modal': typeof TpkConfirmModalComponent;
'tpk-confirm-modal-prefab' : typeof TpkConfirmModalPrefabComponent;
'tpk-table-generic-prefab' : typeof TableGenericPrefabComponent;
}

0 comments on commit 6501c4b

Please sign in to comment.