-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
4032 - Collaborators Grouped UI (#4184)
* 4032 - Ui Collaborators grouped * 4032 - Collaborators Grouped UI
- Loading branch information
Showing
21 changed files
with
243 additions
and
85 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
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,6 @@ | ||
@import 'src/client/style/partials'; | ||
|
||
.table-paginated__groups { | ||
display: grid; | ||
grid-row-gap: $spacing-xs; | ||
} |
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,43 +1,42 @@ | ||
import './Body.scss' | ||
import React from 'react' | ||
|
||
import classNames from 'classnames' | ||
import { Objects } from 'utils/objects' | ||
|
||
import { useTablePaginatedData } from 'client/store/ui/tablePaginated' | ||
import DataColumn from 'client/components/DataGridDeprecated/DataColumn' | ||
import Rows from 'client/components/TablePaginated/Body/Rows' | ||
import RowsGroup from 'client/components/TablePaginated/Body/RowsGroup' | ||
import RowsSkeleton from 'client/components/TablePaginated/Body/RowsSkeleton' | ||
import { Props as BaseProps } from 'client/components/TablePaginated/types' | ||
|
||
import { useTablePaginatedBodyData } from './hooks/useTablePaginatedBodyData' | ||
|
||
const Body = <Datum extends object>(props: BaseProps<Datum>) => { | ||
const { columns, compareFn, limit, path, wrapCells, skeleton } = props | ||
const { columns, groups, limit, wrapCells, skeleton } = props | ||
|
||
const data = useTablePaginatedData<Datum>(path, compareFn) | ||
const data = useTablePaginatedBodyData<Datum>(props) | ||
|
||
if (Objects.isNil(data)) { | ||
return <RowsSkeleton columns={columns} limit={limit} skeleton={skeleton} /> | ||
} | ||
|
||
return ( | ||
<> | ||
{data.map((datum, rowIndex) => ( | ||
<React.Fragment key={`row_${String(rowIndex)}}`}> | ||
{columns.map((column) => { | ||
const { component: Component, key } = column | ||
|
||
if (wrapCells) { | ||
return ( | ||
<DataColumn key={key} className={classNames({ withBorder: rowIndex !== 0 })}> | ||
<Component datum={datum} rowIndex={rowIndex} /> | ||
</DataColumn> | ||
) | ||
} | ||
|
||
return <Component key={key} datum={datum} rowIndex={rowIndex} /> | ||
})} | ||
</React.Fragment> | ||
))} | ||
</> | ||
) | ||
if (!Objects.isNil(groups)) { | ||
return ( | ||
<div className="table-paginated__groups"> | ||
{(data as Array<[PropertyKey, Array<Datum>]>).map(([propertyKey, dataRows]) => ( | ||
<RowsGroup | ||
key={propertyKey.toString()} | ||
columns={columns} | ||
data={dataRows} | ||
groups={groups} | ||
propertyKey={propertyKey} | ||
wrapCells={wrapCells} | ||
/> | ||
))} | ||
</div> | ||
) | ||
} | ||
|
||
return <Rows columns={columns} data={data as Array<Datum>} wrapCells={wrapCells} /> | ||
} | ||
|
||
export default Body |
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,34 @@ | ||
import React from 'react' | ||
|
||
import classNames from 'classnames' | ||
|
||
import DataColumn from 'client/components/DataGridDeprecated/DataColumn' | ||
import { Props as BaseProps } from 'client/components/TablePaginated/types' | ||
|
||
type Props<Datum extends object> = Pick<BaseProps<Datum>, 'columns' | 'wrapCells'> & { | ||
data: Array<Datum> | ||
} | ||
|
||
const Rows = <Datum extends object>(props: Props<Datum>) => { | ||
const { columns, data, wrapCells } = props | ||
|
||
return data.map((datum, rowIndex) => ( | ||
<React.Fragment key={`row_${String(rowIndex)}}`}> | ||
{columns.map((column) => { | ||
const { component: Component, key } = column | ||
|
||
if (wrapCells) { | ||
return ( | ||
<DataColumn key={key} className={classNames({ withBorder: rowIndex !== 0 })}> | ||
<Component datum={datum} rowIndex={rowIndex} /> | ||
</DataColumn> | ||
) | ||
} | ||
|
||
return <Component key={key} datum={datum} rowIndex={rowIndex} /> | ||
})} | ||
</React.Fragment> | ||
)) | ||
} | ||
|
||
export default Rows |
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 @@ | ||
export { default } from './Rows' |
31 changes: 31 additions & 0 deletions
31
src/client/components/TablePaginated/Body/RowsGroup/RowsGroup.scss
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,31 @@ | ||
@import 'src/client/style/partials'; | ||
|
||
button.rows-group__header.inverse { | ||
background-color: $ui-bg-light; | ||
border-bottom-left-radius: 0; | ||
border-bottom-right-radius: 0; | ||
border-bottom: 1px solid transparent; | ||
border-left: 1px solid $ui-border; | ||
border-right: 1px solid $ui-border; | ||
border-top: 1px solid $ui-border; | ||
|
||
&.collapsed { | ||
border-bottom-left-radius: 2px; | ||
border-bottom-right-radius: 2px; | ||
border-bottom: 1px solid $ui-border; | ||
|
||
svg { | ||
transform: rotate(-90deg); | ||
} | ||
} | ||
} | ||
|
||
.rows-group__rows { | ||
background-color: $ui-bg-light; | ||
border-bottom-left-radius: 2px; | ||
border-bottom-right-radius: 2px; | ||
border-top-right-radius: 2px; | ||
border: 1px solid $ui-border; | ||
margin-top: -1px; | ||
padding: $spacing-xxs; | ||
} |
41 changes: 41 additions & 0 deletions
41
src/client/components/TablePaginated/Body/RowsGroup/RowsGroup.tsx
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,41 @@ | ||
import './RowsGroup.scss' | ||
import React, { useCallback, useState } from 'react' | ||
|
||
import classNames from 'classnames' | ||
|
||
import Button, { ButtonSize, ButtonType } from 'client/components/Buttons/Button' | ||
import Rows from 'client/components/TablePaginated/Body/Rows' | ||
import { Props as BaseProps } from 'client/components/TablePaginated/types' | ||
|
||
type Props<Datum extends object> = Pick<BaseProps<Datum>, 'columns' | 'groups' | 'wrapCells'> & { | ||
data: Array<Datum> | ||
propertyKey: PropertyKey | ||
} | ||
|
||
const RowsGroup = <Datum extends object>(props: Props<Datum>) => { | ||
const { columns, data, groups, propertyKey, wrapCells } = props | ||
|
||
const [collapsed, setCollapsed] = useState<boolean>(false) | ||
const toggleView = useCallback(() => setCollapsed((prevState) => !prevState), []) | ||
|
||
return ( | ||
<div> | ||
<Button | ||
className={classNames('rows-group__header', { collapsed })} | ||
iconName="small-down" | ||
inverse | ||
label={`${groups.headerLabel(propertyKey)} (${data.length})`} | ||
onClick={toggleView} | ||
size={ButtonSize.m} | ||
type={ButtonType.black} | ||
/> | ||
{!collapsed && ( | ||
<div className="rows-group__rows"> | ||
<Rows columns={columns} data={data} wrapCells={wrapCells} /> | ||
</div> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
export default RowsGroup |
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 @@ | ||
export { default } from './RowsGroup' |
18 changes: 18 additions & 0 deletions
18
src/client/components/TablePaginated/Body/hooks/useTablePaginatedBodyData.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,18 @@ | ||
import { Objects } from 'utils/objects' | ||
|
||
import { useTablePaginatedData } from 'client/store/ui/tablePaginated' | ||
import { Props as BaseProps } from 'client/components/TablePaginated/types' | ||
|
||
type Returned<Datum extends object> = Array<Datum> | Array<[PropertyKey, Array<Datum>]> | undefined | ||
|
||
export const useTablePaginatedBodyData = <Datum extends object>(props: BaseProps<Datum>): Returned<Datum> => { | ||
const { compareFn, groups, path } = props | ||
|
||
const data = useTablePaginatedData<Datum>(path, compareFn) | ||
|
||
if (Objects.isNil(data) || Objects.isNil(groups)) { | ||
return data | ||
} | ||
|
||
return Object.entries(Object.groupBy(data ?? [], groups.keySelector)) | ||
} |
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
27 changes: 27 additions & 0 deletions
27
src/client/components/TablePaginated/hooks/useScrollToTopOnPageUpdate.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,27 @@ | ||
import { MutableRefObject } from 'react' | ||
|
||
import { Objects } from 'utils/objects' | ||
|
||
import { useTablePaginatedData, useTablePaginatedPage } from 'client/store/ui/tablePaginated' | ||
import { useOnUpdate } from 'client/hooks' | ||
|
||
type Props = { | ||
divRef: MutableRefObject<HTMLDivElement> | ||
path: string | ||
} | ||
|
||
export const useScrollToTopOnPageUpdate = (props: Props): void => { | ||
const { divRef, path } = props | ||
|
||
const data = useTablePaginatedData(path) | ||
const page = useTablePaginatedPage(path) | ||
|
||
useOnUpdate(() => { | ||
if (!Objects.isNil(data)) { | ||
setTimeout(() => { | ||
const opts: ScrollIntoViewOptions = { behavior: 'smooth', block: 'start', inline: 'nearest' } | ||
divRef.current?.parentElement?.parentElement?.scrollIntoView(opts) | ||
}) | ||
} | ||
}, [page]) | ||
} |
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.