Skip to content

Commit

Permalink
review I
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierM committed Aug 24, 2021
1 parent dd832c0 commit 4b2943c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export function AlertsTableTGrid(props: AlertsTableTGridProps) {

const casePermissions = useGetUserCasesPermissions();

const hasAlertsPermissions = useCallback(
const hasAlertsCrudPermissions = useCallback(
(featureId: string) => {
return getAlertsPermissions(capabilities, featureId).crud;
},
Expand Down Expand Up @@ -337,7 +337,7 @@ export function AlertsTableTGrid(props: AlertsTableTGridProps) {
defaultCellActions: getDefaultCellActions({ addToQuery }),
end: rangeTo,
filters: [],
hasAlertsPermissions,
hasAlertsCrudPermissions,
indexNames,
itemsPerPage: 10,
itemsPerPageOptions: [10, 25, 50],
Expand Down Expand Up @@ -375,7 +375,7 @@ export function AlertsTableTGrid(props: AlertsTableTGridProps) {
casePermissions,
addToQuery,
rangeTo,
hasAlertsPermissions,
hasAlertsCrudPermissions,
indexNames,
workflowStatus,
kuery,
Expand Down
16 changes: 8 additions & 8 deletions x-pack/plugins/timelines/public/components/t_grid/body/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ interface OwnProps {
trailingControlColumns?: ControlColumnProps[];
unit?: (total: number) => React.ReactNode;
hasAlertsCrud?: boolean;
hasAlertsPermissions?: (featureId: string) => boolean;
hasAlertsCrudPermissions?: (featureId: string) => boolean;
totalSelectAllAlerts?: number;
}

Expand Down Expand Up @@ -146,7 +146,7 @@ const transformControlColumns = ({
theme,
setEventsLoading,
setEventsDeleted,
hasAlertsPermissions,
hasAlertsCrudPermissions,
}: {
actionColumnsWidth: number;
columnHeaders: ColumnHeaderOptions[];
Expand All @@ -167,7 +167,7 @@ const transformControlColumns = ({
theme: EuiTheme;
setEventsLoading: SetEventsLoading;
setEventsDeleted: SetEventsDeleted;
hasAlertsPermissions?: (featureId: string) => boolean;
hasAlertsCrudPermissions?: (featureId: string) => boolean;
}): EuiDataGridControlColumn[] =>
controlColumns.map(
({ id: columnId, headerCellRender = EmptyHeaderCellRender, rowCellRender, width }, i) => ({
Expand Down Expand Up @@ -206,11 +206,11 @@ const transformControlColumns = ({
}: EuiDataGridCellValueElementProps) => {
addBuildingBlockStyle(data[rowIndex].ecs, theme, setCellProps);
let disabled = false;
if (columnId === 'checkbox-control-column' && hasAlertsPermissions != null) {
if (columnId === 'checkbox-control-column' && hasAlertsCrudPermissions != null) {
const alertConsumers =
data[rowIndex].data.find((d) => d.field === ALERT_RULE_CONSUMER)?.value ?? [];
disabled = alertConsumers.reduce<boolean>(
(acc, consumer) => acc || !hasAlertsPermissions(consumer),
(acc, consumer) => acc || !hasAlertsCrudPermissions(consumer),
false
);
}
Expand Down Expand Up @@ -290,7 +290,7 @@ export const BodyComponent = React.memo<StatefulBodyProps>(
trailingControlColumns = EMPTY_CONTROL_COLUMNS,
unit = defaultUnit,
hasAlertsCrud,
hasAlertsPermissions,
hasAlertsCrudPermissions,
totalSelectAllAlerts,
}) => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -563,7 +563,7 @@ export const BodyComponent = React.memo<StatefulBodyProps>(
theme,
setEventsLoading,
setEventsDeleted,
hasAlertsPermissions,
hasAlertsCrudPermissions,
})
);
}, [
Expand All @@ -586,7 +586,7 @@ export const BodyComponent = React.memo<StatefulBodyProps>(
theme,
setEventsLoading,
setEventsDeleted,
hasAlertsPermissions,
hasAlertsCrudPermissions,
]);

const columnsWithCellActions: EuiDataGridColumn[] = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export interface TGridStandaloneProps {
filters: Filter[];
footerText: React.ReactNode;
filterStatus: AlertStatus;
hasAlertsPermissions: (featureId: string) => boolean;
hasAlertsCrudPermissions: (featureId: string) => boolean;
height?: number;
indexNames: string[];
itemsPerPage: number;
Expand Down Expand Up @@ -127,7 +127,7 @@ const TGridStandaloneComponent: React.FC<TGridStandaloneProps> = ({
filters,
footerText,
filterStatus,
hasAlertsPermissions,
hasAlertsCrudPermissions,
indexNames,
itemsPerPage,
itemsPerPageOptions,
Expand Down Expand Up @@ -231,7 +231,7 @@ const TGridStandaloneComponent: React.FC<TGridStandaloneProps> = ({
totalSelectAllAlerts: number;
}>(
(acc, [featureId, nbrAlerts]) => {
const featureHasPermission = hasAlertsPermissions(featureId);
const featureHasPermission = hasAlertsCrudPermissions(featureId);
return {
hasAlertsCrud: featureHasPermission || acc.hasAlertsCrud,
totalSelectAllAlerts: featureHasPermission
Expand All @@ -244,7 +244,7 @@ const TGridStandaloneComponent: React.FC<TGridStandaloneProps> = ({
totalSelectAllAlerts: 0,
}
);
}, [consumers, hasAlertsPermissions]);
}, [consumers, hasAlertsCrudPermissions]);

const totalCountMinusDeleted = useMemo(
() => (totalCount > 0 ? totalCount - deletedEventIds.length : 0),
Expand Down Expand Up @@ -349,7 +349,7 @@ const TGridStandaloneComponent: React.FC<TGridStandaloneProps> = ({
defaultCellActions={defaultCellActions}
filterQuery={filterQuery}
hasAlertsCrud={hasAlertsCrud}
hasAlertsPermissions={hasAlertsPermissions}
hasAlertsCrudPermissions={hasAlertsCrudPermissions}
id={STANDALONE_ID}
indexNames={indexNames}
isEventViewer={true}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const AppRoot = React.memo(
refetch.current = _refetch;
}, []);

const hasAlertsCrudPermissions = useCallback(() => true, []);

return (
<I18nProvider>
<Router history={parameters.history}>
Expand All @@ -73,6 +75,7 @@ const AppRoot = React.memo(
end: '',
footerText: 'Events',
filters: [],
hasAlertsCrudPermissions,
itemsPerPage: 50,
itemsPerPageOptions: [1, 2, 3],
loadingText: 'Loading events',
Expand Down

0 comments on commit 4b2943c

Please sign in to comment.