Skip to content
Draft
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
6 changes: 6 additions & 0 deletions packages/react-mui-audit-log-viewer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.0.4] - 2025-07-28

### Fixed

- Add support filter menu accessible from column headers, onFiltersChange callback

## [2.0.3] - 2025-07-01

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion packages/react-mui-audit-log-viewer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pangeacyber/react-mui-audit-log-viewer",
"version": "2.0.3",
"version": "2.0.4-beta.5",
"description": "An extension of material ui data-grid for Pangea audit log records",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
Expand Down
5 changes: 5 additions & 0 deletions packages/react-mui-audit-log-viewer/src/AuditLogViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ export interface AuditLogViewerProps<Event = Audit.DefaultEvent> {
/** The public audit query to filter the audit log data */
filters?: PublicAuditQuery;

/** Callback handler for everytime the filters are updated */
onFiltersChange?: (filters: PublicAuditQuery) => void;

/** Authentication configuration. It is used to fetch your project's custom Audit schema, so the AuditLogViewer component can dynamically update when you update your configuration in the Pangea Console */
config?: AuthConfig;

Expand All @@ -129,6 +132,7 @@ const AuditLogViewerWithProvider = <Event,>({
schemaOptions,
initialQuery,
filters,
onFiltersChange,
fpeOptions,
filterOptions,
...props
Expand Down Expand Up @@ -295,6 +299,7 @@ const AuditLogViewerWithProvider = <Event,>({
rowToLeafIndex={rowToLeafIndex}
initialQuery={initialQuery}
filters={filters}
onFiltersChange={onFiltersChange}
filterOptions={filterOptions}
>
<AuditLogViewerComponent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FC, useCallback, useEffect, useMemo, useRef } from "react";
import { FC, useCallback, useEffect, useMemo, useRef, useState } from "react";
import mapValues from "lodash/mapValues";

import { Box } from "@mui/material";
Expand All @@ -11,7 +11,7 @@ import {
usePagination,
useAuditBody,
} from "../../hooks/context";
import { LinedPangeaDataGrid } from "@pangeacyber/react-mui-shared";
import { LinedPangeaDataGrid, PopoutCard } from "@pangeacyber/react-mui-shared";
import AuditPreviewRow from "../AuditPreviewRow";
import { AuditSecureColumn } from "./secureColumn";
import AuditTimeFilterButton from "./AuditTimeFilterButton";
Expand Down Expand Up @@ -101,12 +101,34 @@ const AuditLogViewerComponent: FC<ViewerProps> = ({

filterOptions,
} = useAuditContext();
const { body, bodyWithoutQuery } = useAuditBody(limit, maxResults);
const { body, bodyWithoutQuery, tableSettingsQuery } = useAuditBody(
limit,
maxResults
);
const pagination = usePagination();
const defaultVisibility = useDefaultVisibility(schema);
const defaultOrder = useDefaultOrder(schema);

const schemaColumns = useAuditColumns(schema, fields, fieldTypes);
const headerRefMap = useRef<Record<string, HTMLDivElement | null>>({});
const [activeFilterColumn, setActiveFilterColumn] = useState<string | null>(
null
);

const handleGetFilterRef = (field: string) => (el: any) => {
headerRefMap.current[field] = el;
};

const handleOnFilterOpen = (field: string, event: any) => {
setActiveFilterColumn(field);
};

const schemaColumns = useAuditColumns(
schema,
fields,
fieldTypes,
handleOnFilterOpen,
handleGetFilterRef
);
const columns = useAuditColumnsWithErrors(schemaColumns, logs);
const filterFields = useAuditFilterFields(schema, filterOptions);
const conditionalOptions = useAuditConditionalOptions(schema, filterOptions);
Expand All @@ -121,6 +143,20 @@ const AuditLogViewerComponent: FC<ViewerProps> = ({
return onSearch(bodyRef.current);
};

useEffect(() => {
if (
tableSettingsQuery &&
!searchOnChange &&
// Check mount ref, so multiple use effects are not triggering the handleSearch
hasMountedRef.current !== undefined
) {
setTimeout(() => {
handleSearch();
// Add slight delay since since filters may update the query string
}, 100);
}
}, [tableSettingsQuery, searchOnChange]);

useEffect(() => {
const initialQuery_ = initialQuery ?? "";
if (
Expand Down Expand Up @@ -179,6 +215,17 @@ const AuditLogViewerComponent: FC<ViewerProps> = ({
".MuiDataGrid-root .MuiDataGrid-row.Mui-selected .MuiDataGrid-cell": {
borderBottom: "none",
},

".AuditLogViewer-FilterButton": {
opacity: 0,
},

".MuiDataGrid-columnHeader:hover": {
".AuditLogViewer-FilterButton": {
opacity: 0.6,
},
},

...sx,
}}
>
Expand Down Expand Up @@ -272,6 +319,38 @@ const AuditLogViewerComponent: FC<ViewerProps> = ({
},
}}
/>
{activeFilterColumn && !!queryObj && (
<PopoutCard
anchorRef={{
current: activeFilterColumn
? headerRefMap.current[activeFilterColumn]
: null,
}}
open={!!activeFilterColumn}
setOpen={(open) => {
if (!open) setActiveFilterColumn(null);
}}
flatTop
>
<div style={{ minWidth: "700px" }}>
<AuditLogViewerFiltersForm
initialField={activeFilterColumn}
knownLogs={logs}
// @ts-ignore
filters={queryObj}
options={filterFields}
onFilterChange={(values) => {
setQueryObj(
mapValues(values, (v: any) =>
typeof v === "string" ? v.trim() : v
)
);
setActiveFilterColumn(null);
}}
/>
</div>
</PopoutCard>
)}
</Box>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {

import find from "lodash/find";
import { getFieldValueOptions } from "../../hooks/schema";
import { Audit } from "../../types";

export interface AuditFieldFilter {
id: string;
Expand All @@ -22,13 +23,16 @@ interface Props {
onValueChange: (value: AuditFieldFilter) => void;

options: FilterOptions<any>;

knownLogs?: Audit.FlattenedAuditRecord<any>[];
}

const FilterField: FC<Props> = ({
value,
onValueChange,

options,
knownLogs,
}) => {
const { schema } = useAuditContext();

Expand Down Expand Up @@ -95,7 +99,7 @@ const FilterField: FC<Props> = ({
return option?.valueOptions;
}

return getFieldValueOptions(field, undefined);
return getFieldValueOptions(field, undefined, knownLogs);
}, [value.id, field, options]);

return (
Expand Down Expand Up @@ -130,6 +134,9 @@ const FilterField: FC<Props> = ({
}
FieldProps={{
type: "singleSelect",
ValueTypographyProps: {
variant: "body2",
},
options: {
valueOptions: fieldOptions,
},
Expand All @@ -142,7 +149,7 @@ const FilterField: FC<Props> = ({
}}
/>
</Stack>
<Stack width="26%">
<Stack width="26%" sx={{ maxWidth: "125px" }}>
<SelectField
onValueChange={(operator) =>
onValueChange({
Expand All @@ -153,6 +160,9 @@ const FilterField: FC<Props> = ({
value={value.operator}
FieldProps={{
type: "singleSelect",
ValueTypographyProps: {
variant: "body2",
},
options: {
valueOptions: operationOptions,
},
Expand All @@ -168,7 +178,7 @@ const FilterField: FC<Props> = ({
}}
/>
</Stack>
<Stack width="37%">
<Stack width="37%" sx={{ width: "-webkit-fill-available" }}>
<StringField
value={value.value}
onValueChange={(v) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,26 @@ import FilterField, { AuditFieldFilter } from "./FilterField";
import JoinChip from "./JoinChip";
import { useAuditContext } from "../../hooks/context";
import { getAppliedFiltersQuery } from "./utils";
import { Audit } from "../../types";

interface AuditQueryFilters {
fields: AuditFieldFilter[];
}

interface Props<FiltersObj = AuditQueryFilters> {
initialField?: string;

knownLogs?: Audit.FlattenedAuditRecord[];

filters: FiltersObj;
options: FilterOptions<FiltersObj>;
onFilterChange: (filter: FiltersObj) => void;
}

const AuditLogViewerFiltersForm: FC<Props> = ({
initialField,
knownLogs,

filters,
options,
onFilterChange,
Expand All @@ -39,15 +47,15 @@ const AuditLogViewerFiltersForm: FC<Props> = ({
const options_ = Object.keys(options);
return [
{
id: !!options_?.length ? options_[0] : "",
id: initialField ?? (!!options_?.length ? options_[0] : ""),
operator: "=",
value: "",
},
] as AuditFieldFilter[];
}

return values.fields;
}, [values, options]);
}, [values, options, initialField]);

const isValid = useMemo(() => {
return !!fields.filter(
Expand Down Expand Up @@ -132,6 +140,7 @@ const AuditLogViewerFiltersForm: FC<Props> = ({
value={f}
onValueChange={(f) => handleUpdate(f, idx)}
options={options}
knownLogs={knownLogs}
/>
{idx !== 0 && (
<RemoveButton onClick={() => handleRemoveCondition(idx)} />
Expand Down
Loading
Loading