Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add NPE checks on Object.values() calls #595

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading