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

fix: Adds success messaging for add to collection modal #1093

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions app/components/collection/modal/add-to-collection/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { createCollectionBody, getCollectionsWithoutPipeline } from './util';
export default class CollectionModalAddToCollectionModalComponent extends Component {
@service shuttle;

@tracked errorMessage;
@tracked errorMessage = null;

@tracked successMessage = null;

@tracked newCollectionName = '';

Expand Down Expand Up @@ -60,6 +62,7 @@ export default class CollectionModalAddToCollectionModalComponent extends Compon
)
)
.then(() => {
this.successMessage = `Successfully created new collection: ${this.newCollectionName}`;
this.newCollectionName = '';
this.newCollectionDescription = '';
})
Expand Down Expand Up @@ -95,6 +98,7 @@ export default class CollectionModalAddToCollectionModalComponent extends Compon
async submitCollections() {
this.isAwaitingResponse = true;
this.errorMessage = null;
this.successMessage = null;

return new Promise(resolve => {
Promise.allSettled([
Expand All @@ -114,12 +118,24 @@ export default class CollectionModalAddToCollectionModalComponent extends Compon
)}`;
}
} else {
this.selectedCollections.forEach(collection => {
document.getElementById(
`collection-${collection.id}`
).disabled = true;
});
this.selectedCollections = [];
const collectionNames = this.selectedCollections
.map(collection => collection.name)
.join(', ');

if (collectionNames.length > 0) {
if (this.successMessage) {
this.successMessage += `. Also added pipeline to collections: ${collectionNames}`;
} else {
this.successMessage = `Successfully added pipeline to collections: ${collectionNames}`;
}

this.selectedCollections.forEach(collection => {
document.getElementById(
`collection-${collection.id}`
).disabled = true;
});
this.selectedCollections = [];
}
}
resolve();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
@icon="exclamation-triangle"
/>
{{/if}}
{{#if this.successMessage}}
<InfoMessage
@message={{this.successMessage}}
@type="success"
@icon="check-circle"
/>
{{/if}}
<div class="modal-title">Add to a new collection</div>
<div class="create-new-collection">
<label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ module(
assert.dom('#submit-collections').isEnabled();
});

test('it makes API request to create new collection', async function (assert) {
test('it makes show message indicating new collection was created successfully', async function (assert) {
const shuttle = this.owner.lookup('service:shuttle');
const shuttleStub = sinon.stub(shuttle, 'fetchFromApi').resolves();

Expand All @@ -146,6 +146,10 @@ module(
),
true
);
assert.dom('.alert').exists({ count: 1 });
assert
.dom('.alert > span')
.hasText('Successfully created new collection: New Collection');
});

test('it sets error message when creating a new collection fails', async function (assert) {
Expand All @@ -169,11 +173,11 @@ module(

assert.dom('.alert').exists({ count: 1 });
assert
.dom('.alert')
.hasText('× Failed to create new collection: New Collection');
.dom('.alert > span')
.hasText('Failed to create new collection: New Collection');
});

test('it makes API request to add to an existing collection', async function (assert) {
test('it displays message indicating adding pipeline to existing collection was successful', async function (assert) {
const shuttle = this.owner.lookup('service:shuttle');
const shuttleStub = sinon.stub(shuttle, 'fetchFromApi').resolves();

Expand All @@ -198,6 +202,10 @@ module(
shuttleStub.calledWith('put', '/collections/1', { pipelineIds: [123] }),
true
);
assert.dom('.alert').exists({ count: 1 });
assert
.dom('.alert > span')
.hasText('Successfully added pipeline to collections: Test');
});

test('it sets error message when adding to an existing collection fails', async function (assert) {
Expand All @@ -223,11 +231,11 @@ module(

assert.dom('.alert').exists({ count: 1 });
assert
.dom('.alert')
.hasText('× Failed to add pipeline to collections: Test');
.dom('.alert > span')
.hasText('Failed to add pipeline to collections: Test');
});

test('it makes API requests when creating and adding to collections', async function (assert) {
test('it displays message indicating creating and adding to collections was successful', async function (assert) {
const shuttle = this.owner.lookup('service:shuttle');
const shuttleStub = sinon.stub(shuttle, 'fetchFromApi').resolves();

Expand All @@ -253,6 +261,12 @@ module(
await click('#submit-collections');

assert.equal(shuttleStub.callCount, 3);
assert.dom('.alert').exists({ count: 1 });
assert
.dom('.alert > span')
.hasText(
'Successfully created new collection: New Collection. Also added pipeline to collections: Test, Funny'
);
});

test('it sets error messages when creating and adding to collections fails', async function (assert) {
Expand Down Expand Up @@ -283,9 +297,9 @@ module(

assert.dom('.alert').exists({ count: 1 });
assert
.dom('.alert')
.dom('.alert > span')
.hasText(
'× Failed to create new collection: New Collection. Also failed to add pipeline to collections: Test, Funny'
'Failed to create new collection: New Collection. Also failed to add pipeline to collections: Test, Funny'
);
});
}
Expand Down