Skip to content

Commit

Permalink
Fixes and enhancements to the client table. (#468)
Browse files Browse the repository at this point in the history
* Fix sorting and order for name.

* Add the ability to sort display names.

* Remove no-unstable-nested-components rule.

* Use includes() rather than startsWith() for better 'searching' semantics.
  • Loading branch information
funkyhippo committed Apr 23, 2022
1 parent d78e28f commit f625c31
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
24 changes: 20 additions & 4 deletions web/components/client-table.tsx
@@ -1,6 +1,7 @@
import { Table } from 'antd';
import { SortOrder } from 'antd/lib/table/interface';
import { Input, Table } from 'antd';
import { FilterDropdownProps, SortOrder } from 'antd/lib/table/interface';
import { ColumnsType } from 'antd/es/table';
import { SearchOutlined } from '@ant-design/icons';
import { formatDistanceToNow } from 'date-fns';
import { Client } from '../types/chat';
import UserPopover from './user-popover';
Expand All @@ -22,7 +23,22 @@ export default function ClientTable({ data }: ClientTableProps) {
</UserPopover>
);
},
sorter: (a: any, b: any) => a.user.displayName - b.user.displayName,
sorter: (a: any, b: any) => b.user.displayName.localeCompare(a.user.displayName),
filterIcon: <SearchOutlined />,
// eslint-disable-next-line react/no-unstable-nested-components
filterDropdown: ({ setSelectedKeys, selectedKeys, confirm }: FilterDropdownProps) => (
<div style={{ padding: 8 }}>
<Input
placeholder="Search display names..."
value={selectedKeys[0]}
onChange={e => {
setSelectedKeys(e.target.value ? [e.target.value] : []);
confirm({ closeDropdown: false });
}}
/>
</div>
),
onFilter: (value: string, record: Client) => record.user.displayName.includes(value),
sortDirections: ['descend', 'ascend'] as SortOrder[],
},
{
Expand All @@ -42,7 +58,7 @@ export default function ClientTable({ data }: ClientTableProps) {
defaultSortOrder: 'ascend',
render: (time: Date) => formatDistanceToNow(new Date(time)),
sorter: (a: any, b: any) =>
new Date(a.connectedAt).getTime() - new Date(b.connectedAt).getTime(),
new Date(b.connectedAt).getTime() - new Date(a.connectedAt).getTime(),
sortDirections: ['descend', 'ascend'] as SortOrder[],
},
{
Expand Down
4 changes: 3 additions & 1 deletion web/styles/ant-overrides.scss
Expand Up @@ -308,6 +308,7 @@ textarea.ant-input {

// ANT TABLE
.ant-table-thead > tr > th,
.ant-table-filter-dropdown,
.ant-table-small .ant-table-thead > tr > th {
transition-duration: var(--ant-transition-duration);
background-color: var(--purple-dark);
Expand Down Expand Up @@ -349,7 +350,8 @@ textarea.ant-input {
background-color: var(--textfield-border);
}
}
.ant-table-thead th.ant-table-column-sort {
.ant-table-thead th.ant-table-column-sort,
.ant-dropdown-trigger.active {
background-color: var(--owncast-purple-25);
opacity: 0.75;
}
Expand Down

0 comments on commit f625c31

Please sign in to comment.