-
Notifications
You must be signed in to change notification settings - Fork 0
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(table): adds single row selection mode for data table #888
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -28,6 +28,8 @@ type RowSize = 'small' | 'medium'; | |||||
|
||||||
type UtilityColumnType = 'selection' | 'numbers' | 'expand'; | ||||||
|
||||||
type SelectionMode = 'single' | 'multiple'; | ||||||
|
||||||
function getThPadding(device: DeviceType, rowSize?: RowSize): string { | ||||||
if (rowSize === 'small') { | ||||||
switch (device) { | ||||||
|
@@ -140,31 +142,55 @@ const ExpandButton = styled(IconButton) <{ $expanded: boolean }>` | |||||
} | ||||||
`; | ||||||
|
||||||
function getUtilityColumn<T extends object>(type: UtilityColumnType, t: TFunction<'translation'>): TableColumn<T> { | ||||||
const RadioButton = styled.input` | ||||||
margin: 3px 3px 3px 5px; | ||||||
vertical-align: inherit; | ||||||
`; | ||||||
|
||||||
function getUtilityColumn<T extends object>( | ||||||
type: UtilityColumnType, | ||||||
t: TFunction<'translation'>, | ||||||
selectionMode?: SelectionMode, | ||||||
): TableColumn<T> { | ||||||
const column: TableColumn<T> = { | ||||||
id: type, | ||||||
className: utilColumnClassName, | ||||||
}; | ||||||
|
||||||
switch (type) { | ||||||
case 'selection': | ||||||
column.header = ({ table }) => ( | ||||||
<Checkbox | ||||||
data-testid="row-checkbox-all" | ||||||
checked={table.getIsAllRowsSelected()} | ||||||
indeterminate={table.getIsSomeRowsSelected()} | ||||||
onChange={table.getToggleAllRowsSelectedHandler()} | ||||||
/> | ||||||
); | ||||||
column.cell = ({ row }) => ( | ||||||
<Checkbox | ||||||
data-testid={`row-checkbox-${row.index}`} | ||||||
checked={row.getIsSelected()} | ||||||
disabled={!row.getCanSelect()} | ||||||
indeterminate={row.getIsSomeSelected()} | ||||||
onChange={row.getToggleSelectedHandler()} | ||||||
/> | ||||||
); | ||||||
if (selectionMode === 'multiple') { | ||||||
column.header = ({ table }) => ( | ||||||
<Checkbox | ||||||
data-testid="row-checkbox-all" | ||||||
checked={table.getIsAllRowsSelected()} | ||||||
indeterminate={table.getIsSomeRowsSelected()} | ||||||
onChange={table.getToggleAllRowsSelectedHandler()} | ||||||
/> | ||||||
); | ||||||
column.cell = ({ row }) => ( | ||||||
<Checkbox | ||||||
data-testid={`row-checkbox-${row.index}`} | ||||||
checked={row.getIsSelected()} | ||||||
disabled={!row.getCanSelect()} | ||||||
indeterminate={row.getIsSomeSelected()} | ||||||
onChange={row.getToggleSelectedHandler()} | ||||||
/> | ||||||
); | ||||||
} else if (selectionMode === 'single') { | ||||||
column.cell = ({ table, row }) => ( | ||||||
<RadioButton | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. La radio button devrait avoir un
Comme mentionné dans un autre commentaire, il faudrait utiliser le composant de radio button du DS. Ça va p-e demander du boulot dans le composant radio-button par contre. |
||||||
data-testid={`row-radiobutton-${row.index}`} | ||||||
type="radio" | ||||||
checked={row.getIsSelected()} | ||||||
disabled={!row.getCanSelect()} | ||||||
onChange={row.getToggleSelectedHandler()} | ||||||
onClick={() => { | ||||||
table.toggleAllRowsSelected(false); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. J'ouvre la discussion, mais le radio button a un comportement de toggle presentement, si tu le re-click, ca va le deselectionner. Et je ne sais pas si c'est voulu ou conforme. Dans mon experience je n'ai jamais vu un radio qui peut se deselectionner. En meme temps, on a pas d'autre moyen d'enlever une selection non plus. C'est quoi vos opinions la dessus? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je l'ai fait comme ça parce que j'étais pas certain qu'on devait locker le user dans un choix ou non. Je suis ouvert aux propositions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pas une réponse concrète mais un peu de recherche. Les exemples que j'ai trouvés pour un single select avec bouton radio n'offraient pas de moyen de désélectionner: Celle-là le permet mais elle n'a pas de bouton radio. Ça retire l'ambiguité mais ça communique moins bien la possibilité d'interaction selon moi: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah le datatables.net m'apparait pas trop clair, j'ai pas l'impression de vraiment selectionner le row. Ca peut confondre avec un action de juste highlighter un row pour faciliter la lecture.
Comment on lines
+188
to
+189
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. J'ai testé la nouvelle fonctionnalité et dite moi si je sors du scope de la tâche. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. J'aime vraiment la réflexion.
Je sais que nous pourrions contourner tout ça d'une manière xyz mais je préfère garder ca le plus simple possible. Ce que nous pourrions faire par contre serait d'avoir la cell clickable au lieu de toute la row. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 pour le cell cliquable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comme on s'enligne pour créer notre propre component pour le radio button, il devrait inclure un élément Je ne pense pas que le |
||||||
}} | ||||||
/> | ||||||
); | ||||||
} | ||||||
break; | ||||||
|
||||||
case 'numbers': | ||||||
|
@@ -214,7 +240,7 @@ export interface TableProps<T extends object> { | |||||
* @default medium | ||||||
*/ | ||||||
rowSize?: RowSize; | ||||||
selectableRows?: boolean; | ||||||
selectionMode?: SelectionMode; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C'est un BREAKING CHANGE, il faut ajouter un
https://www.conventionalcommits.org/en/v1.0.0/#commit-message-with-both--and-breaking-change-footer There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On a aussi un
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. C'est débatable. Honnnêtement je trouve que There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah ton point est valide, pour moi c'est pas tant le nom mais plus le fait qu'on pourrait garder une certaine similitude entre les noms. Ca pourrait etre expandableRows qui se renomme a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Par contre je me demande si on ne devrait pas garder |
||||||
/** | ||||||
* Adds striped rows | ||||||
* @default false | ||||||
|
@@ -239,7 +265,7 @@ export const Table = <T extends object>({ | |||||
stickyFooter = false, | ||||||
rowNumbers = false, | ||||||
rowSize = 'medium', | ||||||
selectableRows, | ||||||
selectionMode, | ||||||
striped = false, | ||||||
manualSort = false, | ||||||
onRowClick, | ||||||
|
@@ -257,16 +283,16 @@ export const Table = <T extends object>({ | |||||
const columns = useMemo(() => { | ||||||
const cols = [...providedColumns]; | ||||||
|
||||||
if (selectableRows) { | ||||||
cols.unshift(getUtilityColumn<T>('selection', t)); | ||||||
if (selectionMode) { | ||||||
cols.unshift(getUtilityColumn<T>('selection', t, selectionMode)); | ||||||
} else if (expandableRows) { | ||||||
cols.unshift(getUtilityColumn<T>('expand', t)); | ||||||
} else if (rowNumbers) { | ||||||
cols.unshift(getUtilityColumn<T>('numbers', t)); | ||||||
} | ||||||
|
||||||
return cols; | ||||||
}, [selectableRows, expandableRows, rowNumbers, providedColumns, t]); | ||||||
}, [selectionMode, expandableRows, rowNumbers, providedColumns, t]); | ||||||
|
||||||
const tableOptions: TableOptions<T> = { | ||||||
data, | ||||||
|
@@ -311,13 +337,13 @@ export const Table = <T extends object>({ | |||||
const currentRowSelection = table.getState().rowSelection; | ||||||
|
||||||
useEffect(() => { | ||||||
if (selectableRows && onSelectedRowsChange) { | ||||||
if (selectionMode && onSelectedRowsChange) { | ||||||
const selectedRowIds = currentRowSelection; | ||||||
const selectedIndexes = Object.keys(selectedRowIds).filter((index) => selectedRowIds[index]); | ||||||
const selectedRows = selectedIndexes.map((index) => data[parseInt(index, 10)]); | ||||||
onSelectedRowsChange(selectedRows); | ||||||
} | ||||||
}, [selectableRows, currentRowSelection, onSelectedRowsChange, data]); | ||||||
}, [selectionMode, currentRowSelection, onSelectedRowsChange, data]); | ||||||
|
||||||
return ( | ||||||
<StyledTable | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ca n'a pas le design du Radio Button
Actuel
Expected
On a deja ca dans Radio-Button-Group, il faudrait comme extraire juste le input pis faire un component Radio Button seul.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On s'inspire du King, I see