-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpage-variables.page.ts
More file actions
106 lines (104 loc) · 3.71 KB
/
Copy pathpage-variables.page.ts
File metadata and controls
106 lines (104 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
import { definePage } from '@objectstack/spec/ui';
/**
* Page Variables — master/detail driven by page-local state (PageSchema.variables).
*
* Demonstrates the end-to-end page-variable loop:
* 1. `variables` declares `selectedProjectId`, fed by the component whose id
* is `project_picker` (PageVariableSchema.source = that component id).
* 2. `element:record_picker` (id: project_picker) writes the chosen project's
* id into that variable on selection.
* 3. Sibling components gate on `page.selectedProjectId` via `visibility`:
* the empty-state hint shows while nothing is picked; the detail panel
* appears the moment a project is chosen — re-evaluated live, no reload.
*
* This is the canonical low-code "filtered detail" pattern: one picker drives
* what the rest of the page shows, with no custom code.
*/
export const PageVariablesPage = definePage({
name: 'showcase_page_variables',
label: 'Page Variables (Master/Detail)',
icon: 'mouse-pointer-click',
type: 'app',
template: 'header-sidebar-main',
isDefault: false,
// Page-local state. `selectedProjectId` is written by the `project_picker`
// element (source = its component id) and read by predicates as `page.selectedProjectId`.
variables: [
{ name: 'selectedProjectId', type: 'record_id', source: 'project_picker' },
],
regions: [
{
name: 'header',
width: 'full',
components: [
{
type: 'page:header',
properties: {
title: 'Page Variables',
subtitle: 'Pick a project — page-local state drives what shows below, live.',
},
},
],
},
{
name: 'main',
width: 'large',
components: [
{
type: 'element:text',
properties: {
content:
'This page declares a `selectedProjectId` variable. The record picker writes the selected project into it; the detail panel below is gated on `page.selectedProjectId` and only appears once you choose. No custom code — just metadata.',
variant: 'body',
},
},
{
type: 'element:record_picker',
id: 'project_picker',
dataSource: { object: 'showcase_project', limit: 50 },
properties: {
label: 'Project',
labelField: 'name',
placeholder: 'Choose a project…',
},
},
// Empty state — visible until a project is chosen.
{
type: 'element:text',
id: 'empty_hint',
visibility: "page.selectedProjectId == ''",
properties: {
content: '↑ Select a project above to reveal its detail panel.',
variant: 'caption',
},
},
// Detail panel — gated on the page variable. Appears once a project is picked.
{
type: 'element:divider',
id: 'detail_divider',
visibility: "page.selectedProjectId != ''",
},
{
type: 'element:text',
id: 'detail_heading',
visibility: "page.selectedProjectId != ''",
properties: {
content: '✓ Project selected',
variant: 'subheading',
},
},
{
type: 'element:text',
id: 'detail_body',
visibility: "page.selectedProjectId != ''",
properties: {
content:
'This panel is gated on `page.selectedProjectId != ""`. It became visible the instant the picker wrote the variable — the same page-local state any other component (or its data filter) can read.',
variant: 'body',
},
},
],
},
],
});