Commit 3af09062 authored by Martin Wortschack's avatar Martin Wortschack

Merge branch 'tq/loading-spinner-on-load-for-design-images' into 'master'

Show spinner on Design Card images when loading

See merge request gitlab-org/gitlab!27475
parents c27e6fc5 b5fa12d7
...@@ -37,12 +37,17 @@ export default { ...@@ -37,12 +37,17 @@ export default {
required: false, required: false,
default: null, default: null,
}, },
isLoading: { isUploading: {
type: Boolean, type: Boolean,
required: false, required: false,
default: false, default: true,
}, },
}, },
data() {
return {
imageLoading: true,
};
},
computed: { computed: {
icon() { icon() {
const normalizedEvent = this.event.toLowerCase(); const normalizedEvent = this.event.toLowerCase();
...@@ -69,6 +74,14 @@ export default { ...@@ -69,6 +74,14 @@ export default {
notesLabel() { notesLabel() {
return n__('%d comment', '%d comments', this.notesCount); return n__('%d comment', '%d comments', this.notesCount);
}, },
showLoadingSpinner() {
return this.imageLoading || this.isUploading;
},
},
methods: {
onImageLoad() {
this.imageLoading = false;
},
}, },
DESIGN_ROUTE_NAME, DESIGN_ROUTE_NAME,
}; };
...@@ -89,13 +102,14 @@ export default { ...@@ -89,13 +102,14 @@ export default {
<icon :name="icon.name" :size="18" :class="icon.classes" /> <icon :name="icon.name" :size="18" :class="icon.classes" />
</span> </span>
</div> </div>
<gl-loading-icon v-if="isLoading" size="md" /> <gl-loading-icon v-show="showLoadingSpinner" size="md" />
<img <img
v-else v-show="!showLoadingSpinner"
:src="image" :src="image"
:alt="filename" :alt="filename"
class="block ml-auto mr-auto mw-100 mh-100 design-img" class="block ml-auto mr-auto mw-100 mh-100 design-img"
data-qa-selector="design_image" data-qa-selector="design_image"
@load="onImageLoad"
/> />
</div> </div>
<div class="card-footer d-flex w-100"> <div class="card-footer d-flex w-100">
......
...@@ -270,7 +270,7 @@ export default { ...@@ -270,7 +270,7 @@ export default {
</li> </li>
<li v-for="design in designs" :key="design.id" class="col-md-6 col-lg-4 mb-3"> <li v-for="design in designs" :key="design.id" class="col-md-6 col-lg-4 mb-3">
<design-dropzone @change="onExistingDesignDropzoneChange($event, design.filename)" <design-dropzone @change="onExistingDesignDropzoneChange($event, design.filename)"
><design v-bind="design" :is-loading="isDesignToBeSaved(design.filename)" ><design v-bind="design" :is-uploading="isDesignToBeSaved(design.filename)"
/></design-dropzone> /></design-dropzone>
<input <input
......
---
title: Display loading spinner when Design Card images are loading
merge_request: 27475
author:
type: added
...@@ -29,7 +29,7 @@ describe 'User views an SVG design that contains XSS', :js do ...@@ -29,7 +29,7 @@ describe 'User views an SVG design that contains XSS', :js do
end end
it 'displays the SVG' do it 'displays the SVG' do
expect(page).to have_selector("img.design-img[alt='xss.svg']", count: 1) expect(page).to have_selector("img.design-img[alt='xss.svg']", count: 1, visible: false)
end end
it 'does not execute the JavaScript within the SVG' do it 'does not execute the JavaScript within the SVG' do
......
...@@ -23,6 +23,13 @@ exports[`Design management list item component with no notes renders item with c ...@@ -23,6 +23,13 @@ exports[`Design management list item component with no notes renders item with c
</span> </span>
</div> </div>
<gl-loading-icon-stub
color="orange"
label="Loading"
size="md"
style="display: none;"
/>
<img <img
alt="test" alt="test"
class="block ml-auto mr-auto mw-100 mh-100 design-img" class="block ml-auto mr-auto mw-100 mh-100 design-img"
...@@ -85,6 +92,13 @@ exports[`Design management list item component with no notes renders item with c ...@@ -85,6 +92,13 @@ exports[`Design management list item component with no notes renders item with c
</span> </span>
</div> </div>
<gl-loading-icon-stub
color="orange"
label="Loading"
size="md"
style="display: none;"
/>
<img <img
alt="test" alt="test"
class="block ml-auto mr-auto mw-100 mh-100 design-img" class="block ml-auto mr-auto mw-100 mh-100 design-img"
...@@ -147,6 +161,13 @@ exports[`Design management list item component with no notes renders item with c ...@@ -147,6 +161,13 @@ exports[`Design management list item component with no notes renders item with c
</span> </span>
</div> </div>
<gl-loading-icon-stub
color="orange"
label="Loading"
size="md"
style="display: none;"
/>
<img <img
alt="test" alt="test"
class="block ml-auto mr-auto mw-100 mh-100 design-img" class="block ml-auto mr-auto mw-100 mh-100 design-img"
...@@ -196,6 +217,13 @@ exports[`Design management list item component with no notes renders item with n ...@@ -196,6 +217,13 @@ exports[`Design management list item component with no notes renders item with n
> >
<!----> <!---->
<gl-loading-icon-stub
color="orange"
label="Loading"
size="md"
style="display: none;"
/>
<img <img
alt="test" alt="test"
class="block ml-auto mr-auto mw-100 mh-100 design-img" class="block ml-auto mr-auto mw-100 mh-100 design-img"
...@@ -235,7 +263,7 @@ exports[`Design management list item component with no notes renders item with n ...@@ -235,7 +263,7 @@ exports[`Design management list item component with no notes renders item with n
</router-link-stub> </router-link-stub>
`; `;
exports[`Design management list item component with no notes renders loading spinner when isLoading is true 1`] = ` exports[`Design management list item component with no notes renders loading spinner when isUploading is true 1`] = `
<router-link-stub <router-link-stub
class="card cursor-pointer text-plain js-design-list-item design-list-item" class="card cursor-pointer text-plain js-design-list-item design-list-item"
to="[object Object]" to="[object Object]"
...@@ -250,6 +278,14 @@ exports[`Design management list item component with no notes renders loading spi ...@@ -250,6 +278,14 @@ exports[`Design management list item component with no notes renders loading spi
label="Loading" label="Loading"
size="md" size="md"
/> />
<img
alt="test"
class="block ml-auto mr-auto mw-100 mh-100 design-img"
data-qa-selector="design_image"
src="http://via.placeholder.com/300"
style="display: none;"
/>
</div> </div>
<div <div
...@@ -293,6 +329,13 @@ exports[`Design management list item component with notes renders item with mult ...@@ -293,6 +329,13 @@ exports[`Design management list item component with notes renders item with mult
> >
<!----> <!---->
<gl-loading-icon-stub
color="orange"
label="Loading"
size="md"
style="display: none;"
/>
<img <img
alt="test" alt="test"
class="block ml-auto mr-auto mw-100 mh-100 design-img" class="block ml-auto mr-auto mw-100 mh-100 design-img"
...@@ -359,6 +402,13 @@ exports[`Design management list item component with notes renders item with sing ...@@ -359,6 +402,13 @@ exports[`Design management list item component with notes renders item with sing
> >
<!----> <!---->
<gl-loading-icon-stub
color="orange"
label="Loading"
size="md"
style="display: none;"
/>
<img <img
alt="test" alt="test"
class="block ml-auto mr-auto mw-100 mh-100 design-img" class="block ml-auto mr-auto mw-100 mh-100 design-img"
......
...@@ -19,7 +19,8 @@ describe('Design management list item component', () => { ...@@ -19,7 +19,8 @@ describe('Design management list item component', () => {
function createComponent({ function createComponent({
notesCount = 0, notesCount = 0,
event = DESIGN_VERSION_EVENT.NO_CHANGE, event = DESIGN_VERSION_EVENT.NO_CHANGE,
isLoading = false, isUploading = false,
imageLoading = false,
} = {}) { } = {}) {
wrapper = shallowMount(Item, { wrapper = shallowMount(Item, {
localVue, localVue,
...@@ -28,11 +29,16 @@ describe('Design management list item component', () => { ...@@ -28,11 +29,16 @@ describe('Design management list item component', () => {
id: 1, id: 1,
filename: 'test', filename: 'test',
image: 'http://via.placeholder.com/300', image: 'http://via.placeholder.com/300',
isLoading, isUploading,
event, event,
notesCount, notesCount,
updatedAt: '01-01-2019', updatedAt: '01-01-2019',
}, },
data() {
return {
imageLoading,
};
},
stubs: ['router-link'], stubs: ['router-link'],
}); });
} }
...@@ -80,8 +86,8 @@ describe('Design management list item component', () => { ...@@ -80,8 +86,8 @@ describe('Design management list item component', () => {
expect(wrapper.element).toMatchSnapshot(); expect(wrapper.element).toMatchSnapshot();
}); });
it('renders loading spinner when isLoading is true', () => { it('renders loading spinner when isUploading is true', () => {
createComponent({ isLoading: true }); createComponent({ isUploading: true });
expect(wrapper.element).toMatchSnapshot(); expect(wrapper.element).toMatchSnapshot();
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment