Skip to content

Conversation

@Tim-Siu
Copy link
Contributor

@Tim-Siu Tim-Siu commented Mar 9, 2024

What is the purpose of this pull request?

  • Documentation update
  • Bug fix
  • Feature addition or enhancement
  • Code maintenance
  • DevOps
  • Improve developer experience
  • Others, please explain:

Overview of changes:

Contribute to #896

Added a dataTable plugin. When we put a table into <m-table sortable> tag, it will become a Sortable Table. When we put a table into <m-table searable> tag, it will become a Searchable Table. Both functions can be used together.

DataTable is used.

Sample usage:

<m-table sortable searchable>
| Name | Age | Country |
|------|-----|---------|
| John | 28  | USA     |
| Emily| 32  | Canada  |
| Michael | 41 | UK    |
| Sophia | 25 | Germany|
| David | 37  | Australia |
</m-table>

Result:

Screen.Recording.2024-03-14.at.21.43.26.mov

Anything you'd like to highlight/discuss:
This has the potential of breaking the rendering pipeline. I am still conducting tests.

Testing instructions:
See overview.

Proposed commit message: (wrap lines at 72 characters)

Add dataTable plugin


Checklist: ☑️

  • Updated the documentation for feature additions and enhancements
  • Added tests for bug fixes or features
  • Linked all related issues
  • No unrelated changes

Reviewer checklist:

Indicate the SEMVER impact of the PR:

  • Major (when you make incompatible API changes)
  • Minor (when you add functionality in a backward compatible manner)
  • Patch (when you make backward compatible bug fixes)

At the end of the review, please label the PR with the appropriate label: r.Major, r.Minor, r.Patch.

Breaking change release note preparation (if applicable):

  • To be included in the release note for any feature that is made obsolete/breaking

Previously tables do not support searching and sorting.
Authors can now enable these features by adding dataTable as a site plugin and add the respective syntax around the table.

Give a brief explanation note about:

  • what was the old feature that was made obsolete
  • any replacement feature (if any), and
  • how the author should modify his website to migrate from the old feature to the replacement feature (if possible).

@codecov
Copy link

codecov bot commented Mar 9, 2024

Codecov Report

Attention: Patch coverage is 96.66667% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 51.05%. Comparing base (cb59668) to head (e254c05).

Files Patch % Lines
packages/core/src/plugins/dataTable.ts 96.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2446      +/-   ##
==========================================
+ Coverage   50.80%   51.05%   +0.25%     
==========================================
  Files         125      126       +1     
  Lines        5437     5467      +30     
  Branches     1170     1174       +4     
==========================================
+ Hits         2762     2791      +29     
- Misses       2380     2381       +1     
  Partials      295      295              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@yucheng11122017 yucheng11122017 left a comment

Choose a reason for hiding this comment

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

Hi @Tim-Siu thanks for the work on this!

Before you continue, I think one is that this will always sort by text.. which is not necessarily what is needed. For example, the example that you gave perhaps you want to sort by numbers instead? But currently, if you add 28 vs 201, 201 will come before 28.

Also, could you make sure that this will work for external imports as well? I think it doesn't work for now.

@Tim-Siu Tim-Siu changed the title Add SortableTable plugin [WIP] Add SortableTable plugin Mar 9, 2024
@yiwen101
Copy link
Contributor

yiwen101 commented Mar 9, 2024

Hi @Tim-Siu thank you for the amazing work;
After settling other issues and reviews, could you also help update the user doc regrading this?

@Tim-Siu Tim-Siu marked this pull request as draft March 9, 2024 23:41
@damithc
Copy link
Contributor

damithc commented Mar 10, 2024

Nice effort @Tim-Siu
Some things to think about:

  • sortable sounds like an attribute, so something like <m-table sortable> seems more intuitive? Allows to add more attributes later too.
  • For number columns, sorting should be by value (i.e., 2 is smaller than 15), not lexicographic. Is it handled automatically? Or is there a way for the user to specify? e.g., <m-table sortable sorting="text, number, text">

@Tim-Siu Tim-Siu marked this pull request as ready for review March 11, 2024 16:47
@Tim-Siu Tim-Siu changed the title [WIP] Add SortableTable plugin Add SortableTable plugin Mar 11, 2024
@itsyme
Copy link
Contributor

itsyme commented Mar 12, 2024

Great addition to tables @Tim-Siu!

I just have two small nits from a UI perspective.

  1. Perhaps you may want to explore other options for the icon for the unordered state (currently arrow up and down) to something that depicts its function more clearly. In my opinion the current icon is resembles cursor: resize giving me an impression that I can resize/move the column.

  2. I felt that the current design may be a little too distracting. Perhaps something like decreasing the opacity and upping it on hover could declutter the column headers a little. You can take some inspiration from MUI Tables

Great work so far!

@kaixin-hc
Copy link
Contributor

