Skip to content

Commit 6f8db69

Browse files
authored
Merge pull request #120 from green-code-initiative/95-provide-a-first-page-template
95 provide a first page template
2 parents a849979 + 5367cc7 commit 6f8db69

File tree

7 files changed

+445
-11
lines changed

7 files changed

+445
-11
lines changed

apps/vue-app/src/assets/main.css

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#app {
44
max-width: 1280px;
55
margin: 0 auto;
6-
padding: 2rem;
76
font-weight: normal;
87
}
98

@@ -26,10 +25,4 @@ a,
2625
display: flex;
2726
place-items: center;
2827
}
29-
30-
#app {
31-
display: grid;
32-
grid-template-columns: 1fr 1fr;
33-
padding: 0 2rem;
34-
}
3528
}

apps/vue-app/src/components/pages/DashboardPage.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<script setup>
22
import { onMounted, reactive } from 'vue';
33
4-
import { AbcdeScore } from '@creedengo/vue-ui'
54
import SonarAPI from '@creedengo/sonar-services'
65
import core from '@creedengo/core-services';
6+
import { DashboardPageTemplate } from '@creedengo/vue-ui';
77
8-
const { api, calculateProjectScore } = core;
8+
const { api, calculateProjectScore, getScoreTexts } = core;
99
1010
api.init(SonarAPI)
1111
const props = defineProps({
@@ -23,7 +23,9 @@ const state = reactive({ score: '', error: null });
2323
2424
onMounted(async () => {
2525
try {
26-
state.score = await calculateProjectScore({ ...props });
26+
const value = await calculateProjectScore({ ...props });
27+
const { label, description, tips } = getScoreTexts(value);
28+
state.score = { value, label, description, tips };
2729
} catch (error) {
2830
state.score = 'N/A';
2931
globalThis.console.error('Error fetching score:', error);
@@ -45,7 +47,7 @@ onMounted(async () => {
4547
<i class="fa fa-exclamation-triangle" /> Score not available - {{ state.error }}
4648
</span>
4749
<span v-else>
48-
<AbcdeScore :value="state.score" />
50+
<DashboardPageTemplate :score="state.score" />
4951
</span>
5052
</div>
5153
</main>

shared/core-services/src/score.service.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,34 @@
55

66
import api from './adapter.js';
77

8+
const scoreTexts = {
9+
A: {
10+
label: "Your app is fully optimized, congratulations!",
11+
description: "Don't forget to check it again if you update your app.",
12+
tips: "100 % optimized, congrats!"
13+
},
14+
B: {
15+
label: "Your app is nearly optimized.",
16+
description: "Well done! You can continue by fixing the recommended rule on the right side. This is the one that currently has the highest impact on your app.",
17+
tips: "You have between 1 and 9 minor severities."
18+
},
19+
C: {
20+
label: "Your app is not fully optimized.",
21+
description: "Keep going! You can continue by fixing the recommended rule on the right side. This is the one that currently has the highest impact on your app.",
22+
tips: "You have between 10 and 19 minor severities or you have 1 or many major severity."
23+
},
24+
D: {
25+
label: "Many elements of your application can be optimized.",
26+
description: "Don't worry! You can start by fixing the recommended rule on the right side. This is the one that currently has the highest impact on your app.",
27+
tips: "You have more than 20 minor severities or more than 10 major severities or 1 or many critical severities."
28+
},
29+
E: {
30+
label: "Several elements of your application can be optimized.",
31+
description: "Don't worry! You can start by fixing the recommended rule on the right side. This is the one that currently has the highest impact on your app.",
32+
tips: "You have 1 or more than 1 blocker severities."
33+
}
34+
};
35+
836
/**
937
* Calculate an ABCDE score from the sustainability issues related to the project size.
1038
* @param {Object} config
@@ -35,3 +63,12 @@ export async function calculateProjectScore(config) {
3563
}
3664
return 'A';
3765
}
66+
67+
/**
68+
* Returns the texts corresponding to the score.
69+
* @param {string} score the value of the project's score.
70+
* @returns {Object} texts corresponding to the project score.
71+
*/
72+
export function getScoreTexts(score) {
73+
return scoreTexts[score]
74+
}

shared/vue-ui/src/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import SettingsForm from './molecules/SettingsForm/SettingsForm.vue'
1919
// Organisms
2020
import ScoreBlock from './organisms/ScoreBlock/ScoreBlock.vue'
2121
import TagCard from './organisms/TagCard/TagCard.vue'
22+
// Page Templates
23+
import DashboardPageTemplate from './page-templates/DashboardPageTemplate.vue'
2224

2325
// Design Tokens
2426
export { IconArrowRight, IconBug, IconCpu, IconDisk, IconMaintenance, IconNetwork, IconRam }
@@ -28,3 +30,5 @@ export { ImpactTag }
2830
export { AbcdeScore, BulletCriticities, PieChart, RuleIconTag, RuleCriticities, SettingsForm, TooltipBox }
2931
// Organisms
3032
export { ScoreBlock, TagCard }
33+
// Page Templates
34+
export { DashboardPageTemplate }

shared/vue-ui/src/organisms/ScoreBlock/ScoreBlock.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,15 @@ const projectLink = computed(() => {
6262
</template>
6363

6464
<style scoped>
65+
h2 {
66+
margin-top: 30px;
67+
}
6568
.rate-description {
6669
padding-top: 20px;
6770
}
6871
.tooltip-calc {
6972
margin-top: 20px;
73+
margin-bottom: 1.25rem;
7074
text-decoration: underline;
7175
display: inline-block;
7276
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
import DashboardPageTemplate from "./DashboardPageTemplate.vue";
2+
3+
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories
4+
export default {
5+
title: 'Page Templates/DashboardPageTemplate',
6+
component: DashboardPageTemplate,
7+
tags: ['autodocs'],
8+
argTypes: {
9+
score: {
10+
control: {
11+
type: 'object'
12+
},
13+
required: true
14+
},
15+
rule: {
16+
control: {
17+
type: 'object'
18+
},
19+
required: true
20+
},
21+
metricTags: {
22+
control: {
23+
type: 'array'
24+
},
25+
required: true
26+
}
27+
}
28+
};
29+
30+
const score = {
31+
value: "C",
32+
label: "Your app is not fully optimized.",
33+
description: "Keep going! You can continue by fixing the recommended rule on the right side. This is the one that currently has the highest impact on your app.",
34+
tips: "You have between 10 and 19 minor severities or you have 1 or many major severity.",
35+
projectKey: 'FOO',
36+
branch: 'main',
37+
minorSeverities: 15,
38+
majorSeverities: 3,
39+
criticalSeverities: 0
40+
}
41+
42+
const priorityRule = {
43+
percentage: 25,
44+
ruleKey: "typescript:S1774",
45+
ruleName: "Avoid Using Ternary Operator",
46+
ruleHtmlDesc: `
47+
Ternary expressions, while concise, can often lead to code that is difficult
48+
to read and understand, especially when they are nested or complex.
49+
Prioritizing readability fosters maintainability and reduces the likelihood of bugs.
50+
Therefore, they should be removed in favor of more explicit control structures,
51+
such as if/else statements, to improve the clarity and readability of the code.
52+
`,
53+
ruleImpact: "High",
54+
ruleMetricTags: ["Maintenance"]
55+
}
56+
57+
const cpuTag = {
58+
name: "CPU",
59+
nbRules: 19,
60+
optimizedRules: 12,
61+
minorIssues: 40,
62+
majorIssues: 19,
63+
criticalIssues: 0,
64+
projectKey: 'foo',
65+
branch: 'main'
66+
}
67+
68+
const ramTag = {
69+
name: "RAM",
70+
nbRules: 17,
71+
optimizedRules: 11,
72+
minorIssues: 40,
73+
majorIssues: 17,
74+
criticalIssues: 0,
75+
projectKey: 'foo',
76+
branch: 'main'
77+
}
78+
79+
const networkTag = {
80+
name: "Network",
81+
nbRules: 1,
82+
optimizedRules: 1,
83+
minorIssues: 0,
84+
majorIssues: 0,
85+
criticalIssues: 0,
86+
projectKey: 'foo',
87+
branch: 'main'
88+
}
89+
90+
const diskTag = {
91+
name: "Disk",
92+
nbRules: 1,
93+
optimizedRules: 1,
94+
minorIssues: 0,
95+
majorIssues: 0,
96+
criticalIssues: 0,
97+
projectKey: 'foo',
98+
branch: 'main'
99+
}
100+
101+
export const CompleteDashboard = {
102+
args: {
103+
score,
104+
priorityRule,
105+
metricTags: [
106+
cpuTag,
107+
ramTag,
108+
networkTag,
109+
diskTag
110+
]
111+
}
112+
};
113+
114+
export const WithoutNetworkAndDiskTags = {
115+
args: {
116+
score,
117+
priorityRule,
118+
metricTags: [
119+
cpuTag,
120+
ramTag
121+
]
122+
}
123+
};
124+
125+
export const WithoutScore = {
126+
args: {
127+
priorityRule,
128+
metricTags: [
129+
cpuTag,
130+
ramTag,
131+
networkTag,
132+
diskTag
133+
]
134+
}
135+
};
136+
137+
export const WithoutPriorityRule = {
138+
args: {
139+
score,
140+
metricTags: [
141+
cpuTag,
142+
ramTag,
143+
networkTag,
144+
diskTag
145+
]
146+
}
147+
};
148+
149+
export const WithoutMetricTags = {
150+
args: {
151+
score,
152+
priorityRule,
153+
metricTags: []
154+
}
155+
};

0 commit comments

Comments
 (0)