Skip to content

Commit 4ce97d6

Browse files
authored
[#2425] Fix incorrect widgets in portfolio mode (#2435)
Fix incorrect widgets in portfolio mode Widgets in portfolio were displaying incorrect charts. Let's fix these issues and ensure widgets in portfolio mode follows portfolio mode behavior.
1 parent ee63f1b commit 4ce97d6

9 files changed

+117
-18
lines changed

frontend/cypress/configs/portfolio/repo-config.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ https://github.com/reposense/testrepo-Empty4.git,master,,,,,,,,,
66
https://github.com/reposense/testrepo-Empty5.git,master,,,,,,,,,
77
https://github.com/reposense/publish-RepoSense.git,master,,,,,,,,20/01/2019,29/12/2019
88
https://github.com/reposense/RepoSense-auth-helper.git,master,,,,,,,,01/02/2023,02/02/2023
9+
https://github.com/reposense/repoSense-action.git,main,,,,,,,,29/04/2022,02/02/2023

frontend/cypress/tests/portfolioView/portfolioView_filterBreakdown.cy.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,5 @@ describe('portfolio view filter breakdown',
7676
cy.get('#summary div.fileTypes input[id="all"]')
7777
.should('not.be.checked');
7878
});
79-
});
79+
},
80+
);

frontend/cypress/tests/portfolioView/portfolioView_header.cy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ describe('portfolio view',
3535
cy.get('#summary .summary-chart__title--name')
3636
.should('not.exist');
3737
});
38-
}
38+
},
3939
);

frontend/cypress/tests/portfolioView/portfolioView_optimiseTimeline.cy.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,4 +154,5 @@ describe('optimise timeline',
154154
cy.wrap(title).should('eq', '[2019-08-18] AboutUs: update team members (#867): +94 -12 lines ');
155155
});
156156
});
157-
});
157+
},
158+
);
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
describe('widget',
2+
{baseUrl: Cypress.env('portfolioBaseUrl')},
3+
() => {
4+
beforeEach(() => {
5+
// Stub the clipboard API to capture copied content
6+
cy.window().then((win) => {
7+
cy.stub(win.navigator.clipboard, 'writeText').as('clipboardWrite');
8+
});
9+
10+
});
11+
12+
it('group link should open the correct group\'s widget', () => {
13+
cy.get('.summary-charts__title .fa-clipboard')
14+
.first()
15+
.click()
16+
17+
// Verify clipboard content includes the iframe tag
18+
cy.get('@clipboardWrite').should('have.been.called');
19+
20+
// Verify clipboard content includes the iframe tag
21+
cy.get('@clipboardWrite').then((clipboardCall) => {
22+
const copiedText = clipboardCall.args[0][0];
23+
expect(copiedText).to.include('<iframe');
24+
expect(copiedText).to.include('src="');
25+
26+
// Extract and visit the iframe src
27+
const srcMatch = copiedText.match(/src="([^"]+)"/);
28+
expect(srcMatch).to.not.be.null;
29+
const iframeSrc = srcMatch[1];
30+
cy.visit(iframeSrc);
31+
32+
cy.get('.summary-charts__title--groupname')
33+
.should('have.length', 1)
34+
.contains('reposense/publish-RepoSense[master]');
35+
36+
cy.get('.summary-chart')
37+
.should('have.length', 1);
38+
});
39+
});
40+
41+
it('user link should open the correct user\'s widget', () => {
42+
cy.get('.summary-charts')
43+
.eq(1)
44+
.find('.summary-chart__title .fa-clipboard')
45+
.first()
46+
.click()
47+
48+
// Verify clipboard content includes the iframe tag
49+
cy.get('@clipboardWrite').should('have.been.calledOnce');
50+
51+
// Verify clipboard content includes the iframe tag
52+
cy.get('@clipboardWrite').then((clipboardCall) => {
53+
const copiedText = clipboardCall.args[0][0];
54+
expect(copiedText).to.include('<iframe');
55+
expect(copiedText).to.include('src="');
56+
57+
// Extract and visit the iframe src
58+
const srcMatch = copiedText.match(/src="([^"]+)"/);
59+
expect(srcMatch).to.not.be.null;
60+
const iframeSrc = srcMatch[1];
61+
cy.visit(iframeSrc);
62+
63+
cy.get('.summary-charts__title--groupname')
64+
.should('have.length', 1)
65+
.contains('reposense/repoSense-action[main]');
66+
67+
cy.get('.summary-chart')
68+
.should('have.length', 1);
69+
});
70+
});
71+
},
72+
);

