Skip to content

Commit

Permalink
feat(ota): allow sorting by ota update avaliable state
Browse files Browse the repository at this point in the history
resolves #1819
  • Loading branch information
nurikk committed Nov 19, 2023
1 parent 1213a79 commit a298487
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/components/grid/ReactTableCom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ import {
import cx from 'classnames';
import { useTranslation } from 'react-i18next';

import debounce from 'lodash/debounce';
import { local } from '@toolz/local-storage';
type PartialTableState = Partial<TableState<Record<string, unknown>>>;

interface Props {
id: string;
columns: Array<Column<any>>;
data: Array<any>;
initialState?: PartialTableState;
}

type GlobalFilterProps = {
Expand Down Expand Up @@ -86,8 +87,9 @@ const stateReducer = (
return newState;
};

export const Table: React.FC<Props> = ({ columns, data, id }) => {
const initialState = local.getItem<Partial<TableState<Record<string, unknown>>>>(getStorageKey(id)) || {};

export const Table: React.FC<Props> = ({ columns, data, id, initialState={} }) => {
const storedOrDefaultState = local.getItem<PartialTableState>(getStorageKey(id)) || initialState;
const { getTableProps, getTableBodyProps, headerGroups, rows, prepareRow, state, visibleColumns, setGlobalFilter } =
useTable<Record<string, unknown>>(
{
Expand All @@ -97,7 +99,7 @@ export const Table: React.FC<Props> = ({ columns, data, id }) => {
data,
autoResetSortBy: false,
autoResetFilters: false,
initialState,
initialState: storedOrDefaultState,
},
useGlobalFilter,
useSortBy,
Expand Down
13 changes: 13 additions & 0 deletions src/components/ota-page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ class OtaPage extends Component<PropsFromStore & OtaApi & WithTranslation<'ota'>
{t('check_all')}
</Button>
),
accessor: ({ state }) => {
return (((state?.update ?? {}) as OTAState).state) + ''
},
id: 'check_all',
Cell: ({
row: {
Expand All @@ -168,6 +171,16 @@ class OtaPage extends Component<PropsFromStore & OtaApi & WithTranslation<'ota'>
id="otaDevices"
columns={columns as unknown as Column<Record<string, unknown>>[]}
data={otaDevices}
initialState={
{
sortBy: [
{
id: "check_all",
desc: false
}
]
}
}
/>
</div>
</div>
Expand Down

0 comments on commit a298487

Please sign in to comment.