Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(angular-table): adds Angular adapter for tanstack/table #5326

Merged

Conversation

jrgokavalsa
Copy link
Contributor

Adds angular adapter for tanstack/table

@KevinVandy
Copy link
Member

so how does this adapter work? I just see config files. Could a basic example using the adapter be created in the examples dir?

@jrgokavalsa
Copy link
Contributor Author

Sure, definately

@KevinVandy
Copy link
Member

@crutchcorn , I'm not really well-versed in how the Angular ecosystem works. Would you be able to help with this? FYI @lachlancollins too

@KevinVandy
Copy link
Member

Thanks for your work @jrgokavalsa . Going to bring in more help polishing this and getting more docs ready before we ship. Your continued involvement will still be appreciated.

@Lord-AY
Copy link

Lord-AY commented Feb 17, 2024

@jrgokavalsa, I noticed the lib directory that is being referenced in the public-api.ts file is not available in this PR, this is most likely due to lib being referenced in .gitignore

@KevinVandy
Copy link
Member

Yeah, that's what I was confused about. It seems the actual adapter is not in this PR yet.

@Lord-AY
Copy link

Lord-AY commented Feb 17, 2024

Yeah he might have to change the folder name to something else

@ducin
Copy link

ducin commented Feb 17, 2024

hi 👋 do I see correctly that the actual adapter (lib folder) is outside of that PR?

packages/angular-table/src/public-api.ts:

export * from '@tanstack/table-core'
export * from './lib/flexrender.directive'
export * from './lib/index'

