-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'hotfix/0.24.4' into develop
- Loading branch information
Showing
17 changed files
with
176 additions
and
60 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
0.24.3 | ||
0.24.4 |
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
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
37 changes: 27 additions & 10 deletions
37
client/src/themes/default/components/Table/Client/_types.ts
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 |
---|---|---|
@@ -1,21 +1,38 @@ | ||
import type { Merge } from 'type-fest'; | ||
import type { Column as CoreColumn } from '../@types'; | ||
import type { ColumnSorter } from 'vue-tables-2-premium'; | ||
import type { ColumnSearcher, ColumnSorter } from 'vue-tables-2-premium'; | ||
|
||
export type Column<Datum = any> = Merge<CoreColumn<Datum>, { | ||
/** | ||
* Fonction personnalisé de tri de la colonne. | ||
* Le tri doit-il être activé sur cette colonne ? | ||
* | ||
* Cette fonction, à qui la direction de tri souhaité est passé (via `ascending`), | ||
* doit renvoyer une autre fonction qui s'occupera de comparer deux éléments de | ||
* la colonne et devra renvoyé si le premier élément (`a`) arrive avant (= `-1`) ou | ||
* après (= `1`) le deuxième (`b`) (ou s'ils sont égaux (= `0`)). | ||
* Peut contenir: | ||
* - Un booléen, auquel cas le tri consistera en une simple comparaison des valeurs | ||
* (e.g si ascendant: `a > b ? 1 : -1`) en ayant au préalable mis les chaînes | ||
* de caractères en minuscules (si ce sont des chaînes qui sont comparées). | ||
* - Une fonction personnalisée de tri pour la colonne. | ||
* Cette fonction, à qui la direction de tri souhaité est passée (via `ascending`), | ||
* doit renvoyer une autre fonction qui s'occupera de comparer deux éléments de | ||
* la colonne et devra renvoyer si le premier élément (`a`) arrive avant (= `-1`) ou | ||
* après (= `1`) le deuxième (`b`) (ou s'ils sont égaux (= `0`)). | ||
* | ||
* Si non spécifié, le tri consistera en une simple comparaison des valeurs | ||
* (e.g si ascendant: `a > b ? 1 : -1`) en ayant au préalable mis les chaînes | ||
* de caractères en minuscules (si ce sont des chaînes qui sont comparés). | ||
* @default false | ||
*/ | ||
sorter?: ColumnSorter<Datum>, | ||
sortable?: boolean | ColumnSorter<Datum>, | ||
|
||
/** | ||
* La recherche doit-elle être activée sur cette colonne ? | ||
* | ||
* Peut contenir: | ||
* - Un booléen, auquel cas une fonction de recherche "universelle" sera utilisée pour la recherche. | ||
* {@see {@link import('./_utils.ts').defaultSearcher}} | ||
* - Une fonction personnalisée de recherche pour la colonne. | ||
* Cette fonction doit retourner un booléen en fonction de si oui ou non la colonne | ||
* est satisfaisante pour la recherche passée en paramètre (`query`). | ||
* | ||
* @default false | ||
*/ | ||
searchable?: boolean | ColumnSearcher<Datum>, | ||
}>; | ||
|
||
export type Columns<Data> = Array<Column<Data>>; |
57 changes: 57 additions & 0 deletions
57
client/src/themes/default/components/Table/Client/_utils.ts
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,57 @@ | ||
/* eslint-disable import/prefer-default-export */ | ||
|
||
import Color from '@/utils/color'; | ||
import DateTime from '@/utils/datetime'; | ||
import Day from '@/utils/day'; | ||
import stringIncludes from '@/utils/stringIncludes'; | ||
import get from 'lodash/get'; | ||
|
||
import type { ColumnSearcher } from 'vue-tables-2-premium'; | ||
|
||
// @see https://github.com/matfish2/vue-tables-2-private/blob/master/lib/methods/client-search.js | ||
export const defaultSearcher = (key: string): ColumnSearcher => { | ||
const isMatching = (value: unknown, query: string): boolean => { | ||
if (value === undefined || value === null || typeof query !== 'string') { | ||
return false; | ||
} | ||
|
||
if (['string', 'number', 'boolean'].includes(typeof value)) { | ||
const normalizedValue = String(value).toLowerCase(); | ||
return stringIncludes(normalizedValue, query); | ||
} | ||
|
||
if (value instanceof Color) { | ||
const normalizedValue = value.toHexString(); | ||
return stringIncludes(normalizedValue, query); | ||
} | ||
|
||
if (value instanceof Day || value instanceof DateTime || value instanceof Date) { | ||
return false; | ||
} | ||
|
||
if (typeof value === 'object') { | ||
return Object.values(value).some( | ||
(subValue: unknown) => isMatching(subValue, query), | ||
); | ||
} | ||
|
||
// - Affiche un message, en développement uniquement, quand on arrive pas à traiter | ||
// explicitement la valeur de la colonne via les conditions ci-dessus. | ||
if (process.env.NODE_ENV !== 'production') { | ||
// eslint-disable-next-line no-console | ||
console.warn(`Unhandled search value type \`${typeof value}\``, value); | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
return (row: unknown, query: string): boolean => { | ||
if (typeof row !== 'object' || row === null) { | ||
return false; | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression | ||
const value: unknown = get(row, key, undefined); | ||
return isMatching(value, query); | ||
}; | ||
}; |
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
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,9 @@ | ||
import type { Merge } from 'type-fest'; | ||
import type { Column as CoreColumn } from '../@types'; | ||
|
||
export type Column<Datum = any> = Merge<CoreColumn<Datum>, { | ||
/** Le tri doit-il être activé sur cette colonne ? */ | ||
sortable?: boolean, | ||
}>; | ||
|
||
export type Columns<Data> = Array<Column<Data>>; |
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
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 |
---|---|---|
@@ -1,10 +1,2 @@ | ||
// - Types | ||
export type { Columns, Column } from './@types'; | ||
export type { | ||
Column as ClientColumn, | ||
Columns as ClientColumns, | ||
} from './Client'; | ||
|
||
// - Tables | ||
export { default as ServerTable } from './Server'; | ||
export { default as ClientTable } from './Client'; |
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
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
Oops, something went wrong.