-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
644 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { useEffect, useState } from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
// Custom | ||
import Select from "../UIElements/Select"; | ||
import { fetchAircraftCategories } from "../../util/http/aircraft"; | ||
|
||
export const AircraftCategories = ({ gsize, value, handleChange }) => { | ||
const navigate = useNavigate(); | ||
const [options, setOptions] = useState([]) | ||
|
||
const { data: categories } = useQuery({ | ||
queryFn: ({ signal }) => fetchAircraftCategories({ signal, navigate }), | ||
queryKey: ['aircraft-categories'], | ||
}) | ||
|
||
useEffect(() => { | ||
if (categories) { | ||
setOptions(categories); | ||
} | ||
}, [categories]) | ||
|
||
return ( | ||
<Select gsize={gsize} | ||
id="category" | ||
label="Category" | ||
handleChange={handleChange} | ||
value={value} | ||
tooltip={"Aircraft Category"} | ||
options={options} | ||
multiple | ||
freeSolo={true} | ||
/> | ||
); | ||
} | ||
|
||
export default AircraftCategories; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { MaterialReactTable, useMaterialReactTable, MRT_TableHeadCellFilterContainer, MRT_ExpandAllButton } from 'material-react-table'; | ||
import { useMemo, useState } from 'react'; | ||
import { useLocalStorageState } from '@toolpad/core/useLocalStorageState'; | ||
import { useNavigate } from "react-router-dom"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
// MUI UI elements | ||
import Box from '@mui/material/Box'; | ||
import Drawer from '@mui/material/Drawer'; | ||
import LinearProgress from '@mui/material/LinearProgress'; | ||
// Custom components and libraries | ||
import CSVAircraftExportButton from './CSVAircraftExportButton'; | ||
import { tableJSONCodec } from '../../constants/constants'; | ||
import { fetchAircrafts } from "../../util/http/aircraft"; | ||
import { useErrorNotification } from "../../hooks/useAppNotifications"; | ||
import { dateFilterFn } from '../../util/helpers'; | ||
|
||
const paginationKey = 'aircrafts-table-page-size'; | ||
const columnVisibilityKey = 'aircrafts-table-column-visibility'; | ||
|
||
const tableOptions = { | ||
initialState: { density: 'compact' }, | ||
positionToolbarAlertBanner: 'bottom', | ||
groupedColumnMode: 'remove', | ||
enableColumnResizing: true, | ||
enableGlobalFilterModes: true, | ||
enableColumnFilters: true, | ||
enableColumnDragging: false, | ||
enableColumnPinning: false, | ||
enableGrouping: true, | ||
enableDensityToggle: false, | ||
columnResizeMode: 'onEnd', | ||
muiTablePaperProps: { variant: 'outlined', elevation: 0 }, | ||
columnFilterDisplayMode: 'custom', | ||
enableFacetedValues: true, | ||
enableSorting: true, | ||
enableColumnActions: true, | ||
} | ||
|
||
export const AircraftsTable = ({ ...props }) => { | ||
const [isFilterDrawerOpen, setIsFilterDrawerOpen] = useState(false); | ||
const [columnFilters, setColumnFilters] = useState([]); | ||
const [columnVisibility, setColumnVisibility] = useLocalStorageState(columnVisibilityKey, {}, { codec: tableJSONCodec }); | ||
const [pagination, setPagination] = useLocalStorageState(paginationKey, { pageIndex: 0, pageSize: 15 }, { codec: tableJSONCodec }); | ||
const filterFns = useMemo(() => ({ dateFilterFn: dateFilterFn }), []); | ||
|
||
const navigate = useNavigate(); | ||
|
||
const { data, isLoading, isError, error } = useQuery({ | ||
queryKey: ['aircrafts'], | ||
queryFn: ({ signal }) => fetchAircrafts({ signal, navigate }), | ||
}); | ||
useErrorNotification({ isError, error, fallbackMessage: 'Failed to load aircrafts' }); | ||
|
||
const columns = useMemo(() => [ | ||
{ accessorKey: "reg", header: "Registration", size: 120 }, | ||
{ accessorKey: "model", header: "Type", size: 110 }, | ||
{ accessorKey: "category", header: "Category", grow: true }, | ||
], []); | ||
|
||
const table = useMaterialReactTable({ | ||
isLoading: isLoading, | ||
columns: columns, | ||
data: data ?? [], | ||
onShowColumnFiltersChange: () => (setIsFilterDrawerOpen(true)), | ||
filterFns: filterFns, | ||
onColumnFiltersChange: setColumnFilters, | ||
onColumnVisibilityChange: setColumnVisibility, | ||
renderTopToolbarCustomActions: ({ table }) => ( | ||
<Box sx={{ display: 'flex', flexWrap: 'wrap' }}> | ||
<CSVAircraftExportButton table={table} /> | ||
</Box> | ||
), | ||
onPaginationChange: setPagination, | ||
state: { pagination, columnFilters: columnFilters, columnVisibility }, | ||
defaultColumn: { | ||
muiFilterTextFieldProps: ({ column }) => ({ label: `Filter by ${column.columnDef.header}` }), | ||
}, | ||
...tableOptions | ||
}); | ||
|
||
return ( | ||
<> | ||
{isLoading && <LinearProgress />} | ||
<MaterialReactTable table={table} {...props} /> | ||
<Drawer anchor="right" open={isFilterDrawerOpen} onClose={() => setIsFilterDrawerOpen(false)} sx={{ | ||
'& .MuiDrawer-paper': { | ||
marginTop: '64px', | ||
height: 'calc(100% - 64px)', | ||
}, | ||
}}> | ||
<Box sx={{ width: 350, padding: 2 }}> | ||
{table.getLeafHeaders().map((header) => { | ||
if (header.id.startsWith('mrt-') || header.id.startsWith('Expire') || header.id.startsWith('center_1_')) return null; | ||
return < MRT_TableHeadCellFilterContainer key={header.id} header={header} table={table} in /> | ||
})} | ||
</Box> | ||
</Drawer> | ||
</> | ||
); | ||
} | ||
|
||
export default AircraftsTable; |
39 changes: 39 additions & 0 deletions
39
app/ui/src/components/Aircrafts/CSVAircraftExportButton.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useCallback } from 'react'; | ||
// MUI UI elements | ||
import Tooltip from '@mui/material/Tooltip'; | ||
import IconButton from '@mui/material/IconButton'; | ||
// MUI Icons | ||
import FileDownloadOutlinedIcon from '@mui/icons-material/FileDownloadOutlined'; | ||
|
||
import { mkConfig, generateCsv, download } from 'export-to-csv'; | ||
|
||
const csvConfig = mkConfig({ | ||
fieldSeparator: ',', | ||
decimalSeparator: '.', | ||
useKeysAsHeaders: true, | ||
filename: 'aircrafts', | ||
}); | ||
|
||
const handleExportRows = (rows) => { | ||
const rowData = rows.map((row) => ({ | ||
"Registration": row.original.reg, | ||
"Model": row.original.model, | ||
"Category": row.original.category, | ||
})); | ||
const csv = generateCsv(csvConfig)(rowData); | ||
download(csvConfig)(csv); | ||
}; | ||
|
||
export const CSVAircraftExportButton = ({ table }) => { | ||
const handleCSVExport = useCallback((table) => { | ||
handleExportRows(table.getPrePaginationRowModel().rows); | ||
}, []); | ||
|
||
return ( | ||
<Tooltip title="Quick CSV Export"> | ||
<IconButton onClick={() => handleCSVExport(table)} size="small"><FileDownloadOutlinedIcon /></IconButton> | ||
</Tooltip> | ||
) | ||
} | ||
|
||
export default CSVAircraftExportButton; |
38 changes: 38 additions & 0 deletions
38
app/ui/src/components/Aircrafts/CSVCategoriesExportButton.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { useCallback } from 'react'; | ||
// MUI UI elements | ||
import Tooltip from '@mui/material/Tooltip'; | ||
import IconButton from '@mui/material/IconButton'; | ||
// MUI Icons | ||
import FileDownloadOutlinedIcon from '@mui/icons-material/FileDownloadOutlined'; | ||
|
||
import { mkConfig, generateCsv, download } from 'export-to-csv'; | ||
|
||
const csvConfig = mkConfig({ | ||
fieldSeparator: ',', | ||
decimalSeparator: '.', | ||
useKeysAsHeaders: true, | ||
filename: 'categories', | ||
}); | ||
|
||
const handleExportRows = (rows) => { | ||
const rowData = rows.map((row) => ({ | ||
"Type": row.original.model, | ||
"Category": row.original.category, | ||
})); | ||
const csv = generateCsv(csvConfig)(rowData); | ||
download(csvConfig)(csv); | ||
}; | ||
|
||
export const CSVCategoriesExportButton = ({ table }) => { | ||
const handleCSVExport = useCallback((table) => { | ||
handleExportRows(table.getPrePaginationRowModel().rows); | ||
}, []); | ||
|
||
return ( | ||
<Tooltip title="Quick CSV Export"> | ||
<IconButton onClick={() => handleCSVExport(table)} size="small"><FileDownloadOutlinedIcon /></IconButton> | ||
</Tooltip> | ||
) | ||
} | ||
|
||
export default CSVCategoriesExportButton; |
Oops, something went wrong.