From 47ee66e8ddf676621ad61dc8a666c672b4711103 Mon Sep 17 00:00:00 2001 From: Erling Hauan Date: Tue, 8 Oct 2024 13:08:00 +0200 Subject: [PATCH 1/4] Add null checks for 'tasks' --- backend/src/Designer/Models/LayoutSets.cs | 4 +++- .../Services/Implementation/AppDevelopmentService.cs | 2 +- .../ConfigPanel/ConfigContent/ConfigContent.tsx | 8 +++++--- .../RecommendedActionChangeName.tsx | 1 + 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/backend/src/Designer/Models/LayoutSets.cs b/backend/src/Designer/Models/LayoutSets.cs index 1d19842bbc8..9efb83fba5a 100644 --- a/backend/src/Designer/Models/LayoutSets.cs +++ b/backend/src/Designer/Models/LayoutSets.cs @@ -23,10 +23,12 @@ public class LayoutSetConfig public string Id { get; set; } [JsonPropertyName("dataType")] - [CanBeNull] public string DataType { get; set; } + [CanBeNull] + public string DataType { get; set; } [JsonPropertyName("tasks")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [CanBeNull] public List Tasks { get; set; } [JsonPropertyName("type")] diff --git a/backend/src/Designer/Services/Implementation/AppDevelopmentService.cs b/backend/src/Designer/Services/Implementation/AppDevelopmentService.cs index 9f59ec42bdf..34177cd0c6d 100644 --- a/backend/src/Designer/Services/Implementation/AppDevelopmentService.cs +++ b/backend/src/Designer/Services/Implementation/AppDevelopmentService.cs @@ -305,7 +305,7 @@ public async Task AddLayoutSet(AltinnRepoEditingContext altinnRepoEd { throw new NonUniqueLayoutSetIdException($"Layout set name, {newLayoutSet.Id}, already exists."); } - if (newLayoutSet.Tasks != null && layoutSets.Sets.Exists(set => set.Tasks[0] == newLayoutSet.Tasks[0])) + if (newLayoutSet.Tasks != null && layoutSets.Sets.Exists(set => set.Tasks?[0] == newLayoutSet.Tasks[0])) { throw new NonUniqueTaskForLayoutSetException($"Layout set with task, {newLayoutSet.Tasks[0]}, already exists."); } diff --git a/frontend/packages/process-editor/src/components/ConfigPanel/ConfigContent/ConfigContent.tsx b/frontend/packages/process-editor/src/components/ConfigPanel/ConfigContent/ConfigContent.tsx index 7f9c51e7b89..563d8389632 100644 --- a/frontend/packages/process-editor/src/components/ConfigPanel/ConfigContent/ConfigContent.tsx +++ b/frontend/packages/process-editor/src/components/ConfigPanel/ConfigContent/ConfigContent.tsx @@ -20,11 +20,13 @@ export const ConfigContent = (): React.ReactElement => { const { t } = useTranslation(); const { bpmnDetails } = useBpmnContext(); const { layoutSets, availableDataModelIds } = useBpmnApiContext(); - const layoutSet = layoutSets?.sets.find((set) => set.tasks.includes(bpmnDetails.id)); + const layoutSet = layoutSets?.sets.find((set) => set.tasks?.includes(bpmnDetails.id)); const existingDataTypeForTask = layoutSet?.dataType; const isSigningTask = bpmnDetails.taskType === 'signing'; - const taskHasConnectedLayoutSet = layoutSets?.sets?.some((set) => set.tasks[0] == bpmnDetails.id); + const taskHasConnectedLayoutSet = layoutSets?.sets?.some( + (set) => set.tasks && set.tasks[0] == bpmnDetails.id, + ); const { shouldDisplayAction } = useStudioRecommendedNextActionContext(); const studioModeler = new StudioModeler(); @@ -70,7 +72,7 @@ export const ConfigContent = (): React.ReactElement => { diff --git a/frontend/packages/process-editor/src/components/ConfigPanel/ConfigContent/EditLayoutSetNameRecommendedAction/RecommendedActionChangeName.tsx b/frontend/packages/process-editor/src/components/ConfigPanel/ConfigContent/EditLayoutSetNameRecommendedAction/RecommendedActionChangeName.tsx index aa2a37c720a..b3c91dcbe33 100644 --- a/frontend/packages/process-editor/src/components/ConfigPanel/ConfigContent/EditLayoutSetNameRecommendedAction/RecommendedActionChangeName.tsx +++ b/frontend/packages/process-editor/src/components/ConfigPanel/ConfigContent/EditLayoutSetNameRecommendedAction/RecommendedActionChangeName.tsx @@ -25,6 +25,7 @@ export const RecommendedActionChangeName = (): React.ReactElement => { if (newNameError || newName === '') { return false; } + mutateLayoutSetId({ layoutSetIdToUpdate: bpmnDetails.element.id, newLayoutSetId: newName }); removeAction(bpmnDetails.element.id); }; From 935cb6ca50ca75fca9790d59356e997945b9da97 Mon Sep 17 00:00:00 2001 From: Erling Hauan Date: Tue, 8 Oct 2024 13:16:58 +0200 Subject: [PATCH 2/4] Add null check in bpmnHandlerUtils --- .../features/processEditor/bpmnHandlerUtils/bpmnHandlerUtils.ts | 2 +- .../src/components/ConfigPanel/ConfigContent/ConfigContent.tsx | 2 +- .../RecommendedActionChangeName.tsx | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/frontend/app-development/features/processEditor/bpmnHandlerUtils/bpmnHandlerUtils.ts b/frontend/app-development/features/processEditor/bpmnHandlerUtils/bpmnHandlerUtils.ts index 4ea9be4742c..f2e6a8ca2e0 100644 --- a/frontend/app-development/features/processEditor/bpmnHandlerUtils/bpmnHandlerUtils.ts +++ b/frontend/app-development/features/processEditor/bpmnHandlerUtils/bpmnHandlerUtils.ts @@ -1,6 +1,6 @@ import type { LayoutSets } from 'app-shared/types/api/LayoutSetsResponse'; export const getLayoutSetIdFromTaskId = (elementId: string, layoutSets: LayoutSets) => { - const layoutSet = layoutSets.sets.find((set) => set.tasks[0] === elementId); + const layoutSet = layoutSets.sets.find((set) => set.tasks && set?.tasks[0] === elementId); return layoutSet?.id; }; diff --git a/frontend/packages/process-editor/src/components/ConfigPanel/ConfigContent/ConfigContent.tsx b/frontend/packages/process-editor/src/components/ConfigPanel/ConfigContent/ConfigContent.tsx index 563d8389632..b99cb379853 100644 --- a/frontend/packages/process-editor/src/components/ConfigPanel/ConfigContent/ConfigContent.tsx +++ b/frontend/packages/process-editor/src/components/ConfigPanel/ConfigContent/ConfigContent.tsx @@ -72,7 +72,7 @@ export const ConfigContent = (): React.ReactElement => { diff --git a/frontend/packages/process-editor/src/components/ConfigPanel/ConfigContent/EditLayoutSetNameRecommendedAction/RecommendedActionChangeName.tsx b/frontend/packages/process-editor/src/components/ConfigPanel/ConfigContent/EditLayoutSetNameRecommendedAction/RecommendedActionChangeName.tsx index b3c91dcbe33..aa2a37c720a 100644 --- a/frontend/packages/process-editor/src/components/ConfigPanel/ConfigContent/EditLayoutSetNameRecommendedAction/RecommendedActionChangeName.tsx +++ b/frontend/packages/process-editor/src/components/ConfigPanel/ConfigContent/EditLayoutSetNameRecommendedAction/RecommendedActionChangeName.tsx @@ -25,7 +25,6 @@ export const RecommendedActionChangeName = (): React.ReactElement => { if (newNameError || newName === '') { return false; } - mutateLayoutSetId({ layoutSetIdToUpdate: bpmnDetails.element.id, newLayoutSetId: newName }); removeAction(bpmnDetails.element.id); }; From 26ce87dc09bac310f6866af0780de57fe059c1fc Mon Sep 17 00:00:00 2001 From: Erling Hauan Date: Tue, 8 Oct 2024 13:29:32 +0200 Subject: [PATCH 3/4] Fix dotnet build warning --- backend/src/Designer/Models/LayoutSets.cs | 2 ++ .../features/processEditor/bpmnHandlerUtils/bpmnHandlerUtils.ts | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/src/Designer/Models/LayoutSets.cs b/backend/src/Designer/Models/LayoutSets.cs index 9efb83fba5a..4044f0552a8 100644 --- a/backend/src/Designer/Models/LayoutSets.cs +++ b/backend/src/Designer/Models/LayoutSets.cs @@ -1,5 +1,6 @@ #nullable enable using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Text.Json.Serialization; using JetBrains.Annotations; @@ -20,6 +21,7 @@ public class LayoutSets : Altinn.App.Core.Models.LayoutSets public class LayoutSetConfig { [JsonPropertyName("id")] + [Required] public string Id { get; set; } [JsonPropertyName("dataType")] diff --git a/frontend/app-development/features/processEditor/bpmnHandlerUtils/bpmnHandlerUtils.ts b/frontend/app-development/features/processEditor/bpmnHandlerUtils/bpmnHandlerUtils.ts index f2e6a8ca2e0..708927a83f4 100644 --- a/frontend/app-development/features/processEditor/bpmnHandlerUtils/bpmnHandlerUtils.ts +++ b/frontend/app-development/features/processEditor/bpmnHandlerUtils/bpmnHandlerUtils.ts @@ -1,6 +1,6 @@ import type { LayoutSets } from 'app-shared/types/api/LayoutSetsResponse'; export const getLayoutSetIdFromTaskId = (elementId: string, layoutSets: LayoutSets) => { - const layoutSet = layoutSets.sets.find((set) => set.tasks && set?.tasks[0] === elementId); + const layoutSet = layoutSets.sets.find((set) => set.tasks && set.tasks[0] === elementId); return layoutSet?.id; }; From d721b58c0d25efa18216b3bb075bb12f0a306b67 Mon Sep 17 00:00:00 2001 From: Erling Hauan Date: Tue, 8 Oct 2024 13:43:48 +0200 Subject: [PATCH 4/4] Remove 'Required' data annotation --- backend/src/Designer/Models/LayoutSets.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/backend/src/Designer/Models/LayoutSets.cs b/backend/src/Designer/Models/LayoutSets.cs index 4044f0552a8..9efb83fba5a 100644 --- a/backend/src/Designer/Models/LayoutSets.cs +++ b/backend/src/Designer/Models/LayoutSets.cs @@ -1,6 +1,5 @@ #nullable enable using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; using System.Text.Json.Serialization; using JetBrains.Annotations; @@ -21,7 +20,6 @@ public class LayoutSets : Altinn.App.Core.Models.LayoutSets public class LayoutSetConfig { [JsonPropertyName("id")] - [Required] public string Id { get; set; } [JsonPropertyName("dataType")]