Commit 9b5e5ff4 authored by Phil Hughes's avatar Phil Hughes

Adds a shouldCollapse computed prop to widget extensions

Adds the a `shouldCollapse` computed property to widget extension
which can be used to tell the base component that more content
will be available if expanded.

Closes https://gitlab.com/gitlab-org/gitlab/-/issues/354492
parent 496e7198
...@@ -66,7 +66,15 @@ export default { ...@@ -66,7 +66,15 @@ export default {
return this.loadingState === LOADING_STATES.expandedLoading; return this.loadingState === LOADING_STATES.expandedLoading;
}, },
isCollapsible() { isCollapsible() {
return !this.isLoadingSummary && this.loadingState !== LOADING_STATES.collapsedError; if (!this.isLoadingSummary && this.loadingState !== LOADING_STATES.collapsedError) {
if (this.shouldCollapse) {
return this.shouldCollapse();
}
return true;
}
return false;
}, },
hasFullData() { hasFullData() {
return this.fullData.length > 0; return this.fullData.length > 0;
...@@ -128,7 +136,7 @@ export default { ...@@ -128,7 +136,7 @@ export default {
} }
}), }),
toggleCollapsed(e) { toggleCollapsed(e) {
if (!e?.target?.closest('.btn:not(.btn-icon),a')) { if (this.isCollapsible && !e?.target?.closest('.btn:not(.btn-icon),a')) {
this.isCollapsed = !this.isCollapsed; this.isCollapsed = !this.isCollapsed;
this.triggerRedisTracking(); this.triggerRedisTracking();
...@@ -226,7 +234,12 @@ export default { ...@@ -226,7 +234,12 @@ export default {
<template> <template>
<section class="media-section" data-testid="widget-extension"> <section class="media-section" data-testid="widget-extension">
<div class="media gl-p-5 gl-cursor-pointer" @mousedown="onRowMouseDown" @mouseup="onRowMouseUp"> <div
:class="{ 'gl-cursor-pointer': isCollapsible }"
class="media gl-p-5"
@mousedown="onRowMouseDown"
@mouseup="onRowMouseUp"
>
<status-icon <status-icon
:name="$options.label || $options.name" :name="$options.label || $options.name"
:is-loading="isLoadingSummary" :is-loading="isLoadingSummary"
......
...@@ -48,6 +48,9 @@ export default { ...@@ -48,6 +48,9 @@ export default {
{ text: 'Full report', href: this.conflictsDocsPath, target: '_blank' }, { text: 'Full report', href: this.conflictsDocsPath, target: '_blank' },
]; ];
}, },
shouldCollapse() {
return true;
},
}, },
methods: { methods: {
// Fetches the collapsed data // Fetches the collapsed data
......
...@@ -40,6 +40,7 @@ export default { ...@@ -40,6 +40,7 @@ export default {
summary(data) {}, // Required: Level 1 summary text summary(data) {}, // Required: Level 1 summary text
statusIcon(data) {}, // Required: Level 1 status icon statusIcon(data) {}, // Required: Level 1 status icon
tertiaryButtons() {}, // Optional: Level 1 action buttons tertiaryButtons() {}, // Optional: Level 1 action buttons
shouldCollapse() {}, // Optional: Add logic to determine if the widget can expand or not
}, },
methods: { methods: {
fetchCollapsedData(props) {}, // Required: Fetches data required for collapsed state fetchCollapsedData(props) {}, // Required: Fetches data required for collapsed state
......
...@@ -46,6 +46,8 @@ describe('MrWidgetOptions', () => { ...@@ -46,6 +46,8 @@ describe('MrWidgetOptions', () => {
let mock; let mock;
const COLLABORATION_MESSAGE = 'Members who can merge are allowed to add commits'; const COLLABORATION_MESSAGE = 'Members who can merge are allowed to add commits';
const findExtensionToggleButton = () =>
wrapper.find('[data-testid="widget-extension"] [data-testid="toggle-button"]');
beforeEach(() => { beforeEach(() => {
gl.mrWidgetData = { ...mockData }; gl.mrWidgetData = { ...mockData };
...@@ -905,7 +907,7 @@ describe('MrWidgetOptions', () => { ...@@ -905,7 +907,7 @@ describe('MrWidgetOptions', () => {
beforeEach(() => { beforeEach(() => {
pollRequest = jest.spyOn(Poll.prototype, 'makeRequest'); pollRequest = jest.spyOn(Poll.prototype, 'makeRequest');
registerExtension(workingExtension); registerExtension(workingExtension());
createComponent(); createComponent();
}); });
...@@ -937,9 +939,7 @@ describe('MrWidgetOptions', () => { ...@@ -937,9 +939,7 @@ describe('MrWidgetOptions', () => {
it('renders full data', async () => { it('renders full data', async () => {
await waitForPromises(); await waitForPromises();
wrapper findExtensionToggleButton().trigger('click');
.find('[data-testid="widget-extension"] [data-testid="toggle-button"]')
.trigger('click');
await nextTick(); await nextTick();
...@@ -975,6 +975,24 @@ describe('MrWidgetOptions', () => { ...@@ -975,6 +975,24 @@ describe('MrWidgetOptions', () => {
}); });
}); });
describe('expansion', () => {
it('hides collapse button', async () => {
registerExtension(workingExtension(false));
createComponent();
await waitForPromises();
expect(findExtensionToggleButton().exists()).toBe(false);
});
it('shows collapse button', async () => {
registerExtension(workingExtension(true));
createComponent();
await waitForPromises();
expect(findExtensionToggleButton().exists()).toBe(true);
});
});
describe('mock polling extension', () => { describe('mock polling extension', () => {
let pollRequest; let pollRequest;
let pollStop; let pollStop;
......
import { EXTENSION_ICONS } from '~/vue_merge_request_widget/constants'; import { EXTENSION_ICONS } from '~/vue_merge_request_widget/constants';
export const workingExtension = { export const workingExtension = (shouldCollapse = true) => ({
name: 'WidgetTestExtension', name: 'WidgetTestExtension',
props: ['targetProjectFullPath'], props: ['targetProjectFullPath'],
expandEvent: 'test_expand_event', expandEvent: 'test_expand_event',
...@@ -11,6 +11,9 @@ export const workingExtension = { ...@@ -11,6 +11,9 @@ export const workingExtension = {
statusIcon({ count }) { statusIcon({ count }) {
return count > 0 ? EXTENSION_ICONS.warning : EXTENSION_ICONS.success; return count > 0 ? EXTENSION_ICONS.warning : EXTENSION_ICONS.success;
}, },
shouldCollapse() {
return shouldCollapse;
},
}, },
methods: { methods: {
fetchCollapsedData({ targetProjectFullPath }) { fetchCollapsedData({ targetProjectFullPath }) {
...@@ -36,7 +39,7 @@ export const workingExtension = { ...@@ -36,7 +39,7 @@ export const workingExtension = {
]); ]);
}, },
}, },
}; });
export const collapsedDataErrorExtension = { export const collapsedDataErrorExtension = {
name: 'WidgetTestCollapsedErrorExtension', name: 'WidgetTestCollapsedErrorExtension',
...@@ -99,7 +102,7 @@ export const fullDataErrorExtension = { ...@@ -99,7 +102,7 @@ export const fullDataErrorExtension = {
}; };
export const pollingExtension = { export const pollingExtension = {
...workingExtension, ...workingExtension(),
enablePolling: true, enablePolling: true,
}; };
......
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