fixed bug
This commit is contained in:
@@ -128,8 +128,8 @@ const OperatorList = () => {
|
|||||||
props.dependencyFieldValue.value === ""
|
props.dependencyFieldValue.value === ""
|
||||||
? "empty"
|
? "empty"
|
||||||
: loadingSubItemsList
|
: loadingSubItemsList
|
||||||
? "loading"
|
? "loading"
|
||||||
: props.filterParameters.value
|
: props.filterParameters.value
|
||||||
}
|
}
|
||||||
columnSelectOption={getColumnSelectOptions}
|
columnSelectOption={getColumnSelectOptions}
|
||||||
/>
|
/>
|
||||||
@@ -282,7 +282,7 @@ const OperatorList = () => {
|
|||||||
grow: false,
|
grow: false,
|
||||||
size: 100,
|
size: 100,
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorFn: (row) => moment(row.created_at).locale("fa").format("HH:mm | yyyy/MM/DD"),
|
accessorFn: (row) => moment(row.created_at).locale("fa").format("HH:mm | yyyy/MM/DD"),
|
||||||
|
|||||||
@@ -378,7 +378,7 @@ const SupervisorList = () => {
|
|||||||
grow: false,
|
grow: false,
|
||||||
size: 100,
|
size: 100,
|
||||||
},
|
},
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorFn: (row) => moment(row.created_at).locale("fa").format("HH:mm | yyyy/MM/DD"),
|
accessorFn: (row) => moment(row.created_at).locale("fa").format("HH:mm | yyyy/MM/DD"),
|
||||||
|
|||||||
@@ -5,14 +5,25 @@ import isArrayEmpty from "@/core/utils/isArrayEmpty";
|
|||||||
import useDataTable from "@/lib/hooks/useDataTable";
|
import useDataTable from "@/lib/hooks/useDataTable";
|
||||||
import useRequest from "@/lib/hooks/useRequest";
|
import useRequest from "@/lib/hooks/useRequest";
|
||||||
import { useMaterialReactTable } from "material-react-table";
|
import { useMaterialReactTable } from "material-react-table";
|
||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useReducer, useState } from "react";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
import { FA_DATATABLE_LOCALIZATION } from "./localization/fa/datatable";
|
import { FA_DATATABLE_LOCALIZATION } from "./localization/fa/datatable";
|
||||||
import DataTable_Paper from "./table/Paper";
|
import DataTable_Paper from "./table/Paper";
|
||||||
|
|
||||||
|
const rowSelectionReducer = (state, action) => {
|
||||||
|
switch (action.type) {
|
||||||
|
case "TOGGLE_ROW":
|
||||||
|
return { [action.payload]: true };
|
||||||
|
case "RESET":
|
||||||
|
return {};
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const DataTable_Main = (props) => {
|
const DataTable_Main = (props) => {
|
||||||
const request = useRequest();
|
const request = useRequest();
|
||||||
const [rowSelection, setRowSelection] = useState({});
|
const [rowSelection, dispatchRowSelection] = useReducer(rowSelectionReducer, {});
|
||||||
const { filterData, sortData, setSortData, hideData } = useDataTable();
|
const { filterData, sortData, setSortData, hideData } = useDataTable();
|
||||||
const {
|
const {
|
||||||
need_filter,
|
need_filter,
|
||||||
@@ -75,7 +86,8 @@ const DataTable_Main = (props) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setRowSelection({});
|
if (!isValidating) return;
|
||||||
|
dispatchRowSelection({ type: "RESET" });
|
||||||
}, [isValidating]);
|
}, [isValidating]);
|
||||||
|
|
||||||
const table = useMaterialReactTable({
|
const table = useMaterialReactTable({
|
||||||
@@ -83,11 +95,8 @@ const DataTable_Main = (props) => {
|
|||||||
columns,
|
columns,
|
||||||
data: data ?? [],
|
data: data ?? [],
|
||||||
muiTableBodyRowProps: ({ row }) => ({
|
muiTableBodyRowProps: ({ row }) => ({
|
||||||
onClick: () =>
|
onClick: () => dispatchRowSelection({ type: "TOGGLE_ROW", payload: row.id }),
|
||||||
setRowSelection((prev) => ({
|
selected: !!rowSelection[row.id],
|
||||||
[row.id]: true,
|
|
||||||
})),
|
|
||||||
selected: rowSelection[row.id],
|
|
||||||
}),
|
}),
|
||||||
initialState: {
|
initialState: {
|
||||||
density: "compact",
|
density: "compact",
|
||||||
|
|||||||
Reference in New Issue
Block a user