Skip to content

Commit

Permalink
make sonarqube happy
Browse files Browse the repository at this point in the history
  • Loading branch information
duranb committed Mar 4, 2025
1 parent 7060e56 commit 226943b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 35 deletions.
12 changes: 8 additions & 4 deletions src/components/constraints/ConstraintForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/constraints/ConstraintsPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,15 @@
},
],
]}
on:click={() => $plan && effects.checkConstraints($plan, true, user)}
on:click={() => $plan && effects.checkConstraints($plan, user, true)}
>
<RefreshIcon />
</PanelHeaderActionButton>
<PanelHeaderActionButton
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,
Expand Down
32 changes: 16 additions & 16 deletions src/routes/plans/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -322,7 +322,7 @@
}
$: if ($initialPlan && $planDatasets) {
let datasetNames = [];
const datasetNames = [];
for (const dataset of $planDatasets) {
for (const profile of dataset.dataset.profiles) {
Expand Down Expand Up @@ -498,19 +498,19 @@
}
async function onEditView(event: CustomEvent<View>) {
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();
}
}
}
async function onRestoreSnapshot(event: CustomEvent<PlanSnapshot>) {
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();
Expand Down Expand Up @@ -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
>
<VerticalCollapseIcon />
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/effects.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ describe('Handle modal and requests in effects', () => {
id: 1,
owner: 'test',
} as Plan,
false,
mockUser,
false,
);

expect(catchErrorSpy).toHaveBeenCalledWith(
Expand Down
17 changes: 5 additions & 12 deletions src/utilities/effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ const effects = {
}
},

async checkConstraints(plan: Plan, force: boolean = false, user: User | null): Promise<void> {
async checkConstraints(plan: Plan, user: User | null, force: boolean = false): Promise<void> {
try {
checkConstraintsQueryStatusStore.set(Status.Incomplete);
if (plan !== null) {
Expand Down Expand Up @@ -692,15 +692,12 @@ const effects = {
},

async createConstraint(
name: string,
isPublic: boolean,
metadataTags: ConstraintTagsInsertInput[],
constraintToCreate: Omit<ConstraintInsertInput, 'versions'>,
definitionType: ConstraintDefinitionType,
definition: string,
file: File | null,
definitionTags: ConstraintTagsInsertInput[],
user: User | null,
description?: string,
): Promise<number | null> {
try {
if (!queryPermissions.CREATE_CONSTRAINT(user)) {
Expand All @@ -717,12 +714,7 @@ const effects = {
}

const constraintInsertInput: ConstraintInsertInput = {
...(description ? { description } : {}),
name,
public: isPublic,
tags: {
data: metadataTags,
},
...constraintToCreate,
versions: {
data: [
{
Expand All @@ -736,6 +728,7 @@ const effects = {
],
},
};

const data = await reqHasura<ConstraintMetadata>(
gql.CREATE_CONSTRAINT,
{ constraint: constraintInsertInput },
Expand All @@ -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);
Expand Down

0 comments on commit 226943b

Please sign in to comment.