@ossy/consultancy 3.18.0 → 3.20.0

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 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
- | `forecasts.page.jsx` | `consultancy/forecasts` | `/consultancy/forecasts`, `/konsultverksamhet/prognoser` |
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, Forecasts, and Margins are in-product tabs under that surface.
15
+ One sidebar item (**Consultancy**). Overview (home), Margins, and Org Details are in-product tabs under that surface.
16
16
 
17
- The overview page shows company data (fiscal years, registration, VAT) via `@ossy/calendar`'s `useCompany` hook. Forecasts use `@ossy/calendar`'s `useForecast` / `ForecastClient` (engine stays in calendar). Margins is a standalone calculator (not yet wired to live resources).
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.18.0",
4
+ "version": "3.20.0",
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.18.0"
28
+ "@ossy/schema": "^3.20.0"
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": "8ceef98795a01c3b3486034db1d3b72b4350ccf1"
41
+ "gitHead": "edab6a966f41c07a68bdd86f3864cc2ad02e3406"
42
42
  }
@@ -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
- /** KPI Overview first, Margins middle, Org Details last. Route ids stay unchanged. */
5
+ /** Overview (home) first, Margins middle, Org Details last. */
6
6
  const TABS = [
7
7
  {
8
- id: 'consultancy/forecasts',
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/home',
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
- { key: 'projectedIncome', label: 'consultancy.forecasts.income', color: 'var(--color-primary)' },
38
- { key: 'monthlyCostOfEmployees', label: 'consultancy.forecasts.salaryCost', color: 'var(--separator-primary, var(--separator))' },
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
- * Each series is normalized to its own max so money and hours can share one chart.
74
+ * Money KPIs share one Y-scale; hours use a secondary scale (dashed stroke).
73
75
  */
74
76
  function ForecastKpiChart ({ months }) {
75
- const chart = useMemo(() => {
76
- if (!months?.length) return null
77
-
78
- const width = Math.max(280, months.length * 36)
79
- const height = 120
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,58 @@ 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
- <View style={{ overflowX: 'auto' }}>
143
- <svg
144
- data-consultancy-kpi-chart
145
- viewBox={`0 0 ${chart.width} ${chart.height}`}
146
- width={chart.width}
147
- height={chart.height}
148
- style={{ display: 'block', maxWidth: '100%' }}
149
- >
150
- {chart.seriesPaths.map((series) => (
151
- series.path ? (
152
- <path
153
- key={series.key}
154
- d={series.path}
155
- fill="none"
156
- stroke={series.color}
157
- strokeWidth={2}
158
- strokeLinejoin="round"
159
- strokeLinecap="round"
160
- />
161
- ) : null
162
- ))}
163
- </svg>
164
- </View>
165
- <View layout="row" gap="s" style={{ justifyContent: 'space-between' }}>
166
- <Text variant="small" style={{ marginBottom: 0 }}>
167
- {months[0]?.month}
168
- </Text>
169
- <Text variant="small" style={{ marginBottom: 0 }}>
170
- {months[months.length - 1]?.month}
171
- </Text>
172
- </View>
119
+ <svg
120
+ data-consultancy-kpi-chart
121
+ viewBox={`0 0 ${chart.viewWidth} ${chart.viewHeight}`}
122
+ width="100%"
123
+ height={chart.viewHeight}
124
+ style={{ display: 'block', width: '100%' }}
125
+ preserveAspectRatio="none"
126
+ >
127
+ {chart.seriesPaths.map((series) => (
128
+ series.path ? (
129
+ <path
130
+ key={series.key}
131
+ d={series.path}
132
+ fill="none"
133
+ stroke={series.color}
134
+ strokeWidth={2}
135
+ strokeLinejoin="round"
136
+ strokeLinecap="round"
137
+ strokeDasharray={series.dashed ? '4 3' : undefined}
138
+ vectorEffect="non-scaling-stroke"
139
+ />
140
+ ) : null
141
+ ))}
142
+ {chart.monthLabels.map((label) => (
143
+ <text
144
+ key={`month-${label.index}`}
145
+ data-consultancy-kpi-month={label.label}
146
+ x={label.x}
147
+ y={label.y}
148
+ textAnchor="middle"
149
+ fill="var(--fg-secondary, currentColor)"
150
+ fontSize={7}
151
+ style={{ opacity: 0.75 }}
152
+ >
153
+ {label.label}
154
+ </text>
155
+ ))}
156
+ </svg>
173
157
  </View>
174
158
  )
175
159
  }
@@ -1,6 +1,8 @@
1
- import React from 'react'
2
- import { Text, View, Page, Tags } from '@ossy/design-system'
3
- import { Overview } from './Overview.jsx'
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={<CreateConsultancyButton />}
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={<Overview />} />
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-consultancy="overview"]', timeout: 10000 } },
44
+ { result: { selector: '[data-forecasts-status="on"]', timeout: 10000 } },
45
+ { result: { selector: '[data-consultancy-year-summary]', timeout: 10000 } },
45
46
  ],
46
47
  }
