@zohodesk/library-platform 1.1.3-exp.2 → 1.1.3-exp.4
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/es/bc/zhttp/Errors.js +14 -0
- package/es/bc/zhttp/index.js +3 -1
- package/es/bc/zlist/Constants.js +6 -1
- package/es/bc/zlist/Events.js +140 -0
- package/es/bc/zlist/index.js +2 -1
- package/es/cc/component/FallbackView.js +1 -0
- package/es/cc/fields/currency/Model.js +2 -0
- package/es/cc/fields/field/Properties.js +1 -1
- package/es/cc/fields/formula/Model.js +5 -0
- package/es/cc/index.js +1 -0
- package/es/cc/link/Properties.js +0 -1
- package/es/cc/table-connected/ErrorEventType.js +32 -0
- package/es/cc/table-connected/Events.js +96 -0
- package/es/cc/table-connected/SdkContract.js +120 -0
- package/es/cc/table-connected/constants/Events.js +2 -0
- package/es/cc/table-connected/index.js +3 -1
- package/es/cc/table-list/Properties.js +9 -0
- package/es/cc/table-list/row/Properties.js +9 -0
- package/es/index.js +2 -1
- package/es/library/custom-component/adapters/gateways/event-manager/EventManager.js +116 -4
- package/es/library/custom-component/applications/interfaces/gateways/ISchemaValidator.js +1 -0
- package/es/library/custom-component/applications/usecases/InitializeUseCase.js +3 -2
- package/es/library/custom-component/applications/usecases/UpdatePropertyUseCase.js +3 -2
- package/es/library/custom-component/domain/entities/Component.js +16 -3
- package/es/library/custom-component/domain/entities/Properties.js +19 -1
- package/es/library/custom-component/frameworks/json-schema-validator/Validator.js +36 -1
- package/es/library/custom-component/frameworks/ui/CreateCustomComponent.js +23 -11
- package/es/library/custom-component/frameworks/ui/DependencyFactory.js +4 -3
- package/es/library/dot/components/table-list/frameworks/hooks/useRowData.js +12 -5
- package/es/library/dot/components/table-list/frameworks/hooks/useTableRowReorder.js +17 -5
- package/es/library/dot/components/table-list/frameworks/ui/TableListView.js +35 -26
- package/es/library/dot/components/table-list/frameworks/ui/css/TableList.module.css +152 -56
- package/es/library/dot/components/table-list/frameworks/ui/sub-components/Header.js +22 -16
- package/es/library/dot/components/table-list/frameworks/ui/sub-components/Rows.js +7 -4
- package/es/library/dot/components/table-list/frameworks/ui/sub-components/header/MassAction.js +5 -13
- package/es/library/dot/components/table-list/frameworks/ui/sub-components/row/Row.js +31 -34
- package/es/library/dot/components/table-list/frameworks/ui/sub-components/row/RowSelection.js +3 -8
- package/es/library/dot/components/table-list/frameworks/utils/getHeaderClasses.js +37 -0
- package/es/library/dot/components/table-list/frameworks/utils/getTableListClassName.js +37 -0
- package/es/library/dot/components/table-list/frameworks/utils/reOrder.js +28 -14
- package/es/library/dot/legacy-to-new-arch/text-area/frameworks/ui/TextAreaView.js +1 -1
- package/es/platform/client-actions/components/action-event-mediator/frameworks/ui/ClientActionsAdapter.js +96 -0
- package/es/platform/client-actions/components/action-event-mediator/frameworks/ui/EventHandlersFactory.js +11 -3
- package/es/platform/client-actions/template-resolver/index.js +1 -0
- package/es/platform/client-actions/translators/context-resolver/index.js +6 -6
- package/es/platform/components/table-connected/adapters/controllers/ColumnChooserOpenedController.js +1 -1
- package/es/platform/components/table-connected/adapters/resources/ErrorPrinter.js +20 -0
- package/es/platform/components/table-connected/adapters/resources/SmartTableResource.js +71 -0
- package/es/platform/components/table-connected/frameworks/ErrorEventHandlersFactory.js +126 -0
- package/es/platform/components/table-connected/frameworks/EventHandlersFactory.js +34 -1
- package/es/platform/components/table-connected/frameworks/TableConnectedFactory.js +2 -0
- package/es/platform/components/table-connected/frameworks/TableConnectedView.js +5 -1
- package/es/platform/zdata-source/domain/entities/DataSource.js +18 -12
- package/es/platform/zfield/domain/entities/fields-manager/FieldsManager.js +7 -1
- package/es/platform/zform/adapters/presenter/FormTranslator.js +6 -127
- package/es/platform/zform/adapters/presenter/translators/SectionTranslator.js +32 -0
- package/es/platform/zform/adapters/presenter/translators/fields/BooleanFieldTranslator.js +20 -0
- package/es/platform/zform/adapters/presenter/translators/fields/CurrencyFieldTranslator.js +29 -0
- package/es/platform/zform/adapters/presenter/translators/fields/DateFieldTranslator.js +20 -0
- package/es/platform/zform/adapters/presenter/translators/fields/DateTimeFieldTranslator.js +21 -0
- package/es/platform/zform/adapters/presenter/translators/fields/DecimalFieldTranslator.js +29 -0
- package/es/platform/zform/adapters/presenter/translators/fields/EmailFieldTranslator.js +30 -0
- package/es/platform/zform/adapters/presenter/translators/fields/LookUpFieldTranslator.js +30 -0
- package/es/platform/zform/adapters/presenter/translators/fields/MultiselectFieldTranslator.js +29 -0
- package/es/platform/zform/adapters/presenter/translators/fields/NumberFieldTranslator.js +30 -0
- package/es/platform/zform/adapters/presenter/translators/fields/PercentageFieldTranslator.js +30 -0
- package/es/platform/zform/adapters/presenter/translators/fields/PhoneFieldTranslator.js +29 -0
- package/es/platform/zform/adapters/presenter/translators/fields/PicklistFieldTranslator.js +29 -0
- package/es/platform/zform/adapters/presenter/translators/fields/TextAreaFieldTranslator.js +30 -0
- package/es/platform/zform/adapters/presenter/translators/fields/TextFieldTranslator.js +27 -0
- package/es/platform/zform/adapters/presenter/translators/fields/URLFieldTranslator.js +30 -0
- package/es/platform/zform/adapters/presenter/translators/fields/index.js +15 -0
- package/es/platform/zform/applications/usecases/MyFormSuccessUseCase.js +3 -1
- package/es/platform/zform/domain/ZField.js +61 -16
- package/es/platform/zform/domain/ZSection.js +20 -7
- package/es/platform/zhttp/applications/usecases/FetchUseCase.js +111 -66
- package/es/platform/zlist/adapters/controllers/FieldExecuteFailedController.js +25 -0
- package/es/platform/zlist/adapters/gateways/Repository.js +5 -2
- package/es/platform/zlist/adapters/presenters/TableTranslator.js +12 -5
- package/es/platform/zlist/adapters/presenters/translators/ColumnTranslator.js +2 -2
- package/es/platform/zlist/adapters/presenters/translators/EmptyViewModel.js +2 -1
- package/es/platform/zlist/adapters/presenters/translators/Header.js +3 -2
- package/es/platform/zlist/adapters/presenters/translators/HeadersTranslator.js +3 -2
- package/es/platform/zlist/adapters/presenters/translators/fields/CurrencyFieldTranslator.js +1 -0
- package/es/platform/zlist/adapters/presenters/translators/fields/FormulaFieldTranslator.js +3 -0
- package/es/platform/zlist/applications/entities-factory/ListFactory.js +3 -2
- package/es/platform/zlist/applications/usecases/FetchMoreUseCase.js +1 -1
- package/es/platform/zlist/applications/usecases/RecordExecuteFailedUseCase.js +3 -2
- package/es/platform/zlist/domain/entities/List.js +12 -63
- package/es/platform/zlist/domain/entities/ListErrorState.js +167 -0
- package/es/platform/zlist/frameworks/EventHandlersFactory.js +6 -0
- package/es/platform/zlist/frameworks/ZListBehaviourFactory.js +6 -1
- package/package.json +3 -3
|
@@ -3,11 +3,27 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
3
3
|
// @ts-ignore
|
|
4
4
|
if (__DEVELOPMENT__) {
|
|
5
5
|
globalThis.enableEventLogging = false;
|
|
6
|
+
globalThis.enableEventVerbose = false;
|
|
6
7
|
}
|
|
7
8
|
|
|
9
|
+
var ErrorCode = /*#__PURE__*/function (ErrorCode) {
|
|
10
|
+
ErrorCode["InvalidData"] = "Invalid data";
|
|
11
|
+
ErrorCode["InvalidSchema"] = "Invalid Schema";
|
|
12
|
+
return ErrorCode;
|
|
13
|
+
}(ErrorCode || {});
|
|
14
|
+
|
|
8
15
|
class EventManager {
|
|
9
|
-
constructor() {
|
|
16
|
+
constructor(name, jsonValidator) {
|
|
17
|
+
let events = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
18
|
+
this.name = name;
|
|
19
|
+
this.jsonValidator = jsonValidator;
|
|
20
|
+
this.events = events;
|
|
21
|
+
|
|
10
22
|
_defineProperty(this, "_element", void 0);
|
|
23
|
+
|
|
24
|
+
_defineProperty(this, "alreadyWarnedAboutEventPayloadSchemaNotFound", {});
|
|
25
|
+
|
|
26
|
+
this.alreadyWarnedAboutEventPayloadSchemaNotFound = {};
|
|
11
27
|
}
|
|
12
28
|
|
|
13
29
|
setElement(element) {
|
|
@@ -56,12 +72,96 @@ class EventManager {
|
|
|
56
72
|
});
|
|
57
73
|
}
|
|
58
74
|
|
|
75
|
+
verifySchema(data, schema) {
|
|
76
|
+
let error = null;
|
|
77
|
+
|
|
78
|
+
try {
|
|
79
|
+
const {
|
|
80
|
+
isValid,
|
|
81
|
+
errors
|
|
82
|
+
} = this.jsonValidator(schema, data);
|
|
83
|
+
|
|
84
|
+
if (!isValid) {
|
|
85
|
+
error = {
|
|
86
|
+
code: ErrorCode.InvalidData,
|
|
87
|
+
errors
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
} catch (e) {
|
|
91
|
+
error = {
|
|
92
|
+
code: ErrorCode.InvalidSchema,
|
|
93
|
+
error: e
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return error;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
printEventPayloadSchemaNotFountError(event) {
|
|
101
|
+
const {
|
|
102
|
+
type
|
|
103
|
+
} = event; // @ts-ignore
|
|
104
|
+
|
|
105
|
+
if (!this.alreadyWarnedAboutEventPayloadSchemaNotFound[type] && __DEVELOPMENT__ && global.enableEventVerbose) {
|
|
106
|
+
console.warn(`${this.name}'s Event type "${type}" not found in event metadata.`);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
this.alreadyWarnedAboutEventPayloadSchemaNotFound[type] = true;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
printEventPayloadSchemaInvalidError(eventName, error) {
|
|
113
|
+
let dataName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '(root)';
|
|
114
|
+
const {
|
|
115
|
+
msg,
|
|
116
|
+
styles: nameStyles
|
|
117
|
+
} = this.eventNameConsoleStyle(eventName);
|
|
118
|
+
console.group(`${msg}%c's ${dataName} Validation Errors:`, ...nameStyles, 'color: initial; font-weight: initial');
|
|
119
|
+
|
|
120
|
+
if (error.code === ErrorCode.InvalidSchema) {
|
|
121
|
+
console.error(`%cInvalid Schema:`, 'color: #FF6F61; font-weight: bold;', error.error);
|
|
122
|
+
} else if (error.code === ErrorCode.InvalidData) {
|
|
123
|
+
error.errors.forEach((_ref, i) => {
|
|
124
|
+
let {
|
|
125
|
+
dataPath,
|
|
126
|
+
message
|
|
127
|
+
} = _ref;
|
|
128
|
+
console.error(`%c${i + 1}. %c${dataName + dataPath}%c → ${message}`, 'color: initial;', 'color: #FF6F61; font-weight: bold;', 'color: #FFA500;');
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
console.groupEnd(); // }
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
verifyEventPayload(event) {
|
|
136
|
+
const {
|
|
137
|
+
type,
|
|
138
|
+
payload
|
|
139
|
+
} = event;
|
|
140
|
+
const eventMeta = this.events.find(event => event.type === type);
|
|
141
|
+
const payloadMeta = eventMeta ? eventMeta.payload : null;
|
|
142
|
+
|
|
143
|
+
if (this.jsonValidator && payloadMeta) {
|
|
144
|
+
const error = this.verifySchema(payload, payloadMeta);
|
|
145
|
+
error && this.printEventPayloadSchemaInvalidError(event.type, error, 'payload');
|
|
146
|
+
return error ? false : true;
|
|
147
|
+
} else {
|
|
148
|
+
this.printEventPayloadSchemaNotFountError(event);
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
59
153
|
dispatchEvent(event) {
|
|
60
154
|
let {
|
|
61
155
|
payload,
|
|
62
156
|
metaData,
|
|
63
157
|
type
|
|
64
158
|
} = event;
|
|
159
|
+
const isValid = this.verifyEventPayload(event);
|
|
160
|
+
|
|
161
|
+
if (!isValid) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
65
165
|
this._element && this._element.dispatchEvent(new CustomEvent(type, {
|
|
66
166
|
bubbles: true,
|
|
67
167
|
detail: {
|
|
@@ -71,14 +171,26 @@ class EventManager {
|
|
|
71
171
|
}));
|
|
72
172
|
}
|
|
73
173
|
|
|
174
|
+
eventNameConsoleStyle(type) {
|
|
175
|
+
const index = type.indexOf('#');
|
|
176
|
+
return {
|
|
177
|
+
msg: '%c' + type.slice(0, index) + '%c' + type.slice(index),
|
|
178
|
+
styles: ['color: #55c355;font-weight: bold', 'color: #5a9de9;font-weight: bold']
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
74
182
|
log(type, payload, metaData) {
|
|
75
183
|
// @ts-ignore
|
|
76
184
|
if (__DEVELOPMENT__) {
|
|
77
185
|
if (globalThis.enableEventLogging && type) {
|
|
78
|
-
const
|
|
79
|
-
|
|
186
|
+
const {
|
|
187
|
+
msg,
|
|
188
|
+
styles: nameStyles
|
|
189
|
+
} = this.eventNameConsoleStyle(type);
|
|
190
|
+
console.log(`%cEvent ${msg}`, 'font-weight: bold', ...nameStyles, {
|
|
80
191
|
payload,
|
|
81
|
-
metaData
|
|
192
|
+
metaData,
|
|
193
|
+
host: this._element
|
|
82
194
|
});
|
|
83
195
|
}
|
|
84
196
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -6,12 +6,13 @@ class InitializeUseCase extends AbstractUseCase {
|
|
|
6
6
|
let {
|
|
7
7
|
presenter,
|
|
8
8
|
jsonValidator,
|
|
9
|
-
repository
|
|
9
|
+
repository,
|
|
10
|
+
schemaValidator
|
|
10
11
|
} = this.dependencies;
|
|
11
12
|
let component = createComponent(input, input.helpers);
|
|
12
13
|
|
|
13
14
|
try {
|
|
14
|
-
component.init(jsonValidator, input.newProps);
|
|
15
|
+
component.init(jsonValidator, input.newProps, schemaValidator);
|
|
15
16
|
let state = component.getState();
|
|
16
17
|
presenter.render(state);
|
|
17
18
|
} catch (e) {
|
|
@@ -6,11 +6,12 @@ class UpdatePropertyUseCase extends AbstractUseCase {
|
|
|
6
6
|
repository,
|
|
7
7
|
jsonValidator,
|
|
8
8
|
eventManager,
|
|
9
|
-
presenter
|
|
9
|
+
presenter,
|
|
10
|
+
schemaValidator
|
|
10
11
|
} = this.dependencies;
|
|
11
12
|
let component = repository.getComponent();
|
|
12
13
|
let properties = component.getProperties();
|
|
13
|
-
let isUpdated = component.updateProperties(jsonValidator, newProps);
|
|
14
|
+
let isUpdated = component.updateProperties(jsonValidator, newProps, schemaValidator);
|
|
14
15
|
|
|
15
16
|
if (isUpdated) {
|
|
16
17
|
let updatedProperties = component.getProperties();
|
|
@@ -122,7 +122,15 @@ export default class Component {
|
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
updateProperties(jsonValidator, newProps) {
|
|
125
|
+
updateProperties(jsonValidator, newProps, schemaValidator) {
|
|
126
|
+
const entries = Object.fromEntries(this._properties.data.entries());
|
|
127
|
+
let property = entries === undefined ? {} : entries;
|
|
128
|
+
let propertyValue = newProps === undefined ? {} : newProps;
|
|
129
|
+
|
|
130
|
+
let isBhvrErrorVisible = this._properties.validateRequiredProperty(schemaValidator, this._behavioursProperties, propertyValue);
|
|
131
|
+
|
|
132
|
+
let isCompErrorVisible = this._properties.validateRequiredProperty(schemaValidator, property, propertyValue);
|
|
133
|
+
|
|
126
134
|
let isChanged = false;
|
|
127
135
|
Object.keys(newProps).forEach(key => {
|
|
128
136
|
let property = null;
|
|
@@ -148,8 +156,13 @@ export default class Component {
|
|
|
148
156
|
throw new Error(`props '${key}' not exist `);
|
|
149
157
|
}
|
|
150
158
|
});
|
|
159
|
+
|
|
160
|
+
if (isBhvrErrorVisible && isCompErrorVisible) {
|
|
161
|
+
throw "";
|
|
162
|
+
}
|
|
151
163
|
/* return this._properties.updateAllPropertiesValue(jsonValidator, newProps); */
|
|
152
164
|
|
|
165
|
+
|
|
153
166
|
return isChanged;
|
|
154
167
|
}
|
|
155
168
|
|
|
@@ -169,8 +182,8 @@ export default class Component {
|
|
|
169
182
|
return allBehavioursInitialState;
|
|
170
183
|
}
|
|
171
184
|
|
|
172
|
-
init(jsonValidator, newProps) {
|
|
173
|
-
this.updateProperties(jsonValidator, newProps);
|
|
185
|
+
init(jsonValidator, newProps, schemaValidator) {
|
|
186
|
+
this.updateProperties(jsonValidator, newProps, schemaValidator);
|
|
174
187
|
|
|
175
188
|
const properties = this._properties.getAllPropertiesValue();
|
|
176
189
|
|
|
@@ -111,6 +111,24 @@ export default class Properties {
|
|
|
111
111
|
return this.data.get(key).getTypeMetadata().schema;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
validateRequiredProperty(validator, properties, newProps) {
|
|
115
|
+
let errorWarn = validator(properties, newProps);
|
|
116
|
+
let isErrorVisible = false;
|
|
117
|
+
|
|
118
|
+
if (errorWarn.warnings && errorWarn.warnings.length > 0) {
|
|
119
|
+
errorWarn.warnings.forEach(warning => {
|
|
120
|
+
console.warn(`%c Property Validation Warnings in %c ${this.componentName}%c :\n${warning}`, 'font-weight: initial', 'color: #FF6F61;font-weight: bold', 'color: #FFA500;font-weight: initial');
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (errorWarn.errors && errorWarn.errors.length > 0) {
|
|
125
|
+
console.error(`%c Property Validation Errors in %c ${this.componentName}%c :\n${errorWarn.errors.join('\n')}`, 'font-weight: initial', 'color: #FF6F61;font-weight: bold', 'color: #FFF;font-weight: initial');
|
|
126
|
+
isErrorVisible = true;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return isErrorVisible;
|
|
130
|
+
}
|
|
131
|
+
|
|
114
132
|
validateSingleProperty(validator, onePropKey, onePropValue, optionalSchema) {
|
|
115
133
|
let schema = this.getSchema(onePropKey, optionalSchema); // INFO: Validate the property adheres to its schema
|
|
116
134
|
|
|
@@ -128,7 +146,7 @@ export default class Properties {
|
|
|
128
146
|
errors,
|
|
129
147
|
schema: schema
|
|
130
148
|
};
|
|
131
|
-
console.
|
|
149
|
+
console.error('Property validation failed', error);
|
|
132
150
|
throw new Error('Property validation failed');
|
|
133
151
|
}
|
|
134
152
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import Ajv from 'ajv';
|
|
2
|
-
let jsonValidator = new Ajv(
|
|
2
|
+
let jsonValidator = new Ajv({
|
|
3
|
+
useDefaults: true
|
|
4
|
+
});
|
|
3
5
|
|
|
4
6
|
class Validator {
|
|
5
7
|
static validate(schema, value) {
|
|
@@ -26,6 +28,39 @@ class Validator {
|
|
|
26
28
|
};
|
|
27
29
|
}
|
|
28
30
|
|
|
31
|
+
static validatePropsAgainstSchema(schemaProps, props) {
|
|
32
|
+
const warnings = [];
|
|
33
|
+
const errors = [];
|
|
34
|
+
|
|
35
|
+
for (const key in schemaProps) {
|
|
36
|
+
const schemaDef = schemaProps[key];
|
|
37
|
+
const isRequired = schemaDef.required === true;
|
|
38
|
+
const hasDefault = Object.prototype.hasOwnProperty.call(schemaDef, 'defaultValue');
|
|
39
|
+
const isProvided = Object.prototype.hasOwnProperty.call(props, key); // Handle missing required top-level properties
|
|
40
|
+
|
|
41
|
+
if (!isProvided) {
|
|
42
|
+
if (isRequired) {
|
|
43
|
+
if (hasDefault) {
|
|
44
|
+
if (schemaDef.defaultValue === undefined) {
|
|
45
|
+
errors.push(`Required property '${key}' is missing — default value is undefined.`);
|
|
46
|
+
} else {
|
|
47
|
+
warnings.push(`Required property '${key}' is missing. Default value will be used.`);
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
errors.push(`Required property '${key}' is missing — neither a value nor a default value is present.`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
warnings,
|
|
60
|
+
errors
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
29
64
|
}
|
|
30
65
|
|
|
31
66
|
export default Validator;
|
|
@@ -34,6 +34,15 @@ const createCustomComponent = input => {
|
|
|
34
34
|
|
|
35
35
|
_defineProperty(this, "helpers", void 0);
|
|
36
36
|
|
|
37
|
+
_defineProperty(this, "setRef", element => {
|
|
38
|
+
const {
|
|
39
|
+
setElement
|
|
40
|
+
} = this.eventManager;
|
|
41
|
+
setElement.bind(this.eventManager)(element);
|
|
42
|
+
this.eventManager.setElement(element);
|
|
43
|
+
this.props.getRef && this.props.getRef(element);
|
|
44
|
+
});
|
|
45
|
+
|
|
37
46
|
this.state = null;
|
|
38
47
|
let {
|
|
39
48
|
controller,
|
|
@@ -48,11 +57,10 @@ const createCustomComponent = input => {
|
|
|
48
57
|
this.setState(() => state);
|
|
49
58
|
}
|
|
50
59
|
}
|
|
51
|
-
});
|
|
60
|
+
}, input);
|
|
52
61
|
this.presenter = presenter;
|
|
53
62
|
this.controller = controller;
|
|
54
63
|
this.eventManager = eventManager;
|
|
55
|
-
eventManager.name = input.name;
|
|
56
64
|
const {
|
|
57
65
|
updateState,
|
|
58
66
|
updateProperties,
|
|
@@ -109,21 +117,25 @@ const createCustomComponent = input => {
|
|
|
109
117
|
throw this.state.error;
|
|
110
118
|
}
|
|
111
119
|
|
|
112
|
-
const {
|
|
113
|
-
setElement
|
|
114
|
-
} = this.eventManager;
|
|
115
120
|
console.log(this.state.error);
|
|
121
|
+
const {
|
|
122
|
+
FallbackView
|
|
123
|
+
} = input;
|
|
124
|
+
|
|
125
|
+
if (FallbackView) {
|
|
126
|
+
return /*#__PURE__*/React.createElement(FallbackView, {
|
|
127
|
+
ref: this.setRef,
|
|
128
|
+
error: this.state.error
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
116
132
|
return /*#__PURE__*/React.createElement("div", {
|
|
117
|
-
ref:
|
|
133
|
+
ref: element => this.setRef(element)
|
|
118
134
|
}, "error");
|
|
119
135
|
} else {
|
|
120
|
-
const {
|
|
121
|
-
setElement
|
|
122
|
-
} = this.eventManager;
|
|
123
136
|
return /*#__PURE__*/React.createElement(View, {
|
|
124
137
|
ref: element => {
|
|
125
|
-
|
|
126
|
-
this.props.getRef && this.props.getRef(element);
|
|
138
|
+
this.setRef(element);
|
|
127
139
|
},
|
|
128
140
|
helpers: this.helpers,
|
|
129
141
|
state: this.state,
|
|
@@ -6,7 +6,7 @@ import Validator from "../json-schema-validator/Validator";
|
|
|
6
6
|
import EventManager from "../../adapters/gateways/event-manager/EventManager";
|
|
7
7
|
|
|
8
8
|
class DependencyFactory {
|
|
9
|
-
static create(_ref) {
|
|
9
|
+
static create(_ref, input) {
|
|
10
10
|
let {
|
|
11
11
|
updateState
|
|
12
12
|
} = _ref;
|
|
@@ -14,12 +14,13 @@ class DependencyFactory {
|
|
|
14
14
|
const presenter = new Presenter({
|
|
15
15
|
updateState
|
|
16
16
|
});
|
|
17
|
-
const eventManager = new EventManager();
|
|
17
|
+
const eventManager = new EventManager(input.name, Validator.validate, input.events);
|
|
18
18
|
const service = new Service({
|
|
19
19
|
repository,
|
|
20
20
|
presenter,
|
|
21
21
|
eventManager,
|
|
22
|
-
jsonValidator: Validator.validate
|
|
22
|
+
jsonValidator: Validator.validate,
|
|
23
|
+
schemaValidator: Validator.validatePropsAgainstSchema
|
|
23
24
|
});
|
|
24
25
|
const controller = new Controller(service);
|
|
25
26
|
return {
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import { useState,
|
|
1
|
+
import { useState, useMemo, useRef } from 'react';
|
|
2
2
|
export function useRowData(rows) {
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const rowRef = useRef(null);
|
|
4
|
+
useMemo(() => {
|
|
5
|
+
rowRef.current = rows;
|
|
6
6
|
}, [rows]);
|
|
7
|
-
|
|
7
|
+
const [, forceUpdate] = useState(rows);
|
|
8
|
+
|
|
9
|
+
function setRowData(rows) {
|
|
10
|
+
rowRef.current = rows;
|
|
11
|
+
forceUpdate(rows);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return [rowRef.current, setRowData];
|
|
8
15
|
}
|
|
@@ -2,7 +2,7 @@ import { useCallback } from 'react';
|
|
|
2
2
|
import TableListEventConstants from "../../../../../../cc/table-list/Constants";
|
|
3
3
|
import { useRowData } from "./useRowData";
|
|
4
4
|
import { useDropIndicator } from "./useDropIndicator";
|
|
5
|
-
import { reorderArray,
|
|
5
|
+
import { reorderArray, setTableInteractionClass, adjustHelperElementPosition, getDropIndicator } from "../utils/reOrder"; // @ts-ignore
|
|
6
6
|
|
|
7
7
|
import style from "./../ui/css/TableList.module.css";
|
|
8
8
|
export function useTableRowReorder(_ref) {
|
|
@@ -22,8 +22,9 @@ export function useTableRowReorder(_ref) {
|
|
|
22
22
|
let {
|
|
23
23
|
index
|
|
24
24
|
} = _ref2;
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
setTableInteractionClass(TableRef, style.preventTextSelection, true);
|
|
26
|
+
setTableInteractionClass(TableRef, style.preventPointerEvents, true);
|
|
27
|
+
adjustHelperElementPosition(TableRef, getHelperClass());
|
|
27
28
|
dispatch({
|
|
28
29
|
type: TABLE_LIST_ROW_DRAG_START,
|
|
29
30
|
payload: {
|
|
@@ -37,7 +38,8 @@ export function useTableRowReorder(_ref) {
|
|
|
37
38
|
oldIndex,
|
|
38
39
|
newIndex
|
|
39
40
|
} = _ref3;
|
|
40
|
-
|
|
41
|
+
setTableInteractionClass(TableRef, style.preventTextSelection, false);
|
|
42
|
+
setTableInteractionClass(TableRef, style.preventPointerEvents, false);
|
|
41
43
|
let arr = reorderArray(rowData, oldIndex, newIndex);
|
|
42
44
|
setRowData(arr);
|
|
43
45
|
setDropIndicator({
|
|
@@ -80,6 +82,14 @@ export function useTableRowReorder(_ref) {
|
|
|
80
82
|
width: TableRef.current.offsetWidth
|
|
81
83
|
};
|
|
82
84
|
}, [TableRef]);
|
|
85
|
+
const getHelperContainer = useCallback(() => {
|
|
86
|
+
return TableRef.current;
|
|
87
|
+
}, [TableRef]);
|
|
88
|
+
|
|
89
|
+
const getHelperClass = () => {
|
|
90
|
+
return style.dragging;
|
|
91
|
+
};
|
|
92
|
+
|
|
83
93
|
return {
|
|
84
94
|
rowData,
|
|
85
95
|
dropIndicator,
|
|
@@ -88,6 +98,8 @@ export function useTableRowReorder(_ref) {
|
|
|
88
98
|
handleSortOver,
|
|
89
99
|
getHelperDimensions,
|
|
90
100
|
setRowData,
|
|
91
|
-
setDropIndicator
|
|
101
|
+
setDropIndicator,
|
|
102
|
+
getHelperContainer,
|
|
103
|
+
getHelperClass
|
|
92
104
|
};
|
|
93
105
|
}
|
|
@@ -9,7 +9,8 @@ import Loading from "./sub-components/Loading";
|
|
|
9
9
|
import ColumnResizingLine from "./sub-components/ColumnResizingLine";
|
|
10
10
|
import handleScroll from "./handlers/HandleScroll";
|
|
11
11
|
import { useTableRowReorder } from "../hooks/useTableRowReorder";
|
|
12
|
-
import { SortableContainer } from 'react-sortable-hoc';
|
|
12
|
+
import { SortableContainer } from 'react-sortable-hoc';
|
|
13
|
+
import getTableListClassName from "../utils/getTableListClassName"; // @ts-ignore
|
|
13
14
|
|
|
14
15
|
import style from "./css/TableList.module.css";
|
|
15
16
|
|
|
@@ -25,6 +26,7 @@ function TableListView(_ref2, _ref) {
|
|
|
25
26
|
const {
|
|
26
27
|
data,
|
|
27
28
|
isLoading,
|
|
29
|
+
isReOrderLoading,
|
|
28
30
|
resizerState,
|
|
29
31
|
reOrderConfig,
|
|
30
32
|
selectionConfig,
|
|
@@ -49,24 +51,26 @@ function TableListView(_ref2, _ref) {
|
|
|
49
51
|
const isDataEmpty = !hasRows && !isLoading && !isError; // TODO: derive from state.properties
|
|
50
52
|
|
|
51
53
|
const isKeyboardControlsEnabled = keyboardControlsConfig.isEnabled;
|
|
52
|
-
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
const isReorderEnabled = reOrderConfig.isEnabled;
|
|
55
|
+
const isSelectionEnabled = selectionConfig.isEnabled;
|
|
56
|
+
const className = getTableListClassName({
|
|
57
|
+
isKeyboardControlsEnabled,
|
|
58
|
+
isReorderEnabled,
|
|
59
|
+
isSelectionEnabled
|
|
60
|
+
});
|
|
57
61
|
return /*#__PURE__*/React.createElement("div", {
|
|
58
|
-
className: style.wrapper
|
|
62
|
+
className: `${style.wrapper} ${style[className]}`,
|
|
59
63
|
ref: _ref
|
|
60
64
|
}, /*#__PURE__*/React.createElement(Table, {
|
|
61
|
-
ref:
|
|
65
|
+
ref: TableRef,
|
|
62
66
|
$event_onScroll: e => handleScroll(dispatch, {
|
|
63
67
|
scrollEvent: e
|
|
64
68
|
})
|
|
65
69
|
}, renderHeader({
|
|
66
70
|
headers,
|
|
67
71
|
resizerState,
|
|
68
|
-
|
|
69
|
-
|
|
72
|
+
isReorderEnabled,
|
|
73
|
+
isSelectionEnabled,
|
|
70
74
|
selection,
|
|
71
75
|
isKeyboardControlsEnabled,
|
|
72
76
|
isFlexibleColumns,
|
|
@@ -79,13 +83,14 @@ function TableListView(_ref2, _ref) {
|
|
|
79
83
|
headers,
|
|
80
84
|
rows,
|
|
81
85
|
isFlexibleColumns,
|
|
82
|
-
|
|
83
|
-
|
|
86
|
+
isReorderEnabled,
|
|
87
|
+
isSelectionEnabled,
|
|
84
88
|
isKeyboardControlsEnabled,
|
|
85
89
|
rowCursor,
|
|
86
90
|
hasRowActions,
|
|
87
91
|
rowActionsColumnWidth,
|
|
88
|
-
hasRows
|
|
92
|
+
hasRows,
|
|
93
|
+
isReOrderLoading
|
|
89
94
|
}), /*#__PURE__*/React.createElement(NoData, {
|
|
90
95
|
isDataEmpty: isDataEmpty,
|
|
91
96
|
emptyStateUiType: emptyStateUiType
|
|
@@ -101,8 +106,8 @@ function renderHeader(_ref3) {
|
|
|
101
106
|
let {
|
|
102
107
|
headers,
|
|
103
108
|
resizerState,
|
|
104
|
-
|
|
105
|
-
|
|
109
|
+
isReorderEnabled,
|
|
110
|
+
isSelectionEnabled,
|
|
106
111
|
selection,
|
|
107
112
|
isKeyboardControlsEnabled,
|
|
108
113
|
isFlexibleColumns,
|
|
@@ -111,8 +116,8 @@ function renderHeader(_ref3) {
|
|
|
111
116
|
dispatch
|
|
112
117
|
} = _ref3;
|
|
113
118
|
return /*#__PURE__*/React.createElement(Header, {
|
|
114
|
-
isReorderEnabled:
|
|
115
|
-
isSelectionEnabled:
|
|
119
|
+
isReorderEnabled: isReorderEnabled,
|
|
120
|
+
isSelectionEnabled: isSelectionEnabled,
|
|
116
121
|
isResizerEnabled: resizerState.isEnabled,
|
|
117
122
|
isKeyboardControlsEnabled: isKeyboardControlsEnabled,
|
|
118
123
|
currentlyResizingColumn: resizerState.currentlyResizingColumn,
|
|
@@ -146,13 +151,14 @@ function renderBody(_ref4) {
|
|
|
146
151
|
headers,
|
|
147
152
|
rows,
|
|
148
153
|
isFlexibleColumns,
|
|
149
|
-
|
|
150
|
-
|
|
154
|
+
isReorderEnabled,
|
|
155
|
+
isSelectionEnabled,
|
|
151
156
|
isKeyboardControlsEnabled,
|
|
152
157
|
rowCursor,
|
|
153
158
|
hasRowActions,
|
|
154
159
|
rowActionsColumnWidth,
|
|
155
|
-
hasRows
|
|
160
|
+
hasRows,
|
|
161
|
+
isReOrderLoading
|
|
156
162
|
} = _ref4;
|
|
157
163
|
const {
|
|
158
164
|
rowData,
|
|
@@ -160,7 +166,9 @@ function renderBody(_ref4) {
|
|
|
160
166
|
handleSortStart,
|
|
161
167
|
handleSortEnd,
|
|
162
168
|
handleSortOver,
|
|
163
|
-
getHelperDimensions
|
|
169
|
+
getHelperDimensions,
|
|
170
|
+
getHelperContainer,
|
|
171
|
+
getHelperClass
|
|
164
172
|
} = useTableRowReorder({
|
|
165
173
|
rows,
|
|
166
174
|
TableRef,
|
|
@@ -174,9 +182,9 @@ function renderBody(_ref4) {
|
|
|
174
182
|
return /*#__PURE__*/React.createElement(SortableTableContainer, {
|
|
175
183
|
hasRows: hasRows,
|
|
176
184
|
isFlexibleColumns: isFlexibleColumns,
|
|
177
|
-
helperClass:
|
|
185
|
+
helperClass: getHelperClass(),
|
|
178
186
|
useDragHandle: true,
|
|
179
|
-
helperContainer:
|
|
187
|
+
helperContainer: getHelperContainer,
|
|
180
188
|
onSortStart: handleSortStart,
|
|
181
189
|
onSortEnd: handleSortEnd,
|
|
182
190
|
onSortOver: handleSortOver,
|
|
@@ -189,13 +197,14 @@ function renderBody(_ref4) {
|
|
|
189
197
|
headers: headers,
|
|
190
198
|
rows: rowData,
|
|
191
199
|
isFlexibleColumns: isFlexibleColumns,
|
|
192
|
-
isReorderEnabled:
|
|
193
|
-
isSelectionEnabled:
|
|
200
|
+
isReorderEnabled: isReorderEnabled,
|
|
201
|
+
isSelectionEnabled: isSelectionEnabled,
|
|
194
202
|
rowCursor: rowCursor,
|
|
195
203
|
hasRowActions: hasRowActions,
|
|
196
204
|
rowActionsColumnWidth: rowActionsColumnWidth,
|
|
197
205
|
isKeyboardControlsEnabled: isKeyboardControlsEnabled,
|
|
198
|
-
dropIndicator: dropIndicator
|
|
206
|
+
dropIndicator: dropIndicator,
|
|
207
|
+
isReOrderLoading: isReOrderLoading
|
|
199
208
|
}));
|
|
200
209
|
}
|
|
201
210
|
|