Skip to content

Commit

Permalink
More PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Dec 2, 2021
1 parent 4f7896b commit 43ac5ff
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const CaseActionBarComponent: React.FC<CaseActionBarProps> = ({
onRefresh,
onUpdateField,
}) => {
const { syncAlerts: syncAlertsFeatureOption } = useCasesFeatures();
const { isSyncAlertsEnabled } = useCasesFeatures();
const date = useMemo(() => getStatusDate(caseData), [caseData]);
const title = useMemo(() => getStatusTitle(caseData.status), [caseData.status]);
const onStatusChanged = useCallback(
Expand Down Expand Up @@ -114,7 +114,7 @@ const CaseActionBarComponent: React.FC<CaseActionBarProps> = ({
responsive={false}
justifyContent="spaceBetween"
>
{userCanCrud && syncAlertsFeatureOption && (
{userCanCrud && isSyncAlertsEnabled && (
<EuiFlexItem grow={false}>
<EuiDescriptionListTitle>
<EuiFlexGroup
Expand Down
11 changes: 5 additions & 6 deletions x-pack/plugins/cases/public/components/cases_context/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@ export const CasesProvider: React.FC<{ value: CasesContextProps }> = ({
value: { owner, userCanCrud, basePath = DEFAULT_BASE_PATH, features = {} },
}) => {
const { appId, appTitle } = useApplication();
/**
* The empty object at the beginning avoids the mutation
* of the DEFAULT_FEATURES object
*/
const featuresOptions = merge({}, DEFAULT_FEATURES, features);
const [value, setValue] = useState<CasesContextStateValue>({
owner,
userCanCrud,
basePath,
features: featuresOptions,
/**
* The empty object at the beginning avoids the mutation
* of the DEFAULT_FEATURES object
*/
features: merge({}, DEFAULT_FEATURES, features),
});

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ import { useMemo } from 'react';
import { useCasesContext } from './use_cases_context';

interface UseCasesFeaturesReturn {
syncAlerts: boolean;
isSyncAlertsEnabled: boolean;
}

export const useCasesFeatures = (): UseCasesFeaturesReturn => {
const { features } = useCasesContext();
const memoizedReturnValue = useMemo(() => ({ syncAlerts: features.alerts.sync }), [features]);
const memoizedReturnValue = useMemo(
() => ({ isSyncAlertsEnabled: features.alerts.sync }),
[features]
);
return memoizedReturnValue;
};
8 changes: 4 additions & 4 deletions x-pack/plugins/cases/public/components/create/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const empty: ActionConnector[] = [];
export const CreateCaseFormFields: React.FC<CreateCaseFormFieldsProps> = React.memo(
({ connectors, isLoadingConnectors, hideConnectorServiceNowSir, withSteps }) => {
const { isSubmitting } = useFormContext();
const { syncAlerts } = useCasesFeatures();
const { isSyncAlertsEnabled } = useCasesFeatures();

const firstStep = useMemo(
() => ({
Expand Down Expand Up @@ -118,8 +118,8 @@ export const CreateCaseFormFields: React.FC<CreateCaseFormFieldsProps> = React.m
);

const allSteps = useMemo(
() => [firstStep, ...(syncAlerts ? [secondStep] : []), thirdStep],
[syncAlerts, firstStep, secondStep, thirdStep]
() => [firstStep, ...(isSyncAlertsEnabled ? [secondStep] : []), thirdStep],
[isSyncAlertsEnabled, firstStep, secondStep, thirdStep]
);

return (
Expand All @@ -134,7 +134,7 @@ export const CreateCaseFormFields: React.FC<CreateCaseFormFieldsProps> = React.m
) : (
<>
{firstStep.children}
{syncAlerts && secondStep.children}
{isSyncAlertsEnabled && secondStep.children}
{thirdStep.children}
</>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const FormContext: React.FC<Props> = ({
}) => {
const { connectors, loading: isLoadingConnectors } = useConnectors();
const { owner } = useCasesContext();
const { syncAlerts: syncAlertsFeatureOption } = useCasesFeatures();
const { isSyncAlertsEnabled } = useCasesFeatures();
const { postCase } = usePostCase();
const { postComment } = usePostComment();
const { pushCaseToExternalService } = usePostPushToService();
Expand All @@ -56,7 +56,7 @@ export const FormContext: React.FC<Props> = ({
{
connectorId: dataConnectorId,
fields,
syncAlerts = syncAlertsFeatureOption,
syncAlerts = isSyncAlertsEnabled,
...dataWithoutConnectorId
},
isValid
Expand Down Expand Up @@ -93,7 +93,7 @@ export const FormContext: React.FC<Props> = ({
}
},
[
syncAlertsFeatureOption,
isSyncAlertsEnabled,
connectors,
postCase,
caseType,
Expand Down

0 comments on commit 43ac5ff

Please sign in to comment.