@zohodesk/library-platform 1.1.3-exp.3 → 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 +8 -1
- package/es/bc/zlist/Events.js +140 -0
- package/es/bc/zlist/index.js +2 -1
- package/es/bc/zrecord/Constants.js +3 -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/Properties.js +16 -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/Constants.js +4 -0
- package/es/cc/table-list/Properties.js +25 -0
- package/es/cc/table-list/row/Properties.js +44 -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/useDropIndicator.js +8 -0
- package/es/library/dot/components/table-list/frameworks/hooks/useRowData.js +15 -0
- package/es/library/dot/components/table-list/frameworks/hooks/useTableRowReorder.js +105 -0
- package/es/library/dot/components/table-list/frameworks/ui/TableListView.js +85 -15
- package/es/library/dot/components/table-list/frameworks/ui/css/TableList.module.css +240 -1
- package/es/library/dot/components/table-list/frameworks/ui/sub-components/Header.js +28 -4
- package/es/library/dot/components/table-list/frameworks/ui/sub-components/Rows.js +25 -9
- package/es/library/dot/components/table-list/frameworks/ui/sub-components/header/MassAction.js +11 -2
- package/es/library/dot/components/table-list/frameworks/ui/sub-components/row/Row.js +50 -8
- package/es/library/dot/components/table-list/frameworks/ui/sub-components/row/RowSelection.js +6 -1
- 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 +90 -0
- 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/controllers/ReOrderFinishController.js +21 -0
- package/es/platform/components/table-connected/adapters/resources/ErrorPrinter.js +20 -0
- package/es/platform/components/table-connected/adapters/resources/SmartTableResource.js +85 -0
- package/es/platform/components/table-connected/frameworks/ErrorEventHandlersFactory.js +126 -0
- package/es/platform/components/table-connected/frameworks/EventHandlersFactory.js +39 -3
- package/es/platform/components/table-connected/frameworks/ListSdkFactory.js +4 -2
- package/es/platform/components/table-connected/frameworks/TableConnectedFactory.js +2 -0
- package/es/platform/components/table-connected/frameworks/TableConnectedView.js +8 -2
- package/es/platform/data-source/http-template/reOrderRecord.js +44 -0
- package/es/platform/data-source/index.js +2 -0
- package/es/platform/sdk/application/interfaces/gateways/AbstractResource.js +1 -2
- package/es/platform/sdk/domain/entities/ResourceManager.js +1 -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/controllers/ReOrderController.js +25 -0
- package/es/platform/zlist/adapters/controllers/ReOrderFailedController.js +26 -0
- package/es/platform/zlist/adapters/gateways/Repository.js +12 -2
- package/es/platform/zlist/adapters/gateways/Service.js +8 -0
- package/es/platform/zlist/adapters/presenters/TableTranslator.js +15 -4
- package/es/platform/zlist/adapters/presenters/translators/ColumnTranslator.js +11 -12
- 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/adapters/presenters/utils/DefaultClientActions.js +1 -1
- package/es/platform/zlist/applications/entities-factory/ListFactory.js +3 -2
- package/es/platform/zlist/applications/interfaces/input/ReOrderRecordUseCaseInput.js +1 -0
- package/es/platform/zlist/applications/usecases/FetchMoreUseCase.js +1 -1
- package/es/platform/zlist/applications/usecases/ReOrderFailedUseCase.js +22 -0
- package/es/platform/zlist/applications/usecases/ReOrderUseCase.js +25 -0
- package/es/platform/zlist/applications/usecases/RecordExecuteFailedUseCase.js +3 -2
- package/es/platform/zlist/applications/usecases/RecordSuccessCallbackUsecase.js +24 -3
- package/es/platform/zlist/domain/entities/List.js +61 -48
- package/es/platform/zlist/domain/entities/ListErrorState.js +167 -0
- package/es/platform/zlist/frameworks/EventHandlersFactory.js +13 -3
- package/es/platform/zlist/frameworks/ZListBehaviourFactory.js +6 -0
- package/es/platform/zrecord/domain/entities/GetReOrderRecordsStrategy.js +40 -0
- package/es/platform/zrecord/domain/entities/RecordsManager.js +3 -1
- package/package.json +6 -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 {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useState, useMemo, useRef } from 'react';
|
|
2
|
+
export function useRowData(rows) {
|
|
3
|
+
const rowRef = useRef(null);
|
|
4
|
+
useMemo(() => {
|
|
5
|
+
rowRef.current = rows;
|
|
6
|
+
}, [rows]);
|
|
7
|
+
const [, forceUpdate] = useState(rows);
|
|
8
|
+
|
|
9
|
+
function setRowData(rows) {
|
|
10
|
+
rowRef.current = rows;
|
|
11
|
+
forceUpdate(rows);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return [rowRef.current, setRowData];
|
|
15
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import TableListEventConstants from "../../../../../../cc/table-list/Constants";
|
|
3
|
+
import { useRowData } from "./useRowData";
|
|
4
|
+
import { useDropIndicator } from "./useDropIndicator";
|
|
5
|
+
import { reorderArray, setTableInteractionClass, adjustHelperElementPosition, getDropIndicator } from "../utils/reOrder"; // @ts-ignore
|
|
6
|
+
|
|
7
|
+
import style from "./../ui/css/TableList.module.css";
|
|
8
|
+
export function useTableRowReorder(_ref) {
|
|
9
|
+
let {
|
|
10
|
+
rows,
|
|
11
|
+
TableRef,
|
|
12
|
+
dispatch
|
|
13
|
+
} = _ref;
|
|
14
|
+
const [rowData, setRowData] = useRowData(rows);
|
|
15
|
+
const [dropIndicator, setDropIndicator] = useDropIndicator();
|
|
16
|
+
const {
|
|
17
|
+
TABLE_LIST_ROW_DRAG_START,
|
|
18
|
+
TABLE_LIST_ROW_DRAG_END
|
|
19
|
+
} = TableListEventConstants;
|
|
20
|
+
|
|
21
|
+
const handleSortStart = _ref2 => {
|
|
22
|
+
let {
|
|
23
|
+
index
|
|
24
|
+
} = _ref2;
|
|
25
|
+
setTableInteractionClass(TableRef, style.preventTextSelection, true);
|
|
26
|
+
setTableInteractionClass(TableRef, style.preventPointerEvents, true);
|
|
27
|
+
adjustHelperElementPosition(TableRef, getHelperClass());
|
|
28
|
+
dispatch({
|
|
29
|
+
type: TABLE_LIST_ROW_DRAG_START,
|
|
30
|
+
payload: {
|
|
31
|
+
index
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const handleSortEnd = _ref3 => {
|
|
37
|
+
let {
|
|
38
|
+
oldIndex,
|
|
39
|
+
newIndex
|
|
40
|
+
} = _ref3;
|
|
41
|
+
setTableInteractionClass(TableRef, style.preventTextSelection, false);
|
|
42
|
+
setTableInteractionClass(TableRef, style.preventPointerEvents, false);
|
|
43
|
+
let arr = reorderArray(rowData, oldIndex, newIndex);
|
|
44
|
+
setRowData(arr);
|
|
45
|
+
setDropIndicator({
|
|
46
|
+
index: null,
|
|
47
|
+
position: ''
|
|
48
|
+
});
|
|
49
|
+
dispatch({
|
|
50
|
+
type: TABLE_LIST_ROW_DRAG_END,
|
|
51
|
+
payload: {
|
|
52
|
+
oldIndex,
|
|
53
|
+
newIndex
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const handleSortOver = _ref4 => {
|
|
59
|
+
let {
|
|
60
|
+
index,
|
|
61
|
+
oldIndex,
|
|
62
|
+
newIndex
|
|
63
|
+
} = _ref4;
|
|
64
|
+
const dropIndicatorData = getDropIndicator({
|
|
65
|
+
index,
|
|
66
|
+
oldIndex,
|
|
67
|
+
newIndex,
|
|
68
|
+
rowsLength: rows.length
|
|
69
|
+
});
|
|
70
|
+
setDropIndicator({
|
|
71
|
+
index: dropIndicatorData.index,
|
|
72
|
+
position: dropIndicatorData.position
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const getHelperDimensions = useCallback(_ref5 => {
|
|
77
|
+
let {
|
|
78
|
+
node
|
|
79
|
+
} = _ref5;
|
|
80
|
+
return {
|
|
81
|
+
height: node.offsetHeight,
|
|
82
|
+
width: TableRef.current.offsetWidth
|
|
83
|
+
};
|
|
84
|
+
}, [TableRef]);
|
|
85
|
+
const getHelperContainer = useCallback(() => {
|
|
86
|
+
return TableRef.current;
|
|
87
|
+
}, [TableRef]);
|
|
88
|
+
|
|
89
|
+
const getHelperClass = () => {
|
|
90
|
+
return style.dragging;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
return {
|
|
94
|
+
rowData,
|
|
95
|
+
dropIndicator,
|
|
96
|
+
handleSortStart,
|
|
97
|
+
handleSortEnd,
|
|
98
|
+
handleSortOver,
|
|
99
|
+
getHelperDimensions,
|
|
100
|
+
setRowData,
|
|
101
|
+
setDropIndicator,
|
|
102
|
+
getHelperContainer,
|
|
103
|
+
getHelperClass
|
|
104
|
+
};
|
|
105
|
+
}
|