mirror of
https://github.com/Kingsrook/qqq-frontend-material-dashboard.git
synced 2025-07-18 05:10:45 +00:00
Only show tables user has permission to; match search text against table name too
This commit is contained in:
@ -19,6 +19,7 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import {QInstance} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QInstance";
|
||||||
import {QTableMetaData} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QTableMetaData";
|
import {QTableMetaData} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QTableMetaData";
|
||||||
import {Box, FormControlLabel, FormGroup} from "@mui/material";
|
import {Box, FormControlLabel, FormGroup} from "@mui/material";
|
||||||
import Button from "@mui/material/Button";
|
import Button from "@mui/material/Button";
|
||||||
@ -37,6 +38,7 @@ declare module "@mui/x-data-grid"
|
|||||||
interface ColumnsPanelPropsOverrides
|
interface ColumnsPanelPropsOverrides
|
||||||
{
|
{
|
||||||
tableMetaData: QTableMetaData;
|
tableMetaData: QTableMetaData;
|
||||||
|
metaData: QInstance;
|
||||||
initialOpenedGroups: { [name: string]: boolean };
|
initialOpenedGroups: { [name: string]: boolean };
|
||||||
openGroupsChanger: (openedGroups: { [name: string]: boolean }) => void;
|
openGroupsChanger: (openedGroups: { [name: string]: boolean }) => void;
|
||||||
initialFilterText: string;
|
initialFilterText: string;
|
||||||
@ -70,7 +72,11 @@ export const CustomColumnsPanel = forwardRef<any, GridColumnsPanelProps>(
|
|||||||
{
|
{
|
||||||
for (let i = 0; i < props.tableMetaData.exposedJoins.length; i++)
|
for (let i = 0; i < props.tableMetaData.exposedJoins.length; i++)
|
||||||
{
|
{
|
||||||
tables.push(props.tableMetaData.exposedJoins[i].joinTable);
|
const exposedJoin = props.tableMetaData.exposedJoins[i];
|
||||||
|
if (props.metaData.tables.has(exposedJoin.joinTable.name))
|
||||||
|
{
|
||||||
|
tables.push(exposedJoin.joinTable);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,6 +129,33 @@ export const CustomColumnsPanel = forwardRef<any, GridColumnsPanelProps>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const tableLabel = column.headerName.replace(/:.*/, "");
|
||||||
|
if (tableLabel)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
// try to match word-boundary followed by the filter text //
|
||||||
|
// e.g., "name" would match "First Name" or "Last Name" //
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
const re = new RegExp("\\b" + filterText.toLowerCase());
|
||||||
|
if (tableLabel.toLowerCase().match(re))
|
||||||
|
{
|
||||||
|
return (true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (e)
|
||||||
|
{
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// in case text is an invalid regex... well, at least do a starts-with match... //
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
|
if (tableLabel.toLowerCase().startsWith(filterText.toLowerCase()))
|
||||||
|
{
|
||||||
|
return (true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (false);
|
return (false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user