Skip to content

Commit

Permalink
Fix after review
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet committed Jun 23, 2022
1 parent a0cbfd5 commit fa64b82
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 69 deletions.
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pageLoadAssetSize:
indexLifecycleManagement: 107090
indexManagement: 140608
infra: 184320
fleet: 100000
fleet: 126917
ingestPipelines: 58003
inputControlVis: 172675
inspector: 148711
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
EuiSpacer,
EuiButtonEmpty,
} from '@elastic/eui';
import { useRouteMatch } from 'react-router-dom';

import type {
NewPackagePolicy,
Expand Down Expand Up @@ -55,6 +56,12 @@ export const PackagePolicyInputStreamConfig: React.FunctionComponent<{
inputStreamValidationResults,
forceShowErrors,
}) => {
const {
params: { packagePolicyId },
} = useRouteMatch<{ packagePolicyId?: string }>();

const isPackagePolicyEdit = !!packagePolicyId;

// Showing advanced options toggle state
const [isShowingAdvanced, setIsShowingAdvanced] = useState<boolean>();

Expand Down Expand Up @@ -146,80 +153,87 @@ export const PackagePolicyInputStreamConfig: React.FunctionComponent<{
</EuiFlexItem>
);
})}
{/* Advenced section */}
<Fragment>
<EuiFlexItem>
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center">
<EuiFlexItem grow={false}>
<EuiButtonEmpty
size="xs"
iconType={isShowingAdvanced ? 'arrowDown' : 'arrowRight'}
onClick={() => setIsShowingAdvanced(!isShowingAdvanced)}
flush="left"
>
<FormattedMessage
id="xpack.fleet.createPackagePolicy.stepConfigure.toggleAdvancedOptionsButtonText"
defaultMessage="Advanced options"
/>
</EuiButtonEmpty>
</EuiFlexItem>
{!isShowingAdvanced && hasErrors && advancedVarsWithErrorsCount ? (
{/* Advanced section */}
{(isPackagePolicyEdit || advancedVars.length) && (
<Fragment>
<EuiFlexItem>
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center">
<EuiFlexItem grow={false}>
<EuiText color="danger" size="s">
<EuiButtonEmpty
size="xs"
iconType={isShowingAdvanced ? 'arrowDown' : 'arrowRight'}
onClick={() => setIsShowingAdvanced(!isShowingAdvanced)}
flush="left"
>
<FormattedMessage
id="xpack.fleet.createPackagePolicy.stepConfigure.errorCountText"
defaultMessage="{count, plural, one {# error} other {# errors}}"
values={{ count: advancedVarsWithErrorsCount }}
id="xpack.fleet.createPackagePolicy.stepConfigure.toggleAdvancedOptionsButtonText"
defaultMessage="Advanced options"
/>
</EuiText>
</EuiButtonEmpty>
</EuiFlexItem>
) : null}
</EuiFlexGroup>
</EuiFlexItem>
{isShowingAdvanced ? (
<>
{advancedVars.map((varDef) => {
if (!packagePolicyInputStream.vars) return null;
const { name: varName, type: varType } = varDef;
const value = packagePolicyInputStream.vars?.[varName]?.value;
{!isShowingAdvanced && hasErrors && advancedVarsWithErrorsCount ? (
<EuiFlexItem grow={false}>
<EuiText color="danger" size="s">
<FormattedMessage
id="xpack.fleet.createPackagePolicy.stepConfigure.errorCountText"
defaultMessage="{count, plural, one {# error} other {# errors}}"
values={{ count: advancedVarsWithErrorsCount }}
/>
</EuiText>
</EuiFlexItem>
) : null}
</EuiFlexGroup>
</EuiFlexItem>
{isShowingAdvanced ? (
<>
{advancedVars.map((varDef) => {
if (!packagePolicyInputStream.vars) return null;
const { name: varName, type: varType } = varDef;
const value = packagePolicyInputStream.vars?.[varName]?.value;

return (
<EuiFlexItem key={varName}>
<PackagePolicyInputVarField
varDef={varDef}
value={value}
onChange={(newValue: any) => {
updatePackagePolicyInputStream({
vars: {
...packagePolicyInputStream.vars,
[varName]: {
type: varType,
value: newValue,
return (
<EuiFlexItem key={varName}>
<PackagePolicyInputVarField
varDef={varDef}
value={value}
onChange={(newValue: any) => {
updatePackagePolicyInputStream({
vars: {
...packagePolicyInputStream.vars,
[varName]: {
type: varType,
value: newValue,
},
},
},
});
}}
errors={inputStreamValidationResults?.vars![varName]}
forceShowErrors={forceShowErrors}
/>
</EuiFlexItem>
);
})}
<EuiFlexItem>
<PackagePolicyEditorDatastreamPipelines
dataStream={packageInputStream.data_stream}
packageInfo={packageInfo}
/>
</EuiFlexItem>
<EuiFlexItem>
<PackagePolicyEditorDatastreamMappings
dataStream={packageInputStream.data_stream}
packageInfo={packageInfo}
/>
</EuiFlexItem>
</>
) : null}
</Fragment>
});
}}
errors={inputStreamValidationResults?.vars![varName]}
forceShowErrors={forceShowErrors}
/>
</EuiFlexItem>
);
})}
{/* Only show datastream pipelines and mappings on edit */}
{isPackagePolicyEdit && (
<>
<EuiFlexItem>
<PackagePolicyEditorDatastreamPipelines
dataStream={packageInputStream.data_stream}
packageInfo={packageInfo}
/>
</EuiFlexItem>
<EuiFlexItem>
<PackagePolicyEditorDatastreamMappings
dataStream={packageInputStream.data_stream}
packageInfo={packageInfo}
/>
</EuiFlexItem>
</>
)}
</>
) : null}
</Fragment>
)}
</EuiFlexGroup>
</FlexItemWithMaxWidth>
</EuiFlexGrid>
Expand Down

0 comments on commit fa64b82

Please sign in to comment.