looks p good to me! - but wondering 2 things

  1. possible to add tests?
  2. if we're allowing sorting for text and numbers, is it possible / useful to also support sorting by date? if its simple we can do it here if its troublesome perhaps another PR

@Tim-Siu
Copy link
Contributor Author

Tim-Siu commented Mar 12, 2024

Great addition to tables @Tim-Siu!

I just have two small nits from a UI perspective.

  1. Perhaps you may want to explore other options for the icon for the unordered state (currently arrow up and down) to something that depicts its function more clearly. In my opinion the current icon is resembles cursor: resize giving me an impression that I can resize/move the column.
  2. I felt that the current design may be a little too distracting. Perhaps something like decreasing the opacity and upping it on hover could declutter the column headers a little. You can take some inspiration from MUI Tables

Great work so far!

Sure! I will explore different UI. I think there are some existing implementations on the internet for bootstrap tables and I will try to refer to them.

Add support for searching
Improve TS code style
@Tim-Siu Tim-Siu changed the title Add SortableTable plugin Add dataTable plugin Mar 13, 2024
@Tim-Siu
Copy link
Contributor Author

Tim-Siu commented Mar 13, 2024

Hi @damithc ,

I updated the plugin and it is now able to support both sorting and filtering. This is all, however, powered by DataTables, which is a Javascript table library that is loaded from CDN directly. What do you think of the functioinality now? There are additional features like paging and scrolling from DataTable. Are these features needed?

Thanks for your advice.

@damithc
Copy link
Contributor

damithc commented Mar 13, 2024

I updated the plugin and it is now able to support both sorting and filtering. This is all, however, powered by DataTables, which is a Javascript table library that is loaded from CDN directly. What do you think of the functioinality now? There are additional features like paging and scrolling from DataTable. Are these features needed?

@Tim-Siu Good find.
I'm no objections to using a third-party plugin, if the license is permissible. Another issue is the reliability of the CDN.
What's the syntax for enabling filtering and sorting?
What are the other features you think that might be relevant to our context?

@damithc
Copy link
Contributor

damithc commented Mar 13, 2024

Other concerns to check on:

  • How mature the plugin is
  • Is it currently active and likely to stay active for many years
  • The likelihood that the free version will be crippled in some ways in future, to push people to buy the commercial version

@Tim-Siu
Copy link
Contributor Author

Tim-Siu commented Mar 14, 2024

Other concerns to check on:

  • How mature the plugin is
  • Is it currently active and likely to stay active for many years
  • The likelihood that the free version will be crippled in some ways in future, to push people to buy the commercial version

Hi @damithc ,

Thank you for your input!

Regarding your concern:

  1. The syntax for the plugin is that <m-table sortable searchable> to enable both features. We may also include only one feature.
  2. The plugin appears to be quite popular and active. It is open source under MIT license. I have included the minimised js and css in our repo. It should be working fine as long as we are still using Bootstrap5. I guess we can still stick with these js and css files even if they commercialize it?
  3. Some other features include paging. But I fell like it is a bit distracting as it wil add page info and agination control. It may be useful if we intend to have a really long table. But I think we already have panel, so it is not a necessary feature.

I do realise that the plugin is not working inside a panel or modal. It seems to suffer the same problem as the mermaid plugin #2052 . I am still investigating this issue.

@damithc
Copy link
Contributor

damithc commented Mar 14, 2024

I do realise that the plugin is not working inside a panel or modal. It seems to suffer the same problem as the mermaid plugin #2052 . I am still investigating this issue.

@Tim-Siu I see. That's a bummer, but if we figure out a way to fix it, we might be able to add both this and Mermaid to MarkBind, which would be REALLY great. Feel free to join forces with other team members (including mentors) to explore this, as this is likely hard to solve.

@yucheng11122017
Copy link
Contributor

yucheng11122017 commented Mar 14, 2024

Hi @Tim-Siu, can I check how to use this feature? I have added dataTable to the plugins and then used

<m-table sortable searchable>
| Name | Age | Country |
|------|-----|---------|
| John | 28  | USA     |
| Emily| 32  | Canada  |
| Michael | 41 | UK    |
| Sophia | 25 | Germany|
| David | 37  | Australia |
</m-table>

But it doesn't seem to work.

Please add some documentation so that we can test it easily.

@Tim-Siu
Copy link
Contributor Author

Tim-Siu commented Mar 14, 2024

Hi @Tim-Siu, can I check how to use this feature? I have added dataTable to the plugins and then used

<m-table sortable searchable>
| Name | Age | Country |
|------|-----|---------|
| John | 28  | USA     |
| Emily| 32  | Canada  |
| Michael | 41 | UK    |
| Sophia | 25 | Germany|
| David | 37  | Australia |
</m-table>

But it doesn't seem to work.

Please add some documentation so that we can test it easily.

Hi @yucheng11122017 ,

That is the correct usage.

It does work on my side. Can you paste a screenshot of the output on your side?

Screen.Recording.2024-03-14.at.21.43.26.mov

Copy link
Contributor

