Skip to content

Commit

Permalink
Merge branch 'main' into fix/SILVA-515
Browse files Browse the repository at this point in the history
  • Loading branch information
paulushcgcj authored Dec 5, 2024
2 parents fab1e69 + 59b1d87 commit 41bedd5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,23 @@ describe("OpeningsSearchBar", () => {
// Create a new QueryClient instance for each test
const queryClient = new QueryClient();
const handleCheckboxChange = vi.fn()
const setLoadId = vi.fn()
const toggleSpatial = vi.fn()
const showSpatial = false
const data = { data: [], perPage: 0, totalPages: 0 }
const headers = []
const setOpeningIds = vi.fn()
const showSpatial = false
const data = { data: [], perPage: 0, totalPages: 0 }
const headers = []

it("shows appropriate message when no data is in the table", () => {
render(
<MemoryRouter>
<QueryClientProvider client={queryClient}>
<PaginationProvider>
<RecentOpeningsDataTable
<RecentOpeningsDataTable
rows={data?.data || []}
headers={headers}
defaultColumns={headers}
handleCheckboxChange={handleCheckboxChange}
setOpeningId={setLoadId}
toggleSpatial={toggleSpatial}
setOpeningIds={setOpeningIds}
showSpatial={showSpatial}
totalItems={(data?.perPage ?? 0) * (data?.totalPages ?? 0)}
/>
/>
</PaginationProvider>
</QueryClientProvider>
</MemoryRouter>
Expand All @@ -48,16 +44,13 @@ describe("OpeningsSearchBar", () => {
<MemoryRouter>
<QueryClientProvider client={queryClient}>
<PaginationProvider>
<RecentOpeningsDataTable
<RecentOpeningsDataTable
rows={[]}
headers={headers}
defaultColumns={headers}
handleCheckboxChange={handleCheckboxChange}
setOpeningId={setLoadId}
toggleSpatial={toggleSpatial}
setOpeningIds={setOpeningIds}
showSpatial={showSpatial}
totalItems={(data?.perPage ?? 0) * (data?.totalPages ?? 0)}
/>
/>
</PaginationProvider>
</QueryClientProvider>
</MemoryRouter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import ComingSoonModal from "../../../ComingSoonModal";
interface IRecentOpeningsDataTable {
rows: OpeningsSearch[];
headers: ITableHeader[];
defaultColumns: ITableHeader[];
handleCheckboxChange: Function;
setOpeningId: Function;
toggleSpatial: Function;
setOpeningIds: (openingIds: number[]) => void;
showSpatial: boolean;
totalItems: number;
}
Expand All @@ -30,7 +27,8 @@ const RecentOpeningsDataTable: React.FC<IRecentOpeningsDataTable> = ({
rows,
headers,
showSpatial,
totalItems,
setOpeningIds,
totalItems
}) => {
const {
itemsPerPage,
Expand All @@ -43,6 +41,10 @@ const RecentOpeningsDataTable: React.FC<IRecentOpeningsDataTable> = ({
setInitialItemsPerPage(itemsPerPage);
}, [rows, totalItems]);

useEffect(() => {
setOpeningIds(selectedRows.map((id) => parseFloat(id)));
},[selectedRows]);

// Function to handle row selection changes
const handleRowSelectionChanged = (rowId: string) => {
setSelectedRows((prevSelectedRows) =>
Expand All @@ -53,12 +55,7 @@ const RecentOpeningsDataTable: React.FC<IRecentOpeningsDataTable> = ({
};

return (
<>
<TableContainer className="search-data-table">
<TableToolbar aria-label="data table toolbar">
{/* Toolbar content... */}
</TableToolbar>

<TableContainer className="search-data-table">
<Table aria-label="sample table">
<TableHead>
<TableRow>
Expand Down Expand Up @@ -98,7 +95,6 @@ const RecentOpeningsDataTable: React.FC<IRecentOpeningsDataTable> = ({
setOpeningDetails={setOpeningDetails}
/>
</TableContainer>
</>
);
);
};
export default RecentOpeningsDataTable;
1 change: 0 additions & 1 deletion frontend/src/components/OpeningsMap/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ const OpeningsMap: React.FC<MapProps> = ({
setOpenings(results.filter((opening) => opening !== null));

} else {
setOpeningPolygonNotFound(true);
setOpenings([]);
}

Expand Down
12 changes: 4 additions & 8 deletions frontend/src/components/OpeningsTab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface Props {
}

const OpeningsTab: React.FC<Props> = ({ showSpatial, setShowSpatial }) => {
const [loadId, setLoadId] = useState<number | null>(null);
const [selectedOpeningIds,setSelectedOpeningIds] = useState<number[]>([]);
const [openingPolygonNotFound, setOpeningPolygonNotFound] = useState<boolean>(false);
const { data, isFetching } = useUserRecentOpeningQuery(10);

Expand All @@ -36,7 +36,6 @@ const OpeningsTab: React.FC<Props> = ({ showSpatial, setShowSpatial }) => {
renderIcon={Location}
type="button"
onClick={() => toggleSpatial()}
disabled
>
{showSpatial ? 'Hide map' : 'Show map'}
</Button>
Expand All @@ -45,8 +44,8 @@ const OpeningsTab: React.FC<Props> = ({ showSpatial, setShowSpatial }) => {
<div className="row px-2">
<div className="leaflet-container">
<OpeningsMap
openingId={loadId}
openingIds={null}
openingId={null}
openingIds={selectedOpeningIds}
setOpeningPolygonNotFound={setOpeningPolygonNotFound}
/>
</div>
Expand All @@ -70,10 +69,7 @@ const OpeningsTab: React.FC<Props> = ({ showSpatial, setShowSpatial }) => {
<RecentOpeningsDataTable
rows={data?.data || []}
headers={headers}
defaultColumns={headers}
handleCheckboxChange={() => {}}
setOpeningId={setLoadId}
toggleSpatial={toggleSpatial}
setOpeningIds={setSelectedOpeningIds}
showSpatial={showSpatial}
totalItems={(data?.perPage ?? 0) * (data?.totalPages ?? 0)}
/>
Expand Down

0 comments on commit 41bedd5

Please sign in to comment.