@zohodesk/library-platform 1.2.0 → 1.2.2-exp.2

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.
Files changed (22) hide show
  1. package/es/index.js +6 -2
  2. package/es/library/custom-component/frameworks/json-schema-validator/Validator.js +1 -164
  3. package/es/library/custom-component/frameworks/ui/DependencyFactory.js +1 -1
  4. package/es/library/json-schema-validator/Validator.js +338 -0
  5. package/es/library/json-schema-validator/__tests__/Validator.test.js +753 -0
  6. package/es/library/json-schema-validator/index.js +1 -0
  7. package/es/platform/client-actions/behaviour/zclient-actions/adapters/presenters/FilterUtils.js +11 -0
  8. package/es/platform/client-actions/behaviour/zclient-actions/adapters/resources/ClientActionsFetchSDK.js +76 -0
  9. package/es/platform/client-actions/behaviour/zclient-actions/applications/interfaces/ClientActionsAPIGatewayParams.js +1 -0
  10. package/es/platform/client-actions/behaviour/zclient-actions/applications/interfaces/ClientActionsFetchSDKParams.js +10 -0
  11. package/es/platform/client-actions/behaviour/zclient-actions/applications/interfaces/IClientActionsFetchSDK.js +0 -0
  12. package/es/platform/client-scripts/behaviour/zclient-scripts-fetch/adapters/resources/ClientScriptsFetchSDK.js +43 -0
  13. package/es/platform/client-scripts/behaviour/zclient-scripts-fetch/applications/interfaces/ClientScriptsAPIGatewayParams.js +1 -0
  14. package/es/platform/client-scripts/behaviour/zclient-scripts-fetch/applications/interfaces/ClientScriptsSDKFetchParams.js +1 -0
  15. package/es/platform/client-scripts/behaviour/zclient-scripts-fetch/applications/interfaces/IClientScriptsFetchSDK.js +0 -0
  16. package/es/platform/components/smart-action-band/adapters/presenters/ActionBandTranslator.js +7 -4
  17. package/es/platform/data-source/http-template/getPageClientActions.js +23 -0
  18. package/es/platform/sdk/application/interfaces/gateways/AbstractResource.js +1 -1
  19. package/es/platform/zform/adapters/presenter/FormTranslator.js +18 -15
  20. package/es/platform/zform/adapters/presenter/translators/SectionTranslator.js +1 -1
  21. package/es/platform/zlist/adapters/presenters/TableTranslator.js +5 -4
  22. package/package.json +3 -4
