feat: add autoRefresh prop to Field and TypeAsyncDropdown components for enhanced data fetching
This commit is contained in:
parent
06387116f7
commit
2856081525
|
|
@ -67,6 +67,7 @@ export interface FieldProps {
|
||||||
pagination?: boolean;
|
pagination?: boolean;
|
||||||
search?: "api" | "local";
|
search?: "api" | "local";
|
||||||
visibleLabel?: boolean;
|
visibleLabel?: boolean;
|
||||||
|
autoRefresh?: boolean;
|
||||||
}
|
}
|
||||||
export const Field: React.FC<FieldProps> = ({
|
export const Field: React.FC<FieldProps> = ({
|
||||||
fm,
|
fm,
|
||||||
|
|
@ -97,6 +98,7 @@ export const Field: React.FC<FieldProps> = ({
|
||||||
target,
|
target,
|
||||||
pagination = true,
|
pagination = true,
|
||||||
search = "api",
|
search = "api",
|
||||||
|
autoRefresh = false,
|
||||||
}) => {
|
}) => {
|
||||||
let result = null;
|
let result = null;
|
||||||
const field = useLocal({
|
const field = useLocal({
|
||||||
|
|
@ -217,7 +219,7 @@ export const Field: React.FC<FieldProps> = ({
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
is_disable
|
is_disable
|
||||||
? "border border-gray-100 bg-gray-100"
|
? "border border-gray-100 bg-gray-100 is_disable"
|
||||||
: "border border-gray-300 ",
|
: "border border-gray-300 ",
|
||||||
"relative field",
|
"relative field",
|
||||||
!is_disable
|
!is_disable
|
||||||
|
|
@ -355,6 +357,7 @@ export const Field: React.FC<FieldProps> = ({
|
||||||
<TypeAsyncDropdown
|
<TypeAsyncDropdown
|
||||||
label={label}
|
label={label}
|
||||||
fm={fm}
|
fm={fm}
|
||||||
|
autoRefresh={autoRefresh}
|
||||||
fields={initField}
|
fields={initField}
|
||||||
required={required}
|
required={required}
|
||||||
name={name}
|
name={name}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ export const TypeAsyncDropdown: React.FC<any> = ({
|
||||||
pagination = true,
|
pagination = true,
|
||||||
search = "api",
|
search = "api",
|
||||||
required = false,
|
required = false,
|
||||||
|
autoRefresh = false,
|
||||||
}) => {
|
}) => {
|
||||||
const [open, setOpen] = useState(false as boolean);
|
const [open, setOpen] = useState(false as boolean);
|
||||||
const [refreshKey, setRefreshKey] = useState(Date.now());
|
const [refreshKey, setRefreshKey] = useState(Date.now());
|
||||||
|
|
@ -203,7 +204,7 @@ export const TypeAsyncDropdown: React.FC<any> = ({
|
||||||
}
|
}
|
||||||
} else if (typeof value === "object") {
|
} else if (typeof value === "object") {
|
||||||
value = {
|
value = {
|
||||||
value: getLabel(value),
|
value: getValue(value),
|
||||||
label: getLabel(value),
|
label: getLabel(value),
|
||||||
};
|
};
|
||||||
} else if (
|
} else if (
|
||||||
|
|
@ -258,7 +259,9 @@ export const TypeAsyncDropdown: React.FC<any> = ({
|
||||||
classNameTrigger={""}
|
classNameTrigger={""}
|
||||||
arrow={false}
|
arrow={false}
|
||||||
className="rounded-md"
|
className="rounded-md"
|
||||||
onOpenChange={(open: any) => {}}
|
onOpenChange={(open: any) => {
|
||||||
|
setOpen(open);
|
||||||
|
}}
|
||||||
open={true}
|
open={true}
|
||||||
content={
|
content={
|
||||||
<div
|
<div
|
||||||
|
|
@ -335,12 +338,15 @@ export const TypeAsyncDropdown: React.FC<any> = ({
|
||||||
isClearable={clearable}
|
isClearable={clearable}
|
||||||
onMenuOpen={() => {
|
onMenuOpen={() => {
|
||||||
setOpen(true);
|
setOpen(true);
|
||||||
|
if (autoRefresh) {
|
||||||
|
setRefreshKey(Date.now()); // Refresh API saat menu dibuka jika autoRefresh true
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
onMenuClose={() => {
|
onMenuClose={() => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
}}
|
}}
|
||||||
// closeMenuOnSelect={mode === "dropdown" ? true : false}
|
closeMenuOnSelect={mode === "dropdown" ? true : false}
|
||||||
closeMenuOnSelect={false}
|
// closeMenuOnSelect={false}
|
||||||
getOptionValue={(item) => item.value}
|
getOptionValue={(item) => item.value}
|
||||||
getOptionLabel={(item) => item.label}
|
getOptionLabel={(item) => item.label}
|
||||||
value={value}
|
value={value}
|
||||||
|
|
|
||||||
|
|
@ -518,12 +518,12 @@ export const TableList = <T extends object>({
|
||||||
};
|
};
|
||||||
const [pagination, setPagination] = React.useState({
|
const [pagination, setPagination] = React.useState({
|
||||||
pageIndex: 0,
|
pageIndex: 0,
|
||||||
pageSize: 20,
|
pageSize: take,
|
||||||
});
|
});
|
||||||
const table = useReactTable({
|
const table = useReactTable({
|
||||||
data: data,
|
data: data,
|
||||||
columnResizeMode,
|
columnResizeMode,
|
||||||
pageCount: Math.ceil(local.count / 20),
|
pageCount: Math.ceil(local.count / take),
|
||||||
manualPagination: true,
|
manualPagination: true,
|
||||||
columnResizeDirection,
|
columnResizeDirection,
|
||||||
columns,
|
columns,
|
||||||
|
|
@ -534,7 +534,7 @@ export const TableList = <T extends object>({
|
||||||
initialState: {
|
initialState: {
|
||||||
pagination: {
|
pagination: {
|
||||||
pageIndex: 0,
|
pageIndex: 0,
|
||||||
pageSize: 20, //custom default page size
|
pageSize: take, //custom default page size
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
state: {
|
state: {
|
||||||
|
|
@ -1078,7 +1078,7 @@ export const TableList = <T extends object>({
|
||||||
setPage={(page: any) => {
|
setPage={(page: any) => {
|
||||||
setPagination({
|
setPagination({
|
||||||
pageIndex: page,
|
pageIndex: page,
|
||||||
pageSize: 20,
|
pageSize: take,
|
||||||
});
|
});
|
||||||
local.paging = page;
|
local.paging = page;
|
||||||
local.render();
|
local.render();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue