@airtable/blocks 1.3.0 → 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -1
- package/dist/cjs/index.js +30 -11
- package/dist/cjs/injected/airtable_interface.js +2 -1
- package/dist/cjs/models/cursor.js +4 -6
- package/dist/cjs/models/field.js +24 -0
- package/dist/cjs/models/grouped_record_query_result.js +475 -0
- package/dist/cjs/models/models.js +30 -0
- package/dist/cjs/models/mutations.js +41 -9
- package/dist/cjs/models/record_query_result.js +37 -12
- package/dist/cjs/models/session.js +65 -23
- package/dist/cjs/models/table_or_view_query_result.js +306 -97
- package/dist/cjs/models/view.js +71 -1
- package/dist/cjs/models/view_data_store.js +62 -20
- package/dist/cjs/models/view_metadata_query_result.js +41 -8
- package/dist/cjs/sdk.js +2 -2
- package/dist/cjs/testing/mock_airtable_interface.js +1 -110
- package/dist/cjs/types/airtable_interface.js +19 -1
- package/dist/cjs/types/mutations.js +2 -1
- package/dist/cjs/types/view.js +1 -0
- package/dist/cjs/ui/confirmation_dialog.js +12 -4
- package/dist/cjs/ui/expand_record.js +5 -5
- package/dist/cjs/ui/expand_record_list.js +2 -5
- package/dist/cjs/ui/expand_record_picker_async.js +9 -16
- package/dist/cjs/ui/form_field.js +2 -2
- package/dist/cjs/ui/icon_config.js +11 -4
- package/dist/cjs/ui/initialize_block.js +62 -10
- package/dist/cjs/ui/ui.js +9 -2
- package/dist/cjs/ui/use_loadable.js +2 -2
- package/dist/cjs/ui/use_records.js +54 -40
- package/dist/cjs/ui/use_view_metadata.js +1 -1
- package/dist/cjs/unstable_testing_utils.js +163 -0
- package/dist/types/src/color_utils.d.ts +4 -4
- package/dist/types/src/color_utils.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +2 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/injected/airtable_interface.d.ts.map +1 -1
- package/dist/types/src/models/cursor.d.ts +4 -6
- package/dist/types/src/models/cursor.d.ts.map +1 -1
- package/dist/types/src/models/field.d.ts +17 -1
- package/dist/types/src/models/field.d.ts.map +1 -1
- package/dist/types/src/models/grouped_record_query_result.d.ts +61 -0
- package/dist/types/src/models/grouped_record_query_result.d.ts.map +1 -0
- package/dist/types/src/models/models.d.ts +4 -1
- package/dist/types/src/models/models.d.ts.map +1 -1
- package/dist/types/src/models/mutations.d.ts.map +1 -1
- package/dist/types/src/models/record.d.ts +0 -2
- package/dist/types/src/models/record.d.ts.map +1 -1
- package/dist/types/src/models/record_query_result.d.ts +22 -0
- package/dist/types/src/models/record_query_result.d.ts.map +1 -1
- package/dist/types/src/models/session.d.ts +65 -23
- package/dist/types/src/models/session.d.ts.map +1 -1
- package/dist/types/src/models/table_or_view_query_result.d.ts +21 -0
- package/dist/types/src/models/table_or_view_query_result.d.ts.map +1 -1
- package/dist/types/src/models/view.d.ts +26 -1
- package/dist/types/src/models/view.d.ts.map +1 -1
- package/dist/types/src/models/view_data_store.d.ts +2 -0
- package/dist/types/src/models/view_data_store.d.ts.map +1 -1
- package/dist/types/src/models/view_metadata_query_result.d.ts +21 -0
- package/dist/types/src/models/view_metadata_query_result.d.ts.map +1 -1
- package/dist/types/src/sdk.d.ts +3 -0
- package/dist/types/src/sdk.d.ts.map +1 -1
- package/dist/types/src/testing/mock_airtable_interface.d.ts +79 -0
- package/dist/types/src/testing/mock_airtable_interface.d.ts.map +1 -1
- package/dist/types/src/types/airtable_interface.d.ts +28 -1
- package/dist/types/src/types/airtable_interface.d.ts.map +1 -1
- package/dist/types/src/types/field.d.ts +241 -1
- package/dist/types/src/types/field.d.ts.map +1 -1
- package/dist/types/src/types/mutations.d.ts +19 -3
- package/dist/types/src/types/mutations.d.ts.map +1 -1
- package/dist/types/src/types/view.d.ts +26 -1
- package/dist/types/src/types/view.d.ts.map +1 -1
- package/dist/types/src/ui/confirmation_dialog.d.ts +8 -0
- package/dist/types/src/ui/confirmation_dialog.d.ts.map +1 -1
- package/dist/types/src/ui/expand_record.d.ts +1 -0
- package/dist/types/src/ui/expand_record.d.ts.map +1 -1
- package/dist/types/src/ui/expand_record_list.d.ts.map +1 -1
- package/dist/types/src/ui/expand_record_picker_async.d.ts +0 -3
- package/dist/types/src/ui/expand_record_picker_async.d.ts.map +1 -1
- package/dist/types/src/ui/icon_config.d.ts +15 -8
- package/dist/types/src/ui/icon_config.d.ts.map +1 -1
- package/dist/types/src/ui/initialize_block.d.ts +19 -2
- package/dist/types/src/ui/initialize_block.d.ts.map +1 -1
- package/dist/types/src/ui/ui.d.ts +2 -2
- package/dist/types/src/ui/ui.d.ts.map +1 -1
- package/dist/types/src/ui/use_loadable.d.ts +2 -2
- package/dist/types/src/ui/use_records.d.ts +11 -1
- package/dist/types/src/ui/use_records.d.ts.map +1 -1
- package/dist/types/src/unstable_testing_utils.d.ts +13 -0
- package/dist/types/src/unstable_testing_utils.d.ts.map +1 -0
- package/dist/types/test/airtable_interface_mocks/linked_records.d.ts.map +1 -1
- package/dist/types/test/airtable_interface_mocks/mock_airtable_interface_internal.d.ts +32 -1
- package/dist/types/test/airtable_interface_mocks/mock_airtable_interface_internal.d.ts.map +1 -1
- package/dist/types/test/airtable_interface_mocks/project_tracker.d.ts.map +1 -1
- package/dist/types/test/ui/expand_record.test.d.ts +2 -0
- package/dist/types/test/ui/expand_record.test.d.ts.map +1 -0
- package/dist/types/test/ui/expand_record_list.test.d.ts +2 -0
- package/dist/types/test/ui/expand_record_list.test.d.ts.map +1 -0
- package/dist/types/test/ui/expand_record_picker_async.test.d.ts +2 -0
- package/dist/types/test/ui/expand_record_picker_async.test.d.ts.map +1 -0
- package/index.d.ts +4 -2
- package/package.json +4 -4
- package/types.d.ts +3 -0
- package/unstable_testing_utils.d.ts +1 -0
- package/unstable_testing_utils.js +1 -0
- package/dist/cjs/testing/inject_mock_airtable_interface.js +0 -63
- package/dist/cjs/testing/mock_airtable_interface_external.js +0 -741
- package/dist/cjs/testing/test_driver.js +0 -260
- package/dist/cjs/types/test_mutations.js +0 -32
- package/dist/cjs/unstable_testing.js +0 -17
- package/dist/types/src/testing/inject_mock_airtable_interface.d.ts +0 -2
- package/dist/types/src/testing/inject_mock_airtable_interface.d.ts.map +0 -1
- package/dist/types/src/testing/mock_airtable_interface_external.d.ts +0 -107
- package/dist/types/src/testing/mock_airtable_interface_external.d.ts.map +0 -1
- package/dist/types/src/testing/test_driver.d.ts +0 -90
- package/dist/types/src/testing/test_driver.d.ts.map +0 -1
- package/dist/types/src/types/test_mutations.d.ts +0 -27
- package/dist/types/src/types/test_mutations.d.ts.map +0 -1
- package/dist/types/src/unstable_testing.d.ts +0 -3
- package/dist/types/src/unstable_testing.d.ts.map +0 -1
- package/dist/types/test/testing/mock_airtable_interface_external.test.d.ts +0 -2
- package/dist/types/test/testing/mock_airtable_interface_external.test.d.ts.map +0 -1
- package/dist/types/test/testing/test_driver.test.d.ts +0 -2
- package/dist/types/test/testing/test_driver.test.d.ts.map +0 -1
- package/unstable_testing.d.ts +0 -1
- package/unstable_testing.js +0 -1
|
@@ -13,6 +13,12 @@ Object.defineProperty(exports, "FieldType", {
|
|
|
13
13
|
return _field.FieldType;
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
+
Object.defineProperty(exports, "FieldConfig", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function get() {
|
|
19
|
+
return _field.FieldConfig;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
16
22
|
Object.defineProperty(exports, "ViewType", {
|
|
17
23
|
enumerable: true,
|
|
18
24
|
get: function get() {
|
|
@@ -61,6 +67,12 @@ Object.defineProperty(exports, "TableOrViewQueryResult", {
|
|
|
61
67
|
return _table_or_view_query_result.default;
|
|
62
68
|
}
|
|
63
69
|
});
|
|
70
|
+
Object.defineProperty(exports, "GroupedRecordQueryResult", {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
get: function get() {
|
|
73
|
+
return _grouped_record_query_result.default;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
64
76
|
Object.defineProperty(exports, "LinkedRecordsQueryResult", {
|
|
65
77
|
enumerable: true,
|
|
66
78
|
get: function get() {
|
|
@@ -73,6 +85,18 @@ Object.defineProperty(exports, "ViewMetadataQueryResult", {
|
|
|
73
85
|
return _view_metadata_query_result.default;
|
|
74
86
|
}
|
|
75
87
|
});
|
|
88
|
+
Object.defineProperty(exports, "Session", {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
get: function get() {
|
|
91
|
+
return _session.default;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
Object.defineProperty(exports, "Cursor", {
|
|
95
|
+
enumerable: true,
|
|
96
|
+
get: function get() {
|
|
97
|
+
return _cursor.default;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
76
100
|
exports.recordColoring = void 0;
|
|
77
101
|
|
|
78
102
|
var recordColoring = _interopRequireWildcard(require("./record_coloring"));
|
|
@@ -99,10 +123,16 @@ var _record_query_result = _interopRequireDefault(require("./record_query_result
|
|
|
99
123
|
|
|
100
124
|
var _table_or_view_query_result = _interopRequireDefault(require("./table_or_view_query_result"));
|
|
101
125
|
|
|
126
|
+
var _grouped_record_query_result = _interopRequireDefault(require("./grouped_record_query_result"));
|
|
127
|
+
|
|
102
128
|
var _linked_records_query_result = _interopRequireDefault(require("./linked_records_query_result"));
|
|
103
129
|
|
|
104
130
|
var _view_metadata_query_result = _interopRequireDefault(require("./view_metadata_query_result"));
|
|
105
131
|
|
|
132
|
+
var _session = _interopRequireDefault(require("./session"));
|
|
133
|
+
|
|
134
|
+
var _cursor = _interopRequireDefault(require("./cursor"));
|
|
135
|
+
|
|
106
136
|
// istanbul ignore file
|
|
107
137
|
|
|
108
138
|
/** @ignore */
|
|
@@ -47,6 +47,8 @@ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/creat
|
|
|
47
47
|
|
|
48
48
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
49
49
|
|
|
50
|
+
var _airtable_interface = require("../types/airtable_interface");
|
|
51
|
+
|
|
50
52
|
var _mutations = require("../types/mutations");
|
|
51
53
|
|
|
52
54
|
var _private_utils = require("../private_utils");
|
|
@@ -590,6 +592,35 @@ function () {
|
|
|
590
592
|
return;
|
|
591
593
|
}
|
|
592
594
|
|
|
595
|
+
case _mutations.MutationTypes.UPDATE_VIEW_METADATA:
|
|
596
|
+
{
|
|
597
|
+
var _tableId5 = mutation.tableId,
|
|
598
|
+
viewId = mutation.viewId;
|
|
599
|
+
var runContext = this._airtableInterface.sdkInitData.runContext;
|
|
600
|
+
|
|
601
|
+
if (runContext.type !== _airtable_interface.BlockRunContextType.VIEW) {
|
|
602
|
+
throw (0, _error_utils.spawnError)('Setting view metadata is only valid for views');
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
if (runContext.viewId !== viewId || runContext.tableId !== _tableId5) {
|
|
606
|
+
throw (0, _error_utils.spawnError)('Custom views can only set view metadata on themselves');
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
var _table5 = this._base.getTableByIdIfExists(_tableId5);
|
|
610
|
+
|
|
611
|
+
if (!_table5) {
|
|
612
|
+
throw (0, _error_utils.spawnError)("Can't update metadata: No table with id %s exists", _tableId5);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
var view = _table5.getViewByIdIfExists(viewId);
|
|
616
|
+
|
|
617
|
+
if (!view) {
|
|
618
|
+
throw (0, _error_utils.spawnError)("Can't update metadata: No view with id %s exists", viewId);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
return;
|
|
622
|
+
}
|
|
623
|
+
|
|
593
624
|
default:
|
|
594
625
|
throw (0, _error_utils.spawnUnknownSwitchCaseError)('mutation type', mutation, 'type');
|
|
595
626
|
}
|
|
@@ -639,19 +670,19 @@ function () {
|
|
|
639
670
|
|
|
640
671
|
case _mutations.MutationTypes.DELETE_MULTIPLE_RECORDS:
|
|
641
672
|
{
|
|
642
|
-
var
|
|
673
|
+
var _tableId6 = mutation.tableId,
|
|
643
674
|
recordIds = mutation.recordIds;
|
|
644
675
|
|
|
645
|
-
var _recordStore2 = this._base.__getRecordStore(
|
|
676
|
+
var _recordStore2 = this._base.__getRecordStore(_tableId6);
|
|
646
677
|
|
|
647
678
|
if (!_recordStore2.isRecordMetadataLoaded) {
|
|
648
679
|
return [];
|
|
649
680
|
}
|
|
650
681
|
|
|
651
682
|
return [...recordIds.map(recordId => ({
|
|
652
|
-
path: ['tablesById',
|
|
683
|
+
path: ['tablesById', _tableId6, 'recordsById', recordId],
|
|
653
684
|
value: undefined
|
|
654
|
-
})), ...this._base.getTableById(
|
|
685
|
+
})), ...this._base.getTableById(_tableId6).views.flatMap(view => {
|
|
655
686
|
var viewDataStore = _recordStore2.getViewDataStore(view.id);
|
|
656
687
|
|
|
657
688
|
if (!viewDataStore.isDataLoaded) {
|
|
@@ -664,10 +695,10 @@ function () {
|
|
|
664
695
|
|
|
665
696
|
case _mutations.MutationTypes.CREATE_MULTIPLE_RECORDS:
|
|
666
697
|
{
|
|
667
|
-
var
|
|
698
|
+
var _tableId7 = mutation.tableId,
|
|
668
699
|
_records2 = mutation.records;
|
|
669
700
|
|
|
670
|
-
var _recordStore3 = this._base.__getRecordStore(
|
|
701
|
+
var _recordStore3 = this._base.__getRecordStore(_tableId7);
|
|
671
702
|
|
|
672
703
|
if (!_recordStore3.isRecordMetadataLoaded) {
|
|
673
704
|
return [];
|
|
@@ -706,7 +737,7 @@ function () {
|
|
|
706
737
|
}
|
|
707
738
|
|
|
708
739
|
return {
|
|
709
|
-
path: ['tablesById',
|
|
740
|
+
path: ['tablesById', _tableId7, 'recordsById', record.id],
|
|
710
741
|
value: {
|
|
711
742
|
id: record.id,
|
|
712
743
|
cellValuesByFieldId: filteredCellValuesByFieldId,
|
|
@@ -714,7 +745,7 @@ function () {
|
|
|
714
745
|
createdTime: new Date().toJSON()
|
|
715
746
|
}
|
|
716
747
|
};
|
|
717
|
-
}), ...this._base.getTableById(
|
|
748
|
+
}), ...this._base.getTableById(_tableId7).views.flatMap(view => {
|
|
718
749
|
var viewDataStore = _recordStore3.getViewDataStore(view.id);
|
|
719
750
|
|
|
720
751
|
if (!viewDataStore.isDataLoaded) {
|
|
@@ -735,9 +766,10 @@ function () {
|
|
|
735
766
|
|
|
736
767
|
case _mutations.MutationTypes.CREATE_SINGLE_FIELD:
|
|
737
768
|
case _mutations.MutationTypes.UPDATE_SINGLE_FIELD_CONFIG:
|
|
769
|
+
case _mutations.MutationTypes.UPDATE_VIEW_METADATA:
|
|
738
770
|
case _mutations.MutationTypes.CREATE_SINGLE_TABLE:
|
|
739
771
|
{
|
|
740
|
-
// No optimistic updates for field or table mutations.
|
|
772
|
+
// No optimistic updates for field, view metadata, or table mutations.
|
|
741
773
|
return [];
|
|
742
774
|
}
|
|
743
775
|
// The following branch is unreachable because this method's only
|
|
@@ -21,6 +21,7 @@ require("core-js/modules/web.dom-collections.iterator");
|
|
|
21
21
|
Object.defineProperty(exports, "__esModule", {
|
|
22
22
|
value: true
|
|
23
23
|
});
|
|
24
|
+
exports.normalizeSortsOrGroups = normalizeSortsOrGroups;
|
|
24
25
|
exports.default = void 0;
|
|
25
26
|
|
|
26
27
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
@@ -65,6 +66,8 @@ var WatchableRecordQueryResultKeys = Object.freeze({
|
|
|
65
66
|
recordIds: 'recordIds',
|
|
66
67
|
cellValues: 'cellValues',
|
|
67
68
|
recordColors: 'recordColors',
|
|
69
|
+
groups: 'groups',
|
|
70
|
+
groupLevels: 'groupLevels',
|
|
68
71
|
isDataLoaded: 'isDataLoaded'
|
|
69
72
|
});
|
|
70
73
|
var WatchableCellValuesInFieldKeyPrefix = 'cellValuesInField:'; // The string case is to accommodate cellValuesInField:$FieldId.
|
|
@@ -79,6 +82,35 @@ var WatchableCellValuesInFieldKeyPrefix = 'cellValuesInField:'; // The string ca
|
|
|
79
82
|
* - `cellValuesInField:{FIELD_ID}`
|
|
80
83
|
*/
|
|
81
84
|
|
|
85
|
+
/**
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
function _normalizeSortOrGroup(table, sortOrGroup) {
|
|
89
|
+
var _sortOrGroup$directio;
|
|
90
|
+
|
|
91
|
+
var field = table.__getFieldMatching(sortOrGroup.field);
|
|
92
|
+
|
|
93
|
+
if (sortOrGroup.direction !== undefined && sortOrGroup.direction !== 'asc' && sortOrGroup.direction !== 'desc') {
|
|
94
|
+
throw (0, _error_utils.spawnError)('Invalid sort direction: %s', sortOrGroup.direction);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
fieldId: field.id,
|
|
99
|
+
direction: (_sortOrGroup$directio = sortOrGroup.direction) !== null && _sortOrGroup$directio !== void 0 ? _sortOrGroup$directio : 'asc'
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* @internal
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
function normalizeSortsOrGroups(table, sortsOrGroups) {
|
|
108
|
+
if (sortsOrGroups === undefined || sortsOrGroups === null) {
|
|
109
|
+
return sortsOrGroups;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return sortsOrGroups.map(sortOrGroup => _normalizeSortOrGroup(table, sortOrGroup));
|
|
113
|
+
}
|
|
82
114
|
/**
|
|
83
115
|
* A RecordQueryResult represents a set of records. It's a little bit like a one-off View in Airtable: it
|
|
84
116
|
* contains a bunch of records, filtered to a useful subset of the records in the table. Those
|
|
@@ -127,6 +159,8 @@ var WatchableCellValuesInFieldKeyPrefix = 'cellValuesInField:'; // The string ca
|
|
|
127
159
|
*
|
|
128
160
|
* @docsPath models/query results/RecordQueryResult
|
|
129
161
|
*/
|
|
162
|
+
|
|
163
|
+
|
|
130
164
|
var RecordQueryResult =
|
|
131
165
|
/*#__PURE__*/
|
|
132
166
|
function (_AbstractModelWithAsy) {
|
|
@@ -143,25 +177,16 @@ function (_AbstractModelWithAsy) {
|
|
|
143
177
|
}, {
|
|
144
178
|
key: "_shouldLoadDataForKey",
|
|
145
179
|
value: function _shouldLoadDataForKey(key) {
|
|
146
|
-
return key === RecordQueryResult.WatchableKeys.records || key === RecordQueryResult.WatchableKeys.recordIds || key === RecordQueryResult.WatchableKeys.cellValues || key === RecordQueryResult.WatchableKeys.recordColors || key.startsWith(RecordQueryResult.WatchableCellValuesInFieldKeyPrefix);
|
|
180
|
+
return key === RecordQueryResult.WatchableKeys.records || key === RecordQueryResult.WatchableKeys.recordIds || key === RecordQueryResult.WatchableKeys.cellValues || key === RecordQueryResult.WatchableKeys.recordColors || key === RecordQueryResult.WatchableKeys.groups || key === RecordQueryResult.WatchableKeys.groupLevels || key.startsWith(RecordQueryResult.WatchableCellValuesInFieldKeyPrefix);
|
|
147
181
|
}
|
|
148
182
|
/** @internal */
|
|
149
183
|
|
|
150
184
|
}, {
|
|
151
185
|
key: "_normalizeOpts",
|
|
152
186
|
value: function _normalizeOpts(table, recordStore, opts) {
|
|
153
|
-
var
|
|
154
|
-
var field = table.__getFieldMatching(sort.field);
|
|
155
|
-
|
|
156
|
-
if (sort.direction !== undefined && sort.direction !== 'asc' && sort.direction !== 'desc') {
|
|
157
|
-
throw (0, _error_utils.spawnError)('Invalid sort direction: %s', sort.direction);
|
|
158
|
-
}
|
|
187
|
+
var _normalizeSortsOrGrou;
|
|
159
188
|
|
|
160
|
-
|
|
161
|
-
fieldId: field.id,
|
|
162
|
-
direction: sort.direction || 'asc'
|
|
163
|
-
};
|
|
164
|
-
});
|
|
189
|
+
var sorts = (_normalizeSortsOrGrou = normalizeSortsOrGroups(table, opts.sorts)) !== null && _normalizeSortsOrGrou !== void 0 ? _normalizeSortsOrGrou : null;
|
|
165
190
|
var fieldIdsOrNullIfAllFields = null;
|
|
166
191
|
|
|
167
192
|
if (opts.fields) {
|
|
@@ -64,12 +64,16 @@ var WatchableSessionKeys = Object.freeze({
|
|
|
64
64
|
*
|
|
65
65
|
* @example
|
|
66
66
|
* ```js
|
|
67
|
-
* import {
|
|
67
|
+
* import {useSession} from '@airtable/blocks/ui';
|
|
68
68
|
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
69
|
+
* function Username() {
|
|
70
|
+
* const session = useSession();
|
|
71
|
+
*
|
|
72
|
+
* if (session.currentUser !== null) {
|
|
73
|
+
* return <span>The current user's name is {session.currentUser.name}</span>;
|
|
74
|
+
* } else {
|
|
75
|
+
* return <span>This app is being viewed in a public share</span>;
|
|
76
|
+
* }
|
|
73
77
|
* }
|
|
74
78
|
* ```
|
|
75
79
|
* @docsPath models/Session
|
|
@@ -132,11 +136,21 @@ function (_AbstractModel) {
|
|
|
132
136
|
*
|
|
133
137
|
* @example
|
|
134
138
|
* ```js
|
|
135
|
-
* import {
|
|
139
|
+
* import {useSession} from '@airtable/blocks/ui';
|
|
140
|
+
*
|
|
141
|
+
* function UpdateButton({onClick}) {
|
|
142
|
+
* const session = useSession();
|
|
143
|
+
* const updateRecordsCheckResult = session.checkPermissionsForUpdateRecords();
|
|
144
|
+
* const deniedReason = updateRecordsCheckResult.hasPermission
|
|
145
|
+
* ? <span>{updateRecordsCheckResult.reasonDisplayString}</span>
|
|
146
|
+
* : null;
|
|
136
147
|
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
148
|
+
* return <div>
|
|
149
|
+
* {deniedReason}
|
|
150
|
+
* <button onClick={onClick} disabled={!!deniedReason}>
|
|
151
|
+
* Update
|
|
152
|
+
* </button>
|
|
153
|
+
* </div>;
|
|
140
154
|
* }
|
|
141
155
|
*/
|
|
142
156
|
value: function checkPermissionsForUpdateRecords() {
|
|
@@ -166,11 +180,21 @@ function (_AbstractModel) {
|
|
|
166
180
|
*
|
|
167
181
|
* @example
|
|
168
182
|
* ```js
|
|
169
|
-
* import {
|
|
183
|
+
* import {useSession} from '@airtable/blocks/ui';
|
|
170
184
|
*
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
*
|
|
185
|
+
* function CreateButton({onClick}) {
|
|
186
|
+
* const session = useSession();
|
|
187
|
+
* const updateRecordsCheckResult = session.checkPermissionsForCreateRecords();
|
|
188
|
+
* const deniedReason = updateRecordsCheckResult.hasPermission
|
|
189
|
+
* ? <span>{updateRecordsCheckResult.reasonDisplayString}</span>
|
|
190
|
+
* : null;
|
|
191
|
+
*
|
|
192
|
+
* return <div>
|
|
193
|
+
* {deniedReason}
|
|
194
|
+
* <button onClick={onClick} disabled={!!deniedReason}>
|
|
195
|
+
* Create
|
|
196
|
+
* </button>
|
|
197
|
+
* </div>;
|
|
174
198
|
* }
|
|
175
199
|
*/
|
|
176
200
|
|
|
@@ -203,12 +227,21 @@ function (_AbstractModel) {
|
|
|
203
227
|
*
|
|
204
228
|
* @example
|
|
205
229
|
* ```js
|
|
206
|
-
* import {
|
|
230
|
+
* import {useSession} from '@airtable/blocks/ui';
|
|
207
231
|
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
232
|
+
* function DeleteButton({onClick}) {
|
|
233
|
+
* const session = useSession();
|
|
234
|
+
* const updateRecordsCheckResult = session.checkPermissionsForDeleteRecords();
|
|
235
|
+
* const deniedReason = updateRecordsCheckResult.hasPermission
|
|
236
|
+
* ? <span>{updateRecordsCheckResult.reasonDisplayString}</span>
|
|
237
|
+
* : null;
|
|
238
|
+
*
|
|
239
|
+
* return <div>
|
|
240
|
+
* {deniedReason}
|
|
241
|
+
* <button onClick={onClick} disabled={!!deniedReason}>
|
|
242
|
+
* Delete
|
|
243
|
+
* </button>
|
|
244
|
+
* </div>;
|
|
212
245
|
*/
|
|
213
246
|
|
|
214
247
|
}, {
|
|
@@ -355,11 +388,20 @@ function (_AbstractModel) {
|
|
|
355
388
|
*
|
|
356
389
|
* @example
|
|
357
390
|
* ```js
|
|
358
|
-
* import {
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
391
|
+
* import {useSession} from '@airtable/blocks/ui';
|
|
392
|
+
*
|
|
393
|
+
* function CurrentUser() {
|
|
394
|
+
* const session = useSession();
|
|
395
|
+
*
|
|
396
|
+
* if (!session.currentUser) {
|
|
397
|
+
* return <div>This app is being used in a public share.</div>;
|
|
398
|
+
* }
|
|
399
|
+
*
|
|
400
|
+
* return <ul>
|
|
401
|
+
* <li>ID: {session.currentUser.id}</li>
|
|
402
|
+
* <li>E-mail: {session.currentUser.email}</li>
|
|
403
|
+
* <li>Name: {session.currentUser.name}</li>
|
|
404
|
+
* </ul>;
|
|
363
405
|
* }
|
|
364
406
|
* ```
|
|
365
407
|
*/
|