@@ -0,0 +1 @@
1
+ export { Validator } from "./Validator";
@@ -0,0 +1,11 @@
1
+ function validateClientActionLocation(actualLocation, expectedLocation) {
2
+ return actualLocation === expectedLocation || actualLocation.endsWith(`.${expectedLocation}`);
3
+ }
4
+
5
+ function validateClientAction(clientAction, location) {
6
+ return clientAction.location && validateClientActionLocation(clientAction.location, location);
7
+ }
8
+
9
+ export function filterClientActionsByLocation(clientActions, location) {
10
+ return clientActions.filter(clientAction => clientAction && validateClientAction(clientAction, location));
11
+ }
@@ -0,0 +1,76 @@
1
+ import FetchGateWay from "../../../../../zhttp/adapters/gateway/FetchGateWay";
2
+ import APITemplate from "../../../../../zdata-source/domain/entities/APITemplate";
3
+ import getClientActions from "../../../../../data-source/http-template/getPageClientActions";
4
+ import TemplateHelpers from "../../../../../zdata-source/adapters/gateways/TemplateHelpers";
5
+
6
+ //TODO: Remove this SDK when smart page is ready for production
7
+ // Use this SDK only for fetching client actions at page level in desk_client_app until smart page is ready
8
+ class ClientActionsFetchSDK {
9
+ getClientActionsAPIDetails(args) {
10
+ const apiTemplate = new APITemplate(getClientActions, new TemplateHelpers());
11
+ const apiArgs = { ...args,
12
+ servicePrefix: 'supportapi/zd',
13
+ // @ts-ignore - custom property
14
+ orgName: window.currentOrg.portalName
15
+ };
16
+ const apiDetailsModel = apiTemplate.getApiDetails(apiArgs);
17
+ return { ...apiDetailsModel,
18
+ options: {
19
+ headers: {
20
+ // @ts-ignore - custom property
21
+ orgId: window.currentOrg.id
22
+ },
23
+ method: apiDetailsModel.method
24
+ }
25
+ };
26
+ }
27
+
28
+ mapClientActionsByInstanceLocation(clientActions) {
29
+ const filteredClientActionsMap = new Map();
30
+
31
+ for (const clientAction of clientActions) {
32
+ const {
33
+ location,
34
+ component
35
+ } = clientAction;
36
+ const locationPathArr = location.split('.');
37
+ const instanceName = locationPathArr[1] || component;
38
+ const locationName = locationPathArr[2] || location;
39
+
40
+ if (!instanceName || !locationName) {
41
+ continue;
42
+ }
43
+
44
+ if (!filteredClientActionsMap.has(instanceName)) {
45
+ filteredClientActionsMap.set(instanceName, {});
46
+ }
47
+
48
+ const instanceActions = filteredClientActionsMap.get(instanceName);
49
+
50
+ if (!instanceActions[locationName]) {
51
+ instanceActions[locationName] = [];
52
+ }
53
+
54
+ instanceActions[locationName].push(clientAction);
55
+ }
56
+
57
+ return filteredClientActionsMap;
58
+ }
59
+
60
+ async fetchClientActions(params) {
61
+ const apiDetails = this.getClientActionsAPIDetails(params);
62
+ const fetchGateway = new FetchGateWay(window.fetch.bind(window));
63
+ return new Promise((resolve, reject) => {
64
+ fetchGateway.fetch(apiDetails.url, apiDetails.options).then(response => response.json()).then(clientActions => {
65
+ this.clientActions = clientActions;
66
+ const filteredClientActionsMap = this.mapClientActionsByInstanceLocation(this.clientActions);
67
+ return resolve(filteredClientActionsMap);
68
+ }).catch(err => {
69
+ reject(err);
70
+ });
71
+ });
72
+ }
73
+
74
+ }
75
+
76
+ export default ClientActionsFetchSDK;
@@ -0,0 +1,10 @@
1
+ var ClientActionPage = /*#__PURE__*/function (ClientActionPage) {
2
+ ClientActionPage["LIST"] = "list";
3
+ ClientActionPage["DETAILS"] = "details";
4
+ ClientActionPage["CREATE_PAGE"] = "createPage";
5
+ ClientActionPage["EDIT_PAGE"] = "editPage";
6
+ ClientActionPage["ALL_PAGES"] = "allPages";
7
+ return ClientActionPage;
8
+ }(ClientActionPage || {});
9
+
10
+ export {};
@@ -0,0 +1,43 @@
1
+ import APITemplate from "../../../../../zdata-source/domain/entities/APITemplate";
2
+ import TemplateHelpers from "../../../../../zdata-source/adapters/gateways/TemplateHelpers";
3
+ import FetchGateWay from "../../../../../zhttp/adapters/gateway/FetchGateWay";
4
+ import getClientScripts from "../../../../../data-source/http-template/getClientScripts";
5
+
6
+ //TODO: Remove this SDK when smart page is ready for production
7
+ // Use this SDK only for fetching client actions at page level in desk_client_app until smart page is ready
8
+ class ClientScriptsFetchSDK {
9
+ getClientScriptsAPIDetails(args) {
10
+ const apiTemplate = new APITemplate(getClientScripts, new TemplateHelpers());
11
+ const apiArgs = { ...args,
12
+ servicePrefix: 'supportapi/zd',
13
+ // @ts-ignore - custom property
14
+ orgName: window.currentOrg.portalName
15
+ };
16
+ const apiDetailsModel = apiTemplate.getApiDetails(apiArgs);
17
+ return { ...apiDetailsModel,
18
+ options: {
19
+ headers: {
20
+ // @ts-ignore - custom property
21
+ orgId: window.currentOrg.id
22
+ },
23
+ method: apiDetailsModel.method
24
+ }
25
+ };
26
+ }
27
+
28
+ async fetchClientScripts(params) {
29
+ const apiDetails = this.getClientScriptsAPIDetails(params);
30
+ const fetchGateway = new FetchGateWay(window.fetch.bind(window));
31
+ return new Promise((resolve, reject) => {
32
+ fetchGateway.fetch(apiDetails.url, apiDetails.options).then(response => response.json()).then(clientScripts => {
33
+ this.clientScripts = clientScripts;
34
+ return resolve(clientScripts);
35
+ }).catch(err => {
36
+ reject(err);
37
+ });
38
+ });
39
+ }
40
+
41
+ }
42
+
43
+ export default ClientScriptsFetchSDK;
@@ -2,6 +2,7 @@ import ClientActionsTranslator from "../../../../client-actions/translators/clie
2
2
  import DefaultClientActions from "./utils/DefaultClientActions";
3
3
  import { ActionBandLocations } from "../../../../../bc/action-band/Constants";
4
4
  import { i18NProviderUtils } from '@zohodesk/i18n';
