refactor: rename setSorts to onSortsUpdate
This commit is contained in:
@ -16,7 +16,7 @@ type OwnProps<TData> = {
|
|||||||
columns: Array<ColumnDef<TData, any>>;
|
columns: Array<ColumnDef<TData, any>>;
|
||||||
viewName: string;
|
viewName: string;
|
||||||
viewIcon?: IconProp;
|
viewIcon?: IconProp;
|
||||||
setSorts?: React.Dispatch<React.SetStateAction<SortType[]>>;
|
onSortsUpdate?: React.Dispatch<React.SetStateAction<SortType[]>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const StyledTable = styled.table`
|
const StyledTable = styled.table`
|
||||||
@ -67,7 +67,7 @@ function Table<TData>({
|
|||||||
columns,
|
columns,
|
||||||
viewName,
|
viewName,
|
||||||
viewIcon,
|
viewIcon,
|
||||||
setSorts,
|
onSortsUpdate,
|
||||||
}: OwnProps<TData>) {
|
}: OwnProps<TData>) {
|
||||||
const table = useReactTable({
|
const table = useReactTable({
|
||||||
data,
|
data,
|
||||||
@ -80,7 +80,7 @@ function Table<TData>({
|
|||||||
<TableHeader
|
<TableHeader
|
||||||
viewName={viewName}
|
viewName={viewName}
|
||||||
viewIcon={viewIcon}
|
viewIcon={viewIcon}
|
||||||
setSorts={setSorts}
|
onSortsUpdate={onSortsUpdate}
|
||||||
/>
|
/>
|
||||||
<StyledTable>
|
<StyledTable>
|
||||||
<thead>
|
<thead>
|
||||||
|
|||||||
@ -9,7 +9,7 @@ import { useState } from 'react';
|
|||||||
type OwnProps = {
|
type OwnProps = {
|
||||||
viewName: string;
|
viewName: string;
|
||||||
viewIcon?: IconProp;
|
viewIcon?: IconProp;
|
||||||
setSorts?: React.Dispatch<React.SetStateAction<SortType[]>>;
|
onSortsUpdate?: React.Dispatch<React.SetStateAction<SortType[]>>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const StyledContainer = styled.div`
|
const StyledContainer = styled.div`
|
||||||
@ -44,17 +44,8 @@ const StyledFilters = styled.div`
|
|||||||
margin-right: ${(props) => props.theme.spacing(2)};
|
margin-right: ${(props) => props.theme.spacing(2)};
|
||||||
`;
|
`;
|
||||||
|
|
||||||
function TableHeader({
|
function TableHeader({ viewName, viewIcon, onSortsUpdate }: OwnProps) {
|
||||||
viewName,
|
const [sorts, setSorts] = useState([] as Array<SortType>);
|
||||||
viewIcon,
|
|
||||||
setSorts: parentSetSorts,
|
|
||||||
}: OwnProps) {
|
|
||||||
const [sorts, localSetSorts] = useState([] as Array<SortType>);
|
|
||||||
|
|
||||||
const setSorts = (value: React.SetStateAction<SortType[]>) => {
|
|
||||||
parentSetSorts && parentSetSorts(value);
|
|
||||||
localSetSorts(value);
|
|
||||||
};
|
|
||||||
|
|
||||||
const onSortItemSelect = (sortId: string) => {
|
const onSortItemSelect = (sortId: string) => {
|
||||||
setSorts([
|
setSorts([
|
||||||
@ -64,6 +55,7 @@ function TableHeader({
|
|||||||
id: sortId,
|
id: sortId,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
onSortsUpdate && onSortsUpdate(sorts);
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSortItemUnSelect = (sortId: string) => {
|
const onSortItemUnSelect = (sortId: string) => {
|
||||||
|
|||||||
@ -69,7 +69,7 @@ function People() {
|
|||||||
columns={peopleColumns}
|
columns={peopleColumns}
|
||||||
viewName="All People"
|
viewName="All People"
|
||||||
viewIcon={faList}
|
viewIcon={faList}
|
||||||
setSorts={setSorts}
|
onSortsUpdate={setSorts}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</StyledPeopleContainer>
|
</StyledPeopleContainer>
|
||||||
|
|||||||
Reference in New Issue
Block a user