@yucheng11122017 yucheng11122017 left a comment

Choose a reason for hiding this comment

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

Some nits and clean up!


To create a table with DataTable features, use one of the following syntaxes:

1. Sortable Table:
Copy link
Contributor

Choose a reason for hiding this comment

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

As I mean lines 19 to 52 is almost the same as 54 to 100 so its repetitive. We can delete 19 to 52 I think!


let tableClass: string = '';
if (isSortable && isSearchable) {
tableClass += ' sortable-searchable-table';
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
tableClass += ' sortable-searchable-table';
tableClass = ' sortable-searchable-table';

if (isSortable && isSearchable) {
tableClass += ' sortable-searchable-table';
} else if (isSortable) {
tableClass += ' sortable-table';
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
tableClass += ' sortable-table';
tableClass = ' sortable-table';

} else if (isSortable) {
tableClass += ' sortable-table';
} else if (isSearchable) {
tableClass += ' searchable-table';
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
tableClass += ' searchable-table';
tableClass = ' searchable-table';

{
"glob": ["**/index.md", "**/*.md"]
},
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Please delete these two pages - they aren't needed for testing!

jingting1412 and others added 3 commits April 17, 2024 15:02
* Change seamless panels

* Improve look of seamless panels

* Add tests

* Update userguide example
---------

Co-authored-by: Chan Yu Cheng <[email protected]>
Co-authored-by: Hannah <[email protected]>
Copy link
Contributor

@itsyme itsyme left a comment

Choose a reason for hiding this comment

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

Just two small nits to make the documentation and code slightly more readable! Almost there!

$('d-table').each((index: number, node: cheerio.Element) => {
const $node = $(node);
const html = $node.html();
if (html != null) {
Copy link
Contributor

@itsyme itsyme Apr 17, 2024

Choose a reason for hiding this comment

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

My opinion is it would be cleaner to use a guard clause here. i.e. check for html == null instead of html != null and continue/return. This allows the main logic of the code to not be wrapped in the if block, making it cleaner/more readable.

Here's a useful article on guard clauses: https://deviq.com/design-patterns/guard-clause

Copy link
Contributor

@yucheng11122017 yucheng11122017 left a comment

Choose a reason for hiding this comment

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

Some comments

{
"glob": ["**/index.md", "**/*.md"]
},
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @Tim-Siu I meant that by putting these two pages in the site.json, a user can basically access these pages by going to
{{baseUrl}}/others/includeInsideTable.html
which isn't necessary in this case. So please delete it.

You can read more about this in the UG


test('postRender should add appropriate classes and attributes to m-table elements', () => {
const content = `
<m-table sortable>
Copy link
Contributor

Choose a reason for hiding this comment

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

Isnt this supposed to be d-table now?

Copy link
Contributor

Choose a reason for hiding this comment

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

Why does the test case still pass when the tag is m-table?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why does the test case still pass when the tag is m-table?

Thank you for pointing it out. It turns out it is necessary to verify the length of the output. Currently, if I use , the length of the output after the selector is 0, leading to a vacuously true situation.

Fix the problem that there is a additional space in table attribute
Copy link
Contributor

@yucheng11122017 yucheng11122017 left a comment

Choose a reason for hiding this comment

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

Some comments

];

const renderedContent = dataTable.postRender({}, {}, content);
console.log(renderedContent);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this console.log?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I forgot to clean this up...


test('postRender should add appropriate classes and attributes to m-table elements', () => {
const content = `
<d-table sortable>
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the formatting here like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems like that if there are tabs indentation, it will be rendered as code...I haven't figured out why.

Copy link
Contributor Author

@Tim-Siu Tim-Siu Apr 20, 2024

Choose a reason for hiding this comment

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

Why is the formatting here like this?

I think this is the bahaviours for all the Vue components. (The behaviours that if we put indentations, the Vue comoponents won't be rendered correctly.

Copy link
Contributor

@itsyme itsyme left a comment

Choose a reason for hiding this comment

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

LGTM! Ready to be merged after resolving the latest comments from @yucheng11122017!

Copy link
Contributor

@yucheng11122017 yucheng11122017 left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks for the work

@LamJiuFong
Copy link
Contributor

LGTM! Thanks for the work @Tim-Siu

@LamJiuFong LamJiuFong added the r.Major Version resolver: increment by 1.0.0 label Apr 21, 2024
@LamJiuFong LamJiuFong merged commit c9f72c4 into MarkBind:master Apr 21, 2024
@damithc
Copy link
Contributor

damithc commented May 3, 2024

Feature in action: https://nus-cs2103-ay2324s2.github.io/website/schedule/week4/project.html#2-review-some-peer-prs-fri-feb-9th-1600-counted-for-participation

image

@kaixin-hc kaixin-hc added r.Minor Version resolver: increment by 0.1.0 and removed r.Major Version resolver: increment by 1.0.0 labels May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

r.Minor Version resolver: increment by 0.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants