Skip to content

Default filter for table, updated mailbox report #4040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/components/CippComponents/CippTablePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Head from "next/head";
import { CippDataTable } from "../CippTable/CippDataTable";
import { useSettings } from "../../hooks/use-settings";
import { CippHead } from "./CippHead";
import { useState } from "react";

export const CippTablePage = (props) => {
const {
Expand All @@ -23,10 +24,12 @@ export const CippTablePage = (props) => {
queryKey,
tableFilter,
tenantInTitle = true,
filters,
sx = { flexGrow: 1, py: 4 },
...other
} = props;
const tenant = useSettings().currentTenant;
const [tableFilters] = useState(filters || []);
return (
<>
<CippHead title={title} />
Expand Down Expand Up @@ -61,6 +64,13 @@ export const CippTablePage = (props) => {
columns={columns}
columnsFromApi={columnsFromApi}
offCanvas={offCanvas}
filters={tableFilters}
initialState={{
columnFilters: filters ? filters.map(filter => ({
id: filter.id || filter.columnId,
value: filter.value
})) : []
}}
{...other}
/>
</Card>
Expand Down
24 changes: 24 additions & 0 deletions src/components/CippTable/CippDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const CippDataTable = (props) => {
const [actionData, setActionData] = useState({ data: {}, action: {}, ready: false });
const [graphFilterData, setGraphFilterData] = useState({});
const [sorting, setSorting] = useState([]);
const [columnFilters, setColumnFilters] = useState([]);
const waitingBool = api?.url ? true : false;

const settings = useSettings();
Expand All @@ -78,6 +79,12 @@ export const CippDataTable = (props) => {
...graphFilterData,
});

useEffect(() => {
if (filters && Array.isArray(filters) && filters.length > 0) {
setColumnFilters(filters);
}
}, [filters]);

useEffect(() => {
if (Array.isArray(data) && !api?.url) {
if (!isEqual(data, usedData)) {
Expand Down Expand Up @@ -208,6 +215,7 @@ export const CippDataTable = (props) => {
state: {
columnVisibility,
sorting,
columnFilters,
showSkeletons: getRequestData.isFetchingNextPage
? false
: getRequestData.isFetching
Expand All @@ -217,6 +225,7 @@ export const CippDataTable = (props) => {
onSortingChange: (newSorting) => {
setSorting(newSorting ?? []);
},
onColumnFiltersChange: setColumnFilters,
renderEmptyRowsFallback: ({ table }) =>
getRequestData.data?.pages?.[0].Metadata?.QueueMessage ? (
<Box sx={{ py: 4 }}>
Expand Down Expand Up @@ -435,6 +444,21 @@ export const CippDataTable = (props) => {
},
});

useEffect(() => {
if (filters && Array.isArray(filters) && filters.length > 0 && memoizedColumns.length > 0) {
// Make sure the table and columns are ready
setTimeout(() => {
if (table && typeof table.setColumnFilters === 'function') {
const formattedFilters = filters.map(filter => ({
id: filter.id || filter.columnId,
value: filter.value
}));
table.setColumnFilters(formattedFilters);
}
},);
}
}, [filters, memoizedColumns, table]);

useEffect(() => {
if (onChange && table.getSelectedRowModel().rows) {
onChange(table.getSelectedRowModel().rows.map((row) => row.original));
Expand Down
20 changes: 10 additions & 10 deletions src/pages/email/reports/SharedMailboxEnabledAccount/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ import { Layout as DashboardLayout } from "/src/layouts/index.js";
import { CippTablePage } from "/src/components/CippComponents/CippTablePage.jsx";
import { Block } from "@mui/icons-material";

/*
NOTE for Devs:
- The original component used a Redux selector (`useSelector`) for tenant data,
which is handled by `CippTablePage` in the refactored version, thus eliminating `useSelector`.
- The `ModalService` with `confirm` handling was originally used to confirm blocking sign-in.
The action here replaces it with a confirmation text as per current guidelines.
- Original button and `FontAwesomeIcon` (faBan) are not used since action confirmation is handled by CippTablePage.
*/

const Page = () => {
return (
<CippTablePage
Expand All @@ -23,23 +14,32 @@ const Page = () => {
icon: <Block />,
url: "/api/ExecDisableUser",
data: { ID: "id" },
confirmText: "Are you sure you want to block the sign-in for this user?",
confirmText: "Are you sure you want to block the sign-in for this mailbox?",
condition: (row) => row.accountEnabled && !row.onPremisesSyncEnabled,
},
]}
offCanvas={{
extendedInfoFields: [
"UserPrincipalName",
"displayName",
"accountEnabled",
"assignedLicenses",
"onPremisesSyncEnabled",
],
}}
simpleColumns={[
"UserPrincipalName",
"displayName",
"accountEnabled",
"assignedLicenses",
"onPremisesSyncEnabled",
]}
filters={[
{
id: "accountEnabled",
value: "Yes"
}
]}
/>
);
};
Expand Down
Loading