diff --git a/build/growth-baseline.json b/build/growth-baseline.json index 51f67d3..0152bf9 100644 --- a/build/growth-baseline.json +++ b/build/growth-baseline.json @@ -3,7 +3,7 @@ "pages": { "README.md": [110] }, - "totalLines": 5202 + "totalLines": 5313 }, "javascript": { "complexity": { @@ -26,7 +26,7 @@ "modules/PowerShellUniversal.Component.ECharts.Demo/Apps/Showcase.ps1": [1330], "modules/PowerShellUniversal.Component.Pivot.Demo/Apps/Showcase.ps1": [305], "tests/powershell/Pivot.Tests.ps1": [521], - "tests/powershell/PivotReport.Tests.ps1": [1391], + "tests/powershell/PivotReport.Tests.ps1": [1408], "tests/powershell/PivotTemplates.Tests.ps1": [729] }, "functions": { diff --git a/docs/pivot/coming-from-ud-pivot.md b/docs/pivot/coming-from-ud-pivot.md new file mode 100644 index 0000000..e2b68fc --- /dev/null +++ b/docs/pivot/coming-from-ud-pivot.md @@ -0,0 +1,89 @@ +--- +title: Coming from UniversalDashboard.Pivot +description: "Move an app from New-UDPivot of UniversalDashboard.Pivot to New-UDPivotReport: what each parameter becomes, and one report before and after." +--- + +# Coming from UniversalDashboard.Pivot + +`New-UDPivotReport` replaces `New-UDPivot` of [UniversalDashboard.Pivot](https://github.com/eizedev/UniversalDashboard.Pivot), +which wraps react-pivottable. + +## Requirements + +- PowerShell 7.4 or later, in the PSU environment the app runs in. UniversalDashboard.Pivot also ran + on Windows PowerShell 5.1; this module does not load there. +- PowerShell Universal 2026.2 or 2026.3, tested with 2026.2.5 and 2026.3.4. + +[Compatibility](../compatibility.md) has the details and how each version is tested. + +## One report before and after + +The start view moves from parameters into one `-View` ([Views](views.md#the-start-view-view)). The +same rows, before and after: + +```powershell +$data = @( + @{ Team = 'OPS'; Status = 'Open'; Priority = 'High'; Hours = 5 } + @{ Team = 'OPS'; Status = 'Closed'; Priority = 'Low'; Hours = 2 } + @{ Team = 'OPS'; Status = 'Closed'; Priority = 'High'; Hours = 4 } + @{ Team = 'DEV'; Status = 'Open'; Priority = 'High'; Hours = 8 } + @{ Team = 'DEV'; Status = 'Closed'; Priority = 'Medium'; Hours = 3 } + @{ Team = 'DEV'; Status = 'Open'; Priority = 'Low'; Hours = 6 } + @{ Team = 'QA'; Status = 'Open'; Priority = 'Medium'; Hours = 1 } + @{ Team = 'QA'; Status = 'Closed'; Priority = 'High'; Hours = 7 } +) +# before +New-UDPivot -Id 'tickets-before' -Data $data -Rows 'Team' -Cols 'Status' -Vals 'Hours' -AggregatorName 'Sum' -RowOrder 'value_z_to_a' -ValueFilter @{ Priority = @{ Low = $true } } +# after +New-UDPivotReport -Id 'tickets-after' -Data $data -View @{ + rows = @('Team') + cols = @('Status') + values = @(@{ field = 'Hours'; agg = 'sum' }) + filters = @(@{ field = 'Priority'; type = 'in'; items = @('Low'); not = $true; blanks = 'include' }) + sort = @(@{ field = 'Team'; by = 'value'; order = 'desc' }) +} +``` + +Both show the sum of hours without the Low tickets, the teams by their total, highest first: DEV 11, +OPS 9, QA 8. + +## Parameters + +| `New-UDPivot` | `New-UDPivotReport` | +| --- | --- | +| `-Id`, `-Data` | `-Id`, `-Data`: also a DataTable ([Data and loading](data.md)) | +| `-Rows`, `-Cols` | `rows`, `cols` in `-View` | +| `-RowOrder`, `-ColOrder` | `key_a_to_z`: the default. `value_a_to_z`, `value_z_to_a`: `sort = @(@{ field = 'Team'; by = 'value'; order = 'asc' })` or `'desc'`, per row or column field. | +| `-ValueFilter` | `filters`: the listed items with `type = 'in'; not = $true; blanks = 'include'` ([Filters](filters.md)). | +| `-HiddenAttributes` | No counterpart: leave the column out of the rows you pass to `-Data` (`Select-Object -ExcludeProperty` for objects), so it does not reach the browser either. | +| `-HiddenFromAggregators`, `-HiddenFromDragDrop`, `-MenuLimit`, `-UnusedOrientationCutoff` | No counterpart. | + +## Aggregators + +`-Vals` and `-AggregatorName` become `values` in `-View`, each with its field and `agg`. + +| `-AggregatorName` | `agg` in `values` | +| --- | --- | +| `Count` | `count` on a field: it counts the rows where the field has a value. | +| `Count Unique Values`, `List Unique Values` | `countUnique`, `listUnique` | +| `Sum`, `Integer Sum` | `sum`; for `Integer Sum` with `format = 'integer'` | +| `Average`, `Median`, `Minimum`, `Maximum`, `First`, `Last` | `average`, `median`, `min`, `max`, `first`, `last` | +| `Sample Variance`, `Sample Standard Deviation` | `var`, `stdev` | +| `Sum as Fraction of Total`, `of Rows`, `of Columns`; the same for `Count` | `sum` or `count` with `showAs = @{ type = 'percentOfGrandTotal' }`, `'percentOfRowTotal'`, `'percentOfColumnTotal'` | +| `Sum over Sum`, `80% Upper Bound`, `80% Lower Bound` | No counterpart. | + +## Renderers + +`-RendererName` becomes the value's `conditional` or the view's `display` and `chart`. + +| `-RendererName` | In `-View` | +| --- | --- | +| `Table` | The default. | +| `Table Heatmap` | `conditional = @{ type = 'colorScale' }` on the value | +| `Grouped Column Chart`, `Stacked Column Chart` | `display = 'chart'; chart = @{ type = 'bar' }`; for stacked columns `chart = @{ type = 'bar'; stacked = $true }` | +| `Grouped Bar Chart`, `Stacked Bar Chart` | the same as the column charts, with `horizontal = $true` in `chart` | +| `Line Chart`, `Area Chart` | `display = 'chart'; chart = @{ type = 'line' }`, or `type = 'area'` | +| `Exportable TSV` | The reader's export copies the table as tab-separated text. | +| `Table Row Heatmap`, `Table Col Heatmap`, `Dot Chart`, `Scatter Chart`, `Multiple Pie Chart` | No counterpart. `type = 'pie'` draws one pie of the row totals. | + +Next: [Views](views.md), [Data and loading](data.md), [Overview](index.md). diff --git a/docs/pivot/index.md b/docs/pivot/index.md index 0140875..74933a6 100644 --- a/docs/pivot/index.md +++ b/docs/pivot/index.md @@ -40,6 +40,7 @@ New-UDPivotReport -Id 'tickets' -Data (Invoke-Sqlcmd -Query 'SELECT * FROM Ticke | What readers get, and what the app decides for them | [Readers and your app](readers.md) | | What `-Data` takes, large data | [Data and loading](data.md) | | Every parameter | [Commands and parameters](reference.md) | +| Move an app from `New-UDPivot` | [Coming from UniversalDashboard.Pivot](coming-from-ud-pivot.md) | Readers drag fields from a searchable list into **Rows**, **Columns**, **Values** and **Filters** and get a table with totals or a chart, with date grouping, drill-down to the source rows, shared views and diff --git a/docs/pivot/reports-server.md b/docs/pivot/reports-server.md index 5e9d61c..0ca5591 100644 --- a/docs/pivot/reports-server.md +++ b/docs/pivot/reports-server.md @@ -26,7 +26,7 @@ data you send. `-DataName` names the data, `-DataAsOf` says when it is from (sen arrived). `-Data` (and with it `-DataName` and `-DataAsOf`) and `-Parameter` need pivotkit-server 0.2.0 or -later. +later; `-Locale`, `-Numbers` and `-FlatHeader` ([Reports without a browser](reports.md#two-engines)) 0.3.0 or later. The token comes from the server's operator, who makes it with `pivotkit-server token new`; keep it in a PSU secret. pivotkit-server refuses a static token that is easy to guess diff --git a/docs/pivot/reports.md b/docs/pivot/reports.md index a6fec5d..7c87e19 100644 --- a/docs/pivot/reports.md +++ b/docs/pivot/reports.md @@ -34,15 +34,26 @@ file's bytes, for an endpoint's answer or a mail attachment. | Runs | pivotkit's command line on the PSU server | a pivotkit-server somewhere else | | Needs | Node 24 or later and `npm install --global pivotkit-cli` (0.2.1 or later) on the PSU server | a pivotkit-server, its address and a token or OAuth client ([which server](reports-server.md#rest-a-pivotkit-server)) | | Data | `-Data`, written to a temporary folder of its own (mode 0700 on Linux and macOS; on Windows it inherits the ACL of the user's TEMP folder), removed afterwards | `-Data`, sent in the request; or `-Source`, a source the server's operator configured | -| Language, time zone | `-Locale`, `-TimeZone` | the server's | +| Language, time zone | `-Locale`, `-TimeZone` | `-Locale`; the time zone is the server's | | HTML print template | `-Template` | the server's source decides | -| Numbers and header of CSV and JSON | `-Numbers Shown` rounds to the decimals the view shows, `-FlatHeader` writes one CSV header row | the server's | | Result | the file | the file, or a link that expires (`-AsLink`) | Both take `-View` (a hashtable, JSON text or a view file) or `-Layout` (the view by field names), and both check the view against the data first: a view with errors writes nothing, and the error lists what pivotkit found (the field it did not find, the name it probably meant). +A CSV or JSON file holds every number with full precision. `-Numbers Shown` rounds each number to the +decimals the view shows; `-Numbers Full` is the default. `-FlatHeader` gives a CSV file one header +row instead of one per column field; each column names its labels joined with " / ". `-Locale` sets +the language and number format of a view that names none (a CSV in `de-DE` uses `;` and the decimal +comma). With the same `-Locale` and server settings, both engines write the same file. `-Numbers` and +`-FlatHeader` need pivotkit-cli 0.5.0 or later, and all three need pivotkit-server 0.3.0 or later; +the function refuses `-Numbers` and `-FlatHeader` for another format. + +```powershell +Invoke-UDPivotReport -Engine Node -Data $tickets -View $view -OutFile ./tickets.csv -Numbers Shown -FlatHeader -Locale de-DE +``` + ```powershell Invoke-UDPivotReport -Engine Node -Data $tickets -Format html -Title 'Lead time per month' -Layout @{ rows = 'Created' @@ -77,15 +88,6 @@ stream. `-TimeoutSec` (default 120) stops a run that takes longer. A job that is `pivotkit-<32 hex characters>` in the temporary folder of the account PSU runs as; remove such folders now and then. -A CSV or JSON file holds every number with full precision. `-Numbers Shown` rounds each number to the -decimals the view shows, as pivotkit-server writes them; `-Numbers Full` is the default. `-FlatHeader` -gives a CSV file one header row instead of one per column field; each column names its labels joined -with " / ". Both need pivotkit-cli 0.5.0 or later, and the function refuses them for another format. - -```powershell -Invoke-UDPivotReport -Engine Node -Data $tickets -View $view -OutFile ./tickets.csv -Numbers Shown -FlatHeader -``` - An HTML report takes a print template of your own with `-Template`, for your company's look and metadata. It goes with `-Format html` only (or an `-OutFile` that ends in `.html`): diff --git a/docs/pivot/theme-properties.md b/docs/pivot/theme-properties.md new file mode 100644 index 0000000..6719211 --- /dev/null +++ b/docs/pivot/theme-properties.md @@ -0,0 +1,80 @@ +--- +title: Pivot theme properties +description: "Every CSS custom property New-UDPivotReport reads from the app's stylesheet: what it falls back to when unset, what it sets in the report, and its default in light and dark mode." +--- + +# Theme properties + +The properties an app's stylesheet sets for the report, per light and dark mode, as +[Themes and corporate design](themes.md) shows. A property without a value falls back to the next one +in its row; without any, the report keeps the default of its mode. The rows from +`--psu-pivot-zone-rows` to `--psu-pivot-field-hover` take effect with pivotkit 0.11.0 or later in the +module; with an older pivotkit they set nothing. `--psu-pivot-chart-reference`, after them, needs no +minimum. + +| Property | Falls back to | What it sets in the report | Light | Dark | +| --- | --- | --- | --- | --- | +| `--psu-chart-1` ... `--psu-chart-8` | - | series colours of the report's chart, by position; positions without a property keep theirs | pivotkit's palette | pivotkit's palette | +| `--psu-pivot-text` | `--psu-chart-text` | text | `rgba(0, 0, 0, 0.87)` | `rgba(255, 255, 255, 0.87)` | +| `--psu-pivot-muted` | `--psu-chart-muted` | secondary text, chart labels | `rgba(0, 0, 0, 0.62)` | `rgba(255, 255, 255, 0.64)` | +| `--psu-pivot-border` | `--psu-chart-axis` | borders of buttons, chips, panels and menus; the chart's axis line, unless an app sets one of the next row | `#e0e0e0` | `#2e2e2e` | +| `--psu-pivot-chart-axis` | `--psu-chart-axis` | the chart's axis line, apart from the table's lines | as `--psu-pivot-border` | as `--psu-pivot-border` | +| `--psu-pivot-grid` | `--psu-chart-grid` | lines between table cells, chart grid lines | `#eeeeee` | `#232323` | +| `--psu-pivot-accent` | `--psu-chart-accent` | primary buttons, badges, links, opened menus | `#1976d2` | `#90caf9` | +| `--psu-pivot-accent-text` | - | text on the accent | `#ffffff` | `#0b1a2a` | +| `--psu-pivot-focus` | `--psu-pivot-accent`, `--psu-chart-accent` | keyboard focus ring | `#1976d2` | `#90caf9` | +| `--psu-pivot-accent-soft` | 12 % (dark 18 %) of the corporate accent over the surface | badges, opened buttons, focused inputs | `#e3effb` | `#1b2a38` | +| `--psu-pivot-drop` | 18 % (dark 32 %) of the corporate accent over the surface | a zone while a field is dragged over it | `#d6e7f9` | `#1e3a55` | +| `--psu-pivot-note` | 7 % (dark 10 %) of the corporate accent over the surface | notes and hints | `#eef5fc` | `#16212c` | +| `--psu-pivot-surface` | - | background of the report and of the zones | `#ffffff` | `#121212` | +| `--psu-pivot-surface-2` | - | the zones' section, table headers, the field list's panel | `#f5f6f8` | `#1a1a1a` | +| `--psu-pivot-surface-3` | - | hovered controls, the Table/Chart switch | `#eaecef` | `#262626` | +| `--psu-pivot-surface-raised` | - | menus, popovers, the drill-down table, chart tooltips | `#ffffff` | `#1f1f1f` | +| `--psu-pivot-border-strong` | - | frame of a zone, hovered buttons and chips, the switch track, the grand-total line, scroll bars | `#c4c4c4` | `#474747` | +| `--psu-pivot-drop-border` | - | edge of a zone while a field is dragged | `#8a8a8a` | `#7a7a7a` | +| `--psu-pivot-input-border` | - | edge of a text field or a select in a menu | `#808080` | `#858585` | +| `--psu-pivot-rule` | - | line between a menu's groups | `#808080` | `#858585` | +| `--psu-pivot-total` | - | subtotals | `#f5f6f8` | `#1a1a1a` | +| `--psu-pivot-total-strong` | - | the grand total | `#eaecef` | `#242424` | +| `--psu-pivot-heat-low` | - | heatmap chart, lowest value | `#eaf1fb` | `#1d2735` | +| `--psu-pivot-heat-high` | - | heatmap chart, highest value | `#2a78d6` | `#3987e5` | +| `--psu-pivot-chart-other` | - | the grey slice "Other (n)" a pie or donut without a legend puts its smallest slices into; without a value, in the light theme the muted text, in the dark a fixed grey | `rgba(0, 0, 0, 0.62)` | `#6b7280` | +| `--psu-pivot-scale-low` | `--psu-pivot-heat-low` | colour scale of a value without colours of its own, lowest | `#eaf1fb` | `#1d2735` | +| `--psu-pivot-scale-mid` | - | colour scale of a value, middle: set, the scale has three colours | none | none | +| `--psu-pivot-scale-high` | `--psu-pivot-heat-high` | colour scale of a value without colours of its own, highest | `#2a78d6` | `#3987e5` | +| `--psu-pivot-type-string`, `--psu-pivot-type-number`, `--psu-pivot-type-date`, `--psu-pivot-type-boolean` | `--psu-pivot-muted`, `--psu-chart-muted` | the icon of a text, number, date or yes/no field and its pill in the empty report | `rgba(0, 0, 0, 0.62)` | `rgba(255, 255, 255, 0.64)` | +| `--psu-pivot-zone-rows` | - | the Rows zone: its icons, its marks in the field list, its fields' names in the table's header | `#1d5fcc` | `#8db4ff` | +| `--psu-pivot-zone-columns` | - | the Columns zone, the same parts | `#a85a00` | `#f2b559` | +| `--psu-pivot-zone-values` | - | the Values zone, the same parts, also on the grand total | `#0b785c` | `#5fd6ac` | +| `--psu-pivot-zone-filters` | `--psu-pivot-muted`, `--psu-chart-muted` | the Filters zone, the same parts | `rgba(0, 0, 0, 0.62)` | `rgba(255, 255, 255, 0.64)` | +| `--psu-pivot-zone-tint` | - | how much of its zone's colour a chip's fill takes | `16%` | `16%` | +| `--psu-pivot-zone-tint-base` | `--psu-pivot-surface` | what a chip's fill mixes the zone's colour into | `#ffffff` | `#121212` | +| `--psu-pivot-control-icon` | `--psu-pivot-muted`, `--psu-chart-muted` | a chip's grip, menu arrow and remove button | `rgba(0, 0, 0, 0.62)` | `rgba(255, 255, 255, 0.64)` | +| `--psu-pivot-sort-arrow` | `--psu-pivot-text`, `--psu-chart-text` | the sort arrow of the sorted field | `rgba(0, 0, 0, 0.87)` | `rgba(255, 255, 255, 0.87)` | +| `--psu-pivot-field-hover` | `--psu-pivot-surface` | a field in the field list on hover | `#ffffff` | `#121212` | +| `--psu-pivot-chart-reference` | `--psu-pivot-muted`, `--psu-chart-muted` | the chart's reference lines that belong to no series | `rgba(0, 0, 0, 0.62)` | `rgba(255, 255, 255, 0.64)` | +| `--psu-pivot-tab-bg` | - | a tab not shown (Table, Chart): its background | `transparent` | `transparent` | +| `--psu-pivot-tab-text` | `--psu-pivot-muted`, `--psu-chart-muted` | a tab not shown: its text | `rgba(0, 0, 0, 0.62)` | `rgba(255, 255, 255, 0.64)` | +| `--psu-pivot-tab-selected-bg` | `--psu-pivot-surface` | the tab shown: its background | `#ffffff` | `#121212` | +| `--psu-pivot-tab-selected-text` | `--psu-pivot-accent`, `--psu-chart-accent` | the tab shown: its text | `#1976d2` | `#90caf9` | +| `--psu-pivot-icon-button-text` | `--psu-pivot-muted`, `--psu-chart-muted` | a button with only an icon (a field's menu, Close, folding the field list): the icon | `rgba(0, 0, 0, 0.62)` | `rgba(255, 255, 255, 0.64)` | +| `--psu-pivot-icon-button-hover-bg` | `--psu-pivot-surface-3` | such a button on hover and while its menu is open | `#eaecef` | `#262626` | +| `--psu-pivot-button-border` | `--psu-pivot-border`, `--psu-chart-axis` | the frame of a button (the toolbar's, Table settings, Enlarge, Full screen) | `#e0e0e0` | `#2e2e2e` | +| `--psu-pivot-button-border-hover` | `--psu-pivot-border-strong` | the frame of a button on hover | `#c4c4c4` | `#474747` | +| `--psu-pivot-primary-bg` | `--psu-pivot-accent`, `--psu-chart-accent` | the main action of a dialog (Apply, Save, Load): its fill and frame | `#1976d2` | `#90caf9` | +| `--psu-pivot-primary-text` | `--psu-pivot-accent-text` | the main action's text | `#ffffff` | `#0b1a2a` | +| `--psu-pivot-primary-hover-bg` | - | the main action's fill on hover | 88 % of its fill, mixed with the text colour | 88 % of its fill, mixed with the text colour | +| `--psu-pivot-radius` | - | corner radius of the report, panels, zones and popovers | `8px` | `8px` | +| `--psu-pivot-radius-sm` | - | corner radius of buttons, chips, notes, the fields in the field list and their hover, and a field's name in the table's header; pivotkit's smaller corners (links, a chip's grip, badges, a field's type icon) follow it. `4px` is PSU's own corner; pivotkit's is `7px`. Chips and the table's field names follow it with pivotkit 0.11.0 or later | `4px` | `4px` | +| `--psu-pivot-font` | - | font family | the page's font | the page's font | +| `--psu-pivot-font-size` | - | base text size | `max(14px, 1em)` | `max(14px, 1em)` | +| `--psu-pivot-weight-normal` | - | plain text inside a bolder part (hints, table cells) | `400` | `400` | +| `--psu-pivot-weight-medium` | - | light emphasis (row labels, segmented buttons) | `500` | `500` | +| `--psu-pivot-weight-strong` | - | titles, field chips, buttons, subtotals, the admin panel's titles | `600` | `600` | +| `--psu-pivot-weight-bold` | - | grand totals, step numbers | `700` | `700` | + +The report's chart has eight series colours. `--psu-chart-9` ... `--psu-chart-12`, `--psu-chart-tooltip`, +`--psu-chart-tooltip-border` and `--psu-chart-font-size` are ECharts only; the report's tooltips use +`--psu-pivot-surface-raised`. + +Next: [Themes and corporate design](themes.md), [Commands and parameters](reference.md). diff --git a/docs/pivot/themes.md b/docs/pivot/themes.md index 0702009..fca7399 100644 --- a/docs/pivot/themes.md +++ b/docs/pivot/themes.md @@ -50,16 +50,12 @@ the report a value of its own; a `--psu-pivot-*` property wins over its `--psu-c } ``` -The first block is the light mode, the second the dark one. Each mode needs its own values: a -property set only in `:root` applies to both modes, and a dark text colour from the light block would -be unreadable on the dark report. Each block names two selectors: `:root` and `:root[data-theme="dark"]` -for the ECharts charts, which follow the page, and `.ud-pivot-report [data-pk-theme="light"]` and -`[data-pk-theme="dark"]` for the theme the report shows. The second pair matters for the exports. -The Excel export is light (black text in Excel). The HTML report carries both modes: light for paper -and a light screen, dark for a reader whose screen is dark. The report reads each mode's colours by -showing that theme for a moment. With the page's selectors alone, it would inherit the page's current -mode both times and write that mode's values into the file. Colours are hex or `rgb()`/`rgba()`: the report's chart hands the -series colours to ECharts, which does not read every CSS colour syntax. +The first block is the light mode, the second the dark one. `:root` and `:root[data-theme="dark"]` serve +the ECharts charts, which follow the page; `.ud-pivot-report [data-pk-theme="light"]` and +`[data-pk-theme="dark"]` serve the theme the report shows. The exports need the second pair: the report +reads each mode's colours by showing that theme for a moment, and with the page's selectors alone it +would write the page's current mode both times. Colours are hex or `rgb()`/`rgba()`: the report's chart +hands the series colours to ECharts, which does not read every CSS colour syntax. ## Adding the stylesheet to an app @@ -74,88 +70,33 @@ New-PSUPublishedFolder -RequestPath '/assets' -Path 'C:\ProgramData\UniversalAut New-UDApp -Title 'Reports' -Stylesheets @('/assets/corporate.css') -Pages @( ... ) ``` -For a single page, or to try values out, a `' ``` -The properties apply to every chart and report of the page, so this site shows no live example of them. - ## Properties The series colours (`--psu-chart-1` ... `--psu-chart-8`) and the accent (`--psu-chart-accent` or `--psu-pivot-accent`) carry a corporate design: the highlight, drop zone, note, tab and button colours -follow from the accent, and without one they keep PSU's values. The `--psu-pivot-*` properties in the -table set what only the report has or give it a value of its own. Set `--psu-pivot-accent-text` whenever the accent is light in the light mode -or dark in the dark mode: the default text on the accent is white in light mode and near-black in dark. - -
-Every property: what it falls back to when unset, and its default without a corporate stylesheet - -| Property | Falls back to | What it sets in the report | Light | Dark | -| --- | --- | --- | --- | --- | -| `--psu-chart-1` ... `--psu-chart-8` | - | series colours of the report's chart, by position; positions without a property keep theirs | pivotkit's palette | pivotkit's palette | -| `--psu-pivot-text` | `--psu-chart-text` | text | `rgba(0, 0, 0, 0.87)` | `rgba(255, 255, 255, 0.87)` | -| `--psu-pivot-muted` | `--psu-chart-muted` | secondary text, chart labels | `rgba(0, 0, 0, 0.62)` | `rgba(255, 255, 255, 0.64)` | -| `--psu-pivot-border` | `--psu-chart-axis` | borders of buttons, chips, panels and menus; the chart's axis line, unless an app sets one of the next row | `#e0e0e0` | `#2e2e2e` | -| `--psu-pivot-chart-axis` | `--psu-chart-axis` | the chart's axis line, apart from the table's lines | as `--psu-pivot-border` | as `--psu-pivot-border` | -| `--psu-pivot-grid` | `--psu-chart-grid` | lines between table cells, chart grid lines | `#eeeeee` | `#232323` | -| `--psu-pivot-accent` | `--psu-chart-accent` | primary buttons, badges, links, opened menus | `#1976d2` | `#90caf9` | -| `--psu-pivot-accent-text` | - | text on the accent | `#ffffff` | `#0b1a2a` | -| `--psu-pivot-focus` | `--psu-pivot-accent`, `--psu-chart-accent` | keyboard focus ring | `#1976d2` | `#90caf9` | -| `--psu-pivot-accent-soft` | 12 % (dark 18 %) of the corporate accent over the surface | badges, opened buttons, focused inputs | `#e3effb` | `#1b2a38` | -| `--psu-pivot-drop` | 18 % (dark 32 %) of the corporate accent over the surface | a zone while a field is dragged over it | `#d6e7f9` | `#1e3a55` | -| `--psu-pivot-note` | 7 % (dark 10 %) of the corporate accent over the surface | notes and hints | `#eef5fc` | `#16212c` | -| `--psu-pivot-surface` | - | background of the report and of the zones | `#ffffff` | `#121212` | -| `--psu-pivot-surface-2` | - | the zones' section, table headers, the field list's panel | `#f5f6f8` | `#1a1a1a` | -| `--psu-pivot-surface-3` | - | hovered controls, the Table/Chart switch | `#eaecef` | `#262626` | -| `--psu-pivot-surface-raised` | - | menus, popovers, the drill-down table, chart tooltips | `#ffffff` | `#1f1f1f` | -| `--psu-pivot-border-strong` | - | frame of a zone, hovered buttons and chips, the switch track, the grand-total line, scroll bars | `#c4c4c4` | `#474747` | -| `--psu-pivot-drop-border` | - | edge of a zone while a field is dragged | `#8a8a8a` | `#7a7a7a` | -| `--psu-pivot-input-border` | - | edge of a text field or a select in a menu | `#808080` | `#858585` | -| `--psu-pivot-rule` | - | line between a menu's groups | `#808080` | `#858585` | -| `--psu-pivot-total` | - | subtotals | `#f5f6f8` | `#1a1a1a` | -| `--psu-pivot-total-strong` | - | the grand total | `#eaecef` | `#242424` | -| `--psu-pivot-heat-low` | - | heatmap chart, lowest value | `#eaf1fb` | `#1d2735` | -| `--psu-pivot-heat-high` | - | heatmap chart, highest value | `#2a78d6` | `#3987e5` | -| `--psu-pivot-chart-other` | - | the grey slice "Other (n)" a pie or donut without a legend puts its smallest slices into; without a value, in the light theme the muted text, in the dark a fixed grey | `rgba(0, 0, 0, 0.62)` | `#6b7280` | -| `--psu-pivot-scale-low` | `--psu-pivot-heat-low` | colour scale of a value without colours of its own, lowest | `#eaf1fb` | `#1d2735` | -| `--psu-pivot-scale-mid` | - | colour scale of a value, middle: set, the scale has three colours | none | none | -| `--psu-pivot-scale-high` | `--psu-pivot-heat-high` | colour scale of a value without colours of its own, highest | `#2a78d6` | `#3987e5` | -| `--psu-pivot-type-string` | - | the icon of a text field and its pill in the empty report | `#6250d6` | `#a99dff` | -| `--psu-pivot-type-number` | - | the icon of a number field and its pill | `#1a7f5a` | `#5fd3a3` | -| `--psu-pivot-type-date` | - | the icon of a date field and its pill | `#b5560b` | `#f2a65a` | -| `--psu-pivot-type-boolean` | - | the icon of a yes/no field and its pill | `#a3367a` | `#f08cc6` | -| `--psu-pivot-tab-bg` | - | a tab not shown (Table, Chart): its background | `transparent` | `transparent` | -| `--psu-pivot-tab-text` | `--psu-pivot-muted`, `--psu-chart-muted` | a tab not shown: its text | `rgba(0, 0, 0, 0.62)` | `rgba(255, 255, 255, 0.64)` | -| `--psu-pivot-tab-selected-bg` | `--psu-pivot-surface` | the tab shown: its background | `#ffffff` | `#121212` | -| `--psu-pivot-tab-selected-text` | `--psu-pivot-accent`, `--psu-chart-accent` | the tab shown: its text | `#1976d2` | `#90caf9` | -| `--psu-pivot-icon-button-text` | `--psu-pivot-muted`, `--psu-chart-muted` | a button with only an icon (a field's menu, Close, folding the field list): the icon | `rgba(0, 0, 0, 0.62)` | `rgba(255, 255, 255, 0.64)` | -| `--psu-pivot-icon-button-hover-bg` | `--psu-pivot-surface-3` | such a button on hover and while its menu is open | `#eaecef` | `#262626` | -| `--psu-pivot-button-border` | `--psu-pivot-border`, `--psu-chart-axis` | the frame of a button (the toolbar's, Table settings, Enlarge, Full screen) | `#e0e0e0` | `#2e2e2e` | -| `--psu-pivot-button-border-hover` | `--psu-pivot-border-strong` | the frame of a button on hover | `#c4c4c4` | `#474747` | -| `--psu-pivot-primary-bg` | `--psu-pivot-accent`, `--psu-chart-accent` | the main action of a dialog (Apply, Save, Load): its fill and frame | `#1976d2` | `#90caf9` | -| `--psu-pivot-primary-text` | `--psu-pivot-accent-text` | the main action's text | `#ffffff` | `#0b1a2a` | -| `--psu-pivot-primary-hover-bg` | - | the main action's fill on hover | 88 % of its fill, mixed with the text colour | 88 % of its fill, mixed with the text colour | -| `--psu-pivot-radius` | - | corner radius of the report, panels, zones and popovers | `8px` | `8px` | -| `--psu-pivot-radius-sm` | - | corner radius of buttons, fields and notes | `4px` | `4px` | -| `--psu-pivot-font` | - | font family | the page's font | the page's font | -| `--psu-pivot-font-size` | - | base text size | `max(14px, 1em)` | `max(14px, 1em)` | -| `--psu-pivot-weight-normal` | - | plain text inside a bolder part (hints, table cells) | `400` | `400` | -| `--psu-pivot-weight-medium` | - | light emphasis (row labels, segmented buttons) | `500` | `500` | -| `--psu-pivot-weight-strong` | - | titles, field chips, buttons, subtotals, the admin panel's titles | `600` | `600` | -| `--psu-pivot-weight-bold` | - | grand totals, step numbers | `700` | `700` | - -
- -The report's chart has eight series colours: `--psu-chart-9` ... `--psu-chart-12` colour only ECharts -charts. `--psu-chart-tooltip`, `--psu-chart-tooltip-border` and `--psu-chart-font-size` are ECharts -only as well; the report's tooltips use `--psu-pivot-surface-raised`. - -The field type colours are pivotkit's own: a corporate palette sets them per mode, so each stays -readable on its mode's surface. Set the tab and button properties only where a part needs a colour of -its own. +follow from the accent, and without one they keep PSU's values. Set `--psu-pivot-accent-text` whenever +the accent is light in the light mode or dark in the dark mode: the default text on the accent is white +in light mode and near-black in dark. + +Every property, what it falls back to when unset and its default without a corporate stylesheet: +[Theme properties](theme-properties.md). + +With pivotkit 0.11.0 or later in the module, colour marks the zones, not the field types: the type +icons are the muted text. The zone colours are pivotkit's own; a corporate one needs 4.5:1 on `--psu-pivot-surface-2` (the values colour also on +`--psu-pivot-total-strong`) and 3:1 on its chips' fill. For coloured type icons, as the report had +before, set the four type properties per mode: + +```css +:root, .ud-pivot-report [data-pk-theme="light"] { --psu-pivot-type-string: #6250d6; --psu-pivot-type-number: #1a7f5a; --psu-pivot-type-date: #b5560b; --psu-pivot-type-boolean: #a3367a; } +:root[data-theme="dark"], .ud-pivot-report [data-pk-theme="dark"] { --psu-pivot-type-string: #a99dff; --psu-pivot-type-number: #5fd3a3; --psu-pivot-type-date: #f2a65a; --psu-pivot-type-boolean: #f08cc6; } +``` A colour scale a reader adds without picking colours runs from light to strong blue, the heatmap's colours: it says "more", not "good" or "bad", and the Excel export writes the same colours. For @@ -187,14 +128,12 @@ dark** follows the three properties above. ## Light and dark Excel and print are light also from a dark app; the HTML report is light on paper and on a light screen -and dark on a dark one. The report takes light or dark from PSU's `` and switches with the app's toggle, the -table and the chart at once, without a reload, and keeps the reader's view ([Views](views.md#the-start-view-view)); -undo and redo start over. The theme the report shows is `data-pk-theme="light"` or `"dark"` on its -root; the stylesheet above sets the values on it, so a report pinned with `-Theme Light` or -`-Theme Dark` takes the values of its own theme, also in an app of the other mode. Properties set only -on the page root (`:root`, `:root[data-theme="dark"]`) reach the report by inheritance in the page's -current mode; they are fine for a value that is the same in both modes. Set corners, font weights and -the font on `:root`: the admin panel of `-AdminRole` sits next to the report, outside its theme, and -takes `--psu-pivot-radius`, `--psu-pivot-radius-sm` and `--psu-pivot-weight-strong` from there. +and dark on a dark one. The report takes light or dark from PSU's `` and switches with the +app's toggle without a reload, keeping the reader's view ([Views](views.md#the-start-view-view)); undo +and redo start over. The theme it shows is `data-pk-theme="light"` or `"dark"` on its root, where the +stylesheet above sets the values, so a report pinned with `-Theme Light` or `-Theme Dark` takes its own +theme's values in either app mode. A property set only on `:root` reaches both modes: keep it to values +both share, as corners, font weights and the font. The admin panel of `-AdminRole` sits outside the +report's theme and takes `--psu-pivot-radius`, `--psu-pivot-radius-sm` and `--psu-pivot-weight-strong` from `:root`. Next: [Views](views.md), [Templates, view files and roles](templates.md), [Events, security and limits](events.md), [Reference](reference.md). diff --git a/modules/PowerShellUniversal.Component.Pivot/CHANGELOG.md b/modules/PowerShellUniversal.Component.Pivot/CHANGELOG.md index 218b57d..06f741b 100644 --- a/modules/PowerShellUniversal.Component.Pivot/CHANGELOG.md +++ b/modules/PowerShellUniversal.Component.Pivot/CHANGELOG.md @@ -5,8 +5,41 @@ All notable changes to PowerShellUniversal.Component.Pivot. Format: ## [Unreleased] +### Added + +- `Invoke-UDPivotReport -Engine Rest` takes `-Locale`, `-Numbers` and `-FlatHeader` and passes them + to pivotkit-server's render routes as `locale`, `numbers` and `flatHeader`, so with the same + `-Locale` and server settings both engines write the same CSV and JSON. They need pivotkit-server + 0.3.0 or later; an older server's answer names that version. `-TimeZone` stays with `-Engine Node` + ([#135](https://github.com/eizedev/powershell-universal-components/issues/135)). +- Theme properties for pivotkit's zone colours and chip controls: `--psu-pivot-zone-rows`, + `-zone-columns`, `-zone-values`, `-zone-filters`, `-zone-tint`, `-zone-tint-base`, + `--psu-pivot-control-icon`, `--psu-pivot-sort-arrow`, `--psu-pivot-field-hover` and + `--psu-pivot-chart-reference`, per light and dark mode, listed on the new Theme properties page + with every other property. Without them + the report keeps pivotkit's values. The zone colours, the chip controls, the sort arrow and the + field hover take effect with pivotkit 0.11.0; the reference lines already with 0.10.0. +- The page "Coming from UniversalDashboard.Pivot" maps every parameter, aggregator and renderer of + `New-UDPivot` to `New-UDPivotReport`, names those without a counterpart, states the PowerShell and + PSU versions, and shows one report before and after; the pivot overview and the module README + link it + ([#121](https://github.com/eizedev/powershell-universal-components/issues/121)). + +### Fixed + +- `Invoke-UDPivotReport -Engine Rest -Parameter` explains the answer current pivotkit-servers give + when none of their sources takes parameters ("this server has no source that takes params"): + leave `-Parameter` out, or use a source that declares them. The older `no key "params"` still + names pivotkit-server 0.2.0 + ([#132](https://github.com/eizedev/powershell-universal-components/issues/132)). + ### Changed +- The field type icons are the muted text without an app's `--psu-pivot-type-*`, as pivotkit's own + neutral default: colour marks the zones, not the field types. With pivotkit 0.10.0 this also + makes the empty report's field pills and the border of a value chip grey. For the earlier + colours, set the four `--psu-pivot-type-*` properties per mode; the themes page has the light + and dark values. - The component passes the React hooks lint rules, which are now errors in CI: the latest props for its event handlers are kept in a ref written in an effect, not during render ([#217](https://github.com/eizedev/powershell-universal-components/issues/217)). The reader's view, a loaded file, diff --git a/modules/PowerShellUniversal.Component.Pivot/Components/psu.css b/modules/PowerShellUniversal.Component.Pivot/Components/psu.css index c6d6985..9c105dd 100644 --- a/modules/PowerShellUniversal.Component.Pivot/Components/psu.css +++ b/modules/PowerShellUniversal.Component.Pivot/Components/psu.css @@ -25,8 +25,9 @@ * * The tabs and buttons (pivotkit-react) take --psu-pivot-tab-*, --psu-pivot-icon-button-*, * --psu-pivot-button-* and --psu-pivot-primary-*; without them they derive from the general tokens as - * pivotkit does, so they follow PSU. The zone frames follow --pk-border-strong. The field type colours - * take --psu-pivot-type-*; without them they keep pivotkit's own values, repeated below per mode. + * pivotkit does, so they follow PSU. The zone frames follow --pk-border-strong. The zones' colours take + * --psu-pivot-zone-*; without them they keep pivotkit's own values, repeated below per mode. The field + * type icons take --psu-pivot-type-*; without them they are the muted text, pivotkit's neutral default. * * pivotkit's shadows, scrims and its other semantic colours (danger, warning, the switch's knob) stay * pivotkit's: at their alpha the light shadows' blue tint does not show next to PSU's greys. @@ -56,6 +57,8 @@ --psu-default-tab-bg: transparent; /* how much of the primary button's fill stays on hover, mixed with the text colour (pivotkit's) */ --psu-default-mix-primary-hover: 88%; + /* how much of a zone's colour its fill takes (pivotkit's) */ + --psu-default-zone-tint: 16%; } /* ---- PSU's defaults, light ------------------------------------------------------------------- */ @@ -94,11 +97,10 @@ --psu-default-mix-soft: 12%; --psu-default-mix-drop: 18%; --psu-default-mix-note: 7%; - /* the field types' colours: pivotkit's (pivotkit-react's styles.css) */ - --psu-default-type-string: #6250d6; - --psu-default-type-number: #1a7f5a; - --psu-default-type-date: #b5560b; - --psu-default-type-boolean: #a3367a; + /* the zones' colours: pivotkit's (pivotkit-react's styles.css), 4.5:1 on PSU's zone section too */ + --psu-default-zone-rows: #1d5fcc; + --psu-default-zone-columns: #a85a00; + --psu-default-zone-values: #0b785c; } /* ---- PSU's defaults, dark -------------------------------------------------------------------- */ @@ -136,10 +138,9 @@ --psu-default-mix-soft: 18%; --psu-default-mix-drop: 32%; --psu-default-mix-note: 10%; - --psu-default-type-string: #a99dff; - --psu-default-type-number: #5fd3a3; - --psu-default-type-date: #f2a65a; - --psu-default-type-boolean: #f08cc6; + --psu-default-zone-rows: #8db4ff; + --psu-default-zone-columns: #f2b559; + --psu-default-zone-values: #5fd6ac; } /* ---- the bridge, one declaration per token for both modes ------------------------------------ */ @@ -206,11 +207,26 @@ --pk-weight-strong: var(--psu-pivot-weight-strong, var(--psu-default-weight-strong)); --pk-weight-bold: var(--psu-pivot-weight-bold, var(--psu-default-weight-bold)); - /* the field type icons and the empty state's pills */ - --pk-type-string: var(--psu-pivot-type-string, var(--psu-default-type-string)); - --pk-type-number: var(--psu-pivot-type-number, var(--psu-default-type-number)); - --pk-type-date: var(--psu-pivot-type-date, var(--psu-default-type-date)); - --pk-type-boolean: var(--psu-pivot-type-boolean, var(--psu-default-type-boolean)); + /* the field type icons and the empty state's pills: neutral as pivotkit's, so colour marks the zones */ + --pk-type-string: var(--psu-pivot-type-string, var(--pk-muted)); + --pk-type-number: var(--psu-pivot-type-number, var(--pk-muted)); + --pk-type-date: var(--psu-pivot-type-date, var(--pk-muted)); + --pk-type-boolean: var(--psu-pivot-type-boolean, var(--pk-muted)); + + /* each zone's colour (its icons, its marks in the field list, a field's name in the table's header) + and the fill of its chips and names: that share of the colour mixed into the base */ + --pk-zone-rows: var(--psu-pivot-zone-rows, var(--psu-default-zone-rows)); + --pk-zone-columns: var(--psu-pivot-zone-columns, var(--psu-default-zone-columns)); + --pk-zone-values: var(--psu-pivot-zone-values, var(--psu-default-zone-values)); + --pk-zone-filters: var(--psu-pivot-zone-filters, var(--pk-muted)); + --pk-zone-tint: var(--psu-pivot-zone-tint, var(--psu-default-zone-tint)); + --pk-zone-tint-base: var(--psu-pivot-zone-tint-base, var(--pk-surface)); + /* a chip's grip, menu arrow and x; the sort arrow of the sorted field; a field's hover in the list; + the chart's reference lines of no series. Without a value of the app, derived as pivotkit does */ + --pk-control-icon: var(--psu-pivot-control-icon, var(--pk-muted)); + --pk-sort-arrow: var(--psu-pivot-sort-arrow, var(--pk-text)); + --pk-field-hover: var(--psu-pivot-field-hover, var(--pk-surface)); + --pk-chart-reference: var(--psu-pivot-chart-reference, var(--pk-muted)); /* the tabs (Table, Chart) and the buttons; without a value of the app, derived as pivotkit does */ --pk-tab-bg: var(--psu-pivot-tab-bg, var(--psu-default-tab-bg)); diff --git a/modules/PowerShellUniversal.Component.Pivot/Private/Assert-UDPivotReportEngine.ps1 b/modules/PowerShellUniversal.Component.Pivot/Private/Assert-UDPivotReportEngine.ps1 index 5ccd8ad..bbbe748 100644 --- a/modules/PowerShellUniversal.Component.Pivot/Private/Assert-UDPivotReportEngine.ps1 +++ b/modules/PowerShellUniversal.Component.Pivot/Private/Assert-UDPivotReportEngine.ps1 @@ -22,7 +22,7 @@ function Assert-UDPivotReportEngine { if (-not $Bound.ContainsKey('Data')) { throw '-Engine Node needs -Data: the command line runs over the rows you give.' } return } - $wrong = & $given 'CliPath', 'Locale', 'TimeZone', 'Numbers', 'FlatHeader' + $wrong = & $given 'CliPath', 'TimeZone' if ($wrong.Count) { throw ('{0}: only with -Engine Node (pivotkit-server uses its own).' -f ($wrong -join ', ')) } if ($Bound['Template']) { throw '-Template: only with -Engine Node. With -Engine Rest the server''s source decides the template (sources..template in its configuration).' } } diff --git a/modules/PowerShellUniversal.Component.Pivot/Private/Invoke-UDPivotRestReport.ps1 b/modules/PowerShellUniversal.Component.Pivot/Private/Invoke-UDPivotRestReport.ps1 index 76837bc..83be602 100644 --- a/modules/PowerShellUniversal.Component.Pivot/Private/Invoke-UDPivotRestReport.ps1 +++ b/modules/PowerShellUniversal.Component.Pivot/Private/Invoke-UDPivotRestReport.ps1 @@ -4,7 +4,8 @@ function Invoke-UDPivotRestReport { Renders a report with pivotkit-server (Invoke-UDPivotReport -Engine Rest): the file's bytes, or with -AsLink a link to the report the server keeps. .PARAMETER Bound - Invoke-UDPivotReport's $PSBoundParameters: Data, Source, Parameter, DataName, DataAsOf and Uri. + Invoke-UDPivotReport's $PSBoundParameters: Data, Source, Parameter, DataName, DataAsOf, Locale, + Numbers, FlatHeader and Uri. .PARAMETER Report The result of Get-UDPivotReportInput. .PARAMETER Kind @@ -34,7 +35,11 @@ function Invoke-UDPivotRestReport { [switch]$AsLink ) # splatted: a $(...) around -Data would enumerate a DataTable into its rows - $bodyArgs = @{ Source = [string]$Bound['Source']; Parameter = $Bound['Parameter']; Layout = $Report.Layout; Format = $Kind; Title = $Report.Title; DataName = [string]$Bound['DataName']; DataAsOf = $Bound['DataAsOf'] } + $bodyArgs = @{ + Source = [string]$Bound['Source']; Parameter = $Bound['Parameter']; Layout = $Report.Layout; Format = $Kind; Title = $Report.Title + DataName = [string]$Bound['DataName']; DataAsOf = $Bound['DataAsOf'] + Locale = [string]$Bound['Locale']; Numbers = [string]$Bound['Numbers']; FlatHeader = [bool]$Bound['FlatHeader'] + } if ($Bound.ContainsKey('Data')) { $bodyArgs['Data'] = $Bound['Data']; $bodyArgs['MaxBytes'] = $MaxBytes } if ($Report.ViewFile) { $bodyArgs['View'] = $Report.ViewFile.View } if ($AsLink) { diff --git a/modules/PowerShellUniversal.Component.Pivot/Private/New-UDPivotRenderBody.ps1 b/modules/PowerShellUniversal.Component.Pivot/Private/New-UDPivotRenderBody.ps1 index aa6c8f6..8995858 100644 --- a/modules/PowerShellUniversal.Component.Pivot/Private/New-UDPivotRenderBody.ps1 +++ b/modules/PowerShellUniversal.Component.Pivot/Private/New-UDPivotRenderBody.ps1 @@ -3,9 +3,10 @@ function New-UDPivotRenderBody { .SYNOPSIS The input of pivotkit-server's render_view as UTF-8 JSON, the rows written straight into it. .DESCRIPTION - source, then data (columns, rows, rowCount, name, asOf) or params, then view or layout, format and - title. The rows go through Write-UDPivotReportTable: no copy of them as objects or as one JSON - string, and past -MaxBytes it stops with PivotDataTooLarge before the rest is converted. + source, then data (columns, rows, rowCount, name, asOf) or params, then view or layout, format, + title, locale, numbers and flatHeader. The rows go through Write-UDPivotReportTable: no copy of + them as objects or as one JSON string, and past -MaxBytes it stops with PivotDataTooLarge before + the rest is converted. .PARAMETER Data The rows, or $null with -Source. .PARAMETER Source @@ -24,6 +25,12 @@ function New-UDPivotRenderBody { What the data is. .PARAMETER DataAsOf When the data is from. + .PARAMETER Locale + The report's language and number format, for a view that names none. + .PARAMETER Numbers + csv and json: Shown or Full, sent in lower case. + .PARAMETER FlatHeader + csv: one header row. .PARAMETER MaxBytes The most bytes of the body; 0 for no cap. .PARAMETER Save @@ -47,6 +54,9 @@ function New-UDPivotRenderBody { [string]$Title, [string]$DataName, [Nullable[datetime]]$DataAsOf, + [string]$Locale, + [string]$Numbers, + [switch]$FlatHeader, [long]$MaxBytes = 0, [switch]$Save ) @@ -69,6 +79,10 @@ function New-UDPivotRenderBody { else { $writer.WritePropertyName('layout'); $writer.WriteRawValue((ConvertTo-Json -InputObject $Layout -Depth 32 -Compress -WarningAction SilentlyContinue)) } $writer.WriteString('format', $Format) if ($Title) { $writer.WriteString('title', $Title) } + # left out unless given: the server's defaults, and a server older than 0.3.0 still renders + if ($Locale) { $writer.WriteString('locale', $Locale) } + if ($Numbers) { $writer.WriteString('numbers', $Numbers.ToLowerInvariant()) } + if ($FlatHeader) { $writer.WriteBoolean('flatHeader', $true) } if ($Save) { $writer.WriteBoolean('save', $true) } $writer.WriteEndObject() $writer.Flush() diff --git a/modules/PowerShellUniversal.Component.Pivot/Private/New-UDPivotServerError.ps1 b/modules/PowerShellUniversal.Component.Pivot/Private/New-UDPivotServerError.ps1 index d88dcce..ae0b0b6 100644 --- a/modules/PowerShellUniversal.Component.Pivot/Private/New-UDPivotServerError.ps1 +++ b/modules/PowerShellUniversal.Component.Pivot/Private/New-UDPivotServerError.ps1 @@ -6,8 +6,8 @@ function New-UDPivotServerError { .DESCRIPTION The message holds the code, the status, the detail, the findings, when to try again, a hint for the known cases (401, 403 INSUFFICIENT_SCOPE, 413 by its code, the 400 of a server too old for - -Data or -Parameter) and the request id. Exception.Data holds Status, Code, Title, Detail, - RetryAfter, Retryable and RequestId. The error ids: PivotTokenRefused (401, 403 + -Data, -Parameter, -Locale, -Numbers or -FlatHeader) and the request id. Exception.Data holds + Status, Code, Title, Detail, RetryAfter, Retryable and RequestId. The error ids: PivotTokenRefused (401, 403 INSUFFICIENT_SCOPE), PivotDataTooLarge (413), PivotViewHasErrors (422), PivotServerError (anything else). With -RowsRoute, by the rows route's codes: PivotRowsNotAllowed (403 NOT_ALLOWED), PivotNoData (404 SOURCE_NOT_FOUND, DATA_NOT_AVAILABLE), PivotServerBusy (429 @@ -44,11 +44,19 @@ function New-UDPivotServerError { else { 'The data is too large for the server: send fewer rows or columns, or let the operator configure a source for it and use -Source.' }) } # pivotkit-server 0.1.1 knows neither data in the request nor params; its answer reads like a - # fault in the request (#129). 0.2.0 answers params the same way when none of its sources takes any. + # fault in the request (#129). 0.2.0 answers params the same way when none of its sources takes + # any; later versions say that in words, recognised by "takes params" (NO_PARAMS_TEXT, #132): + # that server is new enough, only its sources take no parameters. if ($status -eq 400 -and $code -eq 'INVALID_INPUT' -and $p.Detail -match 'no key "(data|params)"') { $message += [Environment]::NewLine + $(if ($Matches[1] -eq 'data') { '-Data needs pivotkit-server 0.2.0 or later; an older server renders only -Source.' } else { '-Parameter needs a source with parameters on pivotkit-server 0.2.0 or later.' }) } + elseif ($status -eq 400 -and $code -eq 'INVALID_INPUT' -and $p.Detail -match 'takes params') { + $message += [Environment]::NewLine + 'No source on this server takes parameters: leave -Parameter out, or use a source that declares them (Get-UDPivotSource lists them).' + } + elseif ($status -eq 400 -and $code -eq 'INVALID_INPUT' -and $p.Detail -match 'no key "(locale|numbers|flatHeader)"') { + $message += [Environment]::NewLine + '-Locale, -Numbers and -FlatHeader need pivotkit-server 0.3.0 or later.' + } $scopeMissing = $status -eq 403 -and $code -eq 'INSUFFICIENT_SCOPE' if ($scopeMissing -and $RowsRoute) { $message += [Environment]::NewLine + 'The person''s token lacks a scope the server needs (rest.requiredScopes and the source''s scopes): let PSU''s OpenID Connect sign-in ask the provider for it, and make sure the provider puts it into the access token.' } elseif ($scopeMissing) { $message += [Environment]::NewLine + 'The token lacks a scope the server needs: ask the token endpoint for it with -Scope (the scope the operator set in rest.requiredScopes, for example pivotkit:rest), and make sure the OAuth provider grants it to this client.' } diff --git a/modules/PowerShellUniversal.Component.Pivot/Public/Invoke-UDPivotReport.ps1 b/modules/PowerShellUniversal.Component.Pivot/Public/Invoke-UDPivotReport.ps1 index e25abd3..892ca47 100644 --- a/modules/PowerShellUniversal.Component.Pivot/Public/Invoke-UDPivotReport.ps1 +++ b/modules/PowerShellUniversal.Component.Pivot/Public/Invoke-UDPivotReport.ps1 @@ -19,8 +19,8 @@ function Invoke-UDPivotReport { The server's operator turns this on per caller (a profile with data: true, or policy.data) and caps the body (rest.data.maxBytes, default 10 MiB). With -Source instead of -Data the report runs over a source the operator configured (the caller needs results: true). -Data and - -Parameter need pivotkit-server 0.2.0 or later; pivotkit-server 0.1.1 renders -Source without - parameters, and the error of its answer to -Data or -Parameter says so. Sign-in: a static + -Parameter need pivotkit-server 0.2.0 or later, -Locale, -Numbers and -FlatHeader 0.3.0 or + later; the error of an older server's answer to them says so. Sign-in: a static token (-Token), or OAuth client credentials (-Credential with -TokenUri), the access token kept per runspace until shortly before it expires and fetched again once after a 401. Only https, or http to this machine; redirects are not followed; neither the token nor the client secret is @@ -70,7 +70,8 @@ function Invoke-UDPivotReport { -Engine Node: the pivotkit program, or pivotkit-cli's bin/pivotkit.js. Default: pivotkit on the PATH. .PARAMETER Locale - -Engine Node: numbers, dates and the report's words (de-DE writes German ones). Default en-US. + Numbers, dates and the report's words (de-DE writes German ones) for a view that names no + language of its own. Default: en-US with -Engine Node, the server's with -Engine Rest. .PARAMETER TimeZone -Engine Node: the zone of the data's dates (IANA, default UTC). .PARAMETER Uri @@ -112,12 +113,12 @@ function Invoke-UDPivotReport { as --template. pivotkit trusts a template like code: give a file of your own, never one from a reader. With -Engine Rest the server's source decides the template, so it is refused there. .PARAMETER Numbers - -Engine Node with -Format csv or json: Full writes every number with full precision (the command - line's default), Shown rounds it to the decimals the view shows, as pivotkit-server writes them. - Needs pivotkit-cli 0.5.0 or later. + -Format csv or json: Full writes every number with full precision (the default of both + engines), Shown rounds it to the decimals the view shows. Needs pivotkit-cli 0.5.0 or later + (-Engine Node) or pivotkit-server 0.3.0 or later (-Engine Rest). .PARAMETER FlatHeader - -Engine Node with -Format csv: one header row instead of one per column field; each column - names its labels joined with " / ". Needs pivotkit-cli 0.5.0 or later. + -Format csv: one header row instead of one per column field; each column names its labels + joined with " / ". Needs pivotkit-cli 0.5.0 or pivotkit-server 0.3.0 or later. .PARAMETER AsLink -Engine Rest: the server saves the report and the function returns its download link instead of the file (POST /views/render with save: true): a PivotReportLink with Url, ExpiresAt (UTC; empty diff --git a/modules/PowerShellUniversal.Component.Pivot/README.md b/modules/PowerShellUniversal.Component.Pivot/README.md index 1809c57..d9f4e08 100644 --- a/modules/PowerShellUniversal.Component.Pivot/README.md +++ b/modules/PowerShellUniversal.Component.Pivot/README.md @@ -53,6 +53,7 @@ is a showcase app in one line (`New-UDPivotShowcase`). - [Reports without a browser](https://powershell-universal-components.eize.dev/pivot/reports/): `Invoke-UDPivotReport`; [from a pivotkit-server](https://powershell-universal-components.eize.dev/pivot/reports-server/) with `Get-UDPivotSource` - [Themes and corporate design](https://powershell-universal-components.eize.dev/pivot/themes/), shared with the ECharts module - [Reference](https://powershell-universal-components.eize.dev/pivot/reference/): every parameter +- [Coming from UniversalDashboard.Pivot](https://powershell-universal-components.eize.dev/pivot/coming-from-ud-pivot/): `New-UDPivot`'s parameters in `New-UDPivotReport` ## Security notes diff --git a/tests/browser/psu-pivot.spec.mjs b/tests/browser/psu-pivot.spec.mjs index 364cc2d..bb061cf 100644 --- a/tests/browser/psu-pivot.spec.mjs +++ b/tests/browser/psu-pivot.spec.mjs @@ -816,9 +816,9 @@ test.describe("pivot showcase on PSU", () => { const tab = report.locator('.pk-tab[aria-selected="true"]').first(); await expect(icon).toBeVisible(); await expect(tab).toBeVisible(); - // without the app's values: pivotkit's own type colour, and the shown tab in the accent (PSU's blue) + // without the app's values: the muted text, pivotkit's neutral type icons, and the shown tab in the accent (PSU's blue) await setTheme(page, "light"); - await expect(icon).toHaveCSS("color", "rgb(98, 80, 214)"); + await expect(icon).toHaveCSS("color", "rgba(0, 0, 0, 0.62)"); await expect(tab).toHaveCSS("color", "rgb(25, 118, 210)"); await page.addStyleTag({ content: ':root, .ud-pivot-report [data-pk-theme="light"] { --psu-pivot-type-string: #8a1538; --psu-pivot-tab-selected-text: #005500; } ' + @@ -832,6 +832,31 @@ test.describe("pivot showcase on PSU", () => { } }); + test("--psu-pivot-zone-* and the chip controls from the app's stylesheet reach pivotkit's zone tokens, per PSU mode (pivotkit#920)", async ({ page }) => { + await open(page, "tickets"); + const report = page.locator(REPORT); + const token = (name) => report.evaluate((e, n) => getComputedStyle(e).getPropertyValue(n).trim(), name); + // without the app's values: pivotkit's zone colours, as docs/pivot/theme-properties.md lists them + const defaults = { light: ["#1d5fcc", "#a85a00", "#0b785c", "16%"], dark: ["#8db4ff", "#f2b559", "#5fd6ac", "16%"] }; + const names = ["--pk-zone-rows", "--pk-zone-columns", "--pk-zone-values", "--pk-zone-tint"]; + for (const mode of ["light", "dark"]) { + await setTheme(page, mode); + await expect(report).toHaveAttribute("data-pk-theme", mode); + for (const [k, name] of names.entries()) await expect.poll(() => token(name)).toBe(defaults[mode][k]); + await expect.poll(() => token("--pk-control-icon")).toBe(await token("--pk-muted")); + } + await page.addStyleTag({ + content: ':root, .ud-pivot-report [data-pk-theme="light"] { --psu-pivot-zone-rows: #003b6f; --psu-pivot-control-icon: #4a5263; } ' + + ':root[data-theme="dark"], .ud-pivot-report [data-pk-theme="dark"] { --psu-pivot-zone-rows: #6fa8dc; --psu-pivot-control-icon: #a9b1bf; }' + }); + for (const [mode, rows, control] of [["light", "#003b6f", "#4a5263"], ["dark", "#6fa8dc", "#a9b1bf"]]) { + await setTheme(page, mode); + await expect(report).toHaveAttribute("data-pk-theme", mode); + await expect.poll(() => token("--pk-zone-rows")).toBe(rows); + await expect.poll(() => token("--pk-control-icon")).toBe(control); + } + }); + test("a colour scale without colours is blue in PSU's light and dark mode; a dark app exports the light colours of the documented stylesheet", async ({ page }) => { // the start view with a colour scale on the count, as a reader adds it (no colours of its own), as a link const view = { rows: ["Team"], cols: ["Priority"], values: [{ field: "Ticket", agg: "count", conditional: { type: "colorScale" } }] }; diff --git a/tests/js/pivot.test.js b/tests/js/pivot.test.js index c3ceeba..695e98b 100644 --- a/tests/js/pivot.test.js +++ b/tests/js/pivot.test.js @@ -419,6 +419,7 @@ test("stored view: blocked, full or broken storage is ignored", () => { const css = readFileSync(new URL("../../modules/PowerShellUniversal.Component.Pivot/Components/psu.css", import.meta.url), "utf8"); const themesDoc = readFileSync(new URL("../../docs/pivot/themes.md", import.meta.url), "utf8"); +const themePropertiesDoc = readFileSync(new URL("../../docs/pivot/theme-properties.md", import.meta.url), "utf8"); const WRAPPER = ".ud-pivot-report"; const LIGHT = ".ud-pivot-report .pk-root"; const DARK = '.ud-pivot-report .pk-root[data-pk-theme="dark"]'; @@ -484,9 +485,9 @@ const tokensOf = (mode, page = {}) => { // the properties an app may set: every --psu-pivot-* and --psu-chart-* the bridge reads const publicNames = () => [...new Set([...css.replace(/\/\*[\s\S]*?\*\//g, "").matchAll(/var\((--psu-(?:pivot|chart)-[a-z0-9-]+)/g)].map((m) => m[1]))].sort(); -// the table in docs/pivot/themes.md: property, falls back to, what it sets, light, dark +// the table in docs/pivot/theme-properties.md: property, falls back to, what it sets, light, dark function docRows() { - return themesDoc.split("\n").filter((l) => l.startsWith("| `--psu-")).map((line) => { + return themePropertiesDoc.split("\n").filter((l) => l.startsWith("| `--psu-")).map((line) => { const cells = line.split("|").slice(1, -1).map((c) => c.trim()); let names = [...cells[0].matchAll(/`(--psu-[a-z0-9-]+)`/g)].map((m) => m[1]); const range = /^`--psu-([a-z]+)-(\d+)` \.\.\. `--psu-\1-(\d+)`$/.exec(cells[0]); @@ -571,9 +572,9 @@ for (const mode of ["light", "dark"]) { } // pivotkit-react's own values (styles.css, the same in 0.8.1 and 0.9.0) for the tokens the bridge -// maps without changing them: the field types per mode, the tabs and buttons as pivotkit derives -// them. Where the module's packages are installed (CI's pivot step), the test reads them from the -// installed styles.css instead, so a new pivotkit version that changes one fails there. +// maps without changing them: the tabs and buttons as pivotkit derives them. Where the module's +// packages are installed (CI's pivot step), the test reads them from the installed styles.css +// instead, so a new pivotkit version that changes one fails there. const PK_ROOT = { "--pk-tab-bg": "transparent", "--pk-tab-text": "var(--pk-muted)", @@ -587,27 +588,70 @@ const PK_ROOT = { "--pk-primary-text": "var(--pk-accent-text)", "--pk-primary-hover-bg": "color-mix(in srgb, var(--pk-accent) 88%, var(--pk-text))", }; -const PK_TYPES = [ - { "--pk-type-string": "#6250d6", "--pk-type-number": "#1a7f5a", "--pk-type-date": "#b5560b", "--pk-type-boolean": "#a3367a" }, - { "--pk-type-string": "#a99dff", "--pk-type-number": "#5fd3a3", "--pk-type-date": "#f2a65a", "--pk-type-boolean": "#f08cc6" }, -]; const pkStylesUrl = new URL("../../modules/PowerShellUniversal.Component.Pivot/node_modules/pivotkit-react/dist/styles.css", import.meta.url); function pkDeclarations(index) { - if (!existsSync(pkStylesUrl)) return { ...(index ? {} : PK_ROOT), ...PK_TYPES[index] }; - // the first block that sets --pk-type-string is the light root, the second the dark one - const blocks = [...readFileSync(pkStylesUrl, "utf8").matchAll(/\{([^{}]*--pk-type-string[^{}]*)\}/g)].map((m) => m[1]); + if (!existsSync(pkStylesUrl)) return index ? {} : PK_ROOT; + // the first block that sets --pk-chart-1 is the light root, the second the dark one + const blocks = [...readFileSync(pkStylesUrl, "utf8").matchAll(/\{([^{}]*--pk-chart-1:[^{}]*)\}/g)].map((m) => m[1]); return Object.fromEntries([...blocks[index].matchAll(/(--pk-[a-z0-9-]+):\s*([^;]+);/g)].map((m) => [m[1], m[2].trim()])); } const PART_TOKENS = ["tab-bg", "tab-text", "tab-selected-bg", "tab-selected-text", "icon-button-text", "icon-button-hover-bg", "button-border", "button-border-hover", "primary-bg", "primary-text", "primary-hover-bg"]; +// pivotkit-react's tokens of the reworked field area and table header (eizedev/pivotkit#920), as +// pivotkit's main has them: the zone colours per mode, the rest derived from the general tokens, the +// type icons neutral. pivotkit-react 0.10 has none of them but the chart's reference lines; once the +// installed one has the zone colours, the test reads it instead. +const PK_ZONES = [ + { + "--pk-type-string": "var(--pk-muted)", + "--pk-type-number": "var(--pk-muted)", + "--pk-type-date": "var(--pk-muted)", + "--pk-type-boolean": "var(--pk-muted)", + "--pk-zone-rows": "#1d5fcc", + "--pk-zone-columns": "#a85a00", + "--pk-zone-values": "#0b785c", + "--pk-zone-filters": "var(--pk-muted)", + "--pk-zone-tint": "16%", + "--pk-zone-tint-base": "var(--pk-surface)", + "--pk-control-icon": "var(--pk-muted)", + "--pk-sort-arrow": "var(--pk-text)", + "--pk-field-hover": "var(--pk-surface)", + "--pk-chart-reference": "var(--pk-muted)", + }, + { "--pk-zone-rows": "#8db4ff", "--pk-zone-columns": "#f2b559", "--pk-zone-values": "#5fd6ac", "--pk-chart-reference": "var(--pk-muted)" }, +]; +const ZONE_TOKENS = Object.keys(PK_ZONES[0]); +const pkZones = (index) => (existsSync(pkStylesUrl) && pkDeclarations(0)["--pk-zone-rows"] ? pkDeclarations(index) : PK_ZONES[index]); + for (const [mode, index] of [["light", 0], ["dark", 1]]) { - test(`theme bridge (${mode}): the field type colours are pivotkit's without an app's value, --psu-pivot-type-* sets them (#137)`, () => { + test(`theme bridge (${mode}): zone colours, type icons, chip controls, sort arrow, field hover and reference lines are pivotkit's without an app's value, --psu-pivot-* sets each (#137, pivotkit#920)`, () => { + const t = tokensOf(mode); + const pk = { ...pkZones(0), ...(index ? pkZones(1) : {}) }; + // pivotkit's values, its derivations resolved over the bridge's general tokens + const general = Object.fromEntries(Object.entries(t).filter(([n]) => !ZONE_TOKENS.includes(n))); + for (const name of ZONE_TOKENS) { + assert.ok(pk[name], `pivotkit-react has ${name}`); + assert.equal(t[name], substitute(pk[name], {}, general, new Set()), `${name} as pivotkit has it`); + assert.equal(tokensOf(mode, { [name.replace("--pk-", "--psu-pivot-")]: "#123456" })[name], "#123456", name.replace("--pk-", "--psu-pivot-")); + } + // the type icons follow the muted text, also a corporate one + assert.equal(tokensOf(mode, { "--psu-chart-muted": "#4a5263" })["--pk-type-number"], "#4a5263"); + }); + + test(`theme bridge (${mode}): each zone colour 4.5:1 on PSU's zone section, the values colour also on the grand total's header; 3:1 on its own fill; the chip controls 3:1 on every fill`, () => { const t = tokensOf(mode); - const pk = pkDeclarations(index); - for (const type of ["string", "number", "date", "boolean"]) { - assert.ok(pk[`--pk-type-${type}`], `pivotkit sets --pk-type-${type} in ${mode}`); - assert.equal(t[`--pk-type-${type}`], pk[`--pk-type-${type}`], `--pk-type-${type} stays pivotkit's`); - assert.equal(tokensOf(mode, { [`--psu-pivot-type-${type}`]: "#003b6f" })[`--pk-type-${type}`], "#003b6f"); + const base = parseColor(t["--pk-zone-tint-base"]); + const share = Number.parseFloat(t["--pk-zone-tint"]) / 100; + for (const zone of ["rows", "columns", "values"]) { + const colour = parseColor(t[`--pk-zone-${zone}`]); + // the field names in the table's header take their zone's colour; only the values' names sit on the grand total + for (const surface of zone === "values" ? ["--pk-surface-2", "--pk-total-strong"] : ["--pk-surface-2"]) { + assert.ok(contrastRatio(colour, parseColor(t[surface])) >= 4.5, `${zone} on ${surface}`); + } + // the fill: an opaque mix of the zone's colour into the base (pivotkit-react's .pk-zone-fill) + const fill = `rgb(${colour.map((v, i) => Math.round(v * share + base[i] * (1 - share))).join(", ")})`; + assert.ok(contrastRatio(colour, parseColor(fill)) >= 3, `${zone} on its fill`); + assert.ok(contrastRatio(over(t["--pk-control-icon"], fill), parseColor(fill)) >= 3, `chip controls on the ${zone} fill`); } }); @@ -672,7 +716,7 @@ test("theme bridge: dark values go on pivotkit's data-pk-theme, never on the pag } }); -test("theme bridge: docs/pivot/themes.md lists every property the bridge reads, with its fallbacks and defaults", () => { +test("theme bridge: docs/pivot/theme-properties.md lists every property the bridge reads, with its fallbacks and defaults", () => { const rows = docRows(); assert.deepEqual([...new Set(rows.flatMap((r) => [...r.names, ...r.fallbacks]))].sort(), publicNames()); for (const row of rows) { diff --git a/tests/powershell/PivotReport.Tests.ps1 b/tests/powershell/PivotReport.Tests.ps1 index 576e88d..fa2c418 100644 --- a/tests/powershell/PivotReport.Tests.ps1 +++ b/tests/powershell/PivotReport.Tests.ps1 @@ -237,7 +237,7 @@ Describe 'Invoke-UDPivotReport: what goes with which engine' { It 'refuses parameters of the other engine and missing inputs, before anything runs' { { Invoke-UDPivotReport -Engine Node -Data $rows -View $view -Uri 'https://x.example/api/v1' } | Should -Throw '*-Uri: only with -Engine Rest*' { Invoke-UDPivotReport -Engine Node -View $view } | Should -Throw '*-Engine Node needs -Data*' - { Invoke-UDPivotReport -Engine Rest -Uri 'https://x.example/api/v1' -Token 't' -Data $rows -View $view -Locale de-DE } | Should -Throw '*-Locale: only with -Engine Node*' + { Invoke-UDPivotReport -Engine Rest -Uri 'https://x.example/api/v1' -Token 't' -Data $rows -View $view -TimeZone 'Europe/Berlin' } | Should -Throw '*-TimeZone: only with -Engine Node*' { Invoke-UDPivotReport -Engine Rest -Token 't' -Data $rows -View $view } | Should -Throw '*needs -Uri*' { Invoke-UDPivotReport -Engine Rest -Uri 'https://x.example/api/v1' -Token 't' -View $view } | Should -Throw '*either -Data*or -Source*' { Invoke-UDPivotReport -Engine Rest -Uri 'https://x.example/api/v1' -Token 't' -Data $rows -Source 'sales' -View $view } | Should -Throw '*either -Data*or -Source*' @@ -433,7 +433,8 @@ Describe 'Invoke-UDPivotReport -Engine Node (a stand-in command line)' { @((Get-Record).args | Where-Object { $_ -like '--numbers*' -or $_ -eq '--flat-header' }).Count | Should -Be 0 { Invoke-UDPivotReport -Engine Node -CliPath $fakeCli -Data $rows -View $view -Format xlsx -Numbers Shown } | Should -Throw '*-Numbers*csv*json*' { Invoke-UDPivotReport -Engine Node -CliPath $fakeCli -Data $rows -View $view -Format json -FlatHeader } | Should -Throw '*-FlatHeader*csv*' - { Invoke-UDPivotReport -Engine Rest -Uri 'https://reports.example.com/api/v1' -Token 't' -Data $rows -View $view -Format csv -Numbers Shown } | Should -Throw '*-Numbers*-Engine Node*' + { Invoke-UDPivotReport -Engine Rest -Uri 'https://reports.example.com/api/v1' -Token 't' -Data $rows -View $view -Format xlsx -Numbers Shown } | Should -Throw '*-Numbers*csv*json*' + { Invoke-UDPivotReport -Engine Rest -Uri 'https://reports.example.com/api/v1' -Token 't' -Data $rows -View $view -Format json -FlatHeader } | Should -Throw '*-FlatHeader*csv*' } It 'runs render with the view file, the data and the options; returns the bytes; removes its folder' { @@ -572,6 +573,22 @@ Describe 'Invoke-UDPivotReport -Engine Rest (a stand-in pivotkit-server)' { $sent.data.name | Should -Be 'Tickets' $log[0].Body | Should -BeLike '*"asOf":"2026-11-15T06:00:00Z"*' $sent.view.rows | Should -Be @('Team') + # without -Locale, -Numbers and -FlatHeader none is sent: the server's defaults, and older servers still work + foreach ($name in 'locale', 'numbers', 'flatHeader') { $sent.PSObject.Properties.Name | Should -Not -Contain $name } + } + + It '-Locale, -Numbers and -FlatHeader go into the body as pivotkit-server reads them, on both routes, and only when given (#135)' { + $null = Invoke-UDPivotReport @rest -Token 'static-token-0123456789' -Data $rows -View $view -Format csv -Locale de-DE -Numbers Shown -FlatHeader + $sent = (@(Get-Log)[0]).Body | ConvertFrom-Json -Depth 16 + $sent.locale | Should -Be 'de-DE' + $sent.numbers | Should -BeExactly 'shown' + $sent.flatHeader | Should -BeTrue + $null = Invoke-UDPivotReport @rest -Token 'static-token-0123456789' -Source 'sales' -View $view -Format json -Numbers Full -AsLink + $log = @(Get-Log) + $log[0].Path | Should -Be '/api/v1/views/render' + $sent = $log[0].Body | ConvertFrom-Json -Depth 16 + $sent.numbers | Should -BeExactly 'full' + $sent.PSObject.Properties.Name | Should -Not -Contain 'flatHeader' } It 'a SecureString token, a configured source with parameters, a layout' { @@ -584,28 +601,31 @@ Describe 'Invoke-UDPivotReport -Engine Rest (a stand-in pivotkit-server)' { $sent.format | Should -Be 'xlsx' } - It 'a server that does not know -Data or -Parameter: the error names the server version they need (#129)' { - # the answers of pivotkit-server 0.1.1 to data in the request and to params; 0.2.0 answers - # params the same way when none of its sources declares parameters - $mock.Render.Enqueue(@{ Status = 400; Body = '{"type":"https://pivotkit.eize.dev/reference/rest/#error-invalid-input","title":"Invalid input","status":400,"code":"INVALID_INPUT","detail":"input has no key \"data\""}' }) - $caught = $null - try { Invoke-UDPivotReport @rest -Token 'static-token-0123456789' -Data $rows -View $view } catch { $caught = $_ } + It 'a server too old for a parameter: the error names the server version it needs; one without sources that take params says so (#129, #132, #135)' { + # pivotkit-server 0.1.1 knows neither data in the request nor params; 0.2.0 answers params the same + # way when none of its sources declares parameters; before 0.3.0 it knows no locale, numbers or flatHeader + $errorOf = { + param([int]$Status, [string]$Code, [string]$Detail, [hashtable]$Call) + $mock.Render.Enqueue(@{ Status = $Status; Body = (@{ type = 'x'; title = 'x'; status = $Status; code = $Code; detail = $Detail } | ConvertTo-Json -Compress) }) + try { $null = Invoke-UDPivotReport @rest -Token 'static-token-0123456789' @Call } catch { $_ } + } + $data = @{ Data = $rows; View = $view } + $params = @{ Source = 'vms'; Parameter = @{ customer = 'acme' }; View = $view } + $caught = & $errorOf 400 'INVALID_INPUT' 'input has no key "data"' $data $caught.FullyQualifiedErrorId | Should -BeLike 'PivotServerError*' $caught.Exception.Message | Should -BeLike '*INVALID_INPUT (400): input has no key "data"*-Data needs pivotkit-server 0.2.0 or later*-Source*' - $mock.Render.Enqueue(@{ Status = 400; Body = '{"type":"https://pivotkit.eize.dev/reference/rest/#error-invalid-input","title":"Invalid input","status":400,"code":"INVALID_INPUT","detail":"input has no key \"params\""}' }) - $caught = $null - try { Invoke-UDPivotReport @rest -Token 'static-token-0123456789' -Source 'vms' -Parameter @{ customer = 'acme' } -View $view } catch { $caught = $_ } - $caught.Exception.Message | Should -BeLike '*INVALID_INPUT (400): input has no key "params"*-Parameter needs a source with parameters on pivotkit-server 0.2.0 or later*' + (& $errorOf 400 'INVALID_INPUT' 'input has no key "params"' $params).Exception.Message | Should -BeLike '*INVALID_INPUT (400): input has no key "params"*-Parameter needs a source with parameters on pivotkit-server 0.2.0 or later*' + # a current server that says it in words is new enough: the hint is about its sources, not its version + $message = (& $errorOf 400 'INVALID_INPUT' 'this server has no source that takes params; leave params out (GET /sources lists the sources)' $params).Exception.Message + $message | Should -BeLike '*INVALID_INPUT (400): this server has no source that takes params*No source on this server takes parameters: leave -Parameter out*Get-UDPivotSource*' + $message | Should -Not -BeLike '*pivotkit-server 0.*' + (& $errorOf 400 'INVALID_INPUT' 'input has no key "numbers"' ($data + @{ Format = 'csv'; Numbers = 'Shown' })).Exception.Message | + Should -BeLike '*input has no key "numbers"*-Locale, -Numbers and -FlatHeader need pivotkit-server 0.3.0 or later*' # another invalid input, and data refused by the server's policy, get no version hint - $mock.Render.Enqueue(@{ Status = 400; Body = '{"type":"x","title":"Invalid input","status":400,"code":"INVALID_INPUT","detail":"view.rows[0] must be a string"}' }) - $caught = $null - try { Invoke-UDPivotReport @rest -Token 'static-token-0123456789' -Data $rows -View $view } catch { $caught = $_ } - $caught.Exception.Message | Should -Not -BeLike '*pivotkit-server 0.2.0*' - $mock.Render.Enqueue(@{ Status = 403; Body = '{"type":"x","title":"Not allowed","status":403,"code":"NOT_ALLOWED","detail":"this server takes no data sent in the request (the operator allows it per profile: data: true); use a source from GET /sources"}' }) - $caught = $null - try { Invoke-UDPivotReport @rest -Token 'static-token-0123456789' -Data $rows -View $view } catch { $caught = $_ } - $caught.Exception.Message | Should -BeLike '*NOT_ALLOWED (403)*data: true*' - $caught.Exception.Message | Should -Not -BeLike '*pivotkit-server 0.2.0*' + (& $errorOf 400 'INVALID_INPUT' 'view.rows[0] must be a string' $data).Exception.Message | Should -Not -BeLike '*pivotkit-server 0.*' + $message = (& $errorOf 403 'NOT_ALLOWED' 'this server takes no data sent in the request (the operator allows it per profile: data: true); use a source from GET /sources' $data).Exception.Message + $message | Should -BeLike '*NOT_ALLOWED (403)*data: true*' + $message | Should -Not -BeLike '*pivotkit-server 0.*' } It 'a 422 lists the findings and the request id; a 503 says when to try again; a redirect is not followed' { diff --git a/zensical.toml b/zensical.toml index eabbbf4..0b02e02 100644 --- a/zensical.toml +++ b/zensical.toml @@ -63,6 +63,7 @@ nav = [ { "Overview" = "pivot/index.md" }, { "Readers and your app" = "pivot/readers.md" }, { "Showcase app (demo)" = "pivot/demo.md" }, + { "Coming from UniversalDashboard.Pivot" = "pivot/coming-from-ud-pivot.md" }, ] }, { "Build a report" = [ { "Data and loading" = "pivot/data.md" }, @@ -90,6 +91,7 @@ nav = [ ] }, { "Reference" = [ { "Commands and parameters" = "pivot/reference.md" }, + { "Theme properties" = "pivot/theme-properties.md" }, { "Errors" = "pivot/errors.md" }, ] }, ] },