@@ -1,9 +1,11 @@
1
1
  {
2
- "consultancy/home.documentTitle": "Org Details",
3
- "consultancy/forecasts.documentTitle": "Overview",
2
+ "consultancy/home.documentTitle": "Overview",
3
+ "consultancy/org.documentTitle": "Org Details",
4
4
  "consultancy/margins.documentTitle": "Margins",
5
- "consultancy.home.title": "Org Details",
6
- "consultancy.home.description": "Company and fiscal-year details",
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,134 @@
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
+ * @param {object} options
71
+ * @param {Array<Record<string, unknown>>} options.months
72
+ * @param {Array<{ key: string, label: string, color: string, dashed?: boolean }>} options.series
73
+ * @param {string} [options.language='en']
74
+ * @param {number} [options.viewWidth=100]
75
+ * @param {number} [options.plotHeight=100]
76
+ * @param {number} [options.padX=8]
77
+ * @param {number} [options.padTop=10]
78
+ * @param {number} [options.padBottom=22]
79
+ * @returns {{ viewWidth: number, viewHeight: number, seriesPaths: Array<object>, monthLabels: Array<object> } | null}
80
+ */
81
+ export function buildKpiChartLayout ({
82
+ months,
83
+ series,
84
+ language = 'en',
85
+ viewWidth = 100,
86
+ plotHeight = 100,
87
+ padX = 8,
88
+ padTop = 10,
89
+ padBottom = 22,
90
+ }) {
91
+ if (!months?.length || !series?.length) return null
92
+
93
+ const viewHeight = padTop + plotHeight + padBottom
94
+ const innerW = viewWidth - padX * 2
95
+ const innerH = plotHeight
96
+ const step = months.length === 1 ? 0 : innerW / (months.length - 1)
97
+
98
+ const moneyExtent = extentForKeys(months, MONEY_KEYS)
99
+ const hoursExtent = extentForKeys(months, [HOURS_KEY])
100
+
101
+ const seriesPaths = series.map((entry) => {
102
+ const extent = entry.key === HOURS_KEY ? hoursExtent : moneyExtent
103
+ if (!extent) return { ...entry, path: null }
104
+
105
+ const points = months.map((month, index) => {
106
+ const value = Number(month[entry.key]) || 0
107
+ const x = padX + index * step
108
+ const y = valueToY(value, extent, padTop, innerH)
109
+ return `${x},${y}`
110
+ })
111
+ return { ...entry, path: `M ${points.join(' L ')}` }
112
+ })
113
+
114
+ const monthLabels = months.map((month, index) => ({
115
+ index,
116
+ label: shortMonthLabel(month, language),
117
+ x: padX + index * step,
118
+ y: viewHeight - 6,
119
+ }))
120
+
121
+ return {
122
+ viewWidth,
123
+ viewHeight,
124
+ seriesPaths,
125
+ monthLabels,
126
+ step,
127
+ padX,
128
+ padTop,
129
+ padBottom,
130
+ plotHeight,
131
+ innerW,
132
+ innerH,
133
+ }
134
+ }
@@ -0,0 +1,116 @@
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('returns null for empty months', () => {
114
+ expect(buildKpiChartLayout({ months: [], series })).toBeNull()
115
+ })
116
+ })
@@ -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
@@ -1,9 +1,11 @@
1
1
  {
2
- "consultancy/home.documentTitle": "Orgdetaljer",
3
- "consultancy/forecasts.documentTitle": "Översikt",
2
+ "consultancy/home.documentTitle": "Översikt",
3
+ "consultancy/org.documentTitle": "Orgdetaljer",
4
4
  "consultancy/margins.documentTitle": "Marginaler",
5
- "consultancy.home.title": "Orgdetaljer",
6
- "consultancy.home.description": "Företags- och räkenskapsårsdetaljer",
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 forecasts and assert
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 forecasts section',
17
+ 'Signed-in user enables consultancy and opens the consultancy home overview',
18
18
  steps: [
19
19
  ...enableConsultancyFlow.steps,
20
- { page: '@consultancy/forecasts' },
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
  }
@@ -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