frontend/src/mixin/summaryMixin.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export default defineComponent({
3939
fileTypeColors: { [key: string]: string },
4040
filterGroupSelectionWatcherFlag: boolean,
4141
optimiseTimeline: boolean,
42+
chartGroupIndex: number | undefined,
43+
chartIndex: number | undefined,
4244
} {
4345
return {
4446
checkedFileTypes: [],
@@ -48,6 +50,8 @@ export default defineComponent({
4850
fileTypeColors: {} as { [key: string]: string },
4951
filterGroupSelectionWatcherFlag: false,
5052
optimiseTimeline: window.isPortfolio, // Auto select trim timeline if portfolio
53+
chartGroupIndex: undefined as number | undefined,
54+
chartIndex: undefined as number | undefined,
5155
};
5256
},
5357

frontend/src/views/c-summary-portfolio.vue

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@
3131
:filter-until-date="until",
3232
:min-date="since",
3333
:max-date="until",
34-
:optimise-timeline="optimiseTimeline"
34+
:optimise-timeline="optimiseTimeline",
35+
:chart-group-index="chartGroupIndex",
36+
:chart-index="chartIndex"
3537
)
3638

3739
.logo(v-if="isWidgetMode")
@@ -96,6 +98,7 @@ export default defineComponent({
9698
const { addHash, encodeHash, removeHash } = window;
9799
98100
addHash('breakdown', this.filterBreakdown);
101+
addHash('optimiseTimeline', this.optimiseTimeline);
99102
100103
if (this.filterBreakdown) {
101104
const checkedFileTypesHash = this.checkedFileTypes.length > 0
@@ -106,12 +109,6 @@ export default defineComponent({
106109
removeHash('checkedFileTypes');
107110
}
108111
109-
if (this.optimiseTimeline) {
110-
addHash('optimiseTimeline', 'true');
111-
} else {
112-
removeHash('optimiseTimeline');
113-
}
114-
115112
encodeHash();
116113
},
117114
@@ -131,6 +128,15 @@ export default defineComponent({
131128
if (hash.optimiseTimeline) {
132129
this.optimiseTimeline = convertBool(hash.optimiseTimeline);
133130
}
131+
132+
// Widget data
133+
if (hash.chartGroupIndex) {
134+
this.chartGroupIndex = parseInt(hash.chartGroupIndex, 10);
135+
}
136+
137+
if (hash.chartIndex) {
138+
this.chartIndex = parseInt(hash.chartIndex, 10);
139+
}
134140
},
135141
136142
toggleBreakdown(): void {
@@ -166,7 +172,7 @@ export default defineComponent({
166172
167173
const filterControl = {
168174
filterGroupSelection: FilterGroupSelection.GroupByRepos,
169-
sortingOption: SortGroupSelection.GroupTitleDsc.split(' ')[0],
175+
sortingOption: SortGroupSelection.GroupTitle,
170176
sortingWithinOption: SortWithinGroupSelection.Title,
171177
isSortingDsc: false,
172178
isSortingWithinDsc: false,

frontend/src/views/c-summary.vue

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,6 @@ export default defineComponent({
121121
filterHash: string,
122122
minDate: string,
123123
maxDate: string,
124-
chartGroupIndex: number | undefined,
125-
chartIndex: number | undefined,
126124
viewRepoTags: boolean,
127125
filteredFileName: string,
128126
} {
@@ -143,8 +141,6 @@ export default defineComponent({
143141
filterHash: '',
144142
minDate: window.sinceDate,
145143
maxDate: window.untilDate,
146-
chartGroupIndex: undefined as number | undefined,
147-
chartIndex: undefined as number | undefined,
148144
viewRepoTags: false,
149145
filteredFileName: ''
150146
};

frontend/src/views/c-widget.vue

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
template(v-if="userUpdated")
33
#summary-wrapper
44
c-summary.widget-padding(
5+
v-if="!isPortfolio",
6+
ref="summary",
7+
:repos="users",
8+
:error-messages="errorMessages",
9+
:is-widget-mode="true"
10+
)
11+
12+
c-summary-portfolio.widget-padding(
13+
v-else,
514
ref="summary",
615
:repos="users",
716
:error-messages="errorMessages",
@@ -11,12 +20,16 @@ template(v-else)
1120
.empty Widget does not support uploading of .zip file generated by RepoSense.
1221
</template>
1322

14-
<script>
23+
<script lang='ts'>
24+
import { defineComponent } from 'vue';
25+
1526
import cSummary from './c-summary.vue';
27+
import CSummaryPortfolio from "./c-summary-portfolio.vue";
1628
17-
export default {
29+
export default defineComponent({
1830
name: 'c-widget',
1931
components: {
32+
CSummaryPortfolio,
2033
cSummary,
2134
},
2235
props: {
@@ -57,7 +70,12 @@ export default {
5770
required: true,
5871
},
5972
},
60-
};
73+
computed: {
74+
isPortfolio(): boolean {
75+
return window.isPortfolio;
76+
}
77+
},
78+
});
6179
</script>
6280

6381
<style lang="scss">

0 commit comments

Comments
 (0)