Skip to content

Commit 628b683

Browse files
Document the new parser and session APIs
1 parent 1b18303 commit 628b683

1 file changed

Lines changed: 161 additions & 0 deletions

File tree

  • content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/pluggable-widgets/pluggable-widgets-client-apis

content/en/docs/apidocs-mxsdk/apidocs/studio-pro-11/pluggable-widgets/pluggable-widgets-client-apis/_index.md

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,167 @@ if (selection.type === "Single") {
489489

490490
## Exposed Modules
491491

492+
### Session {#session}
493+
494+
The Mendix Platform exposes a `mendix/session` module for inspecting the current user session. It is available in both web and native.
495+
496+
```ts
497+
import { getUserId, getUserName, getUserRoleNames, isGuest, getCSRFToken } from "mendix/session";
498+
```
499+
500+
#### getUserId {#getuserid}
501+
502+
Returns the current user's GUID as a `string`.
503+
504+
```ts
505+
function getUserId(): GUID;
506+
```
507+
508+
#### getUserName {#getusername}
509+
510+
Returns the `Name` attribute of the current user.
511+
512+
```ts
513+
function getUserName(): string;
514+
```
515+
516+
#### getUserRoleNames {#getuserrolenames}
517+
518+
Returns the names of the current user's roles.
519+
520+
```ts
521+
function getUserRoleNames(): string[];
522+
```
523+
524+
#### isGuest {#isguest}
525+
526+
Returns `true` if the current session is anonymous, `false` otherwise.
527+
528+
```ts
529+
function isGuest(): boolean;
530+
```
531+
532+
#### getCSRFToken {#getcsrftoken}
533+
534+
Returns the CSRF token for the current session.
535+
536+
```ts
537+
function getCSRFToken(): string;
538+
```
539+
540+
---
541+
542+
### Parser {#parser}
543+
544+
The Mendix Platform exposes a `mendix/parser` module that provides locale-aware formatting and parsing of attribute values. These functions use the same locale and formatting settings of the built-in Mendix widgets. It is available in both web and native.
545+
546+
```ts
547+
import { formatValue, parseValue } from "mendix/parser";
548+
```
549+
550+
Both functions accept an optional configuration object:
551+
552+
```ts
553+
interface FormatValueConfig {
554+
selector?: "date" | "time" | "datetime";
555+
datePattern?: string;
556+
places?: number;
557+
groups?: boolean;
558+
}
559+
```
560+
561+
#### formatValue {#formatvalue}
562+
563+
Converts a value to its locale-formatted string representation.
564+
565+
```ts
566+
function formatValue(value: unknown, type: AttributeType, config?: FormatValueConfig): string;
567+
```
568+
569+
| Parameter | Type | Description |
570+
|:----------|:--------------------|:------------------------------------------------------------------------------------------------------------|
571+
| `value` | `unknown` | The value to format. |
572+
| `type` | `AttributeType` | The attribute type to use when interpreting the value (for example `"Decimal"`, `"DateTime"`, `"Boolean"`). |
573+
| `config` | `FormatValueConfig` | Optional formatting configuration. |
574+
575+
**Configuration options:**
576+
577+
* `config.selector` — for date conversions: format only the `"date"`, `"time"`, or `"datetime"` part.
578+
* `config.datePattern` — for date conversions: a custom date pattern (see the date pattern table below).
579+
* `config.places` — for numeric conversions: number of decimal digits to display (`-1` to keep original precision).
580+
* `config.groups` — for numeric conversions: whether to include group separators.
581+
582+
```ts
583+
formatValue(Big(3000), "Decimal", { places: 2 }); // "3,000.00"
584+
formatValue(+new Date(1980, 7, 23), "DateTime", { datePattern: "dd-MM-yyyy" }); // "23-08-1980"
585+
```
586+
587+
#### parseValue {#parsevalue}
588+
589+
Converts a locale-formatted string back to a typed value.
590+
591+
```ts
592+
function parseValue(value: string, type: AttributeType, config?: FormatValueConfig): Option<AttributeValue>;
593+
```
594+
595+
| Parameter | Type | Description |
596+
|:----------|:--------------------|:-------------------------------------------------------------------|
597+
| `value` | `string` | The string to parse. |
598+
| `type` | `AttributeType` | The attribute type to use when interpreting the value. |
599+
| `config` | `FormatValueConfig` | Optional formatting configuration (same options as `formatValue`). |
600+
601+
The return type depends on the attribute type:
602+
603+
| Attribute Type | Return Type |
604+
|:-----------------------------|:------------|
605+
| `Integer`, `Long`, `Decimal` | `Big` |
606+
| `AutoNumber` | `string` |
607+
| `DateTime` | `Date` |
608+
| `Enum` | `string` |
609+
| `String` | `string` |
610+
| `Boolean` | `boolean` |
611+
612+
If the string cannot be parsed, the function returns `undefined`.
613+
614+
```ts
615+
parseValue("3,000.00", "Decimal"); // Big(3000)
616+
parseValue("23-8-1980", "DateTime", { datePattern: "dd-M-yyyy" }); // Date(1980, 7, 23)
617+
```
618+
619+
#### Date Pattern Reference {#date-pattern}
620+
621+
The `datePattern` option accepts a string composed of the following tokens:
622+
623+
| Letter | Date or Time Component | Examples |
624+
|:-------|:----------------------------------------------------|:---------|
625+
| `M` | Month in year, digit | 1 |
626+
| `MM` | Month in year, digit with leading zero | 01 |
627+
| `MMM` | Month in year, abbreviated (context sensitive) | Nov |
628+
| `MMMM` | Month in year (context sensitive) | November |
629+
| `L` | Month in year, digit (standalone) | 1 |
630+
| `LL` | Month in year, digit with leading zero (standalone) | 01 |
631+
| `LLL` | Month in year, abbreviated (standalone) | Nov |
632+
| `LLLL` | Month in year (standalone) | November |
633+
| `yy` | Year, two digits | 01 |
634+
| `yyyy` | Year, four digits | 2001 |
635+
| `G` | Era designator | AD |
636+
| `E` | Day name in week, abbreviated | Tue |
637+
| `EEEE` | Day name in week | Tuesday |
638+
| `u` | Day of week (1 = Monday, …, 7 = Sunday) | 5 |
639+
| `w` | Week in year | 11 |
640+
| `W` | Week in month | 2 |
641+
| `D` | Day in year | 133 |
642+
| `d` | Day in month | 7 |
643+
| `F` | Day of week in month | 1 |
644+
| `a` | AM/PM marker | PM |
645+
| `H` | Hour in day (0–23) | 0 |
646+
| `k` | Hour in day (1–24) | 24 |
647+
| `K` | Hour in AM/PM (0–11) | 0 |
648+
| `h` | Hour in AM/PM (1–12) | 12 |
649+
| `m` | Minute in hour | 24 |
650+
| `s` | Second in minute | 50 |
651+
| `S` | Millisecond | 201 |
652+
492653
### Icon {#icon}
493654

494655
Mendix Platform exposes two versions of an `Icon` react component: `mendix/components/web/Icon` and `mendix/components/native/Icon`. Both components are useful helpers to render `WebIcon` and `NativeIcon` values respectively. They should be passed through an `icon` prop. The native `Icon` component additionally accepts `color` (`string`) and `size` (`number`) props.

0 commit comments

Comments
 (0)