-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pop-up with filename to EntityUpload (#955)
- Loading branch information
1 parent
628644e
commit 00d8409
Showing
7 changed files
with
278 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<!-- | ||
Copyright 2024 ODK Central Developers | ||
See the NOTICE file at the top-level directory of this distribution and at | ||
https://github.com/getodk/central-frontend/blob/master/NOTICE. | ||
|
||
This file is part of ODK Central. It is subject to the license terms in | ||
the LICENSE file found in the top-level directory of this distribution and at | ||
https://www.apache.org/licenses/LICENSE-2.0. No part of ODK Central, | ||
including this file, may be copied, modified, propagated, or distributed | ||
except according to the terms contained in the LICENSE file. | ||
--> | ||
<template> | ||
<div id="entity-upload-popup"> | ||
<div id="entity-upload-popup-heading"> | ||
<div v-tooltip.text>{{ filename }}</div> | ||
<button v-show="!awaitingResponse" type="button" class="close" | ||
:aria-label="$t('action.clear')" @click="$emit('clear')"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
<div id="entity-upload-popup-count">{{ $tcn('rowCount', count) }}</div> | ||
<div v-show="awaitingResponse" id="entity-upload-popup-status"> | ||
<spinner :state="true" inline/><span>{{ status }}</span> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { computed } from 'vue'; | ||
import { useI18n } from 'vue-i18n'; | ||
|
||
import Spinner from '../../spinner.vue'; | ||
|
||
defineOptions({ | ||
name: 'EntityUploadPopup' | ||
}); | ||
const props = defineProps({ | ||
filename: { | ||
type: String, | ||
required: true | ||
}, | ||
count: { | ||
type: Number, | ||
required: true | ||
}, | ||
awaitingResponse: Boolean, | ||
progress: { | ||
type: Number, | ||
required: true | ||
} | ||
}); | ||
defineEmits(['clear']); | ||
|
||
const { t, n } = useI18n(); | ||
const status = computed(() => (props.progress < 1 | ||
? t('status.sending', { percentUploaded: n(props.progress, 'percent') }) | ||
: t('status.processing'))); | ||
</script> | ||
|
||
<style lang="scss"> | ||
@use 'sass:color'; | ||
@import '../../../assets/scss/mixins'; | ||
|
||
#entity-upload-popup { | ||
background-color: $color-subpanel-background; | ||
border: 2px solid $color-action-foreground; | ||
border-radius: 6px; | ||
outline: 5px solid #{color.change($color-action-foreground, $alpha: 0.15)}; | ||
padding: 15px; | ||
} | ||
|
||
#entity-upload-popup-heading { | ||
align-items: baseline; | ||
display: flex; | ||
|
||
> div { | ||
@include text-overflow-ellipsis; | ||
font-size: 18px; | ||
font-weight: bold; | ||
} | ||
|
||
.close { | ||
flex-shrink: 0; | ||
margin-left: 6px; | ||
opacity: 0.5; | ||
|
||
&:hover, &:focus { opacity: 0.2; } | ||
} | ||
} | ||
|
||
#entity-upload-popup-status { | ||
margin-bottom: 5px; | ||
margin-top: 15px; | ||
|
||
.spinner + span { | ||
font-weight: bold; | ||
margin-left: 6px; | ||
} | ||
} | ||
</style> | ||
|
||
<i18n lang="json5"> | ||
{ | ||
"en": { | ||
"rowCount": "{count} data row found | {count} data rows found", | ||
"status": { | ||
// This text is shown while a file is being uploaded to the server. | ||
"sending": "Sending file… ({percentUploaded})", | ||
// This text is shown after a file has been uploaded to the server, but | ||
// before the server has finished processing it. | ||
"processing": "Processing file…" | ||
} | ||
} | ||
} | ||
</i18n> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import EntityUploadPopup from '../../../../src/components/entity/upload/popup.vue'; | ||
|
||
import { mergeMountOptions, mount } from '../../../util/lifecycle'; | ||
|
||
const mountComponent = (options = undefined) => | ||
mount(EntityUploadPopup, mergeMountOptions(options, { | ||
props: { filename: 'my_data.csv', count: 1, progress: 0 } | ||
})); | ||
|
||
describe('EntityUploadPopup', () => { | ||
it('shows the filename', async () => { | ||
const div = mountComponent().get('#entity-upload-popup-heading div'); | ||
div.text().should.equal('my_data.csv'); | ||
await div.should.have.textTooltip(); | ||
}); | ||
|
||
describe('clear button', () => { | ||
it('emits a clear event if it is clicked', async () => { | ||
const component = mountComponent(); | ||
await component.get('.close').trigger('click'); | ||
component.emitted().clear.should.eql([[]]); | ||
}); | ||
|
||
it('is hidden if the awaitingResponse prop is true', () => { | ||
const component = mountComponent({ | ||
props: { awaitingResponse: true } | ||
}); | ||
component.get('.close').should.be.hidden(); | ||
}); | ||
}); | ||
|
||
it('shows the count', () => { | ||
const component = mountComponent({ | ||
props: { count: 1000 } | ||
}); | ||
const text = component.get('#entity-upload-popup-count').text(); | ||
text.should.equal('1,000 data rows found'); | ||
}); | ||
|
||
describe('request status', () => { | ||
it('does not show a status if there is no request', () => { | ||
const component = mountComponent({ | ||
props: { awaitingResponse: false } | ||
}); | ||
component.get('#entity-upload-popup-status').should.be.hidden(); | ||
}); | ||
|
||
it('shows the status during a request', () => { | ||
const component = mountComponent({ | ||
props: { awaitingResponse: true } | ||
}); | ||
component.get('#entity-upload-popup-status').should.be.visible(); | ||
}); | ||
|
||
it('shows the upload progress', () => { | ||
const component = mountComponent({ | ||
props: { awaitingResponse: true, progress: 0.5 } | ||
}); | ||
const text = component.get('#entity-upload-popup-status').text(); | ||
text.should.equal('Sending file… (50%)'); | ||
}); | ||
|
||
it('changes the status once all data has been sent', () => { | ||
const component = mountComponent({ | ||
props: { awaitingResponse: true, progress: 1 } | ||
}); | ||
const text = component.get('#entity-upload-popup-status').text(); | ||
text.should.equal('Processing file…'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Spinner from '../../src/components/spinner.vue'; | ||
|
||
import { mount } from '../util/lifecycle'; | ||
|
||
describe('Spinner', () => { | ||
it('adds the correct class if the state prop is true', () => { | ||
const spinner = mount(Spinner, { | ||
props: { state: true } | ||
}); | ||
spinner.classes('active').should.be.true(); | ||
}); | ||
|
||
it('adds the correct class if the inline prop is true', () => { | ||
const spinner = mount(Spinner, { | ||
props: { inline: true } | ||
}); | ||
spinner.classes('inline').should.be.true(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters