Skip to content

Commit

Permalink
Add NPE checks on object.values() calls (#595) (#596)
Browse files Browse the repository at this point in the history
(cherry picked from commit 2a61016)

Signed-off-by: Tyler Ohlsen <ohltyler@amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent e787a4a commit 6579347
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function EditWorkflowMetadataModal(
'This workflow name is already in use. Use a different name',
(name) => {
return !(
Object.values(workflows)
Object.values(workflows || {})
.map((workflow) => workflow.name)
.includes(name || '') && name !== props.workflow?.name
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function ResourceListWithFlyout(props: ResourceListFlyoutProps) {
props.workflow.resourcesCreated.forEach((resource) => {
resourcesMap[resource.id] = resource;
});
setAllResources(Object.values(resourcesMap));
setAllResources(Object.values(resourcesMap || {}));
}
}, [props.workflow?.resourcesCreated]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function AdvancedSettings(props: AdvancedSettingsProps) {
const { values, setFieldValue } = useFormikContext<WorkflowFormValues>();
const { models, connectors } = useSelector((state: AppState) => state.ml);
const ingestMLProcessors = (Object.values(
values?.ingest?.enrich
values?.ingest?.enrich || {}
) as any[]).filter((ingestProcessor) => ingestProcessor?.model !== undefined);
const ingestProcessorModelIds = ingestMLProcessors
.map((ingestProcessor) => ingestProcessor?.model?.id as string | undefined)
Expand All @@ -52,7 +52,7 @@ export function AdvancedSettings(props: AdvancedSettingsProps) {
useEffect(() => {
if (ingestProcessorModelIds.length > 0) {
ingestProcessorModelIds.forEach((ingestProcessorModelId) => {
const processorModel = Object.values(models).find(
const processorModel = Object.values(models || {}).find(
(model) => model.id === ingestProcessorModelId
);
if (processorModel?.connectorId !== undefined) {
Expand Down Expand Up @@ -91,7 +91,7 @@ export function AdvancedSettings(props: AdvancedSettingsProps) {
useEffect(() => {
if (ingestMLProcessors.length > 0) {
ingestMLProcessors.forEach((ingestMLProcessor) => {
const processorModel = Object.values(models).find(
const processorModel = Object.values(models || {}).find(
(model) => model.id === ingestMLProcessor?.model?.id
);
if (processorModel?.connectorId !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export function SourceDataModal(props: SourceDataProps) {
<EuiCompressedComboBox
placeholder="Select an index"
singleSelection={{ asPlainText: true }}
options={Object.values(indices).map((option) => {
options={Object.values(indices || {}).map((option) => {
return { label: option.name };
})}
onChange={(options) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function ConfigureSearchRequest(props: ConfigureSearchRequestProps) {
/>
) : (
<EuiCompressedSuperSelect
options={Object.values(indices).map(
options={Object.values(indices || {}).map(
(option) =>
({
value: option.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function ImportWorkflowModal(props: ImportWorkflowModalProps) {
workflowNameExists
);
}
const workflowNameExists = Object.values(workflows)
const workflowNameExists = Object.values(workflows || {})
.map((workflow) => workflow.name)
.includes(workflowName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function QuickConfigureInputs(props: QuickConfigureInputsProps) {
useEffect(() => {
if (models) {
setDeployedModels(
Object.values(models).filter(
Object.values(models || {}).filter(
(model) => model.state === MODEL_STATE.DEPLOYED
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export function QuickConfigureModal(props: QuickConfigureModalProps) {
const [workflowNameTouched, setWorkflowNameTouched] = useState<boolean>(
false
);
const workflowNameExists = Object.values(workflows)
const workflowNameExists = Object.values(workflows || {})
.map((workflow) => workflow.name)
.includes(workflowName);

Expand Down
2 changes: 1 addition & 1 deletion public/pages/workflows/workflow_list/resource_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function ResourceList(props: ResourceListProps) {
props.workflow.resourcesCreated.forEach((resource) => {
resourcesMap[resource.id] = resource;
});
setAllResources(Object.values(resourcesMap));
setAllResources(Object.values(resourcesMap || {}));
}
}, [props.workflow?.resourcesCreated]);

Expand Down
2 changes: 1 addition & 1 deletion public/utils/config_to_schema_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function indexConfigToSchema(
'name',
'This index name is already in use. Use a different name',
(name) => {
return !Object.values(indices)
return !Object.values(indices || {})
.map((index) => index.name)
.includes(name || '');
}
Expand Down

0 comments on commit 6579347

Please sign in to comment.