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

Hide problem alerts after successful new dataset/property requests #967

Merged
merged 2 commits into from
Apr 15, 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
5 changes: 4 additions & 1 deletion src/components/dataset/new.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ except according to the terms contained in the LICENSE file.
</template>

<script setup>
import { ref, watch } from 'vue';
import { inject, ref, watch } from 'vue';
import { equals } from 'ramda';
import { useI18n } from 'vue-i18n';

Expand Down Expand Up @@ -91,6 +91,7 @@ const step = ref(0);
const createdDataset = ref(null);

const emit = defineEmits(['hide', 'success']);
const alert = inject('alert');

watch(() => props.state, (state) => {
if (!state) name.value = '';
Expand All @@ -108,6 +109,8 @@ const submit = () => {
: null)
})
.then(({ data }) => {
// Reset the alert
alert.blank();
// Reset the form
name.value = '';
step.value = 1;
Expand Down
18 changes: 15 additions & 3 deletions src/components/dataset/overview/new-property.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ except according to the terms contained in the LICENSE file.
</template>

<script setup>
import { ref, watch } from 'vue';
import { inject, ref, watch } from 'vue';
import { equals } from 'ramda';
import { useI18n } from 'vue-i18n';

import Modal from '../../modal.vue';
import FormGroup from '../../form-group.vue';
Expand All @@ -64,18 +66,25 @@ const nameGroup = ref(null);
const name = ref('');

const emit = defineEmits(['hide', 'success']);
const alert = inject('alert');

watch(() => props.state, (state) => {
if (!state) name.value = '';
});

const { t } = useI18n();
const submit = () => {
request({
method: 'POST',
url: apiPaths.datasetProperties(project.id, dataset.name),
data: { name: name.value }
data: { name: name.value },
problemToAlert: ({ code, details }) =>
(code === 409.3 && equals(details.fields, ['name', 'datasetId'])
? t('problem.409_3', { propertyName: details.values[0] })
: null)
})
.then(() => {
alert.blank();
emit('success');
})
.catch(noop);
Expand All @@ -91,7 +100,10 @@ const submit = () => {
"To add an Entity property, choose a unique property name below.",
"You can also add new properties by uploading a Form that references them, in which case the properties are created when the Form is published."
],
"newPropertyName": "New property name"
"newPropertyName": "New property name",
"problem": {
"409_3": "A property already exists in this Entity List with the name of “{propertyName}”."
Copy link
Member

@matthew-white matthew-white Apr 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually just use quotes for strings that might contain a space. Since propertyName will be a single word, what do you think about removing the quotes around {propertyName}? No strong feelings!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the quotes isolate the name better than without them, since there is no other formatting.

},
}
}
</i18n>
21 changes: 21 additions & 0 deletions test/components/dataset/overview/property-new.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,25 @@ describe('DatasetPropertyNew', () => {
connections.find('.caption-cell').text().should.equal('1 of 2 properties');
});
});

it('shows a custom message for a duplicate property name', () =>
mockHttp()
.mount(DatasetPropertyNew, mountOptions())
.request(async (modal) => {
await modal.get('input').setValue('my_new_property');
return modal.get('form').trigger('submit');
})
.respondWithProblem({
code: 409.3,
message: 'A resource already exists with name,datasetId value(s) of my_new_property,1.',
details: {
fields: ['name', 'datasetId'],
values: ['my_new_property', 1]
}
})
.afterResponse(modal => {
modal.should.alert('danger', (message) => {
message.should.startWith('A property already exists in this Entity List with the name of “my_new_property”.');
});
}));
});
5 changes: 5 additions & 0 deletions transifex/strings_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1481,6 +1481,11 @@
},
"newPropertyName": {
"string": "New property name"
},
"problem": {
"409_3": {
"string": "A property already exists in this Entity List with the name of “{propertyName}”."
}
}
},
"DatasetPendingSubmissions": {
Expand Down