@zydon/common 2.8.94 → 2.8.96
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/{chunk-E4Q7LX5L.js → chunk-6ACD5WGD.js} +2 -2
- package/dist/{chunk-7ZCLS5N5.js → chunk-6XOCS4DE.js} +2 -2
- package/dist/chunk-6XOCS4DE.js.map +1 -0
- package/dist/chunk-CG6F55WN.js +6 -0
- package/dist/chunk-CG6F55WN.js.map +1 -0
- package/dist/{chunk-7QZTU4E7.js → chunk-VFDADOF2.js} +3 -3
- package/dist/chunk-VFDADOF2.js.map +1 -0
- package/dist/components/Analytics/OverviewAnalytics/index.js +2 -2
- package/dist/components/Analytics/PartnerAnalysis/index.js +2 -2
- package/dist/components/DataGrid/index.js +1 -1
- package/dist/components/DataView/index.js +2 -2
- package/dist/components/DynamicDataView/index.js +2 -2
- package/dist/components/Filters/index.d.ts +3 -2
- package/dist/components/Filters/index.js +9 -9
- package/dist/components/Filters/index.js.map +1 -1
- package/dist/hooks/useFiltersSearchParams.d.ts +3 -2
- package/dist/hooks/useFiltersSearchParams.js +3 -3
- package/dist/hooks/useFiltersSearchParams.js.map +1 -1
- package/dist/types/period.d.ts +6 -1
- package/dist/types/period.js +1 -1
- package/dist/utils/filters.d.ts +10 -6
- package/dist/utils/filters.js +2 -2
- package/package.json +1 -1
- package/dist/chunk-7QZTU4E7.js.map +0 -1
- package/dist/chunk-7ZCLS5N5.js.map +0 -1
- package/dist/chunk-MEPEYLZT.js +0 -6
- package/dist/chunk-MEPEYLZT.js.map +0 -1
- /package/dist/{chunk-E4Q7LX5L.js.map → chunk-6ACD5WGD.js.map} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as a$9 } from './chunk-R2BCPHRH.js';
|
|
2
2
|
import { a as a$6 } from './chunk-4F2NKGF6.js';
|
|
3
|
-
import { a as a$3 } from './chunk-
|
|
3
|
+
import { a as a$3 } from './chunk-6XOCS4DE.js';
|
|
4
4
|
import { a as a$7 } from './chunk-6U5LS7MP.js';
|
|
5
5
|
import { a as a$5 } from './chunk-PRWQQJDL.js';
|
|
6
6
|
import { i, r, k, n, l, a as a$2, p, j, m, b as b$1, c, d, q, h, f, e, o, g } from './chunk-XUDTPZHF.js';
|
|
@@ -24,4 +24,4 @@ import { GridToolbarColumnsButton } from '@mui/x-data-grid-premium';
|
|
|
24
24
|
var Fo=(o,e)=>typeof o=="function"?o(e):!!o,Ae=(o,e)=>{if(o)return o===!0?{}:typeof o=="function"?o(e):o},ke=({actions:o,context:e})=>{let[t,r]=useState(null),[a$1,i]=useState(null),l=useMemo(()=>o.filter(n=>!Fo(n.hidden,e)),[o,e]),s=useCallback(async n=>{i(n.actionId);try{await n.handler(e);}finally{i(null);}},[e]),d=useCallback(n=>{if(n.confirmation){r(n);return}s(n).catch(()=>{});},[s]),m$1=useCallback(async()=>{t&&(await s(t),r(null));},[t,s]),f=useCallback(()=>{a$1||r(null);},[a$1]),c=Ae(t?.confirmation,e);return jsxs(Fragment,{children:[jsx(m,{children:l.map(n=>{let h=!!a$1||Fo(n.disabled,e),k=a$1===n.actionId;return jsx(Ce,{size:"small",variant:"text",onClick:()=>d(n),loading:k,disabled:h,sx:{color:"text.primary"},startIcon:typeof n.icon=="string"?jsx(a,{icon:n.icon}):n.icon,children:n.label},n.actionId)})}),t&&jsx(a$5,{open:!0,onClose:f,onConfirm:()=>{m$1().catch(()=>{});},confirming:a$1===t.actionId,modalTitle:c?.title??`${t.action??"Excluir"} ${e.selectedCount} ${t.entityName??"registro"}${e.selectedCount!==1?"s":""}?`,message:c?.message??"Esta a\xE7\xE3o n\xE3o poder\xE1 ser desfeita.",cancelButtonText:c?.cancelButtonText??"Cancelar",confirmButtonText:c?.confirmButtonText??"Sim, excluir"})]})},zo=ke;var Re=({title:o,breakpoint:e,actions:t,showActions:r,showAdd:a$1,showHeaderMoreActions:i,showActionsContainer:l,onAdd:s,onOpenMoreActions:d$1})=>jsxs(b$1,{breakpoint:e,children:[jsx(Xo,{variant:"overline",color:"text.secondary",noWrap:!0,children:o}),l&&jsxs(c,{breakpoint:e,children:[r&&t,a$1&&jsxs(Fragment,{children:[r&&jsx(d,{orientation:"vertical",flexItem:!0}),jsx(_o,{startIcon:jsx(a,{icon:"SIMPLE_ADD"}),variant:"contained",onClick:s,children:"Adicionar"})]}),i&&jsxs(Fragment,{children:[(r||a$1)&&jsx(d,{orientation:"vertical",flexItem:!0}),jsx(_o,{color:"inherit",startIcon:jsx(a,{icon:"MORE_BOLD"}),size:"small",onClick:d$1,children:"Mais"})]})]})]}),$o=Re;var De=({fetching:o,loading:e,rows:t,mobileSlots:r$1,mobileSlotsProps:a,slots:i,scrollableNodeRef:l,mobileRender:s,hideFooter:d,onPaginationChange:m,rowCount:f,paginationModel:c})=>jsxs(a$6,{isFetching:o,fetching:jsx(a$7,{}),isLoading:e,loading:jsx(q,{}),isEmpty:t.length===0,empty:jsxs(to,{flex:1,direction:"column",...a,children:[r$1&&r$1,jsx(to,{flex:1,alignItems:"center",justifyContent:"center",children:i?.noRowsOverlay?jsx(i.noRowsOverlay,{}):jsx(Xo,{variant:"body2",color:"text.secondary",children:"Nenhum registro encontrado"})})]}),children:[jsxs(to,{direction:"column",flex:1,minHeight:0,...a,children:[r$1&&r$1,jsx(a$8,{fillContent:!0,ref:l,children:t.map(n=>jsx(Fragment$1,{children:s(n)},n.id))})]}),!d&&m&&jsx(h,{children:jsx(r,{count:f,page:c.page,rowsPerPage:c.pageSize,onPageChange:n=>m?.(n,c.pageSize),onRowsPerPageChange:n=>m?.(0,n)})})]}),qo=De;var z="datagrid-actions";var Ko=(o,e)=>Children.map(o,t=>{if(!isValidElement(t))return t;let r=t.props.onClick,a={};a.onClick=(...l)=>{e(),r&&r(...l);};let i=t.props;return i?.children&&(a.children=Ko(i.children,e)),cloneElement(t,a)}),ve=({children:o,onClose:e})=>o?Ko(o,e):null,ro=memo(ve);var Ve=({breakpoint:o$1,isMobile:e$1,showSearch:t,showMoreActions:r,showTopbarMoreActions:a$1,showHeaderMoreActions:i,filterButton:l,searchValue:s,onSearch:d,onSearchChange:m,moreActions:f$1,popover:c})=>jsxs(f,{breakpoint:o$1,children:[jsxs(to,{flex:1,direction:"row",alignItems:"center",id:z,gap:.5,children:[r&&jsxs(Fragment,{children:[a$1&&jsxs(Fragment,{children:[jsx(_o,{color:"inherit",startIcon:jsx(a,{icon:"MORE_BOLD"}),size:"small",onClick:c.onOpen,children:"Mais"}),!e$1&&jsx(e,{orientation:"vertical",flexItem:!0})]}),(a$1||i)&&jsx(o,{open:c.open,anchorEl:c.open,onClose:c.onClose,disabledArrow:!0,children:jsx(ro,{onClose:c.onClose,children:f$1})})]}),!e$1&&l&&jsxs(Fragment,{children:[l,a$1&&jsx(e,{orientation:"vertical",flexItem:!0})]})]}),t&&jsxs(g,{breakpoint:o$1,children:[jsx(a$9,{value:s,placeholder:"Buscar",onSearch:n=>d(n??""),onChange:n=>m?.(n.target.value),size:"small",fullWidth:!0,iconPosition:"start"}),e$1&&l&&jsx(to,{ml:1,children:l})]})]}),Jo=Ve;var Oe=({rowCount:o,page:e,rowsPerPage:t,onPaginationChange:r$1})=>jsxs(i,{children:[jsxs(to,{direction:"row",alignItems:"center",gap:.5,children:[jsx(Xo,{variant:"body2",color:"text.disabled",children:"Total de itens:"}),jsx(Xo,{variant:"body2",children:o})]}),jsx(r,{count:o,page:e,rowsPerPage:t,onPageChange:a=>r$1(a,t),onRowsPerPageChange:a=>r$1(0,a)})]}),lo=memo(Oe);var ze=forwardRef(({children:o,...e},t)=>jsx(_o,{...e,ref:t,color:"inherit",startIcon:jsx(a,{icon:"COLUMNS"}),children:o??"Colunas"}));ze.displayName="ColumnsButton";var _e=({setFilterButtonEl:o})=>{let e=useCallback(t=>{o(t);},[o]);return jsx(a$4,{container:z,children:jsx(GridToolbarColumnsButton,{ref:e,slotProps:{button:{color:"inherit",startIcon:jsx(a,{icon:"COLUMNS"}),children:"Colunas"}}})})},so=_e;var qe=({slots:o,showColumnButton:e,rowCount:t,paginationModel:r,onPaginationChange:a})=>{let i=useCallback(()=>a?jsx(lo,{rowCount:t,page:r.page,rowsPerPage:r.pageSize,onPaginationChange:a}):null,[t,r,a]);return {dataGridSlots:useMemo(()=>({...o,footer:i,...e&&!o?.toolbar&&{toolbar:so}}),[o,i,e])}},Zo=qe;var Qe=({rows:o,rowSelectionModel:e,onRowSelectionModelChange:t,getRowId:r,bulkActions:a})=>{let i=useMemo(()=>Array.isArray(e)?e:[],[e]),l=i.length,s=useMemo(()=>o.map(S=>r(S)),[o,r]),d=useMemo(()=>new Set(s),[s]),m=useMemo(()=>i.reduce((S,C)=>S+(d.has(C)?1:0),0),[i,d]),f=s.length>0&&m===s.length,c=m>0&&!f,n=useCallback(S=>{t&&t(S);},[t]),h=useCallback(()=>{n([]);},[n]),k=useMemo(()=>new Set(i),[i]),I=useMemo(()=>o.filter(S=>k.has(r(S))),[o,k,r]),_=useMemo(()=>({selectedIds:i,selectedRowsInPage:I,selectedCount:l,clearSelection:h}),[i,I,l,h]),W=!!a?.length,v=useCallback((S,C)=>{if(!t)return;if(C){let M=new Set(i),V=[...i];s.forEach(x=>{M.has(x)||V.push(x);}),n(V);return}let G=i.filter(M=>!d.has(M));n(G);},[t,i,s,d,n]);return {selectionModel:i,numSelected:l,allSelected:f,someSelected:c,hasBulkActions:W,bulkActionContext:_,clearSelection:h,handleSelectAllToggle:v}},jo=Qe;var nt=({title:o,header:e,headerProps:t,breakpoint:r="md",columns:a$4,rows:i=[],mobileSlots:l$1,mobileSlotsProps:s,mobileRender:d,rowCount:m=0,paginationModel:f={page:0,pageSize:25},onPaginationChange:c,actions:n$1,moreActions:h,onAdd:k$1,onSearch:I,searchValue:_,onSearchChange:W,slots:v,slotProps:S,loading:C,fetching:G,fetchingNextPage:M,containerProps:V={height:562,maxHeight:562},hideFooter:x,showColumnButton:mo=!1,filterButton:po,activeFilters:uo,bulkActions:fo,onRowsScrollEnd:E,scrollEndThreshold:$=200,...R})=>{let So=a$1(),T=b("down",r),[te,ne]=useState(null),go=useRef(null);useEffect(()=>{let P=go.current;if(!P||!T||!E)return;let wo=()=>{let{scrollTop:fe,scrollHeight:Se,clientHeight:ge}=P;Se-fe-ge<=$&&E();};return P.addEventListener("scroll",wo,{passive:!0}),()=>{P.removeEventListener("scroll",wo);}},[T,E,$,i.length]);let re=useMemo(()=>R.getRowId??(P=>P.id),[R.getRowId]),{numSelected:q,allSelected:ie,someSelected:ae,hasBulkActions:le,bulkActionContext:se,clearSelection:ce,handleSelectAllToggle:de}=jo({rows:i,rowSelectionModel:Array.isArray(R.rowSelectionModel)?R.rowSelectionModel:void 0,onRowSelectionModelChange:R.onRowSelectionModelChange,getRowId:re,bulkActions:fo}),{dataGridSlots:me}=Zo({slots:v,showColumnButton:mo,rowCount:m,paginationModel:f,onPaginationChange:c}),ho=!!I,Co=!!k$1,Ao=!!n$1,K=!!h,Q=T&&K,ko=!T&&K,pe=Ao||Co||Q,To=ko||ho||mo||!!po||!T,ue=le&&q>0&&jsxs(k,{children:[jsxs(to,{flexDirection:"row",alignItems:"center",gap:1,flex:1,children:[jsx(ee,{title:"Selecione todos nessa pagina",children:jsx(n,{size:"small",checked:ie,indeterminate:ae,onChange:de})}),jsxs(l,{variant:"body2",children:[q," selecionado",q>1?"s":""]}),jsx(ee,{title:"Desselecionar tudo",children:jsx(et,{size:"small",onClick:ce,"aria-label":"Desselecionar tudo",sx:{color:"primary.main"},children:jsx(a,{icon:"CLOSE_MARK_BUTTON",width:18,height:18})})})]}),jsx(zo,{actions:fo??[],context:se})]});return jsxs(a$2,{breakpoint:r,...V,flex:C?1:void 0,minHeight:C||i.length===0?562:void 0,children:[e?jsx(to,{p:3,...t,children:e}):jsxs(Fragment,{children:[jsx($o,{title:o,breakpoint:r,actions:n$1,showActions:Ao,showAdd:Co,showHeaderMoreActions:Q,showActionsContainer:pe,onAdd:k$1,onOpenMoreActions:So.onOpen}),To&&jsx(Jo,{breakpoint:r,isMobile:T,showSearch:ho,showMoreActions:K,showTopbarMoreActions:ko,showHeaderMoreActions:Q,filterButton:po,searchValue:_,onSearch:I,onSearchChange:W,moreActions:h,popover:So}),uo&&uo,!To&&jsx(p,{})]}),T?jsx(qo,{fetching:G,loading:C,rows:i,mobileSlots:l$1,mobileSlotsProps:s,slots:v,scrollableNodeRef:go,mobileRender:d,hideFooter:x,onPaginationChange:c,rowCount:m,paginationModel:f}):jsxs(j,{children:[ue,jsx(a$3,{columns:a$4,rows:i,slots:me,slotProps:{panel:{anchorEl:te},toolbar:{setFilterButtonEl:ne,showQuickFilter:!0},...S},columnHeaderHeight:48,getRowHeight:()=>68,loading:C,fetching:G,hideFooter:x,onRowsScrollEnd:E,scrollEndThreshold:$,...R})]}),M&&jsx(tt,{})]})},yn=memo(nt,ot);
|
|
25
25
|
|
|
26
26
|
export { ro as a, lo as b, so as c, yn as d };
|
|
27
|
-
//# sourceMappingURL=chunk-
|
|
27
|
+
//# sourceMappingURL=chunk-6ACD5WGD.js.map
|
|
@@ -6,7 +6,7 @@ import { GRID_CHECKBOX_SELECTION_COL_DEF, DataGridPremium, GridToolbarContainer,
|
|
|
6
6
|
import x from '@mui/material/Box';
|
|
7
7
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
8
8
|
|
|
9
|
-
var H=({showToolbar:i,disableExport:r,setFilterButtonEl:l,toolbarContent:n})=>{if(i)return jsxs(GridToolbarContainer,{children:[jsx(GridToolbarColumnsButton,{slotProps:{button:{color:"inherit"}}}),jsx(GridToolbarFilterButton,{ref:l,slotProps:{button:{color:"inherit"}}}),jsx(GridToolbarDensitySelector,{slotProps:{button:{color:"inherit"}}}),!r&&jsx(GridToolbarExport,{slotProps:{button:{color:"inherit"}}}),jsx(x,{sx:{flexGrow:1}}),n]})},m=H;var _=({columns:i,rows:r=[],loading:l,fetching:n,hideFooter:p,sx:u,showToolbar:d,disableExport:b,columnHeaderHeight:f=56,rowHeight:h=76,rowSpacingType:
|
|
9
|
+
var H=({showToolbar:i,disableExport:r,setFilterButtonEl:l,toolbarContent:n})=>{if(i)return jsxs(GridToolbarContainer,{children:[jsx(GridToolbarColumnsButton,{slotProps:{button:{color:"inherit"}}}),jsx(GridToolbarFilterButton,{ref:l,slotProps:{button:{color:"inherit"}}}),jsx(GridToolbarDensitySelector,{slotProps:{button:{color:"inherit"}}}),!r&&jsx(GridToolbarExport,{slotProps:{button:{color:"inherit"}}}),jsx(x,{sx:{flexGrow:1}}),n]})},m=H;var _=({columns:i,rows:r=[],loading:l,fetching:n,hideFooter:p,sx:u,showToolbar:d,disableExport:b,columnHeaderHeight:f=56,rowHeight:h=76,rowSpacingType:g="margin",getRowSpacing:C=()=>({top:0,bottom:0}),autoHeight:G=!1,toolbarContent:c,slots:P,...T})=>{let[E,S]=useState(null),w=[{...GRID_CHECKBOX_SELECTION_COL_DEF,width:71},...i];return jsxs(Fragment,{children:[n&&jsx(a,{sx:{zIndex:1}}),jsx(DataGridPremium,{columns:w,rows:r,loading:l,autoHeight:G,hideFooter:r.length===0?!0:p,rowHeight:h,columnHeaderHeight:f,getRowSpacing:C,rowSpacingType:g,disableAggregation:!0,slots:{toolbar:m,noRowsOverlay:()=>jsx(a$1,{title:"Nenhum registro encontrado"}),noResultsOverlay:()=>jsx(a$1,{title:"Nenhum registro encontrado"}),loadingOverlay:a$2,...P},slotProps:{panel:{anchorEl:E},toolbar:{setFilterButtonEl:S,showQuickFilter:!0,disableExport:b,showToolbar:d,toolbarContent:c}},sx:u,...T})]})},Z=_;
|
|
10
10
|
|
|
11
11
|
export { Z as a };
|
|
12
|
-
//# sourceMappingURL=chunk-
|
|
12
|
+
//# sourceMappingURL=chunk-6XOCS4DE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/components/DataGrid/index.tsx","../src/components/DataGrid/CustomToolbar/index.tsx"],"names":["useState","DataGridPremium","GRID_CHECKBOX_SELECTION_COL_DEF","Box","GridToolbarColumnsButton","GridToolbarContainer","GridToolbarDensitySelector","GridToolbarExport","GridToolbarFilterButton","jsx","jsxs","CustomToolbar","showToolbar","disableExport","setFilterButtonEl","toolbarContent","CustomToolbar_default","Fragment","DataGrid","columns","rows","loading","fetching","hideFooter","sx","columnHeaderHeight","rowHeight","rowSpacingType","getRowSpacing","autoHeight","slots","other","filterButtonEl","COLUMNS","FixedProgressBar_default","EmptyContent_default","LoadingOverlay_default","DataGrid_default"],"mappings":"mHAAA,OAAS,YAAAA,MAAgB,QACzB,OACE,mBAAAC,EACA,mCAAAC,MAGK,2BCLP,OAAOC,MAAS,oBAChB,OACE,4BAAAC,EACA,wBAAAC,EACA,8BAAAC,EACA,qBAAAC,EACA,2BAAAC,MACK,2BAaH,OACE,OAAAC,EADF,QAAAC,MAAA,oBATJ,IAAMC,EAAgB,CAAC,CACrB,YAAAC,EACA,cAAAC,EACA,kBAAAC,EACA,eAAAC,CACF,IAA6C,CAC3C,GAAKH,EAEL,OACEF,EAACL,EAAA,CACC,UAAAI,EAACL,EAAA,CAAyB,UAAW,CAAE,OAAQ,CAAE,MAAO,SAAU,CAAE,EAAG,EACvEK,EAACD,EAAA,CACC,IAAKM,EACL,UAAW,CAAE,OAAQ,CAAE,MAAO,SAAU,CAAE,EAC5C,EACAL,EAACH,EAAA,CACC,UAAW,CAAE,OAAQ,CAAE,MAAO,SAAU,CAAE,EAC5C,EACC,CAACO,GACAJ,EAACF,EAAA,CAAkB,UAAW,CAAE,OAAQ,CAAE,MAAO,SAAU,CAAE,EAAG,EAElEE,EAACN,EAAA,CAAI,GAAI,CAAE,SAAU,CAAE,EAAG,EACzBY,GACH,CAEJ,EAEOC,EAAQL,EDUX,mBAAAM,EACe,OAAAR,EADf,QAAAC,MAAA,oBAjCJ,IAAMQ,EAAW,CAAC,CAChB,QAAAC,EACA,KAAAC,EAAO,CAAC,EACR,QAAAC,EACA,SAAAC,EACA,WAAAC,EACA,GAAAC,EACA,YAAAZ,EACA,cAAAC,EACA,mBAAAY,EAAqB,GACrB,UAAAC,EAAY,GACZ,eAAAC,EAAiB,SACjB,cAAAC,EAAgB,KAAO,CACrB,IAAK,EACL,OAAQ,CACV,GACA,WAAAC,EAAa,GACb,eAAAd,EACA,MAAAe,EACA,GAAGC,CACL,IAAqB,CACnB,GAAM,CAACC,EAAgBlB,CAAiB,EACtCd,EAAmC,IAAI,EAEnCiC,EAAU,CACd,CACE,GAAG/B,EACH,MAAO,EACT,EACA,GAAGiB,CACL,EAEA,OACET,EAAAO,EAAA,CACG,UAAAK,GAAYb,EAACyB,EAAA,CAAiB,GAAI,CAAE,OAAQ,CAAE,EAAG,EAElDzB,EAACR,EAAA,CACC,QAASgC,EACT,KAAMb,EACN,QAASC,EACT,WAAYQ,EACZ,WAAYT,EAAK,SAAW,EAAI,GAAOG,EACvC,UAAWG,EACX,mBAAoBD,EACpB,cAAeG,EACf,eAAgBD,EAChB,mBAAkB,GAClB,MAAO,CACL,QAASX,EACT,cAAe,IACbP,EAAC0B,EAAA,CAAa,MAAM,6BAA6B,EAEnD,iBAAkB,IAChB1B,EAAC0B,EAAA,CAAa,MAAM,6BAA6B,EAEnD,eAAgBC,EAChB,GAAGN,CACL,EACA,UAAW,CACT,MAAO,CAAE,SAAUE,CAAe,EAClC,QAAS,CACP,kBAAAlB,EACA,gBAAiB,GACjB,cAAAD,EACA,YAAAD,EACA,eAAAG,CACF,CACF,EACA,GAAIS,EACH,GAAGO,EACN,GACF,CAEJ,EAEOM,EAAQnB","sourcesContent":["import { useState } from 'react';\nimport {\n DataGridPremium,\n GRID_CHECKBOX_SELECTION_COL_DEF,\n GridSlots,\n GridSlotsComponentsProps,\n} from '@mui/x-data-grid-premium';\n\nimport EmptyContent from 'components/EmptyContent';\nimport { DataGridProps } from 'types/dataGridProps';\n\nimport FixedProgressBar from '../FixedProgressBar';\n\nimport CustomToolbar from './CustomToolbar';\nimport LoadingOverlay from './LoadingOverlay';\n\nconst DataGrid = ({\n columns,\n rows = [],\n loading,\n fetching,\n hideFooter,\n sx,\n showToolbar,\n disableExport,\n columnHeaderHeight = 56,\n rowHeight = 76,\n rowSpacingType = 'margin',\n getRowSpacing = () => ({\n top: 0,\n bottom: 0,\n }),\n autoHeight = false,\n toolbarContent,\n slots,\n ...other\n}: DataGridProps) => {\n const [filterButtonEl, setFilterButtonEl] =\n useState<HTMLButtonElement | null>(null);\n\n const COLUMNS = [\n {\n ...GRID_CHECKBOX_SELECTION_COL_DEF,\n width: 71,\n },\n ...columns,\n ];\n\n return (\n <>\n {fetching && <FixedProgressBar sx={{ zIndex: 1 }} />}\n\n <DataGridPremium\n columns={COLUMNS}\n rows={rows}\n loading={loading}\n autoHeight={autoHeight}\n hideFooter={rows.length === 0 ? true : hideFooter}\n rowHeight={rowHeight}\n columnHeaderHeight={columnHeaderHeight}\n getRowSpacing={getRowSpacing}\n rowSpacingType={rowSpacingType}\n disableAggregation\n slots={{\n toolbar: CustomToolbar as unknown as GridSlots['toolbar'],\n noRowsOverlay: () => (\n <EmptyContent title=\"Nenhum registro encontrado\" />\n ),\n noResultsOverlay: () => (\n <EmptyContent title=\"Nenhum registro encontrado\" />\n ),\n loadingOverlay: LoadingOverlay,\n ...slots,\n }}\n slotProps={{\n panel: { anchorEl: filterButtonEl },\n toolbar: {\n setFilterButtonEl,\n showQuickFilter: true,\n disableExport,\n showToolbar,\n toolbarContent,\n } as unknown as GridSlotsComponentsProps['toolbar'],\n }}\n sx={sx}\n {...other}\n />\n </>\n );\n};\n\nexport default DataGrid;\n","import { PropsWithChildren } from 'react';\nimport Box from '@mui/material/Box';\nimport {\n GridToolbarColumnsButton,\n GridToolbarContainer,\n GridToolbarDensitySelector,\n GridToolbarExport,\n GridToolbarFilterButton,\n} from '@mui/x-data-grid-premium';\n\nimport { CustomToolbarProps } from './props';\n\nconst CustomToolbar = ({\n showToolbar,\n disableExport,\n setFilterButtonEl,\n toolbarContent,\n}: PropsWithChildren<CustomToolbarProps>) => {\n if (!showToolbar) return;\n\n return (\n <GridToolbarContainer>\n <GridToolbarColumnsButton slotProps={{ button: { color: 'inherit' } }} />\n <GridToolbarFilterButton\n ref={setFilterButtonEl}\n slotProps={{ button: { color: 'inherit' } }}\n />\n <GridToolbarDensitySelector\n slotProps={{ button: { color: 'inherit' } }}\n />\n {!disableExport && (\n <GridToolbarExport slotProps={{ button: { color: 'inherit' } }} />\n )}\n <Box sx={{ flexGrow: 1 }} />\n {toolbarContent}\n </GridToolbarContainer>\n );\n};\n\nexport default CustomToolbar;\n"]}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { a } from './chunk-VFDADOF2.js';
|
|
2
|
+
|
|
3
|
+
var u=e=>e?.thisYearMode?e.thisYearMode:e?.type==="FUTURE"?"FROM_TODAY":e?.type==="PAST"?"TO_DATE":"FULL",L={["LAST_YEAR"]:"Ano passado",["LAST_MONTH"]:"M\xEAs passado",["LAST_28_DAYS"]:"\xDAltimos 28 dias",["LAST_7_DAYS"]:"\xDAltimos 7 dias",["LAST_WEEK"]:"Semana passada",["YESTERDAY"]:"Ontem",["TODAY"]:"Hoje",["TOMORROW"]:"Amanh\xE3",["NEXT_7_DAYS"]:"Pr\xF3ximos 7 dias",["NEXT_30_DAYS"]:"Pr\xF3ximos 30 dias",["NEXT_90_DAYS"]:"Pr\xF3ximos 90 dias",["NEXT_MONTH"]:"Pr\xF3ximo m\xEAs",["THIS_YEAR"]:"Este ano",["NEXT_YEAR"]:"Pr\xF3ximo ano",["CUSTOM"]:"Personalizado"},O=["TODAY","YESTERDAY","LAST_7_DAYS","LAST_WEEK","LAST_28_DAYS","LAST_MONTH","THIS_YEAR","LAST_YEAR","CUSTOM"],R=["TODAY","TOMORROW","NEXT_7_DAYS","NEXT_30_DAYS","NEXT_90_DAYS","NEXT_MONTH","THIS_YEAR","NEXT_YEAR","CUSTOM"],p=["LAST_YEAR","LAST_MONTH","LAST_28_DAYS","LAST_7_DAYS","LAST_WEEK","YESTERDAY","TODAY","TOMORROW","NEXT_7_DAYS","NEXT_30_DAYS","NEXT_90_DAYS","NEXT_MONTH","THIS_YEAR","NEXT_YEAR","CUSTOM"],M=e=>{switch(e){case"PAST":return O;case"FUTURE":return R;default:return p}},f=e=>{switch(e){case"FUTURE":return "NEXT_7_DAYS";case"PAST":return "LAST_7_DAYS";case"FREE":default:return "TODAY"}},S=(e,r)=>{if(e==="CUSTOM")return {initialDate:null,finalDate:null};let s=new Date,a=new Date(s),t=new Date(s);switch(e){case"TODAY":break;case"YESTERDAY":a.setDate(a.getDate()-1),t.setDate(t.getDate()-1);break;case"TOMORROW":a.setDate(a.getDate()+1),t.setDate(t.getDate()+1);break;case"LAST_7_DAYS":a.setDate(a.getDate()-6);break;case"LAST_28_DAYS":a.setDate(a.getDate()-27);break;case"LAST_WEEK":{t.setDate(t.getDate()-t.getDay()-1),a.setTime(t.getTime()),a.setDate(a.getDate()-6);break}case"LAST_MONTH":a.setMonth(a.getMonth()-1,1),t.setDate(0);break;case"LAST_YEAR":a.setFullYear(a.getFullYear()-1,0,1),t.setFullYear(t.getFullYear()-1,11,31);break;case"NEXT_7_DAYS":t.setDate(t.getDate()+6);break;case"NEXT_30_DAYS":t.setDate(t.getDate()+29);break;case"NEXT_90_DAYS":t.setDate(t.getDate()+89);break;case"NEXT_MONTH":a.setMonth(a.getMonth()+1,1),t.setMonth(t.getMonth()+2,0);break;case"THIS_YEAR":{let o=u(r);o==="FROM_TODAY"?t.setMonth(11,31):o==="TO_DATE"?a.setMonth(0,1):(a.setMonth(0,1),t.setMonth(11,31));break}case"NEXT_YEAR":a.setFullYear(a.getFullYear()+1,0,1),t.setFullYear(t.getFullYear()+1,11,31);break}return a.setHours(0,0,0,0),t.setHours(23,59,59,999),{initialDate:a,finalDate:t}},F=(e,r,s)=>{let a$1=M(e),t=r&&a$1.includes(a[r])?a[r]:f(e);return {period:t,...S(t,{type:e,thisYearMode:s})}},U=(e,r,s,a)=>!e||!r?"CUSTOM":s.find(o=>{if(o==="CUSTOM")return !1;let{initialDate:i,finalDate:n}=S(o,a);return i&&n&&e.toDateString()===i.toDateString()&&r.toDateString()===n.toDateString()})??"CUSTOM",c={["LAST_YEAR"]:"ano-passado",["LAST_MONTH"]:"mes-passado",["LAST_28_DAYS"]:"ultimos-28-dias",["LAST_7_DAYS"]:"ultimos-7-dias",["LAST_WEEK"]:"semana-passada",["YESTERDAY"]:"ontem",["TODAY"]:"hoje",["TOMORROW"]:"amanha",["NEXT_7_DAYS"]:"proximos-7-dias",["NEXT_30_DAYS"]:"proximos-30-dias",["NEXT_90_DAYS"]:"proximos-90-dias",["NEXT_MONTH"]:"proximo-mes",["THIS_YEAR"]:"este-ano",["NEXT_YEAR"]:"proximo-ano",["CUSTOM"]:"personalizado"},m=Object.fromEntries(Object.entries(c).map(([e,r])=>[r,e])),d={paramKey:"periodo",dataKey:"data"},E=e=>{let r=e.getFullYear(),s=String(e.getMonth()+1).padStart(2,"0"),a=String(e.getDate()).padStart(2,"0");return `${r}-${s}-${a}`},Y=e=>{let r=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e);if(!r)return null;let[,s,a,t]=r;return new Date(Number(s),Number(a)-1,Number(t))},X=(e,r={},s)=>{let{paramKey:a,dataKey:t}={...d,...r},o=new URLSearchParams(s??"");return o.set(a,c[e.period]),e.period==="CUSTOM"&&e.initialDate&&e.finalDate?o.set(t,`${E(e.initialDate)}_${E(e.finalDate)}`):o.delete(t),o},b=(e,r={},s)=>{let{paramKey:a,dataKey:t}={...d,...r},o=e.get(a);if(!o)return null;let i=m[o];if(!i)return null;if(i!=="CUSTOM")return {period:i,...S(i,s)};let n=e.get(t);if(!n)return {period:"CUSTOM",initialDate:null,finalDate:null};let[_,A]=n.split("_"),T=_?Y(_):null,l=A?Y(A):null;return T&&T.setHours(0,0,0,0),l&&l.setHours(23,59,59,999),{period:"CUSTOM",initialDate:T,finalDate:l}};
|
|
4
|
+
|
|
5
|
+
export { L as a, M as b, f as c, S as d, F as e, U as f, c as g, d as h, X as i, b as j };
|
|
6
|
+
//# sourceMappingURL=chunk-CG6F55WN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/filters.ts"],"names":["resolveThisYearMode","options","periodLabels","PAST_PERIODS","FUTURE_PERIODS","FREE_PERIODS","getPeriodsByType","type","getDefaultPeriodForType","getPeriodDates","period","now","initialDate","finalDate","mode","buildDefaultFilter","defaultPeriod","thisYearMode","availablePeriods","Period","findMatchingPeriod","startDate","endDate","candidates","periodSlugs","slugToPeriod","key","slug","DEFAULT_FILTER_KEYS","formatDateOnly","date","year","month","day","parseDateOnly","raw","match","serializeFilterToSearchParams","value","keys","baseParams","paramKey","dataKey","params","deserializeFilterFromSearchParams","dataRaw","initialRaw","finalRaw"],"mappings":"wCAaA,IAAMA,EACJC,GAEIA,GAAS,aAAqBA,EAAQ,aACtCA,GAAS,6BACTA,GAAS,+BAIFC,EAAuC,CAClD,YAAiB,EAAG,cACpB,aAAkB,EAAG,iBACrB,eAAoB,EAAG,qBACvB,cAAmB,EAAG,oBACtB,YAAiB,EAAG,iBACpB,YAAiB,EAAG,QACpB,QAAa,EAAG,OAChB,WAAgB,EAAG,YACnB,cAAmB,EAAG,qBACtB,eAAoB,EAAG,sBACvB,eAAoB,EAAG,sBACvB,aAAkB,EAAG,oBACrB,YAAiB,EAAG,WACpB,YAAiB,EAAG,iBACpB,SAAc,EAAG,eACnB,EAEMC,EAAyB,2GAU/B,EAEMC,EAA2B,6GAUjC,EAEMC,EAAyB,2LAgB/B,EAEaC,EAAoBC,GAAsC,CACrE,OAAQA,EAAM,CACZ,WACE,OAAOJ,EACT,aACE,OAAOC,EACT,QACE,OAAOC,CACX,CACF,EAEaG,EAA2BD,GAAoC,CAC1E,OAAQA,EAAM,CACZ,aACE,oBACF,WACE,oBACF,WACA,QACE,aACJ,CACF,EAEaE,EAAiB,CAC5BC,EACAT,IACyD,CACzD,GAAIS,aACF,MAAO,CAAE,YAAa,KAAM,UAAW,IAAK,EAG9C,IAAMC,EAAM,IAAI,KACVC,EAAc,IAAI,KAAKD,CAAG,EAC1BE,EAAY,IA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e,EAAaE,CAAI,EAChC,GAAI,CAACjB,EAAQ,OAAO,KAEpB,GAAIA,aACF,MAAO,CAAE,OAAAA,EAAQ,GAAGD,EAAeC,EAAQT,CAAO,CAAE,EAGtD,IAAM4C,EAAUF,EAAO,IAAID,CAAO,EAClC,GAAI,CAACG,EACH,MAAO,CAAE,gBAAuB,YAAa,KAAM,UAAW,IAAK,EAGrE,GAAM,CAACC,EAAYC,CAAQ,EAAIF,EAAQ,MAAM,GAAG,EAC1CjC,EAAckC,EAAaZ,EAAcY,CAAU,EAAI,KACvDjC,EAAYkC,EAAWb,EAAca,CAAQ,EAAI,KAEvD,OAAInC,GAAaA,EAAY,SAAS,EAAG,EAAG,EAAG,CAAC,EAC5CC,GAAWA,EAAU,SAAS,GAAI,GAAI,GAAI,GAAG,EAE1C,CAAE,gBAAuB,YAAAD,EAAa,UAAAC,CAAU,CACzD","sourcesContent":["import {\n FilterUrlKeys,\n FilterValue,\n Period,\n ThisYearMode,\n Type,\n} from 'types/period';\n\nexport interface PeriodResolutionOptions {\n type?: keyof typeof Type;\n thisYearMode?: keyof typeof ThisYearMode;\n}\n\nconst resolveThisYearMode = (\n options?: PeriodResolutionOptions,\n): keyof typeof ThisYearMode => {\n if (options?.thisYearMode) return options.thisYearMode;\n if (options?.type === Type.FUTURE) return ThisYearMode.FROM_TODAY;\n if (options?.type === Type.PAST) return ThisYearMode.TO_DATE;\n return ThisYearMode.FULL;\n};\n\nexport const periodLabels: Record<Period, string> = {\n [Period.LAST_YEAR]: 'Ano passado',\n [Period.LAST_MONTH]: 'Mês passado',\n [Period.LAST_28_DAYS]: 'Últimos 28 dias',\n [Period.LAST_7_DAYS]: 'Últimos 7 dias',\n [Period.LAST_WEEK]: 'Semana passada',\n [Period.YESTERDAY]: 'Ontem',\n [Period.TODAY]: 'Hoje',\n [Period.TOMORROW]: 'Amanhã',\n [Period.NEXT_7_DAYS]: 'Próximos 7 dias',\n [Period.NEXT_30_DAYS]: 'Próximos 30 dias',\n [Period.NEXT_90_DAYS]: 'Próximos 90 dias',\n [Period.NEXT_MONTH]: 'Próximo mês',\n [Period.THIS_YEAR]: 'Este ano',\n [Period.NEXT_YEAR]: 'Próximo ano',\n [Period.CUSTOM]: 'Personalizado',\n};\n\nconst PAST_PERIODS: Period[] = [\n Period.TODAY,\n Period.YESTERDAY,\n Period.LAST_7_DAYS,\n Period.LAST_WEEK,\n Period.LAST_28_DAYS,\n Period.LAST_MONTH,\n Period.THIS_YEAR,\n Period.LAST_YEAR,\n Period.CUSTOM,\n];\n\nconst FUTURE_PERIODS: Period[] = [\n Period.TODAY,\n Period.TOMORROW,\n Period.NEXT_7_DAYS,\n Period.NEXT_30_DAYS,\n Period.NEXT_90_DAYS,\n Period.NEXT_MONTH,\n Period.THIS_YEAR,\n Period.NEXT_YEAR,\n Period.CUSTOM,\n];\n\nconst FREE_PERIODS: Period[] = [\n Period.LAST_YEAR,\n Period.LAST_MONTH,\n Period.LAST_28_DAYS,\n Period.LAST_7_DAYS,\n Period.LAST_WEEK,\n Period.YESTERDAY,\n Period.TODAY,\n Period.TOMORROW,\n Period.NEXT_7_DAYS,\n Period.NEXT_30_DAYS,\n Period.NEXT_90_DAYS,\n Period.NEXT_MONTH,\n Period.THIS_YEAR,\n Period.NEXT_YEAR,\n Period.CUSTOM,\n];\n\nexport const getPeriodsByType = (type: keyof typeof Type): Period[] => {\n switch (type) {\n case Type.PAST:\n return PAST_PERIODS;\n case Type.FUTURE:\n return FUTURE_PERIODS;\n default:\n return FREE_PERIODS;\n }\n};\n\nexport const getDefaultPeriodForType = (type: keyof typeof Type): Period => {\n switch (type) {\n case Type.FUTURE:\n return Period.NEXT_7_DAYS;\n case Type.PAST:\n return Period.LAST_7_DAYS;\n case Type.FREE:\n default:\n return Period.TODAY;\n }\n};\n\nexport const getPeriodDates = (\n period: Period,\n options?: PeriodResolutionOptions,\n): { initialDate: Date | null; finalDate: Date | null } => {\n if (period === Period.CUSTOM) {\n return { initialDate: null, finalDate: null };\n }\n\n const now = new Date();\n const initialDate = new Date(now);\n const finalDate = new Date(now);\n\n switch (period) {\n case Period.TODAY:\n break;\n\n case Period.YESTERDAY:\n initialDate.setDate(initialDate.getDate() - 1);\n finalDate.setDate(finalDate.getDate() - 1);\n break;\n\n case Period.TOMORROW:\n initialDate.setDate(initialDate.getDate() + 1);\n finalDate.setDate(finalDate.getDate() + 1);\n break;\n\n case Period.LAST_7_DAYS:\n initialDate.setDate(initialDate.getDate() - 6);\n break;\n\n case Period.LAST_28_DAYS:\n initialDate.setDate(initialDate.getDate() - 27);\n break;\n\n case Period.LAST_WEEK: {\n finalDate.setDate(finalDate.getDate() - finalDate.getDay() - 1);\n initialDate.setTime(finalDate.getTime());\n initialDate.setDate(initialDate.getDate() - 6);\n break;\n }\n\n case Period.LAST_MONTH:\n initialDate.setMonth(initialDate.getMonth() - 1, 1);\n finalDate.setDate(0);\n break;\n\n case Period.LAST_YEAR:\n initialDate.setFullYear(initialDate.getFullYear() - 1, 0, 1);\n finalDate.setFullYear(finalDate.getFullYear() - 1, 11, 31);\n break;\n\n case Period.NEXT_7_DAYS:\n finalDate.setDate(finalDate.getDate() + 6);\n break;\n\n case Period.NEXT_30_DAYS:\n finalDate.setDate(finalDate.getDate() + 29);\n break;\n\n case Period.NEXT_90_DAYS:\n finalDate.setDate(finalDate.getDate() + 89);\n break;\n\n case Period.NEXT_MONTH:\n initialDate.setMonth(initialDate.getMonth() + 1, 1);\n finalDate.setMonth(finalDate.getMonth() + 2, 0);\n break;\n\n case Period.THIS_YEAR: {\n const mode = resolveThisYearMode(options);\n if (mode === ThisYearMode.FROM_TODAY) {\n finalDate.setMonth(11, 31);\n } else if (mode === ThisYearMode.TO_DATE) {\n initialDate.setMonth(0, 1);\n } else {\n initialDate.setMonth(0, 1);\n finalDate.setMonth(11, 31);\n }\n break;\n }\n\n case Period.NEXT_YEAR:\n initialDate.setFullYear(initialDate.getFullYear() + 1, 0, 1);\n finalDate.setFullYear(finalDate.getFullYear() + 1, 11, 31);\n break;\n }\n\n initialDate.setHours(0, 0, 0, 0);\n finalDate.setHours(23, 59, 59, 999);\n\n return { initialDate, finalDate };\n};\n\nexport const buildDefaultFilter = (\n type: keyof typeof Type,\n defaultPeriod?: keyof typeof Period,\n thisYearMode?: keyof typeof ThisYearMode,\n): FilterValue => {\n const availablePeriods = getPeriodsByType(type);\n const period =\n defaultPeriod && availablePeriods.includes(Period[defaultPeriod])\n ? Period[defaultPeriod]\n : getDefaultPeriodForType(type);\n\n return { period, ...getPeriodDates(period, { type, thisYearMode }) };\n};\n\nexport const findMatchingPeriod = (\n startDate: Date | null,\n endDate: Date | null,\n candidates: Period[],\n options?: PeriodResolutionOptions,\n): Period => {\n if (!startDate || !endDate) return Period.CUSTOM;\n\n const match = candidates.find(period => {\n if (period === Period.CUSTOM) return false;\n\n const { initialDate, finalDate } = getPeriodDates(period, options);\n\n return (\n initialDate &&\n finalDate &&\n startDate.toDateString() === initialDate.toDateString() &&\n endDate.toDateString() === finalDate.toDateString()\n );\n });\n\n return match ?? Period.CUSTOM;\n};\n\nexport const periodSlugs: Record<Period, string> = {\n [Period.LAST_YEAR]: 'ano-passado',\n [Period.LAST_MONTH]: 'mes-passado',\n [Period.LAST_28_DAYS]: 'ultimos-28-dias',\n [Period.LAST_7_DAYS]: 'ultimos-7-dias',\n [Period.LAST_WEEK]: 'semana-passada',\n [Period.YESTERDAY]: 'ontem',\n [Period.TODAY]: 'hoje',\n [Period.TOMORROW]: 'amanha',\n [Period.NEXT_7_DAYS]: 'proximos-7-dias',\n [Period.NEXT_30_DAYS]: 'proximos-30-dias',\n [Period.NEXT_90_DAYS]: 'proximos-90-dias',\n [Period.NEXT_MONTH]: 'proximo-mes',\n [Period.THIS_YEAR]: 'este-ano',\n [Period.NEXT_YEAR]: 'proximo-ano',\n [Period.CUSTOM]: 'personalizado',\n};\n\nconst slugToPeriod: Record<string, Period> = Object.fromEntries(\n (Object.entries(periodSlugs) as [Period, string][]).map(([key, slug]) => [\n slug,\n key,\n ]),\n);\n\nexport const DEFAULT_FILTER_KEYS: Required<FilterUrlKeys> = {\n paramKey: 'periodo',\n dataKey: 'data',\n};\n\nconst formatDateOnly = (date: Date): string => {\n const year = date.getFullYear();\n const month = String(date.getMonth() + 1).padStart(2, '0');\n const day = String(date.getDate()).padStart(2, '0');\n\n return `${year}-${month}-${day}`;\n};\n\nconst parseDateOnly = (raw: string): Date | null => {\n const match = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(raw);\n if (!match) return null;\n\n const [, year, month, day] = match;\n\n return new Date(Number(year), Number(month) - 1, Number(day));\n};\n\nexport const serializeFilterToSearchParams = (\n value: FilterValue,\n keys: FilterUrlKeys = {},\n baseParams?: URLSearchParams,\n): URLSearchParams => {\n const { paramKey, dataKey } = { ...DEFAULT_FILTER_KEYS, ...keys };\n const params = new URLSearchParams(baseParams ?? '');\n\n params.set(paramKey, periodSlugs[value.period]);\n\n if (value.period === Period.CUSTOM && value.initialDate && value.finalDate) {\n params.set(\n dataKey,\n `${formatDateOnly(value.initialDate)}_${formatDateOnly(value.finalDate)}`,\n );\n } else {\n params.delete(dataKey);\n }\n\n return params;\n};\n\nexport const deserializeFilterFromSearchParams = (\n params: URLSearchParams,\n keys: FilterUrlKeys = {},\n options?: PeriodResolutionOptions,\n): FilterValue | null => {\n const { paramKey, dataKey } = { ...DEFAULT_FILTER_KEYS, ...keys };\n const slug = params.get(paramKey);\n if (!slug) return null;\n\n const period = slugToPeriod[slug];\n if (!period) return null;\n\n if (period !== Period.CUSTOM) {\n return { period, ...getPeriodDates(period, options) };\n }\n\n const dataRaw = params.get(dataKey);\n if (!dataRaw) {\n return { period: Period.CUSTOM, initialDate: null, finalDate: null };\n }\n\n const [initialRaw, finalRaw] = dataRaw.split('_');\n const initialDate = initialRaw ? parseDateOnly(initialRaw) : null;\n const finalDate = finalRaw ? parseDateOnly(finalRaw) : null;\n\n if (initialDate) initialDate.setHours(0, 0, 0, 0);\n if (finalDate) finalDate.setHours(23, 59, 59, 999);\n\n return { period: Period.CUSTOM, initialDate, finalDate };\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _=(T=>(T.LAST_YEAR="LAST_YEAR",T.LAST_MONTH="LAST_MONTH",T.LAST_28_DAYS="LAST_28_DAYS",T.LAST_7_DAYS="LAST_7_DAYS",T.LAST_WEEK="LAST_WEEK",T.YESTERDAY="YESTERDAY",T.TODAY="TODAY",T.TOMORROW="TOMORROW",T.NEXT_7_DAYS="NEXT_7_DAYS",T.NEXT_30_DAYS="NEXT_30_DAYS",T.NEXT_90_DAYS="NEXT_90_DAYS",T.NEXT_MONTH="NEXT_MONTH",T.THIS_YEAR="THIS_YEAR",T.NEXT_YEAR="NEXT_YEAR",T.CUSTOM="CUSTOM",T))(_||{}),E=(A=>(A.FREE="FREE",A.PAST="PAST",A.FUTURE="FUTURE",A))(E||{});
|
|
1
|
+
var _=(T=>(T.LAST_YEAR="LAST_YEAR",T.LAST_MONTH="LAST_MONTH",T.LAST_28_DAYS="LAST_28_DAYS",T.LAST_7_DAYS="LAST_7_DAYS",T.LAST_WEEK="LAST_WEEK",T.YESTERDAY="YESTERDAY",T.TODAY="TODAY",T.TOMORROW="TOMORROW",T.NEXT_7_DAYS="NEXT_7_DAYS",T.NEXT_30_DAYS="NEXT_30_DAYS",T.NEXT_90_DAYS="NEXT_90_DAYS",T.NEXT_MONTH="NEXT_MONTH",T.THIS_YEAR="THIS_YEAR",T.NEXT_YEAR="NEXT_YEAR",T.CUSTOM="CUSTOM",T))(_||{}),E=(A=>(A.FREE="FREE",A.PAST="PAST",A.FUTURE="FUTURE",A))(E||{}),S=(A=>(A.FROM_TODAY="FROM_TODAY",A.TO_DATE="TO_DATE",A.FULL="FULL",A))(S||{});
|
|
2
2
|
|
|
3
|
-
export { _ as a, E as b };
|
|
4
|
-
//# sourceMappingURL=chunk-
|
|
3
|
+
export { _ as a, E as b, S as c };
|
|
4
|
+
//# sourceMappingURL=chunk-VFDADOF2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types/period.ts"],"names":["Period","Type","ThisYearMode"],"mappings":"AAAO,IAAKA,OACVA,EAAA,UAAY,YACZA,EAAA,WAAa,aACbA,EAAA,aAAe,eACfA,EAAA,YAAc,cACdA,EAAA,UAAY,YACZA,EAAA,UAAY,YACZA,EAAA,MAAQ,QACRA,EAAA,SAAW,WACXA,EAAA,YAAc,cACdA,EAAA,aAAe,eACfA,EAAA,aAAe,eACfA,EAAA,WAAa,aACbA,EAAA,UAAY,YACZA,EAAA,UAAY,YACZA,EAAA,OAAS,SAfCA,OAAA,IAkBAC,OACVA,EAAA,KAAO,OACPA,EAAA,KAAO,OACPA,EAAA,OAAS,SAHCA,OAAA,IAMAC,OACVA,EAAA,WAAa,aACbA,EAAA,QAAU,UACVA,EAAA,KAAO,OAHGA,OAAA","sourcesContent":["export enum Period {\n LAST_YEAR = 'LAST_YEAR',\n LAST_MONTH = 'LAST_MONTH',\n LAST_28_DAYS = 'LAST_28_DAYS',\n LAST_7_DAYS = 'LAST_7_DAYS',\n LAST_WEEK = 'LAST_WEEK',\n YESTERDAY = 'YESTERDAY',\n TODAY = 'TODAY',\n TOMORROW = 'TOMORROW',\n NEXT_7_DAYS = 'NEXT_7_DAYS',\n NEXT_30_DAYS = 'NEXT_30_DAYS',\n NEXT_90_DAYS = 'NEXT_90_DAYS',\n NEXT_MONTH = 'NEXT_MONTH',\n THIS_YEAR = 'THIS_YEAR',\n NEXT_YEAR = 'NEXT_YEAR',\n CUSTOM = 'CUSTOM',\n}\n\nexport enum Type {\n FREE = 'FREE',\n PAST = 'PAST',\n FUTURE = 'FUTURE',\n}\n\nexport enum ThisYearMode {\n FROM_TODAY = 'FROM_TODAY',\n TO_DATE = 'TO_DATE',\n FULL = 'FULL',\n}\n\nexport interface FilterValue {\n period: Period;\n initialDate: Date | null;\n finalDate: Date | null;\n}\n\nexport interface FilterUrlKeys {\n paramKey?: string;\n dataKey?: string;\n}\n"]}
|
|
@@ -7,10 +7,10 @@ import { a as a$4 } from '../../../chunk-J5B2YJSR.js';
|
|
|
7
7
|
import { d as d$2 } from '../../../chunk-A7QSCOUE.js';
|
|
8
8
|
import { h, d as d$1, c as c$2 } from '../../../chunk-OF6623HG.js';
|
|
9
9
|
import { a as a$3 } from '../../../chunk-CBW32OUQ.js';
|
|
10
|
-
import { d } from '../../../chunk-
|
|
10
|
+
import { d } from '../../../chunk-6ACD5WGD.js';
|
|
11
11
|
import { a as a$2 } from '../../../chunk-R2BCPHRH.js';
|
|
12
12
|
import { a as a$1 } from '../../../chunk-4F2NKGF6.js';
|
|
13
|
-
import '../../../chunk-
|
|
13
|
+
import '../../../chunk-6XOCS4DE.js';
|
|
14
14
|
import '../../../chunk-LZQ7OFKO.js';
|
|
15
15
|
import '../../../chunk-NIQW2J3M.js';
|
|
16
16
|
import '../../../chunk-6U5LS7MP.js';
|
|
@@ -6,10 +6,10 @@ import { a as a$4 } from '../../../chunk-J5B2YJSR.js';
|
|
|
6
6
|
import { d as d$2 } from '../../../chunk-A7QSCOUE.js';
|
|
7
7
|
import { h, d, a as a$6, c as c$1 } from '../../../chunk-OF6623HG.js';
|
|
8
8
|
import { a as a$3 } from '../../../chunk-CBW32OUQ.js';
|
|
9
|
-
import { d as d$1 } from '../../../chunk-
|
|
9
|
+
import { d as d$1 } from '../../../chunk-6ACD5WGD.js';
|
|
10
10
|
import { a as a$2 } from '../../../chunk-R2BCPHRH.js';
|
|
11
11
|
import { a as a$1 } from '../../../chunk-4F2NKGF6.js';
|
|
12
|
-
import '../../../chunk-
|
|
12
|
+
import '../../../chunk-6XOCS4DE.js';
|
|
13
13
|
import '../../../chunk-LZQ7OFKO.js';
|
|
14
14
|
import '../../../chunk-NIQW2J3M.js';
|
|
15
15
|
import '../../../chunk-6U5LS7MP.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { b as DesktopFooter, a as EnhancedMoreActions, c as Toolbar, d as default } from '../../chunk-
|
|
1
|
+
export { b as DesktopFooter, a as EnhancedMoreActions, c as Toolbar, d as default } from '../../chunk-6ACD5WGD.js';
|
|
2
2
|
import '../../chunk-R2BCPHRH.js';
|
|
3
3
|
import '../../chunk-4F2NKGF6.js';
|
|
4
|
-
import '../../chunk-
|
|
4
|
+
import '../../chunk-6XOCS4DE.js';
|
|
5
5
|
import '../../chunk-LZQ7OFKO.js';
|
|
6
6
|
import '../../chunk-NIQW2J3M.js';
|
|
7
7
|
import '../../chunk-6U5LS7MP.js';
|
|
@@ -3,10 +3,10 @@ export { a as FilterOperator, b as SortType } from '../../chunk-P64QBDAO.js';
|
|
|
3
3
|
import { d, c } from '../../chunk-A7QSCOUE.js';
|
|
4
4
|
import { a as a$4 } from '../../chunk-WLRSUL67.js';
|
|
5
5
|
import { h, a as a$6 } from '../../chunk-OF6623HG.js';
|
|
6
|
-
import { d as d$1 } from '../../chunk-
|
|
6
|
+
import { d as d$1 } from '../../chunk-6ACD5WGD.js';
|
|
7
7
|
import '../../chunk-R2BCPHRH.js';
|
|
8
8
|
import '../../chunk-4F2NKGF6.js';
|
|
9
|
-
import '../../chunk-
|
|
9
|
+
import '../../chunk-6XOCS4DE.js';
|
|
10
10
|
import '../../chunk-LZQ7OFKO.js';
|
|
11
11
|
import '../../chunk-NIQW2J3M.js';
|
|
12
12
|
import '../../chunk-6U5LS7MP.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { Type, FilterValue } from '../../types/period.js';
|
|
2
|
+
import { Type, FilterValue, ThisYearMode } from '../../types/period.js';
|
|
3
3
|
|
|
4
4
|
interface FiltersProps {
|
|
5
5
|
type?: keyof typeof Type;
|
|
@@ -8,8 +8,9 @@ interface FiltersProps {
|
|
|
8
8
|
paramKey?: string;
|
|
9
9
|
dataKey?: string;
|
|
10
10
|
label?: string;
|
|
11
|
+
thisYearMode?: keyof typeof ThisYearMode;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
declare const Filters: ({ type, value, onChange, paramKey, dataKey, label, }: FiltersProps) => react_jsx_runtime.JSX.Element;
|
|
14
|
+
declare const Filters: ({ type, value, onChange, paramKey, dataKey, label, thisYearMode, }: FiltersProps) => react_jsx_runtime.JSX.Element;
|
|
14
15
|
|
|
15
16
|
export { Filters as default };
|
|
@@ -9,19 +9,19 @@ import { a as a$6 } from '../../chunk-2GTD4JW2.js';
|
|
|
9
9
|
import '../../chunk-PBLSVXV5.js';
|
|
10
10
|
import { a as a$8 } from '../../chunk-LQRRMVFN.js';
|
|
11
11
|
import { b } from '../../chunk-2ZJUGM2S.js';
|
|
12
|
-
import { b as b$1, a as a$1, d, f, j as j$1, i } from '../../chunk-
|
|
13
|
-
import '../../chunk-
|
|
12
|
+
import { b as b$1, a as a$1, d, f, j as j$1, i } from '../../chunk-CG6F55WN.js';
|
|
13
|
+
import '../../chunk-VFDADOF2.js';
|
|
14
14
|
import { memo, useState, useMemo, useEffect, useCallback, useRef } from 'react';
|
|
15
|
-
import
|
|
15
|
+
import u from '@mui/material/Stack';
|
|
16
16
|
import { useForm } from 'react-hook-form';
|
|
17
|
-
import
|
|
18
|
-
import
|
|
19
|
-
import
|
|
20
|
-
import
|
|
17
|
+
import uo from '@mui/material/Button';
|
|
18
|
+
import fo from '@mui/material/Checkbox';
|
|
19
|
+
import J from '@mui/material/Divider';
|
|
20
|
+
import X from '@mui/material/Typography';
|
|
21
21
|
import { styled } from '@mui/material/styles';
|
|
22
22
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
23
23
|
|
|
24
|
-
var
|
|
24
|
+
var j=styled(a)(({theme:e})=>({marginTop:10,"& .MuiPopover-paper":{width:580,padding:e.spacing(3),backgroundColor:e.palette.background.paper,borderRadius:e.spacing(1),backgroundImage:"none",[e.breakpoints.down("sm")]:{width:"90vw",maxWidth:"calc(100vw - 32px)",padding:e.spacing(2)}}})),Q=styled(c)(({theme:e})=>({[e.breakpoints.up("sm")]:{"&.MuiDateRangeCalendar-root":{margin:-24}},"& .MuiPickersCalendarHeader-label":{textTransform:"capitalize"},[e.breakpoints.down(400)]:{"& .MuiPickersCalendarHeader-root":{padding:e.spacing(0,7)},"& .MuiDayCalendar-header, & .MuiDayCalendar-weekContainer":{gap:0},"& .MuiPickersDay-root, & .MuiDateRangePickerDay-root":{width:32,height:32},"& .MuiDayCalendar-weekDayLabel":{width:32,height:32},"& .MuiDayCalendar-slideTransition":{minHeight:210}},[e.breakpoints.down(350)]:{"& .MuiPickersDay-root, & .MuiDateRangePickerDay-root":{width:28,height:28},"& .MuiDayCalendar-weekDayLabel":{width:28,height:28},"& .MuiDayCalendar-slideTransition":{minHeight:196}}}));var Do=["D","S","T","Q","Q","S","S"],go=({open:e,onClose:f$1,type:i,value:r,onApply:d$1,thisYearMode:n})=>{let h=b("down","sm"),D=useForm({defaultValues:r}),{handleSubmit:k,getValues:g,setValue:t,watch:c,reset:v}=D,[P,p]=useState([r.initialDate,r.finalDate]),oo=c("initialDate"),eo=c("finalDate"),I=c("period"),to=!oo||!eo,ao=i==="PAST",io=i==="FUTURE",m=useMemo(()=>b$1(i),[i]),R=useMemo(()=>m.map(o=>({label:a$1[o],value:o})),[m]);useEffect(()=>{e&&v(r);},[e,v,r]),useEffect(()=>{p([r.initialDate,r.finalDate]);},[r.finalDate,r.initialDate]);let M=useCallback(o=>{let{initialDate:l,finalDate:s}=d(o,{type:i,thisYearMode:n});p([l,s]),t("period",o),t("initialDate",l),t("finalDate",s);},[t,n,i]),ro=useCallback(o=>{if(p(o),o[0]&&t("initialDate",o[0]),o[1]&&t("finalDate",o[1]),o[0]&&o[1]){let l=f(o[0],o[1],m,{type:i,thisYearMode:n});t("period",l);}},[m,t,n,i]),no=useCallback(o=>{t("initialDate",o);let l=g("finalDate");if(o&&l){let s=[o,l];p(s);let F=f(s[0],s[1],m,{type:i,thisYearMode:n});t("period",F);}},[m,g,t,n,i]),lo=useCallback(o=>{t("finalDate",o);let l=g("initialDate");if(l&&o){let s=[l,o];p(s);let F=f(s[0],s[1],m,{type:i,thisYearMode:n});t("period",F);}},[m,g,t,n,i]),so=useCallback(o=>{d$1(o),f$1();},[d$1,f$1]);return jsx(j,{open:e,onClose:f$1,arrow:h?"top-center":"top-left",disabledArrow:!0,children:jsxs(a$2,{methods:D,onSubmit:k(so),gap:2,children:[jsx(X,{variant:"overline",color:"text.disabled",children:"Defina o per\xEDodo"}),jsxs(u,{direction:"row",alignItems:"center",justifyContent:"space-between",gap:2,children:[jsx(a$3,{name:"initialDate",label:"In\xEDcio",onChange:no,slotProps:{textField:{size:"small"}}}),jsx(a$3,{name:"finalDate",label:"T\xE9rmino",onChange:lo,slotProps:{textField:{size:"small"}}})]}),jsx(u,{display:{xs:"block",sm:"none"},children:jsx(a$4,{name:"period",options:R,onChange:o=>o&&M(o),value:I,size:"small",disableClearable:!0,fullWidth:!0})}),jsxs(u,{direction:{xs:"column",sm:"row"},alignItems:"center",justifyContent:{xs:"center",sm:"space-between"},gap:{xs:2,sm:3},children:[jsx(u,{width:1,overflow:"hidden",children:jsx(a$5,{fillContent:!0,sx:{display:{xs:"none",sm:"flex"},maxHeight:360},children:R.map(o=>jsxs(u,{direction:"row",alignItems:"center",gap:.5,sx:{m:.4},children:[jsx(fo,{id:`period_${o.value}`,name:`period_${o.value}`,icon:jsx(a$6,{icon:"CHECKMARK_CIRCLE_ROUNDED",color:"primary.main"}),checkedIcon:jsx(a$6,{icon:"CHECKMARK_CIRCLE",color:"primary.main"}),checked:I===o.value,onChange:()=>M(o.value)}),jsx(X,{component:"label",htmlFor:`period_${o.value}`,mt:.2,variant:"body2",color:"text.primary",sx:{cursor:"pointer",whiteSpace:"nowrap"},children:o.label})]},o.value))})}),jsx(J,{orientation:"vertical",flexItem:!0,sx:{display:{xs:"none",sm:"block"},mx:3}}),jsx(u,{width:{xs:"100%",sm:"auto"},alignItems:"center",justifyContent:"center",children:jsx(Q,{calendars:1,value:P,onChange:ro,disableFuture:ao,disablePast:io,showDaysOutsideCurrentMonth:!0,fixedWeekNumber:6,dayOfWeekFormatter:o=>Do[o.day()],sx:{"& .MuiDateRangeCalendar-root":{width:{xs:"100%",sm:"auto"}}}})})]}),jsx(J,{flexItem:!0}),jsxs(u,{direction:"row",alignItems:"center",justifyContent:"flex-end",gap:1,children:[jsx(uo,{variant:"outlined",color:"inherit",onClick:f$1,children:"Cancelar"}),jsx(a$7,{actionType:"SAVE",variant:"contained",color:"primary",type:"submit",disabled:to,children:"Aplicar"})]})]})})},Z=memo(go);var K=styled(uo)(({theme:e})=>({color:e.palette.text.primary,borderColor:e.palette.divider,"&:hover":{backgroundColor:"transparent"},[e.breakpoints.down("md")]:{"&.filters-button":{minWidth:"auto",padding:"6px 8px",fontSize:0,overflow:"hidden","& .MuiButton-startIcon":{margin:0,fontSize:"1rem"}}}}));var Y=typeof window>"u",So=({type:e="FREE",value:f,onChange:i$1,paramKey:r,dataKey:d,label:n="Per\xEDodo",thisYearMode:h})=>{let D=a$8(),k=useRef(!1);useEffect(()=>{if(Y||!r||k.current)return;k.current=!0;let t=new URLSearchParams(window.location.search),c=j$1(t,{paramKey:r,dataKey:d},{type:e,thisYearMode:h});c&&i$1(c);},[d,i$1,r,h,e]);let g=useCallback(t=>{if(i$1(t),Y||!r)return;let c=new URLSearchParams(window.location.search),P=i(t,{paramKey:r,dataKey:d},c).toString(),p=`${window.location.pathname}${P?`?${P}`:""}${window.location.hash}`;window.history.replaceState(window.history.state,"",p);},[d,i$1,r]);return jsxs(Fragment,{children:[jsx(u,{alignItems:"flex-start",children:jsx(K,{variant:"outlined",endIcon:jsx(a$6,{icon:"ARROW_DOWN_SIMPLE"}),size:"small",onClick:D.onOpen,children:n})}),jsx(Z,{open:D.open,onClose:D.onClose,type:e,value:f,onApply:g,thisYearMode:h})]})},ie=So;
|
|
25
25
|
|
|
26
|
-
export {
|
|
26
|
+
export { ie as default };
|
|
27
27
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/Filters/index.tsx","../../../src/components/Filters/FilterPopover/index.tsx","../../../src/components/Filters/FilterPopover/styles.ts","../../../src/components/Filters/styles.ts"],"names":["useCallback","useEffect","useRef","Stack","memo","useMemo","useState","useForm","Button","Checkbox","Divider","Typography","styled","MenuPopover","MenuPopover_default","theme","ResponsiveDateRangeCalendar","DateRangeCalendar_default","jsx","jsxs","DAYS_OF_WEEK","FilterPopover","open","onClose","type","value","onApply","isMobile","useResponsive_default","methods","handleSubmit","getValues","setValue","watch","reset","dateRange","setDateRange","watchedInitialDate","watchedFinalDate","watchedPeriod","isSubmitDisabled","disableFuture","disablePast","availablePeriods","getPeriodsByType","periodOptions","period","periodLabels","onPeriodChange","next","initialDate","finalDate","getPeriodDates","handleRangeChange","newRange","matching","findMatchingPeriod","handleInitialDateChange","date","handleFinalDateChange","onSubmit","formData","Form_default","DateField_default","Autocomplete_default","Scrollbar_default","option","Icon_default","day","ActionButton_default","FilterPopover_default","MUIButton","Fragment","IS_SERVER","Filters","onChange","paramKey","dataKey","label","popover","usePopover_default","hydratedRef","params","fromUrl","deserializeFilterFromSearchParams","handleApply","current","search","serializeFilterToSearchParams","url","Filters_default"],"mappings":"ukBAAA,OAAS,eAAAA,GAAa,aAAAC,GAAW,UAAAC,OAAc,QAC/C,OAAOC,OAAW,sBCDlB,OAAS,QAAAC,GAAM,eAAAJ,EAAa,aAAAC,EAAW,WAAAI,EAAS,YAAAC,OAAgB,QAChE,OAAS,WAAAC,OAAe,kBACxB,OAAOC,OAAY,uBACnB,OAAOC,OAAc,yBACrB,OAAOC,MAAa,wBACpB,OAAOP,MAAW,sBAClB,OAAOQ,MAAgB,2BCNvB,OAAS,UAAAC,MAAc,uBAKhB,IAAMC,EAAcD,EAAOE,CAAiB,EAAE,CAAC,CAAE,MAAAC,CAAM,KAAO,CACnE,UAAW,GAEX,sBAAuB,CACrB,MAAO,IACP,QAASA,EAAM,QAAQ,CAAC,EACxB,gBAAiBA,EAAM,QAAQ,WAAW,MAC1C,aA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O,OACP,MAAAC,EACA,SAAAkD,EACA,SAAAC,EACA,QAAAC,EACA,MAAAC,EAAQ,YACV,IAAoB,CAClB,IAAMC,EAAUC,EAAW,EAErBC,EAAc/E,GAAO,EAAK,EAEhCD,GAAU,IAAM,CACd,GAAIwE,GAAa,CAACG,GAAYK,EAAY,QAAS,OAEnDA,EAAY,QAAU,GAEtB,IAAMC,EAAS,IAAI,gBAAgB,OAAO,SAAS,MAAM,EACnDC,EAAUC,EAAkCF,EAAQ,CACxD,SAAAN,EACA,QAAAC,CACF,CAAC,EAEGM,GAASR,EAASQ,CAAO,CAC/B,EAAG,CAACN,EAASF,EAAUC,CAAQ,CAAC,EAEhC,IAAMS,EAAcrF,GACjBiD,GAAsB,CAGrB,GAFA0B,EAAS1B,CAAI,EAETwB,GAAa,CAACG,EAAU,OAE5B,IAAMU,EAAU,IAAI,gBAAgB,OAAO,SAAS,MAAM,EAMpDC,EALSC,EACbvC,EACA,CAAE,SAAA2B,EAAU,QAAAC,CAAQ,EACpBS,CACF,EACsB,SAAS,EACzBG,EAAM,GAAG,OAAO,SAAS,WAC7BF,EAAS,IAAIA,IAAW,KACvB,OAAO,SAAS,OAEnB,OAAO,QAAQ,aAAa,OAAO,QAAQ,MAAO,GAAIE,CAAG,CAC3D,EACA,CAACZ,EAASF,EAAUC,CAAQ,CAC9B,EAEA,OACEzD,GAAAqD,GAAA,CACE,UAAAtD,EAACf,GAAA,CAAM,WAAW,aAChB,SAAAe,EAACV,EAAA,CACC,QAAQ,WACR,QAASU,EAACiD,EAAA,CAAK,yBAAkC,EACjD,KAAK,QACL,QAASY,EAAQ,OAEhB,SAAAD,EACH,EACF,EAEA5D,EAACoD,EAAA,CACC,KAAMS,EAAQ,KACd,QAASA,EAAQ,QACjB,KAAMvD,EACN,MAAOC,EACP,QAAS4D,EACX,GACF,CAEJ,EAEOK,GAAQhB","sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\nimport Stack from '@mui/material/Stack';\n\nimport Icon from 'components/Icon';\nimport usePopover from 'hooks/usePopover';\nimport { Icon as IconEnum } from 'types/icon';\nimport { FilterValue } from 'types/period';\nimport {\n deserializeFilterFromSearchParams,\n serializeFilterToSearchParams,\n} from 'utils/filters';\n\nimport FilterPopover from './FilterPopover';\nimport { FiltersProps } from './props';\nimport { Button } from './styles';\n\nconst IS_SERVER = typeof window === 'undefined';\n\nconst Filters = ({\n type = 'FREE',\n value,\n onChange,\n paramKey,\n dataKey,\n label = 'Período',\n}: FiltersProps) => {\n const popover = usePopover();\n\n const hydratedRef = useRef(false);\n\n useEffect(() => {\n if (IS_SERVER || !paramKey || hydratedRef.current) return;\n\n hydratedRef.current = true;\n\n const params = new URLSearchParams(window.location.search);\n const fromUrl = deserializeFilterFromSearchParams(params, {\n paramKey,\n dataKey,\n });\n\n if (fromUrl) onChange(fromUrl);\n }, [dataKey, onChange, paramKey]);\n\n const handleApply = useCallback(\n (next: FilterValue) => {\n onChange(next);\n\n if (IS_SERVER || !paramKey) return;\n\n const current = new URLSearchParams(window.location.search);\n const params = serializeFilterToSearchParams(\n next,\n { paramKey, dataKey },\n current,\n );\n const search = params.toString();\n const url = `${window.location.pathname}${\n search ? `?${search}` : ''\n }${window.location.hash}`;\n\n window.history.replaceState(window.history.state, '', url);\n },\n [dataKey, onChange, paramKey],\n );\n\n return (\n <>\n <Stack alignItems=\"flex-start\">\n <Button\n variant=\"outlined\"\n endIcon={<Icon icon={IconEnum.ARROW_DOWN_SIMPLE} />}\n size=\"small\"\n onClick={popover.onOpen}\n >\n {label}\n </Button>\n </Stack>\n\n <FilterPopover\n open={popover.open}\n onClose={popover.onClose}\n type={type}\n value={value}\n onApply={handleApply}\n />\n </>\n );\n};\n\nexport default Filters;\n","import { memo, useCallback, useEffect, useMemo, useState } from 'react';\nimport { useForm } from 'react-hook-form';\nimport Button from '@mui/material/Button';\nimport Checkbox from '@mui/material/Checkbox';\nimport Divider from '@mui/material/Divider';\nimport Stack from '@mui/material/Stack';\nimport Typography from '@mui/material/Typography';\n\nimport ActionButton from 'components/ActionButton';\nimport Autocomplete from 'components/Autocomplete';\nimport DateField from 'components/form/DateField';\nimport Form from 'components/form/Form';\nimport Icon from 'components/Icon';\nimport Scrollbar from 'components/Scrollbar';\nimport useResponsive from 'hooks/useResponsive';\nimport { Icon as IconEnum } from 'types/icon';\nimport { FilterValue, Period, Type } from 'types/period';\nimport {\n findMatchingPeriod,\n getPeriodDates,\n getPeriodsByType,\n periodLabels,\n} from 'utils/filters';\n\nimport { FilterPopoverProps } from './props';\nimport { MenuPopover, ResponsiveDateRangeCalendar } from './styles';\n\nconst DAYS_OF_WEEK = ['D', 'S', 'T', 'Q', 'Q', 'S', 'S'];\n\nconst FilterPopover = ({\n open,\n onClose,\n type,\n value,\n onApply,\n}: FilterPopoverProps) => {\n const isMobile = useResponsive('down', 'sm');\n\n const methods = useForm<FilterValue>({\n defaultValues: value,\n });\n const { handleSubmit, getValues, setValue, watch, reset } = methods;\n\n const [dateRange, setDateRange] = useState<[Date | null, Date | null]>([\n value.initialDate,\n value.finalDate,\n ]);\n\n const watchedInitialDate = watch('initialDate');\n const watchedFinalDate = watch('finalDate');\n const watchedPeriod = watch('period');\n\n const isSubmitDisabled = !watchedInitialDate || !watchedFinalDate;\n const disableFuture = type === Type.PAST;\n const disablePast = type === Type.FUTURE;\n\n const availablePeriods = useMemo(() => getPeriodsByType(type), [type]);\n\n const periodOptions = useMemo(\n () =>\n availablePeriods.map(period => ({\n label: periodLabels[period],\n value: period,\n })),\n [availablePeriods],\n );\n\n useEffect(() => {\n if (open) reset(value);\n }, [open, reset, value]);\n\n useEffect(() => {\n setDateRange([value.initialDate, value.finalDate]);\n }, [value.finalDate, value.initialDate]);\n\n const onPeriodChange = useCallback(\n (next: Period) => {\n const { initialDate, finalDate } = getPeriodDates(next);\n\n setDateRange([initialDate, finalDate]);\n\n setValue('period', next);\n setValue('initialDate', initialDate);\n setValue('finalDate', finalDate);\n },\n [setValue],\n );\n\n const handleRangeChange = useCallback(\n (newRange: [Date | null, Date | null]) => {\n setDateRange(newRange);\n\n if (newRange[0]) setValue('initialDate', newRange[0]);\n if (newRange[1]) setValue('finalDate', newRange[1]);\n\n if (newRange[0] && newRange[1]) {\n const matching = findMatchingPeriod(\n newRange[0],\n newRange[1],\n availablePeriods,\n );\n\n setValue('period', matching);\n }\n },\n [availablePeriods, setValue],\n );\n\n const handleInitialDateChange = useCallback(\n (date: Date) => {\n setValue('initialDate', date);\n\n const finalDate = getValues('finalDate');\n\n if (date && finalDate) {\n const newRange: [Date, Date] = [date, finalDate];\n\n setDateRange(newRange);\n\n const matching = findMatchingPeriod(\n newRange[0],\n newRange[1],\n availablePeriods,\n );\n\n setValue('period', matching);\n }\n },\n [availablePeriods, getValues, setValue],\n );\n\n const handleFinalDateChange = useCallback(\n (date: Date) => {\n setValue('finalDate', date);\n\n const initialDate = getValues('initialDate');\n\n if (initialDate && date) {\n const newRange: [Date, Date] = [initialDate, date];\n\n setDateRange(newRange);\n\n const matching = findMatchingPeriod(\n newRange[0],\n newRange[1],\n availablePeriods,\n );\n\n setValue('period', matching);\n }\n },\n [availablePeriods, getValues, setValue],\n );\n\n const onSubmit = useCallback(\n (formData: FilterValue) => {\n onApply(formData);\n onClose();\n },\n [onApply, onClose],\n );\n\n return (\n <MenuPopover\n open={open}\n onClose={onClose}\n arrow={isMobile ? 'top-center' : 'top-left'}\n disabledArrow\n >\n <Form methods={methods} onSubmit={handleSubmit(onSubmit)} gap={2}>\n <Typography variant=\"overline\" color=\"text.disabled\">\n Defina o período\n </Typography>\n\n <Stack\n direction=\"row\"\n alignItems=\"center\"\n justifyContent=\"space-between\"\n gap={2}\n >\n <DateField\n name=\"initialDate\"\n label=\"Início\"\n onChange={handleInitialDateChange}\n slotProps={{ textField: { size: 'small' } }}\n />\n\n <DateField\n name=\"finalDate\"\n label=\"Término\"\n onChange={handleFinalDateChange}\n slotProps={{ textField: { size: 'small' } }}\n />\n </Stack>\n\n <Stack display={{ xs: 'block', sm: 'none' }}>\n <Autocomplete\n name=\"period\"\n options={periodOptions}\n onChange={next => next && onPeriodChange(next as Period)}\n value={watchedPeriod}\n size=\"small\"\n disableClearable\n fullWidth\n />\n </Stack>\n\n <Stack\n direction={{ xs: 'column', sm: 'row' }}\n alignItems=\"center\"\n justifyContent={{ xs: 'center', sm: 'space-between' }}\n gap={{ xs: 2, sm: 3 }}\n >\n <Stack width={1} overflow=\"hidden\">\n <Scrollbar\n fillContent\n sx={{\n display: { xs: 'none', sm: 'flex' },\n maxHeight: 360,\n }}\n >\n {periodOptions.map(option => (\n <Stack\n key={option.value}\n direction=\"row\"\n alignItems=\"center\"\n gap={0.5}\n sx={{ m: 0.4 }}\n >\n <Checkbox\n id={`period_${option.value}`}\n name={`period_${option.value}`}\n icon={\n <Icon\n icon={IconEnum.CHECKMARK_CIRCLE_ROUNDED}\n color=\"primary.main\"\n />\n }\n checkedIcon={\n <Icon\n icon={IconEnum.CHECKMARK_CIRCLE}\n color=\"primary.main\"\n />\n }\n checked={watchedPeriod === option.value}\n onChange={() => onPeriodChange(option.value)}\n />\n\n <Typography\n component=\"label\"\n htmlFor={`period_${option.value}`}\n mt={0.2}\n variant=\"body2\"\n color=\"text.primary\"\n sx={{ cursor: 'pointer', whiteSpace: 'nowrap' }}\n >\n {option.label}\n </Typography>\n </Stack>\n ))}\n </Scrollbar>\n </Stack>\n\n <Divider\n orientation=\"vertical\"\n flexItem\n sx={{ display: { xs: 'none', sm: 'block' }, mx: 3 }}\n />\n\n <Stack\n width={{ xs: '100%', sm: 'auto' }}\n alignItems=\"center\"\n justifyContent=\"center\"\n >\n <ResponsiveDateRangeCalendar\n calendars={1}\n value={dateRange}\n onChange={handleRangeChange}\n disableFuture={disableFuture}\n disablePast={disablePast}\n showDaysOutsideCurrentMonth\n fixedWeekNumber={6}\n dayOfWeekFormatter={day => DAYS_OF_WEEK[day.day()]}\n sx={{\n '& .MuiDateRangeCalendar-root': {\n width: { xs: '100%', sm: 'auto' },\n },\n }}\n />\n </Stack>\n </Stack>\n\n <Divider flexItem />\n\n <Stack\n direction=\"row\"\n alignItems=\"center\"\n justifyContent=\"flex-end\"\n gap={1}\n >\n <Button variant=\"outlined\" color=\"inherit\" onClick={onClose}>\n Cancelar\n </Button>\n\n <ActionButton\n actionType=\"SAVE\"\n variant=\"contained\"\n color=\"primary\"\n type=\"submit\"\n disabled={isSubmitDisabled}\n >\n Aplicar\n </ActionButton>\n </Stack>\n </Form>\n </MenuPopover>\n );\n};\n\nexport default memo(FilterPopover);\n","import { styled } from '@mui/material/styles';\n\nimport CommonDateRangeCalendar from 'components/DateRangeCalendar';\nimport CommonMenuPopover from 'components/MenuPopover';\n\nexport const MenuPopover = styled(CommonMenuPopover)(({ theme }) => ({\n marginTop: 10,\n\n '& .MuiPopover-paper': {\n width: 540,\n padding: theme.spacing(3),\n backgroundColor: theme.palette.background.paper,\n borderRadius: theme.spacing(1),\n backgroundImage: 'none',\n\n [theme.breakpoints.down('sm')]: {\n width: '90vw',\n maxWidth: 'calc(100vw - 32px)',\n padding: theme.spacing(2),\n },\n },\n}));\n\nexport const ResponsiveDateRangeCalendar = styled(CommonDateRangeCalendar)(\n ({ theme }) => ({\n [theme.breakpoints.up('sm')]: {\n '&.MuiDateRangeCalendar-root': {\n margin: -24,\n },\n },\n\n '& .MuiPickersCalendarHeader-label': {\n textTransform: 'capitalize',\n },\n\n [theme.breakpoints.down(400)]: {\n '& .MuiPickersCalendarHeader-root': {\n padding: theme.spacing(0, 7),\n },\n\n '& .MuiDayCalendar-header, & .MuiDayCalendar-weekContainer': {\n gap: 0,\n },\n\n '& .MuiPickersDay-root, & .MuiDateRangePickerDay-root': {\n width: 32,\n height: 32,\n },\n\n '& .MuiDayCalendar-weekDayLabel': {\n width: 32,\n height: 32,\n },\n\n '& .MuiDayCalendar-slideTransition': {\n minHeight: 210,\n },\n },\n\n [theme.breakpoints.down(350)]: {\n '& .MuiPickersDay-root, & .MuiDateRangePickerDay-root': {\n width: 28,\n height: 28,\n },\n\n '& .MuiDayCalendar-weekDayLabel': {\n width: 28,\n height: 28,\n },\n\n '& .MuiDayCalendar-slideTransition': {\n minHeight: 196,\n },\n },\n }),\n);\n","import MUIButton from '@mui/material/Button';\nimport { styled } from '@mui/material/styles';\n\nexport const Button = styled(MUIButton)(({ theme }) => ({\n color: theme.palette.text.primary,\n borderColor: theme.palette.divider,\n\n '&:hover': {\n backgroundColor: 'transparent',\n },\n\n [theme.breakpoints.down('md')]: {\n '&.filters-button': {\n minWidth: 'auto',\n padding: '6px 8px',\n fontSize: 0,\n overflow: 'hidden',\n\n '& .MuiButton-startIcon': {\n margin: 0,\n fontSize: '1rem',\n },\n },\n },\n}));\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Filters/index.tsx","../../../src/components/Filters/FilterPopover/index.tsx","../../../src/components/Filters/FilterPopover/styles.ts","../../../src/components/Filters/styles.ts"],"names":["useCallback","useEffect","useRef","Stack","memo","useMemo","useState","useForm","Button","Checkbox","Divider","Typography","styled","MenuPopover","MenuPopover_default","theme","ResponsiveDateRangeCalendar","DateRangeCalendar_default","jsx","jsxs","DAYS_OF_WEEK","FilterPopover","open","onClose","type","value","onApply","thisYearMode","isMobile","useResponsive_default","methods","handleSubmit","getValues","setValue","watch","reset","dateRange","setDateRange","watchedInitialDate","watchedFinalDate","watchedPeriod","isSubmitDisabled","disableFuture","disablePast","availablePeriods","getPeriodsByType","periodOptions","period","periodLabels","onPeriodChange","next","initialDate","finalDate","getPeriodDates","handleRangeChange","newRange","matching","findMatchingPeriod","handleInitialDateChange","date","handleFinalDateChange","onSubmit","formData","Form_default","DateField_default","Autocomplete_default","Scrollbar_default","option","Icon_default","day","ActionButton_default","FilterPopover_default","MUIButton","Fragment","IS_SERVER","Filters","onChange","paramKey","dataKey","label","popover","usePopover_default","hydratedRef","params","fromUrl","deserializeFilterFromSearchParams","handleApply","current","search","serializeFilterToSearchParams","url","Filters_default"],"mappings":"ukBAAA,OAAS,eAAAA,GAAa,aAAAC,GAAW,UAAAC,OAAc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AACG,EAAU,OAE5B,IAAMU,EAAU,IAAI,gBAAgB,OAAO,SAAS,MAAM,EAMpDC,EALSC,EACbvC,EACA,CAAE,SAAA2B,EAAU,QAAAC,CAAQ,EACpBS,CACF,EACsB,SAAS,EACzBG,EAAM,GAAG,OAAO,SAAS,WAC7BF,EAAS,IAAIA,IAAW,KACvB,OAAO,SAAS,OAEnB,OAAO,QAAQ,aAAa,OAAO,QAAQ,MAAO,GAAIE,CAAG,CAC3D,EACA,CAACZ,EAASF,EAAUC,CAAQ,CAC9B,EAEA,OACE1D,GAAAsD,GAAA,CACE,UAAAvD,EAACf,GAAA,CAAM,WAAW,aAChB,SAAAe,EAACV,EAAA,CACC,QAAQ,WACR,QAASU,EAACkD,EAAA,CAAK,yBAAkC,EACjD,KAAK,QACL,QAASY,EAAQ,OAEhB,SAAAD,EACH,EACF,EAEA7D,EAACqD,EAAA,CACC,KAAMS,EAAQ,KACd,QAASA,EAAQ,QACjB,KAAMxD,EACN,MAAOC,EACP,QAAS6D,EACT,aAAc3D,EAChB,GACF,CAEJ,EAEOgE,GAAQhB","sourcesContent":["import { useCallback, useEffect, useRef } from 'react';\nimport Stack from '@mui/material/Stack';\n\nimport Icon from 'components/Icon';\nimport usePopover from 'hooks/usePopover';\nimport { Icon as IconEnum } from 'types/icon';\nimport { FilterValue } from 'types/period';\nimport {\n deserializeFilterFromSearchParams,\n serializeFilterToSearchParams,\n} from 'utils/filters';\n\nimport FilterPopover from './FilterPopover';\nimport { FiltersProps } from './props';\nimport { Button } from './styles';\n\nconst IS_SERVER = typeof window === 'undefined';\n\nconst Filters = ({\n type = 'FREE',\n value,\n onChange,\n paramKey,\n dataKey,\n label = 'Período',\n thisYearMode,\n}: FiltersProps) => {\n const popover = usePopover();\n\n const hydratedRef = useRef(false);\n\n useEffect(() => {\n if (IS_SERVER || !paramKey || hydratedRef.current) return;\n\n hydratedRef.current = true;\n\n const params = new URLSearchParams(window.location.search);\n const fromUrl = deserializeFilterFromSearchParams(\n params,\n { paramKey, dataKey },\n { type, thisYearMode },\n );\n\n if (fromUrl) onChange(fromUrl);\n }, [dataKey, onChange, paramKey, thisYearMode, type]);\n\n const handleApply = useCallback(\n (next: FilterValue) => {\n onChange(next);\n\n if (IS_SERVER || !paramKey) return;\n\n const current = new URLSearchParams(window.location.search);\n const params = serializeFilterToSearchParams(\n next,\n { paramKey, dataKey },\n current,\n );\n const search = params.toString();\n const url = `${window.location.pathname}${\n search ? `?${search}` : ''\n }${window.location.hash}`;\n\n window.history.replaceState(window.history.state, '', url);\n },\n [dataKey, onChange, paramKey],\n );\n\n return (\n <>\n <Stack alignItems=\"flex-start\">\n <Button\n variant=\"outlined\"\n endIcon={<Icon icon={IconEnum.ARROW_DOWN_SIMPLE} />}\n size=\"small\"\n onClick={popover.onOpen}\n >\n {label}\n </Button>\n </Stack>\n\n <FilterPopover\n open={popover.open}\n onClose={popover.onClose}\n type={type}\n value={value}\n onApply={handleApply}\n thisYearMode={thisYearMode}\n />\n </>\n );\n};\n\nexport default Filters;\n","import { memo, useCallback, useEffect, useMemo, useState } from 'react';\nimport { useForm } from 'react-hook-form';\nimport Button from '@mui/material/Button';\nimport Checkbox from '@mui/material/Checkbox';\nimport Divider from '@mui/material/Divider';\nimport Stack from '@mui/material/Stack';\nimport Typography from '@mui/material/Typography';\n\nimport ActionButton from 'components/ActionButton';\nimport Autocomplete from 'components/Autocomplete';\nimport DateField from 'components/form/DateField';\nimport Form from 'components/form/Form';\nimport Icon from 'components/Icon';\nimport Scrollbar from 'components/Scrollbar';\nimport useResponsive from 'hooks/useResponsive';\nimport { Icon as IconEnum } from 'types/icon';\nimport { FilterValue, Period, Type } from 'types/period';\nimport {\n findMatchingPeriod,\n getPeriodDates,\n getPeriodsByType,\n periodLabels,\n} from 'utils/filters';\n\nimport { FilterPopoverProps } from './props';\nimport { MenuPopover, ResponsiveDateRangeCalendar } from './styles';\n\nconst DAYS_OF_WEEK = ['D', 'S', 'T', 'Q', 'Q', 'S', 'S'];\n\nconst FilterPopover = ({\n open,\n onClose,\n type,\n value,\n onApply,\n thisYearMode,\n}: FilterPopoverProps) => {\n const isMobile = useResponsive('down', 'sm');\n\n const methods = useForm<FilterValue>({\n defaultValues: value,\n });\n const { handleSubmit, getValues, setValue, watch, reset } = methods;\n\n const [dateRange, setDateRange] = useState<[Date | null, Date | null]>([\n value.initialDate,\n value.finalDate,\n ]);\n\n const watchedInitialDate = watch('initialDate');\n const watchedFinalDate = watch('finalDate');\n const watchedPeriod = watch('period');\n\n const isSubmitDisabled = !watchedInitialDate || !watchedFinalDate;\n const disableFuture = type === Type.PAST;\n const disablePast = type === Type.FUTURE;\n\n const availablePeriods = useMemo(() => getPeriodsByType(type), [type]);\n\n const periodOptions = useMemo(\n () =>\n availablePeriods.map(period => ({\n label: periodLabels[period],\n value: period,\n })),\n [availablePeriods],\n );\n\n useEffect(() => {\n if (open) reset(value);\n }, [open, reset, value]);\n\n useEffect(() => {\n setDateRange([value.initialDate, value.finalDate]);\n }, [value.finalDate, value.initialDate]);\n\n const onPeriodChange = useCallback(\n (next: Period) => {\n const { initialDate, finalDate } = getPeriodDates(next, {\n type,\n thisYearMode,\n });\n\n setDateRange([initialDate, finalDate]);\n\n setValue('period', next);\n setValue('initialDate', initialDate);\n setValue('finalDate', finalDate);\n },\n [setValue, thisYearMode, type],\n );\n\n const handleRangeChange = useCallback(\n (newRange: [Date | null, Date | null]) => {\n setDateRange(newRange);\n\n if (newRange[0]) setValue('initialDate', newRange[0]);\n if (newRange[1]) setValue('finalDate', newRange[1]);\n\n if (newRange[0] && newRange[1]) {\n const matching = findMatchingPeriod(\n newRange[0],\n newRange[1],\n availablePeriods,\n { type, thisYearMode },\n );\n\n setValue('period', matching);\n }\n },\n [availablePeriods, setValue, thisYearMode, type],\n );\n\n const handleInitialDateChange = useCallback(\n (date: Date) => {\n setValue('initialDate', date);\n\n const finalDate = getValues('finalDate');\n\n if (date && finalDate) {\n const newRange: [Date, Date] = [date, finalDate];\n\n setDateRange(newRange);\n\n const matching = findMatchingPeriod(\n newRange[0],\n newRange[1],\n availablePeriods,\n { type, thisYearMode },\n );\n\n setValue('period', matching);\n }\n },\n [availablePeriods, getValues, setValue, thisYearMode, type],\n );\n\n const handleFinalDateChange = useCallback(\n (date: Date) => {\n setValue('finalDate', date);\n\n const initialDate = getValues('initialDate');\n\n if (initialDate && date) {\n const newRange: [Date, Date] = [initialDate, date];\n\n setDateRange(newRange);\n\n const matching = findMatchingPeriod(\n newRange[0],\n newRange[1],\n availablePeriods,\n { type, thisYearMode },\n );\n\n setValue('period', matching);\n }\n },\n [availablePeriods, getValues, setValue, thisYearMode, type],\n );\n\n const onSubmit = useCallback(\n (formData: FilterValue) => {\n onApply(formData);\n onClose();\n },\n [onApply, onClose],\n );\n\n return (\n <MenuPopover\n open={open}\n onClose={onClose}\n arrow={isMobile ? 'top-center' : 'top-left'}\n disabledArrow\n >\n <Form methods={methods} onSubmit={handleSubmit(onSubmit)} gap={2}>\n <Typography variant=\"overline\" color=\"text.disabled\">\n Defina o período\n </Typography>\n\n <Stack\n direction=\"row\"\n alignItems=\"center\"\n justifyContent=\"space-between\"\n gap={2}\n >\n <DateField\n name=\"initialDate\"\n label=\"Início\"\n onChange={handleInitialDateChange}\n slotProps={{ textField: { size: 'small' } }}\n />\n\n <DateField\n name=\"finalDate\"\n label=\"Término\"\n onChange={handleFinalDateChange}\n slotProps={{ textField: { size: 'small' } }}\n />\n </Stack>\n\n <Stack display={{ xs: 'block', sm: 'none' }}>\n <Autocomplete\n name=\"period\"\n options={periodOptions}\n onChange={next => next && onPeriodChange(next as Period)}\n value={watchedPeriod}\n size=\"small\"\n disableClearable\n fullWidth\n />\n </Stack>\n\n <Stack\n direction={{ xs: 'column', sm: 'row' }}\n alignItems=\"center\"\n justifyContent={{ xs: 'center', sm: 'space-between' }}\n gap={{ xs: 2, sm: 3 }}\n >\n <Stack width={1} overflow=\"hidden\">\n <Scrollbar\n fillContent\n sx={{\n display: { xs: 'none', sm: 'flex' },\n maxHeight: 360,\n }}\n >\n {periodOptions.map(option => (\n <Stack\n key={option.value}\n direction=\"row\"\n alignItems=\"center\"\n gap={0.5}\n sx={{ m: 0.4 }}\n >\n <Checkbox\n id={`period_${option.value}`}\n name={`period_${option.value}`}\n icon={\n <Icon\n icon={IconEnum.CHECKMARK_CIRCLE_ROUNDED}\n color=\"primary.main\"\n />\n }\n checkedIcon={\n <Icon\n icon={IconEnum.CHECKMARK_CIRCLE}\n color=\"primary.main\"\n />\n }\n checked={watchedPeriod === option.value}\n onChange={() => onPeriodChange(option.value)}\n />\n\n <Typography\n component=\"label\"\n htmlFor={`period_${option.value}`}\n mt={0.2}\n variant=\"body2\"\n color=\"text.primary\"\n sx={{ cursor: 'pointer', whiteSpace: 'nowrap' }}\n >\n {option.label}\n </Typography>\n </Stack>\n ))}\n </Scrollbar>\n </Stack>\n\n <Divider\n orientation=\"vertical\"\n flexItem\n sx={{ display: { xs: 'none', sm: 'block' }, mx: 3 }}\n />\n\n <Stack\n width={{ xs: '100%', sm: 'auto' }}\n alignItems=\"center\"\n justifyContent=\"center\"\n >\n <ResponsiveDateRangeCalendar\n calendars={1}\n value={dateRange}\n onChange={handleRangeChange}\n disableFuture={disableFuture}\n disablePast={disablePast}\n showDaysOutsideCurrentMonth\n fixedWeekNumber={6}\n dayOfWeekFormatter={day => DAYS_OF_WEEK[day.day()]}\n sx={{\n '& .MuiDateRangeCalendar-root': {\n width: { xs: '100%', sm: 'auto' },\n },\n }}\n />\n </Stack>\n </Stack>\n\n <Divider flexItem />\n\n <Stack\n direction=\"row\"\n alignItems=\"center\"\n justifyContent=\"flex-end\"\n gap={1}\n >\n <Button variant=\"outlined\" color=\"inherit\" onClick={onClose}>\n Cancelar\n </Button>\n\n <ActionButton\n actionType=\"SAVE\"\n variant=\"contained\"\n color=\"primary\"\n type=\"submit\"\n disabled={isSubmitDisabled}\n >\n Aplicar\n </ActionButton>\n </Stack>\n </Form>\n </MenuPopover>\n );\n};\n\nexport default memo(FilterPopover);\n","import { styled } from '@mui/material/styles';\n\nimport CommonDateRangeCalendar from 'components/DateRangeCalendar';\nimport CommonMenuPopover from 'components/MenuPopover';\n\nexport const MenuPopover = styled(CommonMenuPopover)(({ theme }) => ({\n marginTop: 10,\n\n '& .MuiPopover-paper': {\n width: 580,\n padding: theme.spacing(3),\n backgroundColor: theme.palette.background.paper,\n borderRadius: theme.spacing(1),\n backgroundImage: 'none',\n\n [theme.breakpoints.down('sm')]: {\n width: '90vw',\n maxWidth: 'calc(100vw - 32px)',\n padding: theme.spacing(2),\n },\n },\n}));\n\nexport const ResponsiveDateRangeCalendar = styled(CommonDateRangeCalendar)(\n ({ theme }) => ({\n [theme.breakpoints.up('sm')]: {\n '&.MuiDateRangeCalendar-root': {\n margin: -24,\n },\n },\n\n '& .MuiPickersCalendarHeader-label': {\n textTransform: 'capitalize',\n },\n\n [theme.breakpoints.down(400)]: {\n '& .MuiPickersCalendarHeader-root': {\n padding: theme.spacing(0, 7),\n },\n\n '& .MuiDayCalendar-header, & .MuiDayCalendar-weekContainer': {\n gap: 0,\n },\n\n '& .MuiPickersDay-root, & .MuiDateRangePickerDay-root': {\n width: 32,\n height: 32,\n },\n\n '& .MuiDayCalendar-weekDayLabel': {\n width: 32,\n height: 32,\n },\n\n '& .MuiDayCalendar-slideTransition': {\n minHeight: 210,\n },\n },\n\n [theme.breakpoints.down(350)]: {\n '& .MuiPickersDay-root, & .MuiDateRangePickerDay-root': {\n width: 28,\n height: 28,\n },\n\n '& .MuiDayCalendar-weekDayLabel': {\n width: 28,\n height: 28,\n },\n\n '& .MuiDayCalendar-slideTransition': {\n minHeight: 196,\n },\n },\n }),\n);\n","import MUIButton from '@mui/material/Button';\nimport { styled } from '@mui/material/styles';\n\nexport const Button = styled(MUIButton)(({ theme }) => ({\n color: theme.palette.text.primary,\n borderColor: theme.palette.divider,\n\n '&:hover': {\n backgroundColor: 'transparent',\n },\n\n [theme.breakpoints.down('md')]: {\n '&.filters-button': {\n minWidth: 'auto',\n padding: '6px 8px',\n fontSize: 0,\n overflow: 'hidden',\n\n '& .MuiButton-startIcon': {\n margin: 0,\n fontSize: '1rem',\n },\n },\n },\n}));\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FilterValue, Type, Period } from '../types/period.js';
|
|
1
|
+
import { FilterValue, Type, Period, ThisYearMode } from '../types/period.js';
|
|
2
2
|
|
|
3
3
|
interface UseFiltersSearchParamsOptions {
|
|
4
4
|
type?: keyof typeof Type;
|
|
@@ -6,7 +6,8 @@ interface UseFiltersSearchParamsOptions {
|
|
|
6
6
|
dataKey?: string;
|
|
7
7
|
defaultValue?: FilterValue;
|
|
8
8
|
defaultPeriod?: keyof typeof Period;
|
|
9
|
+
thisYearMode?: keyof typeof ThisYearMode;
|
|
9
10
|
}
|
|
10
|
-
declare const useFiltersSearchParams: ({ type, paramKey, dataKey, defaultValue, defaultPeriod, }?: UseFiltersSearchParamsOptions) => [FilterValue, (value: FilterValue) => void];
|
|
11
|
+
declare const useFiltersSearchParams: ({ type, paramKey, dataKey, defaultValue, defaultPeriod, thisYearMode, }?: UseFiltersSearchParamsOptions) => [FilterValue, (value: FilterValue) => void];
|
|
11
12
|
|
|
12
13
|
export { useFiltersSearchParams as default };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { e, j, i, h } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
import { e, j, i, h } from '../chunk-CG6F55WN.js';
|
|
2
|
+
import '../chunk-VFDADOF2.js';
|
|
3
3
|
import { useState, useRef, useEffect, useCallback } from 'react';
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var u=typeof window>"u",T=({type:t="FREE",paramKey:o=h.paramKey,dataKey:n=h.dataKey,defaultValue:F,defaultPeriod:S,thisYearMode:a}={})=>{let[P,f]=useState(()=>{let e$1=F??e(t,S,a);if(u)return e$1;let r=new URLSearchParams(window.location.search);return j(r,{paramKey:o,dataKey:n},{type:t,thisYearMode:a})??e$1}),s=useRef({paramKey:o,dataKey:n});s.current={paramKey:o,dataKey:n};let d=useRef({type:t,thisYearMode:a});d.current={type:t,thisYearMode:a},useEffect(()=>{if(u)return;let e=()=>{let r=new URLSearchParams(window.location.search),i=j(r,s.current,d.current);i&&f(i);};return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[]);let y=useCallback(e=>{if(f(e),u)return;let r=new URLSearchParams(window.location.search),w=i(e,s.current,r).toString(),E=`${window.location.pathname}${w?`?${w}`:""}${window.location.hash}`;window.history.replaceState(window.history.state,"",E);},[]);return [P,y]},U=T;
|
|
6
6
|
|
|
7
7
|
export { U as default };
|
|
8
8
|
//# sourceMappingURL=useFiltersSearchParams.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/useFiltersSearchParams.ts"],"names":["useCallback","useEffect","useRef","useState","IS_SERVER","useFiltersSearchParams","type","paramKey","DEFAULT_FILTER_KEYS","dataKey","defaultValue","defaultPeriod","value","setValue","fallback","buildDefaultFilter","params","deserializeFilterFromSearchParams","keysRef","handler","next","update","current","search","serializeFilterToSearchParams","url","useFiltersSearchParams_default"],"mappings":"2FAAA,OAAS,eAAAA,EAAa,aAAAC,EAAW,UAAAC,EAAQ,YAAAC,MAAgB,
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useFiltersSearchParams.ts"],"names":["useCallback","useEffect","useRef","useState","IS_SERVER","useFiltersSearchParams","type","paramKey","DEFAULT_FILTER_KEYS","dataKey","defaultValue","defaultPeriod","thisYearMode","value","setValue","fallback","buildDefaultFilter","params","deserializeFilterFromSearchParams","keysRef","resolutionRef","handler","next","update","current","search","serializeFilterToSearchParams","url","useFiltersSearchParams_default"],"mappings":"2FAAA,OAAS,eAAAA,EAAa,aAAAC,EAAW,UAAAC,EAAQ,YAAAC,MAAgB,QAmBzD,IAAMC,EAAY,OAAO,OAAW,IAE9BC,EAAyB,CAAC,CAC9B,KAAAC,EAAO,OACP,SAAAC,EAAWC,EAAoB,SAC/B,QAAAC,E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AO,GAAIE,CAAG,CAC3D,EAAG,CAAC,CAAC,EAEL,MAAO,CAACd,EAAOU,CAAM,CACvB,EAEOK,EAAQvB","sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\n\nimport { FilterValue, Period, ThisYearMode, Type } from 'types/period';\nimport {\n buildDefaultFilter,\n DEFAULT_FILTER_KEYS,\n deserializeFilterFromSearchParams,\n serializeFilterToSearchParams,\n} from 'utils/filters';\n\ninterface UseFiltersSearchParamsOptions {\n type?: keyof typeof Type;\n paramKey?: string;\n dataKey?: string;\n defaultValue?: FilterValue;\n defaultPeriod?: keyof typeof Period;\n thisYearMode?: keyof typeof ThisYearMode;\n}\n\nconst IS_SERVER = typeof window === 'undefined';\n\nconst useFiltersSearchParams = ({\n type = 'FREE',\n paramKey = DEFAULT_FILTER_KEYS.paramKey,\n dataKey = DEFAULT_FILTER_KEYS.dataKey,\n defaultValue,\n defaultPeriod,\n thisYearMode,\n}: UseFiltersSearchParamsOptions = {}): [\n FilterValue,\n (value: FilterValue) => void,\n] => {\n const [value, setValue] = useState<FilterValue>(() => {\n const fallback =\n defaultValue ?? buildDefaultFilter(type, defaultPeriod, thisYearMode);\n\n if (IS_SERVER) return fallback;\n\n const params = new URLSearchParams(window.location.search);\n\n return (\n deserializeFilterFromSearchParams(\n params,\n { paramKey, dataKey },\n { type, thisYearMode },\n ) ?? fallback\n );\n });\n\n const keysRef = useRef({ paramKey, dataKey });\n keysRef.current = { paramKey, dataKey };\n\n const resolutionRef = useRef({ type, thisYearMode });\n resolutionRef.current = { type, thisYearMode };\n\n useEffect(() => {\n if (IS_SERVER) return;\n\n const handler = () => {\n const params = new URLSearchParams(window.location.search);\n const next = deserializeFilterFromSearchParams(\n params,\n keysRef.current,\n resolutionRef.current,\n );\n\n if (next) setValue(next);\n };\n\n window.addEventListener('popstate', handler);\n\n return () => window.removeEventListener('popstate', handler);\n }, []);\n\n const update = useCallback((next: FilterValue) => {\n setValue(next);\n\n if (IS_SERVER) return;\n\n const current = new URLSearchParams(window.location.search);\n const params = serializeFilterToSearchParams(\n next,\n keysRef.current,\n current,\n );\n const search = params.toString();\n const url = `${window.location.pathname}${\n search ? `?${search}` : ''\n }${window.location.hash}`;\n\n window.history.replaceState(window.history.state, '', url);\n }, []);\n\n return [value, update];\n};\n\nexport default useFiltersSearchParams;\n"]}
|
package/dist/types/period.d.ts
CHANGED
|
@@ -20,6 +20,11 @@ declare enum Type {
|
|
|
20
20
|
PAST = "PAST",
|
|
21
21
|
FUTURE = "FUTURE"
|
|
22
22
|
}
|
|
23
|
+
declare enum ThisYearMode {
|
|
24
|
+
FROM_TODAY = "FROM_TODAY",
|
|
25
|
+
TO_DATE = "TO_DATE",
|
|
26
|
+
FULL = "FULL"
|
|
27
|
+
}
|
|
23
28
|
interface FilterValue {
|
|
24
29
|
period: Period;
|
|
25
30
|
initialDate: Date | null;
|
|
@@ -30,4 +35,4 @@ interface FilterUrlKeys {
|
|
|
30
35
|
dataKey?: string;
|
|
31
36
|
}
|
|
32
37
|
|
|
33
|
-
export { FilterUrlKeys, FilterValue, Period, Type };
|
|
38
|
+
export { FilterUrlKeys, FilterValue, Period, ThisYearMode, Type };
|
package/dist/types/period.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { a as Period, b as Type } from '../chunk-
|
|
1
|
+
export { a as Period, c as ThisYearMode, b as Type } from '../chunk-VFDADOF2.js';
|
|
2
2
|
//# sourceMappingURL=period.js.map
|
package/dist/utils/filters.d.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Type, ThisYearMode, Period, FilterValue, FilterUrlKeys } from '../types/period.js';
|
|
2
2
|
|
|
3
|
+
interface PeriodResolutionOptions {
|
|
4
|
+
type?: keyof typeof Type;
|
|
5
|
+
thisYearMode?: keyof typeof ThisYearMode;
|
|
6
|
+
}
|
|
3
7
|
declare const periodLabels: Record<Period, string>;
|
|
4
8
|
declare const getPeriodsByType: (type: keyof typeof Type) => Period[];
|
|
5
9
|
declare const getDefaultPeriodForType: (type: keyof typeof Type) => Period;
|
|
6
|
-
declare const getPeriodDates: (period: Period,
|
|
10
|
+
declare const getPeriodDates: (period: Period, options?: PeriodResolutionOptions) => {
|
|
7
11
|
initialDate: Date | null;
|
|
8
12
|
finalDate: Date | null;
|
|
9
13
|
};
|
|
10
|
-
declare const buildDefaultFilter: (type: keyof typeof Type, defaultPeriod?: keyof typeof Period) => FilterValue;
|
|
11
|
-
declare const findMatchingPeriod: (startDate: Date | null, endDate: Date | null, candidates: Period[]) => Period;
|
|
14
|
+
declare const buildDefaultFilter: (type: keyof typeof Type, defaultPeriod?: keyof typeof Period, thisYearMode?: keyof typeof ThisYearMode) => FilterValue;
|
|
15
|
+
declare const findMatchingPeriod: (startDate: Date | null, endDate: Date | null, candidates: Period[], options?: PeriodResolutionOptions) => Period;
|
|
12
16
|
declare const periodSlugs: Record<Period, string>;
|
|
13
17
|
declare const DEFAULT_FILTER_KEYS: Required<FilterUrlKeys>;
|
|
14
18
|
declare const serializeFilterToSearchParams: (value: FilterValue, keys?: FilterUrlKeys, baseParams?: URLSearchParams) => URLSearchParams;
|
|
15
|
-
declare const deserializeFilterFromSearchParams: (params: URLSearchParams, keys?: FilterUrlKeys) => FilterValue | null;
|
|
19
|
+
declare const deserializeFilterFromSearchParams: (params: URLSearchParams, keys?: FilterUrlKeys, options?: PeriodResolutionOptions) => FilterValue | null;
|
|
16
20
|
|
|
17
|
-
export { DEFAULT_FILTER_KEYS, buildDefaultFilter, deserializeFilterFromSearchParams, findMatchingPeriod, getDefaultPeriodForType, getPeriodDates, getPeriodsByType, periodLabels, periodSlugs, serializeFilterToSearchParams };
|
|
21
|
+
export { DEFAULT_FILTER_KEYS, PeriodResolutionOptions, buildDefaultFilter, deserializeFilterFromSearchParams, findMatchingPeriod, getDefaultPeriodForType, getPeriodDates, getPeriodsByType, periodLabels, periodSlugs, serializeFilterToSearchParams };
|
package/dist/utils/filters.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { h as DEFAULT_FILTER_KEYS, e as buildDefaultFilter, j as deserializeFilterFromSearchParams, f as findMatchingPeriod, c as getDefaultPeriodForType, d as getPeriodDates, b as getPeriodsByType, a as periodLabels, g as periodSlugs, i as serializeFilterToSearchParams } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
export { h as DEFAULT_FILTER_KEYS, e as buildDefaultFilter, j as deserializeFilterFromSearchParams, f as findMatchingPeriod, c as getDefaultPeriodForType, d as getPeriodDates, b as getPeriodsByType, a as periodLabels, g as periodSlugs, i as serializeFilterToSearchParams } from '../chunk-CG6F55WN.js';
|
|
2
|
+
import '../chunk-VFDADOF2.js';
|
|
3
3
|
//# sourceMappingURL=filters.js.map
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types/period.ts"],"names":["Period","Type"],"mappings":"AAAO,IAAKA,OACVA,EAAA,UAAY,YACZA,EAAA,WAAa,aACbA,EAAA,aAAe,eACfA,EAAA,YAAc,cACdA,EAAA,UAAY,YACZA,EAAA,UAAY,YACZA,EAAA,MAAQ,QACRA,EAAA,SAAW,WACXA,EAAA,YAAc,cACdA,EAAA,aAAe,eACfA,EAAA,aAAe,eACfA,EAAA,WAAa,aACbA,EAAA,UAAY,YACZA,EAAA,UAAY,YACZA,EAAA,OAAS,SAfCA,OAAA,IAkBAC,OACVA,EAAA,KAAO,OACPA,EAAA,KAAO,OACPA,EAAA,OAAS,SAHCA,OAAA","sourcesContent":["export enum Period {\n LAST_YEAR = 'LAST_YEAR',\n LAST_MONTH = 'LAST_MONTH',\n LAST_28_DAYS = 'LAST_28_DAYS',\n LAST_7_DAYS = 'LAST_7_DAYS',\n LAST_WEEK = 'LAST_WEEK',\n YESTERDAY = 'YESTERDAY',\n TODAY = 'TODAY',\n TOMORROW = 'TOMORROW',\n NEXT_7_DAYS = 'NEXT_7_DAYS',\n NEXT_30_DAYS = 'NEXT_30_DAYS',\n NEXT_90_DAYS = 'NEXT_90_DAYS',\n NEXT_MONTH = 'NEXT_MONTH',\n THIS_YEAR = 'THIS_YEAR',\n NEXT_YEAR = 'NEXT_YEAR',\n CUSTOM = 'CUSTOM',\n}\n\nexport enum Type {\n FREE = 'FREE',\n PAST = 'PAST',\n FUTURE = 'FUTURE',\n}\n\nexport interface FilterValue {\n period: Period;\n initialDate: Date | null;\n finalDate: Date | null;\n}\n\nexport interface FilterUrlKeys {\n paramKey?: string;\n dataKey?: string;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/components/DataGrid/index.tsx","../src/components/DataGrid/CustomToolbar/index.tsx"],"names":["useState","DataGridPremium","GRID_CHECKBOX_SELECTION_COL_DEF","Box","GridToolbarColumnsButton","GridToolbarContainer","GridToolbarDensitySelector","GridToolbarExport","GridToolbarFilterButton","jsx","jsxs","CustomToolbar","showToolbar","disableExport","setFilterButtonEl","toolbarContent","CustomToolbar_default","Fragment","DataGrid","columns","rows","loading","fetching","hideFooter","sx","columnHeaderHeight","rowHeight","rowSpacingType","getRowSpacing","autoHeight","slots","other","filterButtonEl","COLUMNS","FixedProgressBar_default","EmptyContent_default","LoadingOverlay_default","DataGrid_default"],"mappings":"mHAAA,OAAS,YAAAA,MAAgB,QACzB,OACE,mBAAAC,EACA,mCAAAC,MAGK,2BCLP,OAAOC,MAAS,oBAChB,OACE,4BAAAC,EACA,wBAAAC,EACA,8BAAAC,EACA,qBAAAC,EACA,2BAAAC,MACK,2BAaH,OACE,OAAAC,EADF,QAAAC,MAAA,oBATJ,IAAMC,EAAgB,CAAC,CACrB,YAAAC,EACA,cAAAC,EACA,kBAAAC,EACA,eAAAC,CACF,IAA6C,CAC3C,GAAKH,EAEL,OACEF,EAACL,EAAA,CACC,UAAAI,EAACL,EAAA,CAAyB,UAAW,CAAE,OAAQ,CAAE,MAAO,SAAU,CAAE,EAAG,EACvEK,EAACD,EAAA,CACC,IAAKM,EACL,UAAW,CAAE,OA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,CAAe,EAClC,QAAS,CACP,kBAAAlB,EACA,gBAAiB,GACjB,cAAAD,EACA,YAAAD,EACA,eAAAG,CACF,CACF,EACA,GAAIS,EACH,GAAGO,EACN,GACF,CAEJ,EAEOM,EAAQnB","sourcesContent":["import { useState } from 'react';\nimport {\n DataGridPremium,\n GRID_CHECKBOX_SELECTION_COL_DEF,\n GridSlots,\n GridSlotsComponentsProps,\n} from '@mui/x-data-grid-premium';\n\nimport EmptyContent from 'components/EmptyContent';\nimport { DataGridProps } from 'types/dataGridProps';\n\nimport FixedProgressBar from '../FixedProgressBar';\n\nimport CustomToolbar from './CustomToolbar';\nimport LoadingOverlay from './LoadingOverlay';\n\nconst DataGrid = ({\n columns,\n rows = [],\n loading,\n fetching,\n hideFooter,\n sx,\n showToolbar,\n disableExport,\n columnHeaderHeight = 56,\n rowHeight = 76,\n rowSpacingType = 'margin',\n getRowSpacing = () => ({\n top: 0,\n bottom: 0,\n }),\n autoHeight = false,\n toolbarContent,\n slots,\n ...other\n}: DataGridProps) => {\n const [filterButtonEl, setFilterButtonEl] =\n useState<HTMLButtonElement | null>(null);\n\n const COLUMNS = [\n {\n ...GRID_CHECKBOX_SELECTION_COL_DEF,\n width: 71,\n },\n ...columns,\n ];\n\n return (\n <>\n {fetching && <FixedProgressBar sx={{ zIndex: 1 }} />}\n\n <DataGridPremium\n columns={COLUMNS}\n rows={rows}\n loading={loading}\n autoHeight={autoHeight}\n hideFooter={rows.length === 0 ? true : hideFooter}\n rowHeight={rowHeight}\n columnHeaderHeight={columnHeaderHeight}\n getRowSpacing={getRowSpacing}\n rowSpacingType={rowSpacingType}\n slots={{\n toolbar: CustomToolbar as unknown as GridSlots['toolbar'],\n noRowsOverlay: () => (\n <EmptyContent title=\"Nenhum registro encontrado\" />\n ),\n noResultsOverlay: () => (\n <EmptyContent title=\"Nenhum registro encontrado\" />\n ),\n loadingOverlay: LoadingOverlay,\n ...slots,\n }}\n slotProps={{\n panel: { anchorEl: filterButtonEl },\n toolbar: {\n setFilterButtonEl,\n showQuickFilter: true,\n disableExport,\n showToolbar,\n toolbarContent,\n } as unknown as GridSlotsComponentsProps['toolbar'],\n }}\n sx={sx}\n {...other}\n />\n </>\n );\n};\n\nexport default DataGrid;\n","import { PropsWithChildren } from 'react';\nimport Box from '@mui/material/Box';\nimport {\n GridToolbarColumnsButton,\n GridToolbarContainer,\n GridToolbarDensitySelector,\n GridToolbarExport,\n GridToolbarFilterButton,\n} from '@mui/x-data-grid-premium';\n\nimport { CustomToolbarProps } from './props';\n\nconst CustomToolbar = ({\n showToolbar,\n disableExport,\n setFilterButtonEl,\n toolbarContent,\n}: PropsWithChildren<CustomToolbarProps>) => {\n if (!showToolbar) return;\n\n return (\n <GridToolbarContainer>\n <GridToolbarColumnsButton slotProps={{ button: { color: 'inherit' } }} />\n <GridToolbarFilterButton\n ref={setFilterButtonEl}\n slotProps={{ button: { color: 'inherit' } }}\n />\n <GridToolbarDensitySelector\n slotProps={{ button: { color: 'inherit' } }}\n />\n {!disableExport && (\n <GridToolbarExport slotProps={{ button: { color: 'inherit' } }} />\n )}\n <Box sx={{ flexGrow: 1 }} />\n {toolbarContent}\n </GridToolbarContainer>\n );\n};\n\nexport default CustomToolbar;\n"]}
|
package/dist/chunk-MEPEYLZT.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { a } from './chunk-7QZTU4E7.js';
|
|
2
|
-
|
|
3
|
-
var f={["LAST_YEAR"]:"Ano passado",["LAST_MONTH"]:"M\xEAs passado",["LAST_28_DAYS"]:"\xDAltimos 28 dias",["LAST_7_DAYS"]:"\xDAltimos 7 dias",["LAST_WEEK"]:"Semana passada",["YESTERDAY"]:"Ontem",["TODAY"]:"Hoje",["TOMORROW"]:"Amanh\xE3",["NEXT_7_DAYS"]:"Pr\xF3ximos 7 dias",["NEXT_30_DAYS"]:"Pr\xF3ximos 30 dias",["NEXT_90_DAYS"]:"Pr\xF3ximos 90 dias",["NEXT_MONTH"]:"Pr\xF3ximo m\xEAs",["THIS_YEAR"]:"Este ano",["NEXT_YEAR"]:"Pr\xF3ximo ano",["CUSTOM"]:"Personalizado"},d=["TODAY","YESTERDAY","LAST_7_DAYS","LAST_WEEK","LAST_28_DAYS","LAST_MONTH","LAST_YEAR","CUSTOM"],u=["TODAY","TOMORROW","NEXT_7_DAYS","NEXT_30_DAYS","NEXT_90_DAYS","NEXT_MONTH","THIS_YEAR","NEXT_YEAR","CUSTOM"],O=["LAST_YEAR","LAST_MONTH","LAST_28_DAYS","LAST_7_DAYS","LAST_WEEK","YESTERDAY","TODAY","TOMORROW","NEXT_7_DAYS","NEXT_30_DAYS","NEXT_90_DAYS","NEXT_MONTH","THIS_YEAR","NEXT_YEAR","CUSTOM"],R=a=>{switch(a){case"PAST":return d;case"FUTURE":return u;default:return O}},m=a=>{switch(a){case"FUTURE":return "NEXT_7_DAYS";case"PAST":return "LAST_7_DAYS";case"FREE":default:return "TODAY"}},D=(a,r)=>{if(a==="CUSTOM")return {initialDate:null,finalDate:null};let s=r?new Date(r):new Date,t=new Date(s),e=new Date(s);switch(a){case"TODAY":break;case"YESTERDAY":t.setDate(t.getDate()-1),e.setDate(e.getDate()-1);break;case"TOMORROW":t.setDate(t.getDate()+1),e.setDate(e.getDate()+1);break;case"LAST_7_DAYS":t.setDate(t.getDate()-6);break;case"LAST_28_DAYS":t.setDate(t.getDate()-27);break;case"LAST_WEEK":{e.setDate(e.getDate()-e.getDay()-1),t.setTime(e.getTime()),t.setDate(t.getDate()-6);break}case"LAST_MONTH":t.setMonth(t.getMonth()-1,1),e.setDate(0);break;case"LAST_YEAR":t.setFullYear(t.getFullYear()-1,0,1),e.setFullYear(e.getFullYear()-1,11,31);break;case"NEXT_7_DAYS":e.setDate(e.getDate()+6);break;case"NEXT_30_DAYS":e.setDate(e.getDate()+29);break;case"NEXT_90_DAYS":e.setDate(e.getDate()+89);break;case"NEXT_MONTH":t.setMonth(t.getMonth()+1,1),e.setMonth(e.getMonth()+2,0);break;case"THIS_YEAR":t.setMonth(0,1),e.setMonth(11,31);break;case"NEXT_YEAR":t.setFullYear(t.getFullYear()+1,0,1),e.setFullYear(e.getFullYear()+1,11,31);break}return t.setHours(0,0,0,0),e.setHours(23,59,59,999),{initialDate:t,finalDate:e}},L=(a$1,r)=>{let s=R(a$1),t=r&&s.includes(a[r])?a[r]:m(a$1);return {period:t,...D(t)}},y=(a,r,s)=>!a||!r?"CUSTOM":s.find(e=>{if(e==="CUSTOM")return !1;let{initialDate:o,finalDate:n}=D(e);return o&&n&&a.toDateString()===o.toDateString()&&r.toDateString()===n.toDateString()})??"CUSTOM",c={["LAST_YEAR"]:"ano-passado",["LAST_MONTH"]:"mes-passado",["LAST_28_DAYS"]:"ultimos-28-dias",["LAST_7_DAYS"]:"ultimos-7-dias",["LAST_WEEK"]:"semana-passada",["YESTERDAY"]:"ontem",["TODAY"]:"hoje",["TOMORROW"]:"amanha",["NEXT_7_DAYS"]:"proximos-7-dias",["NEXT_30_DAYS"]:"proximos-30-dias",["NEXT_90_DAYS"]:"proximos-90-dias",["NEXT_MONTH"]:"proximo-mes",["THIS_YEAR"]:"este-ano",["NEXT_YEAR"]:"proximo-ano",["CUSTOM"]:"personalizado"},p=Object.fromEntries(Object.entries(c).map(([a,r])=>[r,a])),Y={paramKey:"periodo",dataKey:"data"},A=a=>{let r=a.getFullYear(),s=String(a.getMonth()+1).padStart(2,"0"),t=String(a.getDate()).padStart(2,"0");return `${r}-${s}-${t}`},E=a=>{let r=/^(\d{4})-(\d{2})-(\d{2})$/.exec(a);if(!r)return null;let[,s,t,e]=r;return new Date(Number(s),Number(t)-1,Number(e))},F=(a,r={},s)=>{let{paramKey:t,dataKey:e}={...Y,...r},o=new URLSearchParams(s??"");return o.set(t,c[a.period]),a.period==="CUSTOM"&&a.initialDate&&a.finalDate?o.set(e,`${A(a.initialDate)}_${A(a.finalDate)}`):o.delete(e),o},U=(a,r={})=>{let{paramKey:s,dataKey:t}={...Y,...r},e=a.get(s);if(!e)return null;let o=p[e];if(!o)return null;if(o!=="CUSTOM")return {period:o,...D(o)};let n=a.get(t);if(!n)return {period:"CUSTOM",initialDate:null,finalDate:null};let[S,_]=n.split("_"),i=S?E(S):null,T=_?E(_):null;return i&&i.setHours(0,0,0,0),T&&T.setHours(23,59,59,999),{period:"CUSTOM",initialDate:i,finalDate:T}};
|
|
4
|
-
|
|
5
|
-
export { f as a, R as b, m as c, D as d, L as e, y as f, c as g, Y as h, F as i, U as j };
|
|
6
|
-
//# sourceMappingURL=chunk-MEPEYLZT.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/filters.ts"],"names":["periodLabels","PAST_PERIODS","FUTURE_PERIODS","FREE_PERIODS","getPeriodsByType","type","getDefaultPeriodForType","getPeriodDates","period","reference","now","initialDate","finalDate","buildDefaultFilter","defaultPeriod","availablePeriods","Period","findMatchingPeriod","startDate","endDate","candidates","periodSlugs","slugToPeriod","key","slug","DEFAULT_FILTER_KEYS","formatDateOnly","date","year","month","day","parseDateOnly","raw","match","serializeFilterToSearchParams","value","keys","baseParams","paramKey","dataKey","params","deserializeFilterFromSearchParams","dataRaw","initialRaw","finalRaw"],"mappings":"wCAEO,IAAMA,EAAuC,CAClD,YAAiB,EAAG,cACpB,aAAkB,EAAG,iBACrB,eAAoB,EAAG,qBACvB,cAAmB,EAAG,oBACtB,YAAiB,EAAG,iBACpB,YAAiB,EAAG,QACpB,QAAa,EAAG,OAChB,WAAgB,EAAG,YACnB,cAAmB,EAAG,qBACtB,eAAoB,EAAG,sBACvB,eAAoB,EAAG,sBACvB,aAAkB,EAAG,oBACrB,YAAiB,EAAG,WACpB,YAAiB,EAAG,iBACpB,SAAc,EAAG,eACnB,EAEMC,EAAyB,+FAS/B,EAEMC,EAA2B,6GAUjC,EAEMC,EAAyB,2LAgB/B,EAEaC,EAAoBC,GAAsC,CACrE,OAAQA,EAAM,CACZ,WACE,OAAOJ,EACT,aACE,OAAOC,EACT,QACE,OAAOC,CACX,CACF,EAEaG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Z,EAAOgB,EAAO,IAAIF,CAAQ,EAChC,GAAI,CAACd,EAAM,OAAO,KAElB,IAAMhB,EAASc,EAAaE,CAAI,EAChC,GAAI,CAAChB,EAAQ,OAAO,KAEpB,GAAIA,aACF,MAAO,CAAE,OAAAA,EAAQ,GAAGD,EAAeC,CAAM,CAAE,EAG7C,IAAMkC,EAAUF,EAAO,IAAID,CAAO,EAClC,GAAI,CAACG,EACH,MAAO,CAAE,gBAAuB,YAAa,KAAM,UAAW,IAAK,EAGrE,GAAM,CAACC,EAAYC,CAAQ,EAAIF,EAAQ,MAAM,GAAG,EAC1C/B,EAAcgC,EAAaZ,EAAcY,CAAU,EAAI,KACvD/B,EAAYgC,EAAWb,EAAca,CAAQ,EAAI,KAEvD,OAAIjC,GAAaA,EAAY,SAAS,EAAG,EAAG,EAAG,CAAC,EAC5CC,GAAWA,EAAU,SAAS,GAAI,GAAI,GAAI,GAAG,EAE1C,CAAE,gBAAuB,YAAAD,EAAa,UAAAC,CAAU,CACzD","sourcesContent":["import { FilterUrlKeys, FilterValue, Period, Type } from 'types/period';\n\nexport const periodLabels: Record<Period, string> = {\n [Period.LAST_YEAR]: 'Ano passado',\n [Period.LAST_MONTH]: 'Mês passado',\n [Period.LAST_28_DAYS]: 'Últimos 28 dias',\n [Period.LAST_7_DAYS]: 'Últimos 7 dias',\n [Period.LAST_WEEK]: 'Semana passada',\n [Period.YESTERDAY]: 'Ontem',\n [Period.TODAY]: 'Hoje',\n [Period.TOMORROW]: 'Amanhã',\n [Period.NEXT_7_DAYS]: 'Próximos 7 dias',\n [Period.NEXT_30_DAYS]: 'Próximos 30 dias',\n [Period.NEXT_90_DAYS]: 'Próximos 90 dias',\n [Period.NEXT_MONTH]: 'Próximo mês',\n [Period.THIS_YEAR]: 'Este ano',\n [Period.NEXT_YEAR]: 'Próximo ano',\n [Period.CUSTOM]: 'Personalizado',\n};\n\nconst PAST_PERIODS: Period[] = [\n Period.TODAY,\n Period.YESTERDAY,\n Period.LAST_7_DAYS,\n Period.LAST_WEEK,\n Period.LAST_28_DAYS,\n Period.LAST_MONTH,\n Period.LAST_YEAR,\n Period.CUSTOM,\n];\n\nconst FUTURE_PERIODS: Period[] = [\n Period.TODAY,\n Period.TOMORROW,\n Period.NEXT_7_DAYS,\n Period.NEXT_30_DAYS,\n Period.NEXT_90_DAYS,\n Period.NEXT_MONTH,\n Period.THIS_YEAR,\n Period.NEXT_YEAR,\n Period.CUSTOM,\n];\n\nconst FREE_PERIODS: Period[] = [\n Period.LAST_YEAR,\n Period.LAST_MONTH,\n Period.LAST_28_DAYS,\n Period.LAST_7_DAYS,\n Period.LAST_WEEK,\n Period.YESTERDAY,\n Period.TODAY,\n Period.TOMORROW,\n Period.NEXT_7_DAYS,\n Period.NEXT_30_DAYS,\n Period.NEXT_90_DAYS,\n Period.NEXT_MONTH,\n Period.THIS_YEAR,\n Period.NEXT_YEAR,\n Period.CUSTOM,\n];\n\nexport const getPeriodsByType = (type: keyof typeof Type): Period[] => {\n switch (type) {\n case Type.PAST:\n return PAST_PERIODS;\n case Type.FUTURE:\n return FUTURE_PERIODS;\n default:\n return FREE_PERIODS;\n }\n};\n\nexport const getDefaultPeriodForType = (type: keyof typeof Type): Period => {\n switch (type) {\n case Type.FUTURE:\n return Period.NEXT_7_DAYS;\n case Type.PAST:\n return Period.LAST_7_DAYS;\n case Type.FREE:\n default:\n return Period.TODAY;\n }\n};\n\nexport const getPeriodDates = (\n period: Period,\n reference?: Date,\n): { initialDate: Date | null; finalDate: Date | null } => {\n if (period === Period.CUSTOM) {\n return { initialDate: null, finalDate: null };\n }\n\n const now = reference ? new Date(reference) : new Date();\n const initialDate = new Date(now);\n const finalDate = new Date(now);\n\n switch (period) {\n case Period.TODAY:\n break;\n\n case Period.YESTERDAY:\n initialDate.setDate(initialDate.getDate() - 1);\n finalDate.setDate(finalDate.getDate() - 1);\n break;\n\n case Period.TOMORROW:\n initialDate.setDate(initialDate.getDate() + 1);\n finalDate.setDate(finalDate.getDate() + 1);\n break;\n\n case Period.LAST_7_DAYS:\n initialDate.setDate(initialDate.getDate() - 6);\n break;\n\n case Period.LAST_28_DAYS:\n initialDate.setDate(initialDate.getDate() - 27);\n break;\n\n case Period.LAST_WEEK: {\n finalDate.setDate(finalDate.getDate() - finalDate.getDay() - 1);\n initialDate.setTime(finalDate.getTime());\n initialDate.setDate(initialDate.getDate() - 6);\n break;\n }\n\n case Period.LAST_MONTH:\n initialDate.setMonth(initialDate.getMonth() - 1, 1);\n finalDate.setDate(0);\n break;\n\n case Period.LAST_YEAR:\n initialDate.setFullYear(initialDate.getFullYear() - 1, 0, 1);\n finalDate.setFullYear(finalDate.getFullYear() - 1, 11, 31);\n break;\n\n case Period.NEXT_7_DAYS:\n finalDate.setDate(finalDate.getDate() + 6);\n break;\n\n case Period.NEXT_30_DAYS:\n finalDate.setDate(finalDate.getDate() + 29);\n break;\n\n case Period.NEXT_90_DAYS:\n finalDate.setDate(finalDate.getDate() + 89);\n break;\n\n case Period.NEXT_MONTH:\n initialDate.setMonth(initialDate.getMonth() + 1, 1);\n finalDate.setMonth(finalDate.getMonth() + 2, 0);\n break;\n\n case Period.THIS_YEAR:\n initialDate.setMonth(0, 1);\n finalDate.setMonth(11, 31);\n break;\n\n case Period.NEXT_YEAR:\n initialDate.setFullYear(initialDate.getFullYear() + 1, 0, 1);\n finalDate.setFullYear(finalDate.getFullYear() + 1, 11, 31);\n break;\n }\n\n initialDate.setHours(0, 0, 0, 0);\n finalDate.setHours(23, 59, 59, 999);\n\n return { initialDate, finalDate };\n};\n\nexport const buildDefaultFilter = (\n type: keyof typeof Type,\n defaultPeriod?: keyof typeof Period,\n): FilterValue => {\n const availablePeriods = getPeriodsByType(type);\n const period =\n defaultPeriod && availablePeriods.includes(Period[defaultPeriod])\n ? Period[defaultPeriod]\n : getDefaultPeriodForType(type);\n\n return { period, ...getPeriodDates(period) };\n};\n\nexport const findMatchingPeriod = (\n startDate: Date | null,\n endDate: Date | null,\n candidates: Period[],\n): Period => {\n if (!startDate || !endDate) return Period.CUSTOM;\n\n const match = candidates.find(period => {\n if (period === Period.CUSTOM) return false;\n\n const { initialDate, finalDate } = getPeriodDates(period);\n\n return (\n initialDate &&\n finalDate &&\n startDate.toDateString() === initialDate.toDateString() &&\n endDate.toDateString() === finalDate.toDateString()\n );\n });\n\n return match ?? Period.CUSTOM;\n};\n\nexport const periodSlugs: Record<Period, string> = {\n [Period.LAST_YEAR]: 'ano-passado',\n [Period.LAST_MONTH]: 'mes-passado',\n [Period.LAST_28_DAYS]: 'ultimos-28-dias',\n [Period.LAST_7_DAYS]: 'ultimos-7-dias',\n [Period.LAST_WEEK]: 'semana-passada',\n [Period.YESTERDAY]: 'ontem',\n [Period.TODAY]: 'hoje',\n [Period.TOMORROW]: 'amanha',\n [Period.NEXT_7_DAYS]: 'proximos-7-dias',\n [Period.NEXT_30_DAYS]: 'proximos-30-dias',\n [Period.NEXT_90_DAYS]: 'proximos-90-dias',\n [Period.NEXT_MONTH]: 'proximo-mes',\n [Period.THIS_YEAR]: 'este-ano',\n [Period.NEXT_YEAR]: 'proximo-ano',\n [Period.CUSTOM]: 'personalizado',\n};\n\nconst slugToPeriod: Record<string, Period> = Object.fromEntries(\n (Object.entries(periodSlugs) as [Period, string][]).map(([key, slug]) => [\n slug,\n key,\n ]),\n);\n\nexport const DEFAULT_FILTER_KEYS: Required<FilterUrlKeys> = {\n paramKey: 'periodo',\n dataKey: 'data',\n};\n\nconst formatDateOnly = (date: Date): string => {\n const year = date.getFullYear();\n const month = String(date.getMonth() + 1).padStart(2, '0');\n const day = String(date.getDate()).padStart(2, '0');\n\n return `${year}-${month}-${day}`;\n};\n\nconst parseDateOnly = (raw: string): Date | null => {\n const match = /^(\\d{4})-(\\d{2})-(\\d{2})$/.exec(raw);\n if (!match) return null;\n\n const [, year, month, day] = match;\n\n return new Date(Number(year), Number(month) - 1, Number(day));\n};\n\nexport const serializeFilterToSearchParams = (\n value: FilterValue,\n keys: FilterUrlKeys = {},\n baseParams?: URLSearchParams,\n): URLSearchParams => {\n const { paramKey, dataKey } = { ...DEFAULT_FILTER_KEYS, ...keys };\n const params = new URLSearchParams(baseParams ?? '');\n\n params.set(paramKey, periodSlugs[value.period]);\n\n if (value.period === Period.CUSTOM && value.initialDate && value.finalDate) {\n params.set(\n dataKey,\n `${formatDateOnly(value.initialDate)}_${formatDateOnly(value.finalDate)}`,\n );\n } else {\n params.delete(dataKey);\n }\n\n return params;\n};\n\nexport const deserializeFilterFromSearchParams = (\n params: URLSearchParams,\n keys: FilterUrlKeys = {},\n): FilterValue | null => {\n const { paramKey, dataKey } = { ...DEFAULT_FILTER_KEYS, ...keys };\n const slug = params.get(paramKey);\n if (!slug) return null;\n\n const period = slugToPeriod[slug];\n if (!period) return null;\n\n if (period !== Period.CUSTOM) {\n return { period, ...getPeriodDates(period) };\n }\n\n const dataRaw = params.get(dataKey);\n if (!dataRaw) {\n return { period: Period.CUSTOM, initialDate: null, finalDate: null };\n }\n\n const [initialRaw, finalRaw] = dataRaw.split('_');\n const initialDate = initialRaw ? parseDateOnly(initialRaw) : null;\n const finalDate = finalRaw ? parseDateOnly(finalRaw) : null;\n\n if (initialDate) initialDate.setHours(0, 0, 0, 0);\n if (finalDate) finalDate.setHours(23, 59, 59, 999);\n\n return { period: Period.CUSTOM, initialDate, finalDate };\n};\n"]}
|
|
File without changes
|