Skip to content

Commit

Permalink
jsdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Apr 17, 2024
1 parent 73500d5 commit 3ab715b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ export type BrushSelectionUpdateHandler = (
logRateAnalysisType: LogRateAnalysisType
) => void;

/**
* Callback to set the autoRunAnalysis flag
*/
type SetAutoRunAnalysisFn = (isAutoRun: boolean) => void;

/**
* Props for document count chart
*/
Expand Down Expand Up @@ -121,7 +126,7 @@ export interface DocumentCountChartProps {
/** Whether or not brush has been reset */
isBrushCleared: boolean;
/** Callback to set the autoRunAnalysis flag */
setAutoRunAnalysis?: (isAutoRun: boolean) => void;
setAutoRunAnalysis?: SetAutoRunAnalysisFn;
/** Timestamp for start of initial analysis */
autoAnalysisStart?: number | WindowParameters;
/** Optional style to override bar chart */
Expand Down Expand Up @@ -553,6 +558,15 @@ export const DocumentCountChart: FC<DocumentCountChartProps> = (props) => {
);
};

/**
* Functional component that renders a `DocumentCountChart` with additional properties
* managed by the log rate analysis state. It leverages the `useLogRateAnalysisStateContext`
* to acquire state variables like `initialAnalysisStart` and functions such as
* `setAutoRunAnalysis`. These values are then passed as props to the `DocumentCountChart`.
*
* @param props - The properties passed to the DocumentCountChart component.
* @returns The DocumentCountChart component enhanced with automatic analysis start capabilities.
*/
export const DocumentCountChartWithAutoAnalysisStart: FC<DocumentCountChartProps> = (props) => {
const { initialAnalysisStart, setAutoRunAnalysis } = useLogRateAnalysisStateContext();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,30 @@ interface LogRateAnalysisState {

const LogRateAnalysisStateContext = createContext<LogRateAnalysisState | undefined>(undefined);

/**
* Props for LogRateAnalysisStateProvider.
*/
interface LogRateAnalysisStateProviderProps {
/** The parameters to be used to trigger an analysis. */
initialAnalysisStart?: InitialAnalysisStart;
}

export const LogRateAnalysisStateProvider: FC<LogRateAnalysisStateProviderProps> = ({
children,
initialAnalysisStart: incomingInitialAnalysisStart,
}) => {
/**
* Context provider component that manages and provides global state for Log Rate Analysis.
* This provider handles several pieces of state important for controlling and displaying
* log rate analysis data, such as the control of automatic analysis runs, and the management
* of both pinned and selected significant items and groups.
*
* The state includes mechanisms for setting initial analysis parameters, toggling analysis,
* and managing the current selection and pinned state of significant items and groups.
*
* @param props - Props object containing initial settings for the analysis,
* including children components to be wrapped by the Provider.
* @returns A context provider wrapping children with access to log rate analysis state.
*/
export const LogRateAnalysisStateProvider: FC<LogRateAnalysisStateProviderProps> = (props) => {
const { children, initialAnalysisStart: incomingInitialAnalysisStart } = props;

const [autoRunAnalysis, setAutoRunAnalysis] = useState(true);
const [initialAnalysisStart, setInitialAnalysisStart] = useState<
number | WindowParameters | undefined
Expand Down Expand Up @@ -131,6 +147,13 @@ export const LogRateAnalysisStateProvider: FC<LogRateAnalysisStateProviderProps>
);
};

/**
* Custom hook for accessing the state of log rate analysis from the LogRateAnalysisStateContext.
* This hook must be used within a component that is a descendant of the LogRateAnalysisStateContext provider.
*
* @returns The current state of the log rate analysis.
* @throws Throws an error if the hook is used outside of its Provider context.
*/
export const useLogRateAnalysisStateContext = () => {
const logRateAnalysisState = useContext(LogRateAnalysisStateContext);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,36 @@ import type { EuiTableActionsColumnType } from '@elastic/eui';

import type { SignificantItem, SignificantItemGroupItem } from '@kbn/ml-agg-utils';

/**
* Type for defining attributes picked from
* SignificantItemGroupItem used in the grouped table.
*/
export type GroupTableItemGroup = Pick<
SignificantItemGroupItem,
'key' | 'type' | 'fieldName' | 'fieldValue' | 'docCount' | 'pValue' | 'duplicate'
>;

/**
* Represents a single item in the group table.
*/
export interface GroupTableItem {
/** Unique identifier for the group table item. */
id: string;
/** Document count associated with the item. */
docCount: number;
/** Statistical p-value indicating the significance of the item, nullable. */
pValue: number | null;
/** Count of unique items within the group. */
uniqueItemsCount: number;
/** Array of items within the group, sorted by uniqueness. */
groupItemsSortedByUniqueness: GroupTableItemGroup[];
/** Histogram data for the significant item. */
histogram: SignificantItem['histogram'];
}

/**
* Type for action columns in a table that involves SignificantItem or GroupTableItem.
*/
export type TableItemAction = EuiTableActionsColumnType<
SignificantItem | GroupTableItem
>['actions'][number];

0 comments on commit 3ab715b

Please sign in to comment.