5
+ import { filterClientActionsByLocation } from "../../../../client-actions/behaviour/zclient-actions/adapters/presenters/FilterUtils";
5
6
  export default class ActionBandTranslator {
6
7
  static transformState(state) {
7
8
  const {
@@ -83,10 +84,12 @@ export default class ActionBandTranslator {
83
84
 
84
85
  }
85
86
 
86
- const mapper = clientAction => ({
87
- actionBandLeftActions: clientAction.filter(action => action.location === ActionBandLocations.LEFT_ACTIONS),
88
- actionBandRightActions: clientAction.filter(action => action.location === ActionBandLocations.RIGHT_ACTIONS)
89
- });
87
+ function mapper(clientActions) {
88
+ return {
89
+ actionBandLeftActions: filterClientActionsByLocation(clientActions, ActionBandLocations.LEFT_ACTIONS),
90
+ actionBandRightActions: filterClientActionsByLocation(clientActions, ActionBandLocations.RIGHT_ACTIONS)
91
+ };
92
+ }
90
93
 
91
94
  function getColumnChooserProps(columnChooser) {
92
95
  let availableFields = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
@@ -0,0 +1,23 @@
1
+ let getClientActions = {
2
+ name: 'uiActions',
3
+ api: '/{{servicePrefix}}/{{orgName}}/api/v1/clientActions',
4
+ parameters: `{
5
+ "from":{{from}},
6
+ "limit":{{limit}},
7
+ "modules": "{{modules}}",
8
+ "page": "{{page}}"
9
+ }`,
10
+ type: 'GET',
11
+ transformer: data => data,
12
+ properties: {
13
+ modelName: {
14
+ required: true,
15
+ typeMetadata: {
16
+ schema: {
17
+ type: 'string'
18
+ }
19
+ }
20
+ }
21
+ }
22
+ };
23
+ export default getClientActions;
@@ -1,5 +1,5 @@
1
1
  import ErrorPrinter from "../../../../components/table-connected/adapters/resources/ErrorPrinter";
2
- import Validator from "../../../../../library/custom-component/frameworks/json-schema-validator/Validator";
2
+ import { Validator } from "../../../../../library/json-schema-validator";
3
3
  export class AbstractResource {
4
4
  updateDependencies(dependencies) {
5
5
  this.dependencies = dependencies;
@@ -1,6 +1,7 @@
1
1
  import ClientActionsTranslator from "../../../client-actions/translators/client-actions-translator";
2
2
  import SectionTranslator from "./translators/SectionTranslator";
3
3
  import DefaultFormClientActions from "./utils/DefaultClientActions";
4
+ import { filterClientActionsByLocation } from "../../../client-actions/behaviour/zclient-actions/adapters/presenters/FilterUtils";
4
5
  export default class FormTranslator {
5
6
  static transformState(state) {
6
7
  const {
@@ -56,7 +57,7 @@ export default class FormTranslator {
56
57
  Object.entries(mappedClientActions).forEach(_ref => {
57
58
  let [key, value] = _ref;
58
59
 
59
- if (isFooterEnabled && (key === 'footerRightActions' || key === 'footerLeftActions')) {
60
+ if (isFooterEnabled && (key === 'footerLeftActions' || key === 'footerRightActions')) {
60
61
  let footerActions = ClientActionsTranslator.transform(value, instanceName, moduleName, actionContext);
61
62
  transformedClientActions[key] = footerActions;
62
63
  }
@@ -152,17 +153,19 @@ export default class FormTranslator {
152
153
 
153
154
  }
154
155
 
155
- const mapper = clientAction => ({
156
- headerLeftActions: clientAction.filter(action => action.location === 'header_left_actions'),
157
- headerRightActions: clientAction.filter(action => action.location === 'header_right_actions'),
158
- footerLeftActions: clientAction.filter(action => action.location === 'footer_left_actions'),
159
- footerRightActions: clientAction.filter(action => action.location === 'footer_right_actions'),
160
- fieldLabelActions: clientAction.filter(action => action.location === 'field_label_actions'),
161
- fieldActions: clientAction.filter(action => action.location === 'field_actions'),
162
- sectionHeaderLeftActions: clientAction.filter(action => action.location === 'section_header_left_actions'),
163
- sectionHeaderRightActions: clientAction.filter(action => action.location === 'section_header_right_actions'),
164
- sectionTitleLeftActions: clientAction.filter(action => action.location === 'section_title_left_actions'),
165
- sectionTitleRightActions: clientAction.filter(action => action.location === 'section_title_right_actions'),
166
- fieldOptionLeftActions: clientAction.filter(action => action.location === 'field_options_left_actions'),
167
- fieldOptionRightActions: clientAction.filter(action => action.location === 'field_options_right_actions')
168
- });
156
+ const mapper = clientActions => {
157
+ return {
158
+ headerLeftActions: filterClientActionsByLocation(clientActions, 'header_left_actions'),
159
+ headerRightActions: filterClientActionsByLocation(clientActions, 'header_right_actions'),
160
+ footerLeftActions: filterClientActionsByLocation(clientActions, 'footer_left_actions'),
161
+ footerRightActions: filterClientActionsByLocation(clientActions, 'footer_right_actions'),
162
+ fieldLabelActions: filterClientActionsByLocation(clientActions, 'field_label_actions'),
163
+ fieldActions: filterClientActionsByLocation(clientActions, 'field_actions'),
164
+ sectionHeaderLeftActions: filterClientActionsByLocation(clientActions, 'section_header_left_actions'),
165
+ sectionHeaderRightActions: filterClientActionsByLocation(clientActions, 'section_header_right_actions'),
166
+ sectionTitleLeftActions: filterClientActionsByLocation(clientActions, 'section_title_left_actions'),
167
+ sectionTitleRightActions: filterClientActionsByLocation(clientActions, 'section_title_right_actions'),
168
+ fieldOptionLeftActions: filterClientActionsByLocation(clientActions, 'field_options_left_actions'),
169
+ fieldOptionRightActions: filterClientActionsByLocation(clientActions, 'field_options_right_actions')
170
+ };
171
+ };
@@ -109,7 +109,7 @@ function SectionTranslator(_ref) {
109
109
  fieldPreModified['actions'] = transformedDefaultActions.fieldActions.concat(transformedActions.fieldActions);
110
110
  const noPlaceHolderSupport = ['Boolean', 'Date', 'DateTime']; // Placeholder check
111
111
 
112
- if (field.toolTip && field.toolTipType === "placeholder" && !noPlaceHolderSupport.includes(field.type)) {
112
+ if (field.toolTip && field.toolTipType === "placeHolder" && !noPlaceHolderSupport.includes(field.type)) {
113
113
  fieldPreModified["placeholder"] = field.toolTip;
114
114
  } // const optionActionAvailArray = ['Picklist', 'Multiselect'];
115
115
  // // Option Actions check
@@ -13,6 +13,7 @@ import DefaultClientActions from "./utils/DefaultClientActions";
13
13
  import SelectionTranslator from "./SelectionTranslator";
14
14
  import { SortModelOrder } from "../../domain/entities/interfaces/Properties";
15
15
  import { SortOrder } from "../../../../bc/zlist/Types";
16
+ import { filterClientActionsByLocation } from "../../../client-actions/behaviour/zclient-actions/adapters/presenters/FilterUtils";
16
17
  const EMPTY_OBJECT = {};
17
18
  const EMPTY_ARRAY = [];
18
19
 
@@ -220,9 +221,9 @@ function mapClientActions(clientActions) {
220
221
  }
221
222
  });
222
223
  return {
223
- headerActions: clientActions.filter(action => action.location && action.location === 'header_actions'),
224
- fieldActions: clientActions.filter(action => action.location && action.location === 'field_actions'),
225
- rowActions: clientActions.filter(action => action.location && action.location === 'row_actions'),
226
- noLocation: clientActions.filter(action => !action.location)
224
+ headerActions: filterClientActionsByLocation(clientActions, 'header_actions'),
225
+ fieldActions: filterClientActionsByLocation(clientActions, 'field_actions'),
226
+ rowActions: filterClientActionsByLocation(clientActions, 'row_actions'),
227
+ noLocation: filterClientActionsByLocation(clientActions, null)
227
228
  };
228
229
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zohodesk/library-platform",
3
- "version": "1.2.0",
3
+ "version": "1.2.2-exp.2",
4
4
  "description": "",
5
5
  "main": "es/index.js",
6
6
  "files": [
@@ -46,7 +46,7 @@
46
46
  "@zohodesk-private/dot-registry": "0.0.2",
47
47
  "@zohodesk-private/node-plugins": "1.1.9",
48
48
  "@zohodesk/a11y": "2.3.8",
49
- "@zohodesk/codestandard-validator": "1.1.4",
49
+ "@zohodesk/codestandard-validator": "1.3.1",
50
50
  "@zohodesk/components": "1.5.8",
51
51
  "@zohodesk/dot": "1.8.6",
52
52
  "@zohodesk/dotkit": "1.0.7",
@@ -91,8 +91,7 @@
91
91
  "react-sortable-hoc": "1.11.0"
92
92
  },
93
93
  "dependencies": {
94
- "ajv": "6.12.6",
95
94
  "jsep": "0.3.5",
96
95
  "object-path-immutable": "4.1.2"
97
96
  }
98
- }
97
+ }