@ossy/consultancy 3.18.0 → 3.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/package.json +3 -3
- package/src/ConsultancyNav.jsx +3 -3
- package/src/Forecast.jsx +63 -74
- package/src/consultancy.page.jsx +42 -5
- package/src/create-company.flow.js +3 -2
- package/src/en.translations.json +6 -4
- package/src/forecast-kpi-chart.js +137 -0
- package/src/forecast-kpi-chart.spec.js +122 -0
- package/src/org.page.jsx +38 -0
- package/src/sv.translations.json +6 -4
- package/src/view-forecasts.flow.js +4 -3
- package/src/forecasts.page.jsx +0 -75
package/README.md
CHANGED
|
@@ -9,12 +9,12 @@ Consultancy **feature package** for the Ossy platform — schemas and UI for emp
|
|
|
9
9
|
| File | Page id | Default paths |
|
|
10
10
|
|---|---|---|
|
|
11
11
|
| `consultancy.page.jsx` | `consultancy/home` | `/consultancy` (en), `/konsultverksamhet` (sv) |
|
|
12
|
-
| `
|
|
12
|
+
| `org.page.jsx` | `consultancy/org` | `/consultancy/org`, `/konsultverksamhet/orgdetaljer` |
|
|
13
13
|
| `margins.page.jsx` | `consultancy/margins` | `/consultancy/margins`, `/konsultverksamhet/marginaler` |
|
|
14
14
|
|
|
15
|
-
One sidebar item (**Consultancy**). Overview,
|
|
15
|
+
One sidebar item (**Consultancy**). Overview (home), Margins, and Org Details are in-product tabs under that surface.
|
|
16
16
|
|
|
17
|
-
The
|
|
17
|
+
The home Overview tab shows fiscal-year KPIs via `@ossy/calendar`'s `useForecast` / `ForecastClient` (engine stays in calendar). Org Details shows company data (fiscal years, registration, VAT) via `@ossy/calendar`'s `useCompany` hook. Margins is a standalone calculator (not yet wired to live resources).
|
|
18
18
|
|
|
19
19
|
### Schemas (ADR 0006)
|
|
20
20
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/consultancy",
|
|
3
3
|
"description": "Consultancy feature package — schemas, forecasts UI, and assignment margins",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.20.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"module": "./src/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"README.md"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@ossy/schema": "^3.
|
|
28
|
+
"@ossy/schema": "^3.20.1"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@ossy/calendar": "*",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"jest": "^30.2.0"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "3e8bb118b3ef163792a004663ccb803ab51a8601"
|
|
42
42
|
}
|
package/src/ConsultancyNav.jsx
CHANGED
|
@@ -2,10 +2,10 @@ import React from 'react'
|
|
|
2
2
|
import { Tabs } from '@ossy/design-system'
|
|
3
3
|
import { useRouter } from '@ossy/router-react'
|
|
4
4
|
|
|
5
|
-
/**
|
|
5
|
+
/** Overview (home) first, Margins middle, Org Details last. */
|
|
6
6
|
const TABS = [
|
|
7
7
|
{
|
|
8
|
-
id: 'consultancy/
|
|
8
|
+
id: 'consultancy/home',
|
|
9
9
|
label: 'consultancy.nav.overview',
|
|
10
10
|
},
|
|
11
11
|
{
|
|
@@ -13,7 +13,7 @@ const TABS = [
|
|
|
13
13
|
label: 'consultancy.nav.margins',
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
|
-
id: 'consultancy/
|
|
16
|
+
id: 'consultancy/org',
|
|
17
17
|
label: 'consultancy.nav.orgDetails',
|
|
18
18
|
},
|
|
19
19
|
]
|
package/src/Forecast.jsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { useMemo } from 'react'
|
|
2
2
|
import { View, Text, Separator, useLocale } from '@ossy/design-system'
|
|
3
3
|
import { CalendarDaySurfaceStyles, sumFiscalYearTotals, useForecast } from '@ossy/calendar'
|
|
4
|
+
import { buildKpiChartLayout } from './forecast-kpi-chart.js'
|
|
4
5
|
|
|
5
6
|
const grid = {
|
|
6
7
|
width: '100%',
|
|
@@ -34,10 +35,11 @@ const calendarDayLayout = {
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
const KPI_SERIES = [
|
|
37
|
-
|
|
38
|
-
{ key: '
|
|
38
|
+
// --color-primary is paper white in Cloud themes; income must stay visible on surface-primary.
|
|
39
|
+
{ key: 'projectedIncome', label: 'consultancy.forecasts.income', color: 'var(--color-info, hsl(199, 89%, 43%))' },
|
|
40
|
+
{ key: 'monthlyCostOfEmployees', label: 'consultancy.forecasts.salaryCost', color: 'var(--color-warning, hsl(38, 92%, 50%))' },
|
|
39
41
|
{ key: 'revenue', label: 'consultancy.forecasts.revenue', color: 'var(--color-accent, hsl(167, 89%, 43%))' },
|
|
40
|
-
{ key: 'hoursWorked', label: 'consultancy.forecasts.hoursWorked', color: 'var(--fg-secondary, hsl(220, 10%, 45%))' },
|
|
42
|
+
{ key: 'hoursWorked', label: 'consultancy.forecasts.hoursWorked', color: 'var(--fg-secondary, hsl(220, 10%, 45%))', dashed: true },
|
|
41
43
|
]
|
|
42
44
|
|
|
43
45
|
function SectionPanel ({ title, children }) {
|
|
@@ -69,47 +71,14 @@ function SectionPanel ({ title, children }) {
|
|
|
69
71
|
/**
|
|
70
72
|
* Hand-rolled multi-series line chart for fiscal-year KPIs.
|
|
71
73
|
* Matches the no-dependency SVG approach from analytics DailyBarChart (#917).
|
|
72
|
-
*
|
|
74
|
+
* Money KPIs share one Y-scale; hours use a secondary scale (dashed stroke).
|
|
73
75
|
*/
|
|
74
76
|
function ForecastKpiChart ({ months }) {
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const padX = 8
|
|
81
|
-
const padY = 10
|
|
82
|
-
const innerW = width - padX * 2
|
|
83
|
-
const innerH = height - padY * 2
|
|
84
|
-
const step = months.length === 1 ? 0 : innerW / (months.length - 1)
|
|
85
|
-
|
|
86
|
-
const seriesPaths = KPI_SERIES.map((series) => {
|
|
87
|
-
let min = Infinity
|
|
88
|
-
let max = -Infinity
|
|
89
|
-
for (const month of months) {
|
|
90
|
-
const value = Number(month[series.key]) || 0
|
|
91
|
-
if (value < min) min = value
|
|
92
|
-
if (value > max) max = value
|
|
93
|
-
}
|
|
94
|
-
if (!Number.isFinite(min) || !Number.isFinite(max)) {
|
|
95
|
-
return { ...series, path: null }
|
|
96
|
-
}
|
|
97
|
-
if (min === max) {
|
|
98
|
-
min -= 1
|
|
99
|
-
max += 1
|
|
100
|
-
}
|
|
101
|
-
const span = max - min
|
|
102
|
-
const points = months.map((month, index) => {
|
|
103
|
-
const value = Number(month[series.key]) || 0
|
|
104
|
-
const x = padX + index * step
|
|
105
|
-
const y = padY + innerH - ((value - min) / span) * innerH
|
|
106
|
-
return `${x},${y}`
|
|
107
|
-
})
|
|
108
|
-
return { ...series, path: `M ${points.join(' L ')}` }
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
return { width, height, seriesPaths }
|
|
112
|
-
}, [months])
|
|
77
|
+
const { language } = useLocale()
|
|
78
|
+
const chart = useMemo(
|
|
79
|
+
() => buildKpiChartLayout({ months, series: KPI_SERIES, language }),
|
|
80
|
+
[months, language],
|
|
81
|
+
)
|
|
113
82
|
|
|
114
83
|
if (!chart) {
|
|
115
84
|
return (
|
|
@@ -120,7 +89,7 @@ function ForecastKpiChart ({ months }) {
|
|
|
120
89
|
}
|
|
121
90
|
|
|
122
91
|
return (
|
|
123
|
-
<View gap="s" inset="m">
|
|
92
|
+
<View gap="s" inset="m" style={{ width: '100%' }}>
|
|
124
93
|
<View layout="row-wrap" gap="m" style={{ alignItems: 'center' }}>
|
|
125
94
|
{KPI_SERIES.map((series) => (
|
|
126
95
|
<View key={series.key} layout="row" gap="s" style={{ alignItems: 'center' }}>
|
|
@@ -133,43 +102,63 @@ function ForecastKpiChart ({ months }) {
|
|
|
133
102
|
background: series.color,
|
|
134
103
|
display: 'inline-block',
|
|
135
104
|
flexShrink: 0,
|
|
105
|
+
...(series.dashed
|
|
106
|
+
? {
|
|
107
|
+
background: 'transparent',
|
|
108
|
+
borderTop: `2px dashed ${series.color}`,
|
|
109
|
+
height: 0,
|
|
110
|
+
borderRadius: 0,
|
|
111
|
+
}
|
|
112
|
+
: null),
|
|
136
113
|
}}
|
|
137
114
|
/>
|
|
138
115
|
<Text variant="small" style={{ marginBottom: 0 }} text={series.label} />
|
|
139
116
|
</View>
|
|
140
117
|
))}
|
|
141
118
|
</View>
|
|
142
|
-
<
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
119
|
+
<svg
|
|
120
|
+
data-consultancy-kpi-chart
|
|
121
|
+
viewBox={`0 0 ${chart.viewWidth} ${chart.viewHeight}`}
|
|
122
|
+
width="100%"
|
|
123
|
+
role="img"
|
|
124
|
+
style={{
|
|
125
|
+
display: 'block',
|
|
126
|
+
width: '100%',
|
|
127
|
+
height: 'auto',
|
|
128
|
+
aspectRatio: `${chart.viewWidth} / ${chart.viewHeight}`,
|
|
129
|
+
}}
|
|
130
|
+
preserveAspectRatio="xMidYMid meet"
|
|
131
|
+
>
|
|
132
|
+
{chart.seriesPaths.map((series) => (
|
|
133
|
+
series.path ? (
|
|
134
|
+
<path
|
|
135
|
+
key={series.key}
|
|
136
|
+
d={series.path}
|
|
137
|
+
fill="none"
|
|
138
|
+
stroke={series.color}
|
|
139
|
+
strokeWidth={2}
|
|
140
|
+
strokeLinejoin="round"
|
|
141
|
+
strokeLinecap="round"
|
|
142
|
+
strokeDasharray={series.dashed ? '6 4' : undefined}
|
|
143
|
+
vectorEffect="non-scaling-stroke"
|
|
144
|
+
/>
|
|
145
|
+
) : null
|
|
146
|
+
))}
|
|
147
|
+
{chart.monthLabels.map((label) => (
|
|
148
|
+
<text
|
|
149
|
+
key={`month-${label.index}`}
|
|
150
|
+
data-consultancy-kpi-month={label.label}
|
|
151
|
+
x={label.x}
|
|
152
|
+
y={label.y}
|
|
153
|
+
textAnchor="middle"
|
|
154
|
+
fill="var(--fg-secondary, currentColor)"
|
|
155
|
+
fontSize={12}
|
|
156
|
+
style={{ opacity: 0.75 }}
|
|
157
|
+
>
|
|
158
|
+
{label.label}
|
|
159
|
+
</text>
|
|
160
|
+
))}
|
|
161
|
+
</svg>
|
|
173
162
|
</View>
|
|
174
163
|
)
|
|
175
164
|
}
|
package/src/consultancy.page.jsx
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { Text, View, Page, Tags } from '@ossy/design-system'
|
|
3
|
-
import {
|
|
1
|
+
import React, { useState } from 'react'
|
|
2
|
+
import { Button, Text, View, Page, Tags } from '@ossy/design-system'
|
|
3
|
+
import { useSdk } from '@ossy/sdk-react'
|
|
4
|
+
import { PinWidget } from '@ossy/dashboard'
|
|
5
|
+
import { Forecast } from './Forecast.jsx'
|
|
4
6
|
import { DataLoader } from '@ossy/calendar'
|
|
5
7
|
import { Definition } from './Definition.js'
|
|
6
8
|
import { CreateConsultancyButton } from './CreateConsultancyButton.jsx'
|
|
@@ -14,22 +16,57 @@ export const metadata = {
|
|
|
14
16
|
},
|
|
15
17
|
}
|
|
16
18
|
|
|
19
|
+
const FORECAST_WIDGET_ID = '@ossy/consultancy/view/current-month'
|
|
20
|
+
|
|
17
21
|
export const ConsultancyPage = () => {
|
|
22
|
+
const sdk = useSdk()
|
|
23
|
+
const [pinState, setPinState] = useState('idle')
|
|
24
|
+
|
|
18
25
|
const statusTags = (Definition.status ?? [])
|
|
19
26
|
.map((s) => ({ beta: 'Beta', 'coming-soon': 'Coming Soon' }[s]))
|
|
20
27
|
.filter(Boolean)
|
|
21
28
|
|
|
29
|
+
const pinToDashboard = async () => {
|
|
30
|
+
if (pinState === 'pending') return
|
|
31
|
+
setPinState('pending')
|
|
32
|
+
try {
|
|
33
|
+
await sdk.invoke(PinWidget, { componentId: FORECAST_WIDGET_ID })
|
|
34
|
+
setPinState('done')
|
|
35
|
+
} catch {
|
|
36
|
+
setPinState('error')
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
22
40
|
return (
|
|
23
41
|
<Page
|
|
42
|
+
data-forecasts-status="on"
|
|
24
43
|
title="consultancy.home.title"
|
|
25
44
|
near={statusTags.length > 0 ? <Tags tags={statusTags} size="s" /> : undefined}
|
|
26
45
|
description="consultancy.home.description"
|
|
27
|
-
far={
|
|
46
|
+
far={(
|
|
47
|
+
<View layout="row" gap="s" style={{ flexWrap: 'wrap' }}>
|
|
48
|
+
<Button
|
|
49
|
+
{...PinWidget}
|
|
50
|
+
variant="primary"
|
|
51
|
+
disabled={pinState === 'pending' || pinState === 'done'}
|
|
52
|
+
label={
|
|
53
|
+
pinState === 'done'
|
|
54
|
+
? 'consultancy.forecasts.pin.done'
|
|
55
|
+
: pinState === 'error'
|
|
56
|
+
? 'consultancy.forecasts.pin.error'
|
|
57
|
+
: 'consultancy.forecasts.pin.forecast'
|
|
58
|
+
}
|
|
59
|
+
onClick={pinToDashboard}
|
|
60
|
+
data-forecasts-pin
|
|
61
|
+
/>
|
|
62
|
+
<CreateConsultancyButton />
|
|
63
|
+
</View>
|
|
64
|
+
)}
|
|
28
65
|
>
|
|
29
66
|
<View gap="m">
|
|
30
67
|
<ConsultancyNav active="consultancy/home" />
|
|
31
68
|
<Text variant="heading-secondary" as="h2" text="design-system.overview" />
|
|
32
|
-
<DataLoader content={<
|
|
69
|
+
<DataLoader content={<Forecast />} />
|
|
33
70
|
</View>
|
|
34
71
|
</Page>
|
|
35
72
|
)
|
|
@@ -15,7 +15,7 @@ export const metadata = {
|
|
|
15
15
|
export default {
|
|
16
16
|
title: 'Create company',
|
|
17
17
|
description:
|
|
18
|
-
'Signed-in user sees consultancy empty, creates company-basic-info via create-document, then sees the ready overview',
|
|
18
|
+
'Signed-in user sees consultancy empty, creates company-basic-info via create-document, then sees the ready home overview',
|
|
19
19
|
steps: [
|
|
20
20
|
...signUpFlow.steps,
|
|
21
21
|
{ page: '@consultancy/home' },
|
|
@@ -41,6 +41,7 @@ export default {
|
|
|
41
41
|
{ result: { page: '@storage/home', timeout: 20000 } },
|
|
42
42
|
{ page: '@consultancy/home' },
|
|
43
43
|
{ result: { selector: '[data-consultancy-status="ready"]', timeout: 15000 } },
|
|
44
|
-
{ result: { selector: '[data-
|
|
44
|
+
{ result: { selector: '[data-forecasts-status="on"]', timeout: 10000 } },
|
|
45
|
+
{ result: { selector: '[data-consultancy-year-summary]', timeout: 10000 } },
|
|
45
46
|
],
|
|
46
47
|
}
|
package/src/en.translations.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"consultancy/home.documentTitle": "
|
|
3
|
-
"consultancy/
|
|
2
|
+
"consultancy/home.documentTitle": "Overview",
|
|
3
|
+
"consultancy/org.documentTitle": "Org Details",
|
|
4
4
|
"consultancy/margins.documentTitle": "Margins",
|
|
5
|
-
"consultancy.home.title": "
|
|
6
|
-
"consultancy.home.description": "
|
|
5
|
+
"consultancy.home.title": "Overview",
|
|
6
|
+
"consultancy.home.description": "Fiscal-year KPIs, year totals, and monthly capacity from contracts, employees, and vacations",
|
|
7
|
+
"consultancy.org.title": "Org Details",
|
|
8
|
+
"consultancy.org.description": "Company and fiscal-year details",
|
|
7
9
|
"consultancy.nav.title": "Consultancy",
|
|
8
10
|
"consultancy.nav.overview": "Overview",
|
|
9
11
|
"consultancy.nav.forecasts": "Forecasts",
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure layout helpers for the consultancy fiscal-year KPI line chart.
|
|
3
|
+
* Money series share one Y-scale; hours use a secondary scale so shapes stay distinct.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export const MONEY_KEYS = ['projectedIncome', 'monthlyCostOfEmployees', 'revenue']
|
|
7
|
+
export const HOURS_KEY = 'hoursWorked'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 3-letter month label for chart axis (locale-aware short month, truncated).
|
|
11
|
+
*
|
|
12
|
+
* @param {{ year?: number|string, monthNumber?: number|string, month?: string }} month
|
|
13
|
+
* @param {string} [language='en']
|
|
14
|
+
* @returns {string}
|
|
15
|
+
*/
|
|
16
|
+
export function shortMonthLabel (month, language = 'en') {
|
|
17
|
+
const year = Number(month?.year)
|
|
18
|
+
const monthNumber = Number(month?.monthNumber)
|
|
19
|
+
if (Number.isFinite(year) && Number.isFinite(monthNumber) && monthNumber >= 1 && monthNumber <= 12) {
|
|
20
|
+
const locale = language === 'sv' ? 'sv-SE' : 'en'
|
|
21
|
+
const date = new Date(Date.UTC(year, monthNumber - 1, 1))
|
|
22
|
+
const short = new Intl.DateTimeFormat(locale, { month: 'short' }).format(date)
|
|
23
|
+
const letters = short.replace(/\./g, '').trim()
|
|
24
|
+
if (letters.length >= 3) {
|
|
25
|
+
return letters.slice(0, 3).replace(/^./, (c) => c.toUpperCase())
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const fallback = String(month?.month || '').replace(/\./g, '').trim()
|
|
29
|
+
return fallback.slice(0, 3).replace(/^./, (c) => c.toUpperCase())
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @param {Array<Record<string, unknown>>} months
|
|
34
|
+
* @param {string[]} keys
|
|
35
|
+
* @returns {{ min: number, max: number } | null}
|
|
36
|
+
*/
|
|
37
|
+
export function extentForKeys (months, keys) {
|
|
38
|
+
if (!months?.length || !keys?.length) return null
|
|
39
|
+
let min = Infinity
|
|
40
|
+
let max = -Infinity
|
|
41
|
+
for (const month of months) {
|
|
42
|
+
for (const key of keys) {
|
|
43
|
+
const value = Number(month[key]) || 0
|
|
44
|
+
if (value < min) min = value
|
|
45
|
+
if (value > max) max = value
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (!Number.isFinite(min) || !Number.isFinite(max)) return null
|
|
49
|
+
if (min === max) {
|
|
50
|
+
min -= 1
|
|
51
|
+
max += 1
|
|
52
|
+
}
|
|
53
|
+
return { min, max }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @param {number} value
|
|
58
|
+
* @param {{ min: number, max: number }} extent
|
|
59
|
+
* @param {number} padY
|
|
60
|
+
* @param {number} innerH
|
|
61
|
+
*/
|
|
62
|
+
export function valueToY (value, extent, padY, innerH) {
|
|
63
|
+
const span = extent.max - extent.min
|
|
64
|
+
return padY + innerH - ((value - extent.min) / span) * innerH
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Build SVG path strings for KPI series plus all-month X labels.
|
|
69
|
+
*
|
|
70
|
+
* ViewBox defaults use a wide aspect ratio (~3.5:1) so `preserveAspectRatio="meet"`
|
|
71
|
+
* can scale uniformly without squishing axis labels (see #1001).
|
|
72
|
+
*
|
|
73
|
+
* @param {object} options
|
|
74
|
+
* @param {Array<Record<string, unknown>>} options.months
|
|
75
|
+
* @param {Array<{ key: string, label: string, color: string, dashed?: boolean }>} options.series
|
|
76
|
+
* @param {string} [options.language='en']
|
|
77
|
+
* @param {number} [options.viewWidth=560]
|
|
78
|
+
* @param {number} [options.plotHeight=140]
|
|
79
|
+
* @param {number} [options.padX=16]
|
|
80
|
+
* @param {number} [options.padTop=12]
|
|
81
|
+
* @param {number} [options.padBottom=28]
|
|
82
|
+
* @returns {{ viewWidth: number, viewHeight: number, seriesPaths: Array<object>, monthLabels: Array<object> } | null}
|
|
83
|
+
*/
|
|
84
|
+
export function buildKpiChartLayout ({
|
|
85
|
+
months,
|
|
86
|
+
series,
|
|
87
|
+
language = 'en',
|
|
88
|
+
viewWidth = 560,
|
|
89
|
+
plotHeight = 140,
|
|
90
|
+
padX = 16,
|
|
91
|
+
padTop = 12,
|
|
92
|
+
padBottom = 28,
|
|
93
|
+
}) {
|
|
94
|
+
if (!months?.length || !series?.length) return null
|
|
95
|
+
|
|
96
|
+
const viewHeight = padTop + plotHeight + padBottom
|
|
97
|
+
const innerW = viewWidth - padX * 2
|
|
98
|
+
const innerH = plotHeight
|
|
99
|
+
const step = months.length === 1 ? 0 : innerW / (months.length - 1)
|
|
100
|
+
|
|
101
|
+
const moneyExtent = extentForKeys(months, MONEY_KEYS)
|
|
102
|
+
const hoursExtent = extentForKeys(months, [HOURS_KEY])
|
|
103
|
+
|
|
104
|
+
const seriesPaths = series.map((entry) => {
|
|
105
|
+
const extent = entry.key === HOURS_KEY ? hoursExtent : moneyExtent
|
|
106
|
+
if (!extent) return { ...entry, path: null }
|
|
107
|
+
|
|
108
|
+
const points = months.map((month, index) => {
|
|
109
|
+
const value = Number(month[entry.key]) || 0
|
|
110
|
+
const x = padX + index * step
|
|
111
|
+
const y = valueToY(value, extent, padTop, innerH)
|
|
112
|
+
return `${x},${y}`
|
|
113
|
+
})
|
|
114
|
+
return { ...entry, path: `M ${points.join(' L ')}` }
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
const monthLabels = months.map((month, index) => ({
|
|
118
|
+
index,
|
|
119
|
+
label: shortMonthLabel(month, language),
|
|
120
|
+
x: padX + index * step,
|
|
121
|
+
y: viewHeight - 6,
|
|
122
|
+
}))
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
viewWidth,
|
|
126
|
+
viewHeight,
|
|
127
|
+
seriesPaths,
|
|
128
|
+
monthLabels,
|
|
129
|
+
step,
|
|
130
|
+
padX,
|
|
131
|
+
padTop,
|
|
132
|
+
padBottom,
|
|
133
|
+
plotHeight,
|
|
134
|
+
innerW,
|
|
135
|
+
innerH,
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MONEY_KEYS,
|
|
3
|
+
HOURS_KEY,
|
|
4
|
+
extentForKeys,
|
|
5
|
+
valueToY,
|
|
6
|
+
buildKpiChartLayout,
|
|
7
|
+
shortMonthLabel,
|
|
8
|
+
} from './forecast-kpi-chart.js'
|
|
9
|
+
|
|
10
|
+
const sampleMonths = [
|
|
11
|
+
{ year: 2026, monthNumber: '01', month: 'January', projectedIncome: 100, monthlyCostOfEmployees: 50, revenue: 50, hoursWorked: 10 },
|
|
12
|
+
{ year: 2026, monthNumber: '02', month: 'February', projectedIncome: 200, monthlyCostOfEmployees: 50, revenue: 150, hoursWorked: 20 },
|
|
13
|
+
{ year: 2026, monthNumber: '03', month: 'March', projectedIncome: 150, monthlyCostOfEmployees: 50, revenue: 100, hoursWorked: 15 },
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
const series = [
|
|
17
|
+
{ key: 'projectedIncome', label: 'income', color: 'blue' },
|
|
18
|
+
{ key: 'monthlyCostOfEmployees', label: 'salary', color: 'orange' },
|
|
19
|
+
{ key: 'revenue', label: 'revenue', color: 'green' },
|
|
20
|
+
{ key: 'hoursWorked', label: 'hours', color: 'gray', dashed: true },
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
describe('shortMonthLabel', () => {
|
|
24
|
+
it('formats English months as three letters', () => {
|
|
25
|
+
expect(shortMonthLabel({ year: 2026, monthNumber: '01' }, 'en')).toBe('Jan')
|
|
26
|
+
expect(shortMonthLabel({ year: 2026, monthNumber: '09' }, 'en')).toBe('Sep')
|
|
27
|
+
expect(shortMonthLabel({ year: 2026, monthNumber: 12 }, 'en')).toBe('Dec')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('formats Swedish months as three letters without trailing punctuation', () => {
|
|
31
|
+
expect(shortMonthLabel({ year: 2026, monthNumber: '01' }, 'sv')).toBe('Jan')
|
|
32
|
+
expect(shortMonthLabel({ year: 2026, monthNumber: '02' }, 'sv')).toBe('Feb')
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('falls back to the long month name when numbers are missing', () => {
|
|
36
|
+
expect(shortMonthLabel({ month: 'January' }, 'en')).toBe('Jan')
|
|
37
|
+
})
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
describe('extentForKeys', () => {
|
|
41
|
+
it('returns shared min/max across money keys', () => {
|
|
42
|
+
const extent = extentForKeys(sampleMonths, MONEY_KEYS)
|
|
43
|
+
expect(extent).toEqual({ min: 50, max: 200 })
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('expands a constant series so a flat line stays mid-range', () => {
|
|
47
|
+
const flat = [
|
|
48
|
+
{ monthlyCostOfEmployees: 50 },
|
|
49
|
+
{ monthlyCostOfEmployees: 50 },
|
|
50
|
+
]
|
|
51
|
+
const extent = extentForKeys(flat, ['monthlyCostOfEmployees'])
|
|
52
|
+
expect(extent.min).toBe(49)
|
|
53
|
+
expect(extent.max).toBe(51)
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
describe('buildKpiChartLayout', () => {
|
|
58
|
+
it('spans the full viewBox width for N months', () => {
|
|
59
|
+
const layout = buildKpiChartLayout({ months: sampleMonths, series, viewWidth: 100 })
|
|
60
|
+
expect(layout).not.toBeNull()
|
|
61
|
+
expect(layout.padX + (sampleMonths.length - 1) * layout.step).toBeCloseTo(100 - layout.padX)
|
|
62
|
+
expect(layout.viewWidth).toBe(100)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('keeps salary flat and distinct from income under a shared money scale', () => {
|
|
66
|
+
const layout = buildKpiChartLayout({ months: sampleMonths, series })
|
|
67
|
+
const income = layout.seriesPaths.find((s) => s.key === 'projectedIncome')
|
|
68
|
+
const salary = layout.seriesPaths.find((s) => s.key === 'monthlyCostOfEmployees')
|
|
69
|
+
const revenue = layout.seriesPaths.find((s) => s.key === 'revenue')
|
|
70
|
+
const hours = layout.seriesPaths.find((s) => s.key === HOURS_KEY)
|
|
71
|
+
|
|
72
|
+
expect(income.path).not.toBe(salary.path)
|
|
73
|
+
expect(income.path).not.toBe(revenue.path)
|
|
74
|
+
expect(salary.path).not.toBe(revenue.path)
|
|
75
|
+
|
|
76
|
+
// Constant salary → identical Y across months
|
|
77
|
+
const salaryYs = salary.path.match(/[\d.]+,([\d.]+)/g).map((p) => p.split(',')[1])
|
|
78
|
+
expect(new Set(salaryYs).size).toBe(1)
|
|
79
|
+
|
|
80
|
+
// Hours secondary scale is not forced onto the money path
|
|
81
|
+
expect(hours.path).not.toBe(income.path)
|
|
82
|
+
expect(hours.dashed).toBe(true)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('maps shared money extent extremes to plot top/bottom', () => {
|
|
86
|
+
const extent = extentForKeys(sampleMonths, MONEY_KEYS)
|
|
87
|
+
const padTop = 10
|
|
88
|
+
const plotHeight = 100
|
|
89
|
+
expect(valueToY(extent.max, extent, padTop, plotHeight)).toBeCloseTo(padTop)
|
|
90
|
+
expect(valueToY(extent.min, extent, padTop, plotHeight)).toBeCloseTo(padTop + plotHeight)
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('labels every month with a 3-letter abbreviation', () => {
|
|
94
|
+
const fiscalYear = Array.from({ length: 12 }, (_, i) => ({
|
|
95
|
+
year: 2026,
|
|
96
|
+
monthNumber: String(i + 1).padStart(2, '0'),
|
|
97
|
+
month: 'placeholder',
|
|
98
|
+
projectedIncome: 100 + i,
|
|
99
|
+
monthlyCostOfEmployees: 50,
|
|
100
|
+
revenue: 50 + i,
|
|
101
|
+
hoursWorked: 10,
|
|
102
|
+
}))
|
|
103
|
+
const layout = buildKpiChartLayout({ months: fiscalYear, series, language: 'en' })
|
|
104
|
+
expect(layout.monthLabels).toHaveLength(12)
|
|
105
|
+
expect(layout.monthLabels.map((entry) => entry.label)).toEqual([
|
|
106
|
+
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
|
107
|
+
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec',
|
|
108
|
+
])
|
|
109
|
+
expect(layout.monthLabels[0].x).toBe(layout.padX)
|
|
110
|
+
expect(layout.monthLabels[11].x).toBeCloseTo(layout.padX + 11 * layout.step)
|
|
111
|
+
})
|
|
112
|
+
|
|
113
|
+
it('defaults to a wide viewBox so meet-scaling keeps labels readable', () => {
|
|
114
|
+
const layout = buildKpiChartLayout({ months: sampleMonths, series })
|
|
115
|
+
expect(layout.viewWidth).toBe(560)
|
|
116
|
+
expect(layout.viewHeight / layout.viewWidth).toBeLessThan(0.5)
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
it('returns null for empty months', () => {
|
|
120
|
+
expect(buildKpiChartLayout({ months: [], series })).toBeNull()
|
|
121
|
+
})
|
|
122
|
+
})
|
package/src/org.page.jsx
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { Text, View, Page, Tags } from '@ossy/design-system'
|
|
3
|
+
import { Overview } from './Overview.jsx'
|
|
4
|
+
import { DataLoader } from '@ossy/calendar'
|
|
5
|
+
import { Definition } from './Definition.js'
|
|
6
|
+
import { CreateConsultancyButton } from './CreateConsultancyButton.jsx'
|
|
7
|
+
import { ConsultancyNav } from './ConsultancyNav.jsx'
|
|
8
|
+
|
|
9
|
+
export const metadata = {
|
|
10
|
+
id: 'consultancy/org',
|
|
11
|
+
path: {
|
|
12
|
+
sv: '/konsultverksamhet/orgdetaljer',
|
|
13
|
+
en: '/consultancy/org',
|
|
14
|
+
},
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const OrgPage = () => {
|
|
18
|
+
const statusTags = (Definition.status ?? [])
|
|
19
|
+
.map((s) => ({ beta: 'Beta', 'coming-soon': 'Coming Soon' }[s]))
|
|
20
|
+
.filter(Boolean)
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<Page
|
|
24
|
+
title="consultancy.org.title"
|
|
25
|
+
near={statusTags.length > 0 ? <Tags tags={statusTags} size="s" /> : undefined}
|
|
26
|
+
description="consultancy.org.description"
|
|
27
|
+
far={<CreateConsultancyButton />}
|
|
28
|
+
>
|
|
29
|
+
<View gap="m">
|
|
30
|
+
<ConsultancyNav active="consultancy/org" />
|
|
31
|
+
<Text variant="heading-secondary" as="h2" text="consultancy.nav.orgDetails" />
|
|
32
|
+
<DataLoader content={<Overview />} />
|
|
33
|
+
</View>
|
|
34
|
+
</Page>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default OrgPage
|
package/src/sv.translations.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
|
-
"consultancy/home.documentTitle": "
|
|
3
|
-
"consultancy/
|
|
2
|
+
"consultancy/home.documentTitle": "Översikt",
|
|
3
|
+
"consultancy/org.documentTitle": "Orgdetaljer",
|
|
4
4
|
"consultancy/margins.documentTitle": "Marginaler",
|
|
5
|
-
"consultancy.home.title": "
|
|
6
|
-
"consultancy.home.description": "
|
|
5
|
+
"consultancy.home.title": "Översikt",
|
|
6
|
+
"consultancy.home.description": "KPIer för räkenskapsåret, års totalsummor och månadskapacitet från avtal, anställda och semester",
|
|
7
|
+
"consultancy.org.title": "Orgdetaljer",
|
|
8
|
+
"consultancy.org.description": "Företags- och räkenskapsårsdetaljer",
|
|
7
9
|
"consultancy.nav.title": "Konsultverksamhet",
|
|
8
10
|
"consultancy.nav.overview": "Översikt",
|
|
9
11
|
"consultancy.nav.forecasts": "Prognoser",
|
|
@@ -8,16 +8,17 @@ export const metadata = {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* After enabling consultancy from the catalog, open
|
|
11
|
+
* After enabling consultancy from the catalog, open the home overview and assert
|
|
12
12
|
* the workspace forecasts surface is mounted.
|
|
13
13
|
*/
|
|
14
14
|
export default {
|
|
15
15
|
title: 'View forecasts',
|
|
16
16
|
description:
|
|
17
|
-
'Signed-in user enables consultancy and opens the
|
|
17
|
+
'Signed-in user enables consultancy and opens the consultancy home overview',
|
|
18
18
|
steps: [
|
|
19
19
|
...enableConsultancyFlow.steps,
|
|
20
|
-
{ page: '@consultancy/
|
|
20
|
+
{ page: '@consultancy/home' },
|
|
21
21
|
{ result: { selector: '[data-forecasts-status="on"]', timeout: 20000 } },
|
|
22
|
+
{ result: { selector: '[data-consultancy-nav]', timeout: 10000 } },
|
|
22
23
|
],
|
|
23
24
|
}
|
package/src/forecasts.page.jsx
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react'
|
|
2
|
-
import { Button, Text, View, Page, Tags } from '@ossy/design-system'
|
|
3
|
-
import { useSdk } from '@ossy/sdk-react'
|
|
4
|
-
import { PinWidget } from '@ossy/dashboard'
|
|
5
|
-
import { Forecast } from './Forecast.jsx'
|
|
6
|
-
import { DataLoader } from '@ossy/calendar'
|
|
7
|
-
import { Definition } from './Definition.js'
|
|
8
|
-
import { CreateConsultancyButton } from './CreateConsultancyButton.jsx'
|
|
9
|
-
import { ConsultancyNav } from './ConsultancyNav.jsx'
|
|
10
|
-
|
|
11
|
-
export const metadata = {
|
|
12
|
-
id: 'consultancy/forecasts',
|
|
13
|
-
path: {
|
|
14
|
-
sv: '/konsultverksamhet/prognoser',
|
|
15
|
-
en: '/consultancy/forecasts',
|
|
16
|
-
},
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const FORECAST_WIDGET_ID = '@ossy/consultancy/view/current-month'
|
|
20
|
-
|
|
21
|
-
export const ForecastsPage = () => {
|
|
22
|
-
const sdk = useSdk()
|
|
23
|
-
const [pinState, setPinState] = useState('idle')
|
|
24
|
-
|
|
25
|
-
const statusTags = (Definition.status ?? [])
|
|
26
|
-
.map((s) => ({ beta: 'Beta', 'coming-soon': 'Coming Soon' }[s]))
|
|
27
|
-
.filter(Boolean)
|
|
28
|
-
|
|
29
|
-
const pinToDashboard = async () => {
|
|
30
|
-
if (pinState === 'pending') return
|
|
31
|
-
setPinState('pending')
|
|
32
|
-
try {
|
|
33
|
-
await sdk.invoke(PinWidget, { componentId: FORECAST_WIDGET_ID })
|
|
34
|
-
setPinState('done')
|
|
35
|
-
} catch {
|
|
36
|
-
setPinState('error')
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return (
|
|
41
|
-
<Page
|
|
42
|
-
data-forecasts-status="on"
|
|
43
|
-
title="consultancy.forecasts.title"
|
|
44
|
-
near={statusTags.length > 0 ? <Tags tags={statusTags} size="s" /> : undefined}
|
|
45
|
-
description="consultancy.forecasts.description"
|
|
46
|
-
far={(
|
|
47
|
-
<View layout="row" gap="s" style={{ flexWrap: 'wrap' }}>
|
|
48
|
-
<Button
|
|
49
|
-
{...PinWidget}
|
|
50
|
-
variant="primary"
|
|
51
|
-
disabled={pinState === 'pending' || pinState === 'done'}
|
|
52
|
-
label={
|
|
53
|
-
pinState === 'done'
|
|
54
|
-
? 'consultancy.forecasts.pin.done'
|
|
55
|
-
: pinState === 'error'
|
|
56
|
-
? 'consultancy.forecasts.pin.error'
|
|
57
|
-
: 'consultancy.forecasts.pin.forecast'
|
|
58
|
-
}
|
|
59
|
-
onClick={pinToDashboard}
|
|
60
|
-
data-forecasts-pin
|
|
61
|
-
/>
|
|
62
|
-
<CreateConsultancyButton />
|
|
63
|
-
</View>
|
|
64
|
-
)}
|
|
65
|
-
>
|
|
66
|
-
<View gap="m">
|
|
67
|
-
<ConsultancyNav active="consultancy/forecasts" />
|
|
68
|
-
<Text variant="heading-secondary" as="h2" text="design-system.overview" />
|
|
69
|
-
<DataLoader content={<Forecast />} />
|
|
70
|
-
</View>
|
|
71
|
-
</Page>
|
|
72
|
-
)
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export default ForecastsPage
|