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

Sorting tables #310

Merged
merged 23 commits into from
Jan 28, 2025
Merged

Sorting tables #310

merged 23 commits into from
Jan 28, 2025

Conversation

JochemVH1
Copy link
Collaborator

#300: Added sorting for tables, still missing sorting on invoice and invoice months

@JochemVH1 JochemVH1 requested a review from Laoujin January 28, 2025 08:16
@@ -33,6 +33,7 @@ const clientListConfig = (config: ClientFeatureBuilderConfig): IList<ClientModel
<span>{client.btw}</span>
</>
),
sort: (asc) => (c1, c2) => sortResult(c1.name.localeCompare(c2.name) > 0, asc)
Copy link
Member

Choose a reason for hiding this comment

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

Ik zou zelfs iets verder gegaan zijn en hier gezet hebben sort: true

En dan logic ala:

if (sort === true) {
   // sort on element[key]
  // if (typeof element[key] === 'string') --> .localeCompare sort
}

Maar laat dit maar zo, expliciet is ook OK.

Het voordeel van de sort: true zou vb zijn dat je op een bepaald moment kan kiezen om de .localeCompare door iets complexer te vervangen (vb: met een latinize erbij)

<th style={{width}} {...eventHandlers}>
{header ? t(header) : <>&nbsp;</>}
{onSort && showSortIcon ? <SortIcon
fa={filter.sort?.columnName !== columnName || filter.sort?.direction === SortDirections.ASC ? "fa fa-arrow-up" : "fa fa-arrow-down"}
Copy link
Member

@Laoujin Laoujin Jan 28, 2025

Choose a reason for hiding this comment

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

In TypeScript kun je dingen strongly typed maken zonder dat je constants nodig hebt enzo:

type sort = {
  columnName: string;
  direction: 'asc' | 'desc';
}

Of uitsplitsen:

type SortDirection = 'asc' | 'desc';
type sort = {
  columnName: string;
  direction: SortDirection ;
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ik had die constants gedaan omdat ik af en toe zelf 'asc' had gebruikt in de code en dan had ik geen magic strings ^^

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

en het type zelf laten genereren door chatGTP

Copy link
Member

@Laoujin Laoujin Jan 28, 2025

Choose a reason for hiding this comment

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

type Direction = 'asc' | 'desc';

const dir: Direction = 'asc';
const dir2: Direction = 'asc2'; // compile error

Het zijn geen magic strings, je kan aan een Direction enkel 'asc' of 'desc' toekennen, niets anders
Je intellisense gaat dit ook direct aangeven dat dat je 2 opties zijn.

Dit zijn wel magic strings:

const magic1: string = "asc";
const magic2: string = "asc2";
const magic3 = "asc";

@Laoujin Laoujin merged commit b90e98a into master Jan 28, 2025
1 check failed
@Laoujin Laoujin deleted the sorting-tables branch March 17, 2025 09:16
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.

2 participants