mobigrid-module 1.1.5 → 1.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/CustomTable/CustomTable.d.ts +8 -0
- package/dist/components/CustomTable/Pagination.d.ts +8 -0
- package/dist/components/Icon.d.ts +6 -0
- package/dist/components/InvalidConfig.d.ts +2 -0
- package/dist/components/Layout/PageHeader.d.ts +13 -0
- package/dist/components/LoadingConfig.d.ts +2 -0
- package/dist/components/ui/alert.d.ts +8 -0
- package/dist/components/ui/button.d.ts +11 -0
- package/dist/components/ui/calendar.d.ts +8 -0
- package/dist/components/ui/date-picker-with-range.d.ts +7 -0
- package/dist/components/ui/dialog.d.ts +19 -0
- package/dist/components/ui/input.d.ts +3 -0
- package/dist/components/ui/pagination.d.ts +28 -0
- package/dist/components/ui/popover.d.ts +7 -0
- package/dist/components/ui/select.d.ts +13 -0
- package/dist/components/ui/sonner.d.ts +5 -0
- package/dist/components/ui/table.d.ts +10 -0
- package/dist/index.cjs +53 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.esm.js +70 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +53 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/vite.config.d.ts +2 -0
- package/package.json +11 -9
- package/components/CustomTable/CustomTable.tsx +0 -182
- package/components/CustomTable/Pagination.tsx +0 -136
- package/components/Icon.tsx +0 -27
- package/components/InvalidConfig.tsx +0 -26
- package/components/Layout/PageHeader.tsx +0 -270
- package/components/LoadingConfig.tsx +0 -38
- package/components/ui/alert.tsx +0 -59
- package/components/ui/button.tsx +0 -57
- package/components/ui/calendar.tsx +0 -70
- package/components/ui/date-picker-with-range.tsx +0 -167
- package/components/ui/dialog.tsx +0 -120
- package/components/ui/input.tsx +0 -22
- package/components/ui/pagination.tsx +0 -117
- package/components/ui/popover.tsx +0 -31
- package/components/ui/select.tsx +0 -157
- package/components/ui/sonner.tsx +0 -30
- package/components/ui/table.tsx +0 -120
- package/index.d.ts +0 -55
- package/index.tsx +0 -196
- package/lib/utils.ts +0 -6
- package/tsconfig.json +0 -36
package/components/ui/select.tsx
DELETED
@@ -1,157 +0,0 @@
|
|
1
|
-
import * as React from "react"
|
2
|
-
import * as SelectPrimitive from "@radix-ui/react-select"
|
3
|
-
import { Check, ChevronDown, ChevronUp } from "lucide-react"
|
4
|
-
|
5
|
-
import { cn } from "../../lib/utils"
|
6
|
-
|
7
|
-
const Select = SelectPrimitive.Root
|
8
|
-
|
9
|
-
const SelectGroup = SelectPrimitive.Group
|
10
|
-
|
11
|
-
const SelectValue = SelectPrimitive.Value
|
12
|
-
|
13
|
-
const SelectTrigger = React.forwardRef<
|
14
|
-
React.ElementRef<typeof SelectPrimitive.Trigger>,
|
15
|
-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
|
16
|
-
>(({ className, children, ...props }, ref) => (
|
17
|
-
<SelectPrimitive.Trigger
|
18
|
-
ref={ref}
|
19
|
-
className={cn(
|
20
|
-
"flex h-9 w-full items-center justify-between whitespace-nowrap rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-ring disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",
|
21
|
-
className
|
22
|
-
)}
|
23
|
-
{...props}
|
24
|
-
>
|
25
|
-
{children}
|
26
|
-
<SelectPrimitive.Icon asChild>
|
27
|
-
<ChevronDown className="h-4 w-4 opacity-50" />
|
28
|
-
</SelectPrimitive.Icon>
|
29
|
-
</SelectPrimitive.Trigger>
|
30
|
-
))
|
31
|
-
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName
|
32
|
-
|
33
|
-
const SelectScrollUpButton = React.forwardRef<
|
34
|
-
React.ElementRef<typeof SelectPrimitive.ScrollUpButton>,
|
35
|
-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollUpButton>
|
36
|
-
>(({ className, ...props }, ref) => (
|
37
|
-
<SelectPrimitive.ScrollUpButton
|
38
|
-
ref={ref}
|
39
|
-
className={cn(
|
40
|
-
"flex cursor-default items-center justify-center py-1",
|
41
|
-
className
|
42
|
-
)}
|
43
|
-
{...props}
|
44
|
-
>
|
45
|
-
<ChevronUp className="h-4 w-4" />
|
46
|
-
</SelectPrimitive.ScrollUpButton>
|
47
|
-
))
|
48
|
-
SelectScrollUpButton.displayName = SelectPrimitive.ScrollUpButton.displayName
|
49
|
-
|
50
|
-
const SelectScrollDownButton = React.forwardRef<
|
51
|
-
React.ElementRef<typeof SelectPrimitive.ScrollDownButton>,
|
52
|
-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.ScrollDownButton>
|
53
|
-
>(({ className, ...props }, ref) => (
|
54
|
-
<SelectPrimitive.ScrollDownButton
|
55
|
-
ref={ref}
|
56
|
-
className={cn(
|
57
|
-
"flex cursor-default items-center justify-center py-1",
|
58
|
-
className
|
59
|
-
)}
|
60
|
-
{...props}
|
61
|
-
>
|
62
|
-
<ChevronDown className="h-4 w-4" />
|
63
|
-
</SelectPrimitive.ScrollDownButton>
|
64
|
-
))
|
65
|
-
SelectScrollDownButton.displayName =
|
66
|
-
SelectPrimitive.ScrollDownButton.displayName
|
67
|
-
|
68
|
-
const SelectContent = React.forwardRef<
|
69
|
-
React.ElementRef<typeof SelectPrimitive.Content>,
|
70
|
-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
|
71
|
-
>(({ className, children, position = "popper", ...props }, ref) => (
|
72
|
-
<SelectPrimitive.Portal>
|
73
|
-
<SelectPrimitive.Content
|
74
|
-
ref={ref}
|
75
|
-
className={cn(
|
76
|
-
"relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
|
77
|
-
position === "popper" &&
|
78
|
-
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
|
79
|
-
className
|
80
|
-
)}
|
81
|
-
position={position}
|
82
|
-
{...props}
|
83
|
-
>
|
84
|
-
<SelectScrollUpButton />
|
85
|
-
<SelectPrimitive.Viewport
|
86
|
-
className={cn(
|
87
|
-
"p-1",
|
88
|
-
position === "popper" &&
|
89
|
-
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"
|
90
|
-
)}
|
91
|
-
>
|
92
|
-
{children}
|
93
|
-
</SelectPrimitive.Viewport>
|
94
|
-
<SelectScrollDownButton />
|
95
|
-
</SelectPrimitive.Content>
|
96
|
-
</SelectPrimitive.Portal>
|
97
|
-
))
|
98
|
-
SelectContent.displayName = SelectPrimitive.Content.displayName
|
99
|
-
|
100
|
-
const SelectLabel = React.forwardRef<
|
101
|
-
React.ElementRef<typeof SelectPrimitive.Label>,
|
102
|
-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
|
103
|
-
>(({ className, ...props }, ref) => (
|
104
|
-
<SelectPrimitive.Label
|
105
|
-
ref={ref}
|
106
|
-
className={cn("px-2 py-1.5 text-sm font-semibold", className)}
|
107
|
-
{...props}
|
108
|
-
/>
|
109
|
-
))
|
110
|
-
SelectLabel.displayName = SelectPrimitive.Label.displayName
|
111
|
-
|
112
|
-
const SelectItem = React.forwardRef<
|
113
|
-
React.ElementRef<typeof SelectPrimitive.Item>,
|
114
|
-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>
|
115
|
-
>(({ className, children, ...props }, ref) => (
|
116
|
-
<SelectPrimitive.Item
|
117
|
-
ref={ref}
|
118
|
-
className={cn(
|
119
|
-
"relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-2 pr-8 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
|
120
|
-
className
|
121
|
-
)}
|
122
|
-
{...props}
|
123
|
-
>
|
124
|
-
<span className="absolute right-2 flex h-3.5 w-3.5 items-center justify-center">
|
125
|
-
<SelectPrimitive.ItemIndicator>
|
126
|
-
<Check className="h-4 w-4" />
|
127
|
-
</SelectPrimitive.ItemIndicator>
|
128
|
-
</span>
|
129
|
-
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
130
|
-
</SelectPrimitive.Item>
|
131
|
-
))
|
132
|
-
SelectItem.displayName = SelectPrimitive.Item.displayName
|
133
|
-
|
134
|
-
const SelectSeparator = React.forwardRef<
|
135
|
-
React.ElementRef<typeof SelectPrimitive.Separator>,
|
136
|
-
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
|
137
|
-
>(({ className, ...props }, ref) => (
|
138
|
-
<SelectPrimitive.Separator
|
139
|
-
ref={ref}
|
140
|
-
className={cn("-mx-1 my-1 h-px bg-muted", className)}
|
141
|
-
{...props}
|
142
|
-
/>
|
143
|
-
))
|
144
|
-
SelectSeparator.displayName = SelectPrimitive.Separator.displayName
|
145
|
-
|
146
|
-
export {
|
147
|
-
Select,
|
148
|
-
SelectGroup,
|
149
|
-
SelectValue,
|
150
|
-
SelectTrigger,
|
151
|
-
SelectContent,
|
152
|
-
SelectLabel,
|
153
|
-
SelectItem,
|
154
|
-
SelectSeparator,
|
155
|
-
SelectScrollUpButton,
|
156
|
-
SelectScrollDownButton,
|
157
|
-
}
|
package/components/ui/sonner.tsx
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
import React from "react"
|
2
|
-
import { useTheme } from "next-themes"
|
3
|
-
import { Toaster as Sonner } from "sonner"
|
4
|
-
|
5
|
-
type ToasterProps = React.ComponentProps<typeof Sonner>
|
6
|
-
|
7
|
-
const Toaster = ({ ...props }: ToasterProps) => {
|
8
|
-
const { theme = "system" } = useTheme()
|
9
|
-
|
10
|
-
return (
|
11
|
-
<Sonner
|
12
|
-
theme={theme as ToasterProps["theme"]}
|
13
|
-
className="toaster group"
|
14
|
-
toastOptions={{
|
15
|
-
classNames: {
|
16
|
-
toast:
|
17
|
-
"group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
|
18
|
-
description: "group-[.toast]:text-muted-foreground",
|
19
|
-
actionButton:
|
20
|
-
"group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
|
21
|
-
cancelButton:
|
22
|
-
"group-[.toast]:bg-muted group-[.toast]:text-muted-foreground",
|
23
|
-
},
|
24
|
-
}}
|
25
|
-
{...props}
|
26
|
-
/>
|
27
|
-
)
|
28
|
-
}
|
29
|
-
|
30
|
-
export { Toaster }
|
package/components/ui/table.tsx
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
import * as React from "react"
|
2
|
-
|
3
|
-
import { cn } from "../../lib/utils"
|
4
|
-
|
5
|
-
const Table = React.forwardRef<
|
6
|
-
HTMLTableElement,
|
7
|
-
React.HTMLAttributes<HTMLTableElement>
|
8
|
-
>(({ className, ...props }, ref) => (
|
9
|
-
<div className="relative w-full overflow-auto">
|
10
|
-
<table
|
11
|
-
ref={ref}
|
12
|
-
className={cn("w-full caption-bottom text-sm", className)}
|
13
|
-
{...props}
|
14
|
-
/>
|
15
|
-
</div>
|
16
|
-
))
|
17
|
-
Table.displayName = "Table"
|
18
|
-
|
19
|
-
const TableHeader = React.forwardRef<
|
20
|
-
HTMLTableSectionElement,
|
21
|
-
React.HTMLAttributes<HTMLTableSectionElement>
|
22
|
-
>(({ className, ...props }, ref) => (
|
23
|
-
<thead ref={ref} className={cn("[&_tr]:border-b", className)} {...props} />
|
24
|
-
))
|
25
|
-
TableHeader.displayName = "TableHeader"
|
26
|
-
|
27
|
-
const TableBody = React.forwardRef<
|
28
|
-
HTMLTableSectionElement,
|
29
|
-
React.HTMLAttributes<HTMLTableSectionElement>
|
30
|
-
>(({ className, ...props }, ref) => (
|
31
|
-
<tbody
|
32
|
-
ref={ref}
|
33
|
-
className={cn("[&_tr:last-child]:border-0", className)}
|
34
|
-
{...props}
|
35
|
-
/>
|
36
|
-
))
|
37
|
-
TableBody.displayName = "TableBody"
|
38
|
-
|
39
|
-
const TableFooter = React.forwardRef<
|
40
|
-
HTMLTableSectionElement,
|
41
|
-
React.HTMLAttributes<HTMLTableSectionElement>
|
42
|
-
>(({ className, ...props }, ref) => (
|
43
|
-
<tfoot
|
44
|
-
ref={ref}
|
45
|
-
className={cn(
|
46
|
-
"border-t bg-muted/50 font-medium [&>tr]:last:border-b-0",
|
47
|
-
className
|
48
|
-
)}
|
49
|
-
{...props}
|
50
|
-
/>
|
51
|
-
))
|
52
|
-
TableFooter.displayName = "TableFooter"
|
53
|
-
|
54
|
-
const TableRow = React.forwardRef<
|
55
|
-
HTMLTableRowElement,
|
56
|
-
React.HTMLAttributes<HTMLTableRowElement>
|
57
|
-
>(({ className, ...props }, ref) => (
|
58
|
-
<tr
|
59
|
-
ref={ref}
|
60
|
-
className={cn(
|
61
|
-
"border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
|
62
|
-
className
|
63
|
-
)}
|
64
|
-
{...props}
|
65
|
-
/>
|
66
|
-
))
|
67
|
-
TableRow.displayName = "TableRow"
|
68
|
-
|
69
|
-
const TableHead = React.forwardRef<
|
70
|
-
HTMLTableCellElement,
|
71
|
-
React.ThHTMLAttributes<HTMLTableCellElement>
|
72
|
-
>(({ className, ...props }, ref) => (
|
73
|
-
<th
|
74
|
-
ref={ref}
|
75
|
-
className={cn(
|
76
|
-
"h-10 px-2 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
77
|
-
className
|
78
|
-
)}
|
79
|
-
{...props}
|
80
|
-
/>
|
81
|
-
))
|
82
|
-
TableHead.displayName = "TableHead"
|
83
|
-
|
84
|
-
const TableCell = React.forwardRef<
|
85
|
-
HTMLTableCellElement,
|
86
|
-
React.TdHTMLAttributes<HTMLTableCellElement>
|
87
|
-
>(({ className, ...props }, ref) => (
|
88
|
-
<td
|
89
|
-
ref={ref}
|
90
|
-
className={cn(
|
91
|
-
"p-2 align-middle [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
|
92
|
-
className
|
93
|
-
)}
|
94
|
-
{...props}
|
95
|
-
/>
|
96
|
-
))
|
97
|
-
TableCell.displayName = "TableCell"
|
98
|
-
|
99
|
-
const TableCaption = React.forwardRef<
|
100
|
-
HTMLTableCaptionElement,
|
101
|
-
React.HTMLAttributes<HTMLTableCaptionElement>
|
102
|
-
>(({ className, ...props }, ref) => (
|
103
|
-
<caption
|
104
|
-
ref={ref}
|
105
|
-
className={cn("mt-4 text-sm text-muted-foreground", className)}
|
106
|
-
{...props}
|
107
|
-
/>
|
108
|
-
))
|
109
|
-
TableCaption.displayName = "TableCaption"
|
110
|
-
|
111
|
-
export {
|
112
|
-
Table,
|
113
|
-
TableHeader,
|
114
|
-
TableBody,
|
115
|
-
TableFooter,
|
116
|
-
TableHead,
|
117
|
-
TableRow,
|
118
|
-
TableCell,
|
119
|
-
TableCaption,
|
120
|
-
}
|
package/index.d.ts
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
declare module "mobigrid-module" {
|
2
|
-
import { ReactNode } from "react";
|
3
|
-
|
4
|
-
export interface FilterOption {
|
5
|
-
name: string;
|
6
|
-
type: string;
|
7
|
-
urlSource?: string;
|
8
|
-
options?: any[];
|
9
|
-
label?: string;
|
10
|
-
placeholder?: string;
|
11
|
-
required?: boolean;
|
12
|
-
}
|
13
|
-
|
14
|
-
export interface Column {
|
15
|
-
field: string;
|
16
|
-
headerName: string;
|
17
|
-
width?: number;
|
18
|
-
sortable?: boolean;
|
19
|
-
renderCell?: (params: any) => ReactNode;
|
20
|
-
}
|
21
|
-
|
22
|
-
export interface Config {
|
23
|
-
title: string;
|
24
|
-
data_url: string;
|
25
|
-
colomns: Column[];
|
26
|
-
Filters?: FilterOption[][];
|
27
|
-
}
|
28
|
-
|
29
|
-
export interface FilterState {
|
30
|
-
fromDate: string;
|
31
|
-
toDate: string;
|
32
|
-
[key: string]: any;
|
33
|
-
}
|
34
|
-
|
35
|
-
export interface ApiResponse {
|
36
|
-
DATA: any[];
|
37
|
-
PAGESNUM: number;
|
38
|
-
}
|
39
|
-
|
40
|
-
export interface Error {
|
41
|
-
title: string;
|
42
|
-
message: string;
|
43
|
-
}
|
44
|
-
|
45
|
-
export interface MobigridModuleProps {
|
46
|
-
configUrl: string;
|
47
|
-
preJsUrl: string;
|
48
|
-
itemsPerPage?: number;
|
49
|
-
children?: ReactNode;
|
50
|
-
}
|
51
|
-
|
52
|
-
const MobigridModule: React.FC<MobigridModuleProps>;
|
53
|
-
|
54
|
-
export default MobigridModule;
|
55
|
-
}
|
package/index.tsx
DELETED
@@ -1,196 +0,0 @@
|
|
1
|
-
import React from "react";
|
2
|
-
import { useEffect, useState } from "react";
|
3
|
-
import { format } from "date-fns";
|
4
|
-
import axios from "axios";
|
5
|
-
import { Alert, AlertTitle, AlertDescription } from "./components/ui/alert";
|
6
|
-
import { AlertCircle } from "lucide-react";
|
7
|
-
import { PageHeader } from "./components/Layout/PageHeader";
|
8
|
-
import { CustomTable } from "./components/CustomTable/CustomTable";
|
9
|
-
import Pagination from "./components/CustomTable/Pagination";
|
10
|
-
import LoadingConfig from "./components/LoadingConfig";
|
11
|
-
import InvalidConfig from "./components/InvalidConfig";
|
12
|
-
|
13
|
-
const ITEMS_PER_PAGE = 14;
|
14
|
-
|
15
|
-
interface ContainerProps {
|
16
|
-
configUrl: string;
|
17
|
-
preJsUrl: string;
|
18
|
-
itemsPerPage?: number;
|
19
|
-
children?: React.ReactNode;
|
20
|
-
}
|
21
|
-
|
22
|
-
const MobigridModule = ({
|
23
|
-
configUrl,
|
24
|
-
preJsUrl,
|
25
|
-
itemsPerPage = ITEMS_PER_PAGE,
|
26
|
-
children,
|
27
|
-
}: ContainerProps) => {
|
28
|
-
const [config, setConfig] = useState<any>(null);
|
29
|
-
const [invalidConfig, setInvalidConfig] = useState(false);
|
30
|
-
const [errors, setErrors] = useState<
|
31
|
-
Array<{
|
32
|
-
title: string;
|
33
|
-
message: string;
|
34
|
-
}>
|
35
|
-
>([]);
|
36
|
-
const [isLoading, setIsLoading] = useState(false);
|
37
|
-
const [data, setData] = useState([]);
|
38
|
-
const [count, setCount] = useState(0);
|
39
|
-
const [currentPage, setCurrentPage] = useState(1);
|
40
|
-
const [totalPages, setTotalPages] = useState(1);
|
41
|
-
const [filters, setFilters] = useState({
|
42
|
-
fromDate: new Date(
|
43
|
-
new Date().getFullYear(),
|
44
|
-
new Date().getMonth(),
|
45
|
-
1
|
46
|
-
).toLocaleString(),
|
47
|
-
toDate: new Date(
|
48
|
-
new Date().getFullYear(),
|
49
|
-
new Date().getMonth() + 1,
|
50
|
-
0,
|
51
|
-
23,
|
52
|
-
59,
|
53
|
-
59
|
54
|
-
).toLocaleString(),
|
55
|
-
});
|
56
|
-
const [filterOptions, setFilterOptions] = useState<any[]>([]);
|
57
|
-
|
58
|
-
useEffect(() => {
|
59
|
-
const loadConfig = async () => {
|
60
|
-
try {
|
61
|
-
const response = await fetch(configUrl);
|
62
|
-
const data = await response.json();
|
63
|
-
if (data && data.title && data.data_url && data.colomns) {
|
64
|
-
setConfig(data);
|
65
|
-
setFilterOptions(data.Filters?.flat() || []);
|
66
|
-
} else {
|
67
|
-
setInvalidConfig(true);
|
68
|
-
}
|
69
|
-
} catch (error) {
|
70
|
-
setInvalidConfig(true);
|
71
|
-
}
|
72
|
-
};
|
73
|
-
|
74
|
-
const loadFunctions = async () => {
|
75
|
-
const response = await fetch(preJsUrl);
|
76
|
-
const script = document.createElement("script");
|
77
|
-
script.textContent = await response.text();
|
78
|
-
document.head.appendChild(script);
|
79
|
-
};
|
80
|
-
|
81
|
-
if (configUrl && preJsUrl) {
|
82
|
-
loadConfig();
|
83
|
-
loadFunctions();
|
84
|
-
}
|
85
|
-
}, [configUrl, preJsUrl]);
|
86
|
-
|
87
|
-
useEffect(() => {
|
88
|
-
const controller = new AbortController();
|
89
|
-
|
90
|
-
const initializeFilters = async () => {
|
91
|
-
const filters = config?.Filters?.flat() || [];
|
92
|
-
for (const filter of filters) {
|
93
|
-
if (filter.type === "Select" && filter.urlSource) {
|
94
|
-
await fetchFilterOptions(filter, controller.signal);
|
95
|
-
}
|
96
|
-
}
|
97
|
-
};
|
98
|
-
|
99
|
-
if (config) initializeFilters();
|
100
|
-
|
101
|
-
return () => controller.abort();
|
102
|
-
}, [config]);
|
103
|
-
|
104
|
-
const getData = async () => {
|
105
|
-
setErrors([]);
|
106
|
-
const postBody = {
|
107
|
-
page: currentPage,
|
108
|
-
filters: {
|
109
|
-
...filters,
|
110
|
-
fromDate: format(filters.fromDate, "MM-dd-yyyy HH:mm"),
|
111
|
-
toDate: format(filters.toDate, "MM-dd-yyyy HH:mm"),
|
112
|
-
},
|
113
|
-
};
|
114
|
-
|
115
|
-
setIsLoading(true);
|
116
|
-
try {
|
117
|
-
const response = await axios.post(config.data_url, postBody);
|
118
|
-
setIsLoading(false);
|
119
|
-
|
120
|
-
if (response?.data) {
|
121
|
-
setData(response.data?.DATA);
|
122
|
-
setCount(response.data?.PAGESNUM);
|
123
|
-
setTotalPages(Math.ceil(response.data?.PAGESNUM / itemsPerPage) || 1);
|
124
|
-
} else {
|
125
|
-
setInvalidConfig(true);
|
126
|
-
}
|
127
|
-
} catch (error) {
|
128
|
-
setIsLoading(false);
|
129
|
-
setErrors((prev) => [
|
130
|
-
...prev,
|
131
|
-
{
|
132
|
-
title: "Erreur",
|
133
|
-
message: "Une erreur est survenue",
|
134
|
-
},
|
135
|
-
]);
|
136
|
-
}
|
137
|
-
};
|
138
|
-
|
139
|
-
const fetchFilterOptions = async (filter: any, signal?: AbortSignal) => {
|
140
|
-
if (filter.type === "Select" && filter.urlSource) {
|
141
|
-
try {
|
142
|
-
const response = await axios.get(filter.urlSource, { signal });
|
143
|
-
if (response?.status === 200 && response?.data) {
|
144
|
-
const options = Array.isArray(response.data) ? response.data : [];
|
145
|
-
setFilterOptions((prev) =>
|
146
|
-
prev.map((f) => (f.name === filter.name ? { ...f, options } : f))
|
147
|
-
);
|
148
|
-
}
|
149
|
-
} catch (error) {
|
150
|
-
if (!axios.isCancel(error)) {
|
151
|
-
setErrors((prev) => [
|
152
|
-
...prev,
|
153
|
-
{
|
154
|
-
title: "Erreur",
|
155
|
-
message: `Une erreur est survenue lors de la récupération des options pour ${filter.name}`,
|
156
|
-
},
|
157
|
-
]);
|
158
|
-
console.error(`Error fetching options for ${filter.name}:`, error);
|
159
|
-
}
|
160
|
-
}
|
161
|
-
}
|
162
|
-
};
|
163
|
-
|
164
|
-
if (invalidConfig) return <InvalidConfig />;
|
165
|
-
if (!config) return <LoadingConfig />;
|
166
|
-
return (
|
167
|
-
<div className="flex flex-col gap-4 p-4 max-w-[1300px] mx-auto mt-8 mb-">
|
168
|
-
<PageHeader
|
169
|
-
title={config.title}
|
170
|
-
configFilters={filterOptions}
|
171
|
-
filters={filters}
|
172
|
-
setFilters={setFilters}
|
173
|
-
onSearch={() => getData()}
|
174
|
-
count={count}
|
175
|
-
isLoading={isLoading}
|
176
|
-
setCurrentPage={setCurrentPage}
|
177
|
-
/>
|
178
|
-
{errors.map((error, index) => (
|
179
|
-
<Alert key={index} variant="destructive">
|
180
|
-
<AlertCircle className="h-4 w-4" />
|
181
|
-
<AlertTitle>{error.title}</AlertTitle>
|
182
|
-
<AlertDescription>{error.message}</AlertDescription>
|
183
|
-
</Alert>
|
184
|
-
))}
|
185
|
-
<CustomTable data={data} columns={config.colomns} isLoading={isLoading} />
|
186
|
-
<Pagination
|
187
|
-
currentPage={currentPage}
|
188
|
-
totalPages={totalPages}
|
189
|
-
onPageChange={setCurrentPage}
|
190
|
-
/>
|
191
|
-
{children}
|
192
|
-
</div>
|
193
|
-
);
|
194
|
-
};
|
195
|
-
|
196
|
-
export { MobigridModule as default };
|
package/lib/utils.ts
DELETED
package/tsconfig.json
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"compilerOptions": {
|
3
|
-
"target": "ES5",
|
4
|
-
"module": "ESNext",
|
5
|
-
"declaration": true,
|
6
|
-
"declarationDir": "dist/types",
|
7
|
-
"outDir": "dist",
|
8
|
-
"jsx": "react",
|
9
|
-
"strict": true,
|
10
|
-
"esModuleInterop": true,
|
11
|
-
"skipLibCheck": true,
|
12
|
-
"moduleResolution": "node",
|
13
|
-
"baseUrl": "./",
|
14
|
-
"paths": {
|
15
|
-
"*": [
|
16
|
-
"node_modules/*"
|
17
|
-
]
|
18
|
-
},
|
19
|
-
"typeRoots": [
|
20
|
-
"./node_modules/@types",
|
21
|
-
"./typings"
|
22
|
-
],
|
23
|
-
},
|
24
|
-
"include": [
|
25
|
-
"./**/*",
|
26
|
-
"typings",
|
27
|
-
"components",
|
28
|
-
"lib",
|
29
|
-
"types",
|
30
|
-
"index.tsx"
|
31
|
-
],
|
32
|
-
"exclude": [
|
33
|
-
"node_modules",
|
34
|
-
"dist"
|
35
|
-
]
|
36
|
-
}
|