From 226943be8df977229d0e0727479e93fe672531f7 Mon Sep 17 00:00:00 2001 From: bduran Date: Tue, 4 Mar 2025 12:54:30 -0800 Subject: [PATCH] make sonarqube happy --- .../constraints/ConstraintForm.svelte | 12 ++++--- .../constraints/ConstraintsPanel.svelte | 4 +-- src/routes/plans/[id]/+page.svelte | 32 +++++++++---------- src/utilities/effects.test.ts | 2 +- src/utilities/effects.ts | 17 +++------- 5 files changed, 32 insertions(+), 35 deletions(-) diff --git a/src/components/constraints/ConstraintForm.svelte b/src/components/constraints/ConstraintForm.svelte index 9cc515f9ab..e6beeda716 100644 --- a/src/components/constraints/ConstraintForm.svelte +++ b/src/components/constraints/ConstraintForm.svelte @@ -115,15 +115,19 @@ }, } = event; const newConstraintId = await effects.createConstraint( - name, - isPublic, - metadataTags.map(({ id }) => ({ tag_id: id })), + { + description, + name, + public: isPublic, + tags: { + data: metadataTags.map(({ id }) => ({ tag_id: id })), + }, + }, definitionType === DefinitionType.CODE ? ConstraintDefinitionType.EDSL : ConstraintDefinitionType.JAR, definitionCode ?? '', definitionFile ?? null, definitionTags.map(({ id }) => ({ tag_id: id })), user, - description, ); if (newConstraintId !== null) { diff --git a/src/components/constraints/ConstraintsPanel.svelte b/src/components/constraints/ConstraintsPanel.svelte index abdb3070c4..5c189ddbc1 100644 --- a/src/components/constraints/ConstraintsPanel.svelte +++ b/src/components/constraints/ConstraintsPanel.svelte @@ -289,7 +289,7 @@ }, ], ]} - on:click={() => $plan && effects.checkConstraints($plan, true, user)} + on:click={() => $plan && effects.checkConstraints($plan, user, true)} > @@ -297,7 +297,7 @@ disabled={$simulationStatus !== Status.Complete || $constraintsStatus === Status.Complete} tooltipContent={$simulationStatus !== Status.Complete ? 'Completed simulation required' : ''} title="Check Constraints" - on:click={() => $plan && effects.checkConstraints($plan, false, user)} + on:click={() => $plan && effects.checkConstraints($plan, user, false)} use={[ [ permissionHandler, diff --git a/src/routes/plans/[id]/+page.svelte b/src/routes/plans/[id]/+page.svelte index 37a7245c19..8a99a48e9b 100644 --- a/src/routes/plans/[id]/+page.svelte +++ b/src/routes/plans/[id]/+page.svelte @@ -187,15 +187,15 @@ $: ({ invalidActivityCount, ...activityErrorCounts } = $activityErrorRollups.reduce( (prevCounts, activityErrorRollup) => { - let extra = prevCounts.extra + activityErrorRollup.errorCounts.extra; - let invalidAnchor = prevCounts.invalidAnchor + activityErrorRollup.errorCounts.invalidAnchor; - let invalidParameter = prevCounts.invalidParameter + activityErrorRollup.errorCounts.invalidParameter; - let missing = prevCounts.missing + activityErrorRollup.errorCounts.missing; - let outOfBounds = prevCounts.outOfBounds + activityErrorRollup.errorCounts.outOfBounds; - let pending = prevCounts.pending + activityErrorRollup.errorCounts.pending; - let wrongType = prevCounts.wrongType + activityErrorRollup.errorCounts.wrongType; - - let all = extra + invalidAnchor + invalidParameter + missing + outOfBounds + wrongType; + const extra = prevCounts.extra + activityErrorRollup.errorCounts.extra; + const invalidAnchor = prevCounts.invalidAnchor + activityErrorRollup.errorCounts.invalidAnchor; + const invalidParameter = prevCounts.invalidParameter + activityErrorRollup.errorCounts.invalidParameter; + const missing = prevCounts.missing + activityErrorRollup.errorCounts.missing; + const outOfBounds = prevCounts.outOfBounds + activityErrorRollup.errorCounts.outOfBounds; + const pending = prevCounts.pending + activityErrorRollup.errorCounts.pending; + const wrongType = prevCounts.wrongType + activityErrorRollup.errorCounts.wrongType; + + const all = extra + invalidAnchor + invalidParameter + missing + outOfBounds + wrongType; return { all, extra, @@ -322,7 +322,7 @@ } $: if ($initialPlan && $planDatasets) { - let datasetNames = []; + const datasetNames = []; for (const dataset of $planDatasets) { for (const profile of dataset.dataset.profiles) { @@ -498,9 +498,9 @@ } async function onEditView(event: CustomEvent) { - const { detail: view } = event; - if (view && hasUpdateViewPermission) { - const success = await effects.editView(view, data.user); + const { detail: updatedView } = event; + if (updatedView && hasUpdateViewPermission) { + const success = await effects.editView(updatedView, data.user); if (success) { resetOriginalView(); } @@ -508,9 +508,9 @@ } async function onRestoreSnapshot(event: CustomEvent) { - const { detail: planSnapshot } = event; + const { detail: snapshotToRestore } = event; if ($plan) { - const success = await effects.restorePlanSnapshot(planSnapshot, $plan, data.user); + const success = await effects.restorePlanSnapshot(snapshotToRestore, $plan, data.user); if (success) { clearSnapshot(); @@ -719,7 +719,7 @@ : 'You do not have permission to run a constraint check'} status={$constraintsStatus} showStatusInMenu={false} - on:click={() => $plan && effects.checkConstraints($plan, false, data.user)} + on:click={() => $plan && effects.checkConstraints($plan, data.user, false)} indeterminate > diff --git a/src/utilities/effects.test.ts b/src/utilities/effects.test.ts index 1a92cc068d..5563066f65 100644 --- a/src/utilities/effects.test.ts +++ b/src/utilities/effects.test.ts @@ -128,8 +128,8 @@ describe('Handle modal and requests in effects', () => { id: 1, owner: 'test', } as Plan, - false, mockUser, + false, ); expect(catchErrorSpy).toHaveBeenCalledWith( diff --git a/src/utilities/effects.ts b/src/utilities/effects.ts index 036aefb2b5..14c8dcb670 100644 --- a/src/utilities/effects.ts +++ b/src/utilities/effects.ts @@ -450,7 +450,7 @@ const effects = { } }, - async checkConstraints(plan: Plan, force: boolean = false, user: User | null): Promise { + async checkConstraints(plan: Plan, user: User | null, force: boolean = false): Promise { try { checkConstraintsQueryStatusStore.set(Status.Incomplete); if (plan !== null) { @@ -692,15 +692,12 @@ const effects = { }, async createConstraint( - name: string, - isPublic: boolean, - metadataTags: ConstraintTagsInsertInput[], + constraintToCreate: Omit, definitionType: ConstraintDefinitionType, definition: string, file: File | null, definitionTags: ConstraintTagsInsertInput[], user: User | null, - description?: string, ): Promise { try { if (!queryPermissions.CREATE_CONSTRAINT(user)) { @@ -717,12 +714,7 @@ const effects = { } const constraintInsertInput: ConstraintInsertInput = { - ...(description ? { description } : {}), - name, - public: isPublic, - tags: { - data: metadataTags, - }, + ...constraintToCreate, versions: { data: [ { @@ -736,6 +728,7 @@ const effects = { ], }, }; + const data = await reqHasura( gql.CREATE_CONSTRAINT, { constraint: constraintInsertInput }, @@ -748,7 +741,7 @@ const effects = { showSuccessToast('Constraint Created Successfully'); return id; } else { - throw Error(`Unable to create constraint "${name}"`); + throw Error(`Unable to create constraint "${constraintToCreate.name}"`); } } catch (e) { catchError('Constraint Creation Failed', e as Error);