Skip to content

Commit

Permalink
Merge pull request #2396 from codecrafters-io/delete-repository-inline
Browse files Browse the repository at this point in the history
delete repository inline
  • Loading branch information
rohitpaulk authored Nov 16, 2024
2 parents d45b2d2 + 53b3f40 commit 3a94ecc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/components/course-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default class CourseCardComponent extends Component {
return {
name: 'course',
model: this.args.course.slug,
query: { fresh: null },
query: { repo: null }, // Route will pickup the last used repository by default
};
} else {
return {
Expand Down
6 changes: 5 additions & 1 deletion app/components/course-page/delete-repository-modal.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
</div>

<DangerButtonWithTimedConfirmation @onConfirm={{this.deleteRepository}} @size="regular" data-test-delete-repository-button>
Delete
{{#if this.isDeleting}}
Deleting...
{{else}}
Delete
{{/if}}
</DangerButtonWithTimedConfirmation>
</ModalBody>
16 changes: 12 additions & 4 deletions app/components/course-page/delete-repository-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import Component from '@glimmer/component';
import RepositoryModel from 'codecrafters-frontend/models/repository';
import RouterService from '@ember/routing/router-service';
import Store from '@ember-data/store';
import window from 'ember-window-mock';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';

interface Signature {
Element: HTMLDivElement;
Expand All @@ -16,6 +16,8 @@ interface Signature {
}

export default class DeleteRepositoryModalComponent extends Component<Signature> {
@tracked isDeleting: boolean = false;

@service declare router: RouterService;
@service declare store: Store;

Expand All @@ -25,9 +27,15 @@ export default class DeleteRepositoryModalComponent extends Component<Signature>
return;
}

this.router.transitionTo('catalog');
await this.args.repository.destroyRecord();
window.location.reload();
if (this.isDeleting) {
return;
}

this.isDeleting = true;

const trackSlug = this.args.repository.language?.slug; // Store this before we destroy the record
await this.args.repository.destroyRecord(); // TODO: Add failure handling
this.router.transitionTo('course.introduction', { queryParams: { repo: 'new', track: trackSlug } }).followRedirects();
}
}

Expand Down
5 changes: 2 additions & 3 deletions tests/acceptance/course-page/delete-repository-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,11 @@ module('Acceptance | course-page | delete-repository-test', function (hooks) {
assert.notOk(coursePage.deleteRepositoryModal.deleteRepositoryButton.progressIndicator.isVisible, 'progress indicator should not be visible');

await coursePage.deleteRepositoryModal.deleteRepositoryButton.press();
await waitUntil(() => currentURL() === '/catalog');
await waitUntil(() => currentURL() === '/courses/dummy/introduction?repo=new&track=python');
await settled(); // Delete request triggers after redirect

await catalogPage.clickOnCourse('Build your own Dummy');
await courseOverviewPage.clickOnStartCourse();
await coursePage.repositoryDropdown.click();
assert.strictEqual(coursePage.repositoryDropdown.content.nonActiveRepositoryCount, 0, 'no repositories should be available');
assert.notOk(coursePage.repositoryDropdown.content.text.includes('Delete Repository'), 'delete repository action should not be available');
});
});

0 comments on commit 3a94ecc

Please sign in to comment.