<tr>
@for (header of headerGroup.headers; track header.id) {
<th [attr.colSpan]="header.colSpan">
@if (!header.isPlaceholder) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Why not a single @if block ?

>
{{ aggregatedCell }}
</ng-container>
} @else if (cell.getIsPlaceholder()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Would be interesting to know why this is empty.

Comment on lines 6 to 7
export * from './lib/flexrender.directive'
export * from './lib/index'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are those files ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually got messed up by this commit : 91117bc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KevinVandy @JeanMeche @Lord-AY
export * from './lib/flexrender.directive'
export * from './lib/index'
moved above files from lib folder to src folder, updated examples

standalone: true,
})
export class FlexRenderDirective implements OnInit {
// private vcr = inject(ViewContainerRef)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove the commented code.

// private vcr = inject(ViewContainerRef)
// private templateRef = inject(TemplateRef)

private _flexRender: any
Copy link

@JeanMeche JeanMeche Feb 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably do better than any

Suggested change
private _flexRender: any
private _flexRender: string|() => any|null

Maybe we could make the function a generic one, so that we can reuse the generic for flexRenderProps.

private _flexRenderProps: any

@Input({ required: true })
set flexRender(render: any) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, let add constraints on the input type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this looks good or any suggestions

type FlexRenderType = string | null | (() => any) | ((props: any) => any)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tried changing the type getting the following error
Type 'ColumnDefTemplate<HeaderContext<Person, unknown>> | undefined' is not assignable to type 'FlexRenderType'.

I moved back to any

@jrgokavalsa
Copy link
Contributor Author

@JeanMeche Updated the library with selection example and moved flexrender.directive to index.ts file

Copy link

nx-cloud bot commented Feb 24, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 3955792. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this CI Pipeline Execution


🟥 Failed Commands
nx affected --targets=test:format,test:sherif,test:knip,test:lib,test:types,build --parallel=3

Sent with 💌 from NxCloud.

"build:types": "tsc --emitDeclarationOnly"
},
"dependencies": {
"tslib": "^2.3.0",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is tslib a package dependency? Maybe this should just be in the root package.json? Or a devDep here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we can move it root package.json

"test": "ng test"
},
"private": true,
"dependencies": {
Copy link
Member

@KevinVandy KevinVandy Mar 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a dumb question, but would using Vite with Angular be better or worse for these examples?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're wanting to consolidate on Vite as our build tooling for both examples and script packaging - might not be a bad idea to switch both over

// This ensures that if the 'flexRender' input is set before the directive initializes,
// the component will be rendered when ngOnInit is called.
if (this._flexRender) {
this.renderComponent()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code overall LGTM, but I thought ngOnInit doesn't have access to @Input props - how does this code ever run?

/** properties to render */
private _flexRenderProps: any

@Input({ required: true })
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, all input/output should now use signal based input/model/output.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that was a question for me. If using Angular 17 as the minimum peerDep, should this use signals? Or should we support much lower versions of Angular?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am assuming initial version will be experimental like Angular tanstack query so its safe to use latest angular as minimum version I think 17.3 (currently in rc) could be used as minimum if output api is needed, and later it can be changed to 18 too, if this adapter stays as experimental until May 24.

@KevinVandy
Copy link
Member

@imaksp @crutchcorn @jrgokavalsa @Lord-AY @JeanMeche I think that today I will solve merge conflicts, and then merge this into a branch off of main. That way, anyone can work off of the work of the adapter and make a PR to get this over the finish line. I think there might be some work left to do before shipping this.

@KevinVandy KevinVandy changed the base branch from main to feat-angular-table March 25, 2024 04:14
Copy link
Member

@KevinVandy KevinVandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging into the feat-angular-table branch where work will continue.

@KevinVandy KevinVandy merged commit afa27ad into TanStack:feat-angular-table Mar 25, 2024
1 of 2 checks passed
@KevinVandy
Copy link
Member

#5432

KevinVandy added a commit that referenced this pull request May 12, 2024
* feat(angular-table): adds Angular adapter for tanstack/table (#5326)

* Angular adapter for tanstack table initial

* build with: ng packagr

* Add angular examples basic grouping

* Add angular examples basic grouping

* Update angular examples basic grouping

* Add angular example selection

* regen lock file

* package upgrades, angular table docs

* prettier

* move around some deps

* removed unused dependency from angular package

* fix deps

---------

Co-authored-by: Kevin Van Cott <kevinvandy656@gmail.com>

* docs config cleanup

* feat: signal angular table adapter implementation

* update demo

* feat: table proxy detect memoized fns

* fix proxy property returning value

* feat: improve naming

* save new reference of table signal on every update

* computed trap proxy for fns with 1 argument

* update pnpm-lock.yaml

* refactor proxy implementation

* fix dependencies

* cleanup imports

* refactor basic example

* fix build

* run prettier

* add grouping example, fix ci

* add grouping example, fix ci

* add row selection example

* add column visibility example

* update examples add signal input required example

* improve angular table impl, fix flex-render change detection issues

* fix build

* feat(angular-table): improve adapter implementation (#5524)

* feat(angular-table): support render dynamic components and templateRefs in table

* update row selection example using dynamic rendered components

* support change detection on push with flex render

* add column ordering example

* fix flexRender change detection issues

* rename properties

* fix prettier and adjust example budget options

* update basic example

* add again support for table signal

* add column-pinning example

* add column pinning example

* add filters example

* cleanup code

* example cleanup

* update lock file

* feat(angular-table): added injector optional parameter for more flexibility (#5525)

* feat(angular-table): improve adapter implementation (#5524)

* Added optional injector for more flexibility
* Replace runInInjectionContext with injector in effect

* feat(angular-table): Added proxifyTable back

* feat(angular-table): adding back notifier signal for table changed

* feat(angular-table): Improve logic in setting table options
*set table options inside computed before returning the table instance
*remove redundant signals and effect
*remove injector as it no longer required
*update Grouping example to show how to pass signal when creating table

* update angular adapter and state docs

* prettier

* update docs config with angular examples

* update angular table state docs (#5545)

* Angular examples and dependencies improvements (#5546)

* tslib should be a dependency, see:

https://angular.io/guide/angular-package-format#tslib

* ensure angular examples are run as web container on code sandbox

* update lock file

---------

Co-authored-by: Kevin Vandy <kevinvandy656@gmail.com>

* docs(angular-table): Add documentation for FlexRenderDirective (#5543)

* add flexRender documentation

* fix docs

* fix rendering component section heading

* remove double build package.json from angular build

* update link name

* docs pass

* update esm exports in package.json

* update flexrender types

---------

Co-authored-by: jrgokavalsa <86955546+jrgokavalsa@users.noreply.github.com>
Co-authored-by: riccardoperra <riccardo.perra@icloud.com>
Co-authored-by: Riccardo Perra <perrariccardo0@gmail.com>
Co-authored-by: mamerto-g <merto.20@gmail.com>
Co-authored-by: Arnoud <6420061+arnoud-dv@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants