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

Sweep: allow to update the height of an already created rack #108

Closed
6 tasks done
Polyterative opened this issue Jan 24, 2024 · 1 comment
Closed
6 tasks done

Sweep: allow to update the height of an already created rack #108

Polyterative opened this issue Jan 24, 2024 · 1 comment
Labels
sweep Sweep your software chores

Comments

@Polyterative
Copy link
Owner

Polyterative commented Jan 24, 2024

Description

add a functionality that allows you to update the height of an already created rack by actually changing the number in the database without modifying the modules without deleting them in any way by modifying only the size of the rack

Checklist
  • Modify src/app/features/backend/supabase.service.tsd051d76 Edit
  • Running GitHub Actions for src/app/features/backend/supabase.service.tsEdit
  • Modify src/app/components/rack-parts/rack-details/rack-details.component.tsdd9fb49 Edit
  • Running GitHub Actions for src/app/components/rack-parts/rack-details/rack-details.component.tsEdit
  • Modify src/app/components/rack-parts/rack-detail-data.service.ts2e5b3b9 Edit
  • Running GitHub Actions for src/app/components/rack-parts/rack-detail-data.service.tsEdit
@sweep-ai sweep-ai bot added the sweep Sweep your software chores label Jan 24, 2024
Copy link

sweep-ai bot commented Jan 24, 2024

🚀 Here's the PR! #109

See Sweep's progress at the progress dashboard!
Sweep Basic Tier: I'm using GPT-4. You have 4 GPT-4 tickets left for the month and 3 for the day. (tracking ID: 9787f1bc73)

For more GPT-4 tickets, visit our payment portal. For a one week free trial, try Sweep Pro (unlimited GPT-4 tickets).
Install Sweep Configs: Pull Request

Tip

I'll email you at [email protected] when I complete this pull request!


Actions (click)

  • ↻ Restart Sweep

GitHub Actions✓

Here are the GitHub Actions logs prior to making any changes:

Sandbox logs for 5cfd1c8
Checking src/app/features/backend/supabase.service.ts for syntax errors... ✅ src/app/features/backend/supabase.service.ts has no syntax errors! 1/1 ✓
Checking src/app/features/backend/supabase.service.ts for syntax errors...
✅ src/app/features/backend/supabase.service.ts has no syntax errors!

Sandbox passed on the latest develop, so sandbox checks will be enabled for this issue.


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description.

// track if rack is property of current user
this.manageSub(
combineLatest([
this.userService.loggedUser$,
this.singleRackData$
])
.pipe(
tap(x => this.isCurrentRackPropertyOfCurrentUser$.next(false)),
filter(([user, rackData]) => (!!user && !!rackData))
)
.subscribe(([user, rackData]) => {
this.isCurrentRackPropertyOfCurrentUser$.next(user.id === rackData.author.id);
})
);
// when request to remove module is received, find module and remove it, then update the local rack data
this.manageSub(
this.requestRackedModuleRemoval$
.pipe(
withLatestFrom(this.rowedRackedModules$, this.singleRackData$),
switchMap(([rackedModule, rackModules, rack]) => {
this.removeRackedModuleFromArray(rackModules, rackedModule);
this.rowedRackedModules$.next(rackModules);
// this.requestRackedModulesDbSync$.next();
// this does not work, because the rack data are upserted, so we need to delete in the backend manually
return this.backend.delete.rackedModule(rackedModule.rackingData.id);
}),
withLatestFrom(this.singleRackData$)
)
.subscribe(([x, rackData]) => {
this.singleRackData$.next(rackData);
})
);
// when request to duplicate module is received, find module and duplicate it, then update the local rack data
this.manageSub(
this.requestRackedModuleDuplication$
.pipe(
withLatestFrom(this.rowedRackedModules$, this.singleRackData$)
)
.subscribe(([rackedModule, rackModules, rack]) => {
this.duplicateModule(rackModules, rackedModule);
this.rowedRackedModules$.next(rackModules);
this.requestRackedModulesDbSync$.next();
})
);
// on request to sync rack data with backend, update backend
this.manageSub(
this.requestRackedModulesDbSync$
.pipe(
withLatestFrom(this.rowedRackedModules$, this.singleRackData$),
switchMap(([_, rackModules, rack]) => this.backend.update.rackedModules(rackModules.flatMap(row => row))

// when requested similar modules list is updated, update the list
this.updateModulesList$
.pipe(
tap(() => this.similarModulesData$.next(undefined)),
filter(() => this.formData.name.control.value.length !== '' || this.formData.manufacturer.control.value.length !== ''),
switchMap(() => this.backend.get.modulesMinimal(
0, (10) - 1, this.formData.name.control.value, undefined, undefined,
parseInt(getCleanedValueId(this.formData.manufacturer.control)), false
))
)
.subscribe(x => {
this.similarModulesData$.next(x.data);
});
// when user submits the form, we need to add the module on the server
this.submitModuleForm$
.pipe(
switchMap(x => {
const data: ConfirmDialogDataInModel = {
title: 'Submit',
description: 'Are you sure you want to submit this module? Please verify that all information is correct.',
positive: {
label: 'Submit',
theme: 'primary'
},
negative: {
label: 'Cancel',
theme: 'negative'
}
};
return this.dialog.open(
ConfirmDialogComponent,
{
data,
disableClose: false
}
)
.afterClosed()
.pipe(filter((x: ConfirmDialogDataOutModel) => x && x.answer)
);
}),

update = {
module: (data: DbModule) => {
data.manufacturer = undefined;
data.ins = undefined;
data.outs = undefined;
data.tags = undefined; // todo handle tags
data.updated = new Date().toISOString();
return rxFrom(
this.supabase.from(this.paths.modules)
.update(data)
.eq('id', data.id)
.single()
)
.pipe(tap(x => SharedConstants.showSuccessUpdate(this.snackBar)));
},
rackedModules: (data: RackedModule[]) => {
const rackId: number = data[0].rackingData.rackid;
return rxFrom(
this.supabase.from(this.paths.rack_modules)
.upsert(data.filter(x => x.rackingData.id != undefined)
.map(rackedModule => rackedModule.rackingData))
)
.pipe(
// insert where id is undefined
switchMap(x => {
const newRackedModules = data.filter(x => x.rackingData.id === undefined)
.map(rackedModule => rackedModule.rackingData);
const insertNew = rxFrom(
this.supabase.from(this.paths.rack_modules)
.upsert(newRackedModules)
);
// call database for insert if there is any to insert
return newRackedModules.length > 0 ? insertNew : of(x);
})
// this updated rack after its modules are updated
// switchMap(x => this.supabase.from(this.paths.racks)
// .upsert({
// id: rackId
// })
// .filter('id', 'eq', rackId) // forces updated refresh
// );
);
// .pipe(tap(x => SharedConstants.showSuccessUpdate(this.snackBar)));
},
rack: (data: RackMinimal) => {
return rxFrom(
this.supabase.from(this.paths.racks)
.upsert({
id: data.id,
authorid: data.author.id,
name: data.name,
description: data.description,
rows: data.rows,
hp: data.hp,
locked: data.locked
})
);
// .pipe(tap(x => SharedConstants.showSuccessUpdate(this.snackBar)));
},
patch: (data: Patch) => {
data.author = undefined;
return rxFrom(
this.supabase.from(this.paths.patches)
.update(data)
.eq('id', data.id)
.single()
)
.pipe(tap(x => SharedConstants.showSuccessUpdate(this.snackBar)));


Step 2: ⌨️ Coding

  • Modify src/app/features/backend/supabase.service.tsd051d76 Edit
Modify src/app/features/backend/supabase.service.ts with contents:
• Modify the `update.rack` method to accept a new parameter for the rack's height.
• Ensure that the `upsert` call includes the new height in the data payload.
• The method signature should be changed to include the new height parameter, and the payload should be updated accordingly.
--- 
+++ 
@@ -528,10 +528,11 @@
         );
       // .pipe(tap(x => SharedConstants.showSuccessUpdate(this.snackBar)));
     },
-    rack:          (data: RackMinimal) => {
+    rack:          (data: RackMinimal, height: number) => {
       return rxFrom(
         this.supabase.from(this.paths.racks)
             .upsert({
+              height,
               id:          data.id,
               authorid:    data.author.id,
               name:        data.name,
  • Running GitHub Actions for src/app/features/backend/supabase.service.tsEdit
Check src/app/features/backend/supabase.service.ts with contents:

Ran GitHub Actions for d051d768674d213295756e414450bfd8e090c302:

  • Modify src/app/components/rack-parts/rack-details/rack-details.component.tsdd9fb49 Edit
Modify src/app/components/rack-parts/rack-details/rack-details.component.ts with contents:
• Add a new input field to the component's template for users to enter the new height of the rack.
• Bind the input field to a new property in the component's class.
• Add a new method in the component's class to handle the height update, which should call the modified `update.rack` method from the `supabase.service.ts`.
• The new method should pass the current rack's ID and the new height as arguments to the `update.rack` method.
--- 
+++ 
@@ -12,6 +12,7 @@
   changeDetection: ChangeDetectionStrategy.OnPush
 })
 export class RackDetailsComponent extends SubManager implements OnInit {
+  newHeight: number;
   @Input() data: RackMinimal;
   
   constructor(
@@ -28,3 +29,11 @@
   
   
 }
+  updateRackHeight(): void {
+    if (this.newHeight && this.data && this.data.id) {
+      this.backend.update.rack({ ...this.data, height: this.newHeight }).subscribe({
+        next: () => this.snackBar.open('Rack height updated successfully', 'Close', { duration: 3000 }),
+        error: () => this.snackBar.open('Failed to update rack height', 'Close', { duration: 3000 })
+      });
+    }
+  }
  • Running GitHub Actions for src/app/components/rack-parts/rack-details/rack-details.component.tsEdit
Check src/app/components/rack-parts/rack-details/rack-details.component.ts with contents:

Ran GitHub Actions for dd9fb496a33b1eb4302e654194de2c5549af5948:

  • Modify src/app/components/rack-parts/rack-detail-data.service.ts2e5b3b9 Edit
Modify src/app/components/rack-parts/rack-detail-data.service.ts with contents:
• Add a new method to handle the logic for updating the rack's height.
• This method should take the new height as a parameter and call the modified `update.rack` method from `supabase.service.ts`.
• Ensure that the `singleRackData$` observable is updated with the new height after the update is successful.
--- 
+++ 
@@ -17,6 +17,19 @@
 
 @Injectable()
 export class RackDetailDataService extends SubManager {
+
+  updateRackHeight(newHeight: number): void {
+    const currentRackData = this.singleRackData$.value;
+    if (currentRackData) {
+      this.backend.update.rack({...currentRackData, height: newHeight}).subscribe({
+        next: updatedRack => {
+          this.singleRackData$.next(updatedRack);
+          this.snackBar.open('Rack height updated successfully', 'Close', { duration: 3000 });
+        },
+        error: () => this.snackBar.open('Failed to update rack height', 'Close', { duration: 3000 })
+      });
+    }
+  }
   updateSingleRackData$ = new ReplaySubject();
   singleRackData$ = new BehaviorSubject(undefined);
   deleteRack$ = new Subject();
  • Running GitHub Actions for src/app/components/rack-parts/rack-detail-data.service.tsEdit
Check src/app/components/rack-parts/rack-detail-data.service.ts with contents:

Ran GitHub Actions for 2e5b3b944a90705984cc129a835442f07438b618:


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/allow_to_update_the_height_of_an_already.


🎉 Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request.Something wrong? Let us know.

This is an automated message generated by Sweep AI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sweep Sweep your software chores
Projects
None yet
1 participant