@blaze-cms/plugin-data-ui 0.133.0-admin-updates.0 → 0.133.0-project-admin-customisations.0

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 (123) hide show
  1. package/CHANGELOG.md +27 -1
  2. package/README.md +42 -0
  3. package/lib/components/EntityDataListing/EntityDataListing.js +3 -24
  4. package/lib/components/EntityDataListing/EntityDataListing.js.map +1 -1
  5. package/lib/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js +39 -0
  6. package/lib/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js.map +1 -0
  7. package/lib/components/EntityManager/Entity/EntitiyNavLinks/index.js +12 -0
  8. package/lib/components/EntityManager/Entity/EntitiyNavLinks/index.js.map +1 -0
  9. package/lib/components/EntityManager/Entity/Entity.js +16 -3
  10. package/lib/components/EntityManager/Entity/Entity.js.map +1 -1
  11. package/lib/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js +44 -0
  12. package/lib/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js.map +1 -0
  13. package/lib/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js +32 -0
  14. package/lib/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js.map +1 -0
  15. package/lib/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js +45 -0
  16. package/lib/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js.map +1 -0
  17. package/lib/components/EntityManager/Entity/SideBarRelations/index.js +12 -2
  18. package/lib/components/EntityManager/Entity/SideBarRelations/index.js.map +1 -1
  19. package/lib/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js +38 -0
  20. package/lib/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js.map +1 -0
  21. package/lib/components/InfoBoxes/InfoBoxes.js +36 -0
  22. package/lib/components/InfoBoxes/InfoBoxes.js.map +1 -0
  23. package/lib/components/InfoBoxes/container/InfoBoxContainer.js +44 -0
  24. package/lib/components/InfoBoxes/container/InfoBoxContainer.js.map +1 -0
  25. package/lib/components/InfoBoxes/helpers/build-dynamic-query.js +25 -0
  26. package/lib/components/InfoBoxes/helpers/build-dynamic-query.js.map +1 -0
  27. package/lib/components/InfoBoxes/hooks/useData.js +42 -0
  28. package/lib/components/InfoBoxes/hooks/useData.js.map +1 -0
  29. package/lib/components/InfoBoxes/hooks/useInfoBox.js +26 -0
  30. package/lib/components/InfoBoxes/hooks/useInfoBox.js.map +1 -0
  31. package/lib/components/InfoBoxes/index.js +12 -0
  32. package/lib/components/InfoBoxes/index.js.map +1 -0
  33. package/lib/components/InfoBoxes/presentational/InfoBox.js +46 -0
  34. package/lib/components/InfoBoxes/presentational/InfoBox.js.map +1 -0
  35. package/lib/components/ListingTable/ListingTable.js +113 -80
  36. package/lib/components/ListingTable/ListingTable.js.map +1 -1
  37. package/lib/components/ListingTable/ListingTableContent/ListingTableContent.js +8 -20
  38. package/lib/components/ListingTable/ListingTableContent/ListingTableContent.js.map +1 -1
  39. package/lib/components/ListingTable/mappers/populate-rows.js +92 -26
  40. package/lib/components/ListingTable/mappers/populate-rows.js.map +1 -1
  41. package/lib/components/ListingTable/service/index.js +73 -11
  42. package/lib/components/ListingTable/service/index.js.map +1 -1
  43. package/lib/index.js +3 -11
  44. package/lib/index.js.map +1 -1
  45. package/lib/utils/add-content-menu-items.js +64 -13
  46. package/lib/utils/add-content-menu-items.js.map +1 -1
  47. package/lib/utils/build-listing-query.js +11 -2
  48. package/lib/utils/build-listing-query.js.map +1 -1
  49. package/lib/utils/get-default-query-params.js +3 -4
  50. package/lib/utils/get-default-query-params.js.map +1 -1
  51. package/lib-es/components/EntityDataListing/EntityDataListing.js +3 -14
  52. package/lib-es/components/EntityDataListing/EntityDataListing.js.map +1 -1
  53. package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js +30 -0
  54. package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js.map +1 -0
  55. package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/index.js +3 -0
  56. package/lib-es/components/EntityManager/Entity/EntitiyNavLinks/index.js.map +1 -0
  57. package/lib-es/components/EntityManager/Entity/Entity.js +16 -3
  58. package/lib-es/components/EntityManager/Entity/Entity.js.map +1 -1
  59. package/lib-es/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js +30 -0
  60. package/lib-es/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js.map +1 -0
  61. package/lib-es/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js +26 -0
  62. package/lib-es/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js.map +1 -0
  63. package/lib-es/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js +39 -0
  64. package/lib-es/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js.map +1 -0
  65. package/lib-es/components/EntityManager/Entity/SideBarRelations/index.js +12 -2
  66. package/lib-es/components/EntityManager/Entity/SideBarRelations/index.js.map +1 -1
  67. package/lib-es/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js +24 -0
  68. package/lib-es/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js.map +1 -0
  69. package/lib-es/components/InfoBoxes/InfoBoxes.js +28 -0
  70. package/lib-es/components/InfoBoxes/InfoBoxes.js.map +1 -0
  71. package/lib-es/components/InfoBoxes/container/InfoBoxContainer.js +30 -0
  72. package/lib-es/components/InfoBoxes/container/InfoBoxContainer.js.map +1 -0
  73. package/lib-es/components/InfoBoxes/helpers/build-dynamic-query.js +25 -0
  74. package/lib-es/components/InfoBoxes/helpers/build-dynamic-query.js.map +1 -0
  75. package/lib-es/components/InfoBoxes/hooks/useData.js +37 -0
  76. package/lib-es/components/InfoBoxes/hooks/useData.js.map +1 -0
  77. package/lib-es/components/InfoBoxes/hooks/useInfoBox.js +19 -0
  78. package/lib-es/components/InfoBoxes/hooks/useInfoBox.js.map +1 -0
  79. package/lib-es/components/InfoBoxes/index.js +3 -0
  80. package/lib-es/components/InfoBoxes/index.js.map +1 -0
  81. package/lib-es/components/InfoBoxes/presentational/InfoBox.js +31 -0
  82. package/lib-es/components/InfoBoxes/presentational/InfoBox.js.map +1 -0
  83. package/lib-es/components/ListingTable/ListingTable.js +46 -49
  84. package/lib-es/components/ListingTable/ListingTable.js.map +1 -1
  85. package/lib-es/components/ListingTable/ListingTableContent/ListingTableContent.js +11 -19
  86. package/lib-es/components/ListingTable/ListingTableContent/ListingTableContent.js.map +1 -1
  87. package/lib-es/components/ListingTable/mappers/populate-rows.js +76 -24
  88. package/lib-es/components/ListingTable/mappers/populate-rows.js.map +1 -1
  89. package/lib-es/components/ListingTable/service/index.js +65 -7
  90. package/lib-es/components/ListingTable/service/index.js.map +1 -1
  91. package/lib-es/index.js +1 -9
  92. package/lib-es/index.js.map +1 -1
  93. package/lib-es/utils/add-content-menu-items.js +49 -5
  94. package/lib-es/utils/add-content-menu-items.js.map +1 -1
  95. package/lib-es/utils/build-listing-query.js +10 -1
  96. package/lib-es/utils/build-listing-query.js.map +1 -1
  97. package/lib-es/utils/get-default-query-params.js +1 -3
  98. package/lib-es/utils/get-default-query-params.js.map +1 -1
  99. package/package.json +10 -9
  100. package/src/components/EntityDataListing/EntityDataListing.js +3 -12
  101. package/src/components/EntityManager/Entity/EntitiyNavLinks/EntityNavLinks.js +26 -0
  102. package/src/components/EntityManager/Entity/EntitiyNavLinks/index.js +3 -0
  103. package/src/components/EntityManager/Entity/Entity.js +10 -1
  104. package/src/components/EntityManager/Entity/SideBarRelations/container/CustomSidebarInfoContainer.js +22 -0
  105. package/src/components/EntityManager/Entity/SideBarRelations/helpers/build-dynamic-query.js +33 -0
  106. package/src/components/EntityManager/Entity/SideBarRelations/hooks/useCustomSidebarData.js +28 -0
  107. package/src/components/EntityManager/Entity/SideBarRelations/index.js +34 -16
  108. package/src/components/EntityManager/Entity/SideBarRelations/presentational/CustomSidebarInfo.js +33 -0
  109. package/src/components/InfoBoxes/InfoBoxes.js +24 -0
  110. package/src/components/InfoBoxes/container/InfoBoxContainer.js +22 -0
  111. package/src/components/InfoBoxes/helpers/build-dynamic-query.js +25 -0
  112. package/src/components/InfoBoxes/hooks/useData.js +20 -0
  113. package/src/components/InfoBoxes/hooks/useInfoBox.js +13 -0
  114. package/src/components/InfoBoxes/index.js +3 -0
  115. package/src/components/InfoBoxes/presentational/InfoBox.js +34 -0
  116. package/src/components/ListingTable/ListingTable.js +57 -38
  117. package/src/components/ListingTable/ListingTableContent/ListingTableContent.js +8 -22
  118. package/src/components/ListingTable/mappers/populate-rows.js +83 -18
  119. package/src/components/ListingTable/service/index.js +42 -5
  120. package/src/index.js +1 -8
  121. package/src/utils/add-content-menu-items.js +45 -3
  122. package/src/utils/build-listing-query.js +11 -1
  123. package/src/utils/get-default-query-params.js +1 -1
@@ -3,18 +3,22 @@ import { Link } from 'react-router-dom';
3
3
  import TableActions from '../TableActions';
4
4
  import { ACTIONS } from '../../../constants';
5
5
 
6
- const formatRows = ({ rows, url, toggleModal, label, firstColumn = 'name' }) =>
6
+ const formatRows = ({ rows, url, toggleModal, label, firstColumn = 'name', isEnquiry }) =>
7
7
  rows.map(data => {
8
8
  const editUrl = `${url}/update/${data.id}`;
9
- return {
9
+ const rowProps = {
10
10
  ...data,
11
11
  [firstColumn]: (
12
12
  <Link to={editUrl} role="button">
13
13
  {data[firstColumn]}
14
14
  </Link>
15
- ),
16
- actions: <TableActions editUrl={editUrl} data={data} showDeleteModal={toggleModal} />
15
+ )
17
16
  };
17
+ if (!isEnquiry)
18
+ rowProps.actions = (
19
+ <TableActions editUrl={editUrl} data={data} showDeleteModal={toggleModal} />
20
+ );
21
+ return rowProps;
18
22
  });
19
23
 
20
24
  const getSanitizedColumnLabel = columnProp => {
@@ -28,22 +32,82 @@ const getSanitizedColumnLabel = columnProp => {
28
32
  return sanitizedChar;
29
33
  };
30
34
 
31
- const getColumnLabels = (listingProperties, properties, dynamicProperties) => {
32
- const allProperties = { ...properties, ...dynamicProperties };
33
- return listingProperties.reduce((acc, listingProperty) => {
34
- const label = allProperties[listingProperty].label || getSanitizedColumnLabel(listingProperty);
35
- return { ...acc, ...{ [listingProperty]: label } };
36
- }, {});
35
+ const buildArrayRowContent = rowData => (
36
+ <div className="table-row-list">
37
+ {rowData.map(rowGroup => (
38
+ <div className="table-row-list__group">
39
+ {rowGroup.map(({ label, value, url }) => (
40
+ <div className="table-row-list__group__item">
41
+ <span className="table-row-list__group__item__label"> {label}:</span>
42
+ {url ? (
43
+ <Link to={url} role="button" className="table-row-list__group__item__value">
44
+ {value}
45
+ </Link>
46
+ ) : (
47
+ <span className="table-row-list__group__item__value"> {value}</span>
48
+ )}
49
+ </div>
50
+ ))}
51
+ </div>
52
+ ))}
53
+ </div>
54
+ );
55
+
56
+ const buildArrayRowData = rowData => {
57
+ const dataGroups = [];
58
+ const groups = Math.ceil(rowData.length / 3) || 1;
59
+ for (let index = 0; index < groups; index += 1) {
60
+ const currentStart = index * groups;
61
+ dataGroups[index] = rowData.slice(currentStart, currentStart + 3);
62
+ }
63
+
64
+ return buildArrayRowContent(dataGroups);
65
+ };
66
+
67
+ const getParsedRowData = rows =>
68
+ rows.map(rowData =>
69
+ Object.keys(rowData).reduce((acc, key) => {
70
+ const parsedData = Array.isArray(rowData[key])
71
+ ? buildArrayRowData(rowData[key])
72
+ : rowData[key];
73
+ return { ...acc, [key]: parsedData };
74
+ }, {})
75
+ );
76
+
77
+ const getColumnsAndLabels = (listingProperties, allProperties, rows) => {
78
+ const columns = [];
79
+ const labels = {};
80
+
81
+ listingProperties.forEach(listingProperty => {
82
+ const propKey = listingProperty.includes(' ') ? listingProperty.split(' ')[0] : listingProperty;
83
+ const { label } = allProperties[propKey] || {};
84
+ columns.push(propKey);
85
+ labels[propKey] = label || getSanitizedColumnLabel(propKey);
86
+ });
87
+ const parsedRowData = getParsedRowData(rows);
88
+
89
+ return { columns, labels, parsedRowData };
37
90
  };
38
91
 
39
92
  const populateRows = ({ toggleModal, url, entitySchema, rows }) => {
40
- const { listingProperties, properties, dynamicProperties = {}, formProperties } = entitySchema;
41
- const columns = [...listingProperties, ACTIONS];
93
+ const {
94
+ id: schemaId,
95
+ listingProperties,
96
+ properties,
97
+ dynamicProperties = {},
98
+ formProperties
99
+ } = entitySchema;
100
+
101
+ const isEnquiry = schemaId === 'enquiry';
102
+ const columnOptions = !isEnquiry ? [...listingProperties, ACTIONS] : [...listingProperties];
103
+
104
+ const allProperties = { ...properties, ...dynamicProperties };
105
+ const { columns, labels, parsedRowData } = getColumnsAndLabels(
106
+ columnOptions,
107
+ allProperties,
108
+ rows
109
+ );
42
110
  const [firstColumn] = columns;
43
- const labels = {
44
- ...getColumnLabels(listingProperties, properties, dynamicProperties),
45
- [ACTIONS]: ACTIONS
46
- };
47
111
 
48
112
  return {
49
113
  identification: 'id',
@@ -51,8 +115,9 @@ const populateRows = ({ toggleModal, url, entitySchema, rows }) => {
51
115
  columns,
52
116
  labels,
53
117
  orderBy: [...formProperties],
54
- rows: formatRows({ firstColumn, rows, url, toggleModal })
118
+ rows: formatRows({ firstColumn, rows: parsedRowData, url, toggleModal, isEnquiry }),
119
+ isEnquiry
55
120
  };
56
121
  };
57
122
 
58
- export { populateRows, formatRows };
123
+ export { populateRows, formatRows, getParsedRowData };
@@ -1,12 +1,49 @@
1
1
  import buildListingQuery from '../../../utils/build-listing-query';
2
2
 
3
- const fetchData = async ({ client, querySettings: { entitySchema, queryParams } }) => {
4
- const query = buildListingQuery(entitySchema);
3
+ function buildVariables({ entitySchema, isSearchQuery, listFilters = [], queryParams = {} }) {
4
+ const { identifier } = entitySchema;
5
+ const { sort, offset, limit, where } = queryParams;
6
+ const [{ property, direction }] = sort;
7
+ const parsedOffset = `${property}:${direction}`;
8
+
9
+ if (!isSearchQuery)
10
+ return {
11
+ ...queryParams,
12
+ where: !Array.isArray(listFilters) ? listFilters : where
13
+ };
14
+
15
+ const rawQuery = {
16
+ bool: {
17
+ must: listFilters || [],
18
+ filter: [
19
+ {
20
+ term: {
21
+ entityIdentifier: identifier
22
+ }
23
+ }
24
+ ]
25
+ }
26
+ };
27
+
28
+ return {
29
+ limit,
30
+ offset,
31
+ sort: parsedOffset,
32
+ where: JSON.stringify(rawQuery)
33
+ };
34
+ }
35
+
36
+ const fetchData = async ({ client, querySettings: { entitySchema, queryParams }, listFilters }) => {
5
37
  const {
6
- data: { listingData }
7
- } = await client.query({ query, variables: queryParams, fetchPolicy: 'network-only' });
38
+ displayProperties: { adminListings: { dataSource: { source } = {} } = {} } = {}
39
+ } = entitySchema;
40
+
41
+ const isSearchQuery = source === 'search';
42
+ const query = buildListingQuery(entitySchema, isSearchQuery);
43
+ const variables = buildVariables({ entitySchema, listFilters, queryParams, isSearchQuery });
44
+ const { data = {} } = await client.query({ query, variables, fetchPolicy: 'network-only' });
8
45
 
9
- return listingData;
46
+ return data.searchResults ? data.searchResults.results : data.listingData;
10
47
  };
11
48
 
12
49
  export { fetchData };
package/src/index.js CHANGED
@@ -12,14 +12,7 @@ const EntityManager = React.lazy(() =>
12
12
  );
13
13
 
14
14
  export default async function load(app) {
15
- // To load different plugin information into menu
16
- const sectionKey = 'content';
17
-
18
- app.events.once('load:menu-section', addSection => {
19
- addSection(sectionKey, { header: 'content', order: 100 });
20
- });
21
-
22
- app.events.once('load:menu-items', getAddContentMenuItems(app, sectionKey));
15
+ app.events.once('admin:menu:config:load', getAddContentMenuItems(app));
23
16
 
24
17
  app.events.once('load:custom:field:type', addFieldType => {
25
18
  Object.keys(formFieldTypes).forEach(type => {
@@ -2,8 +2,8 @@ import { getQuery } from '@blaze-cms/admin-ui-utils';
2
2
 
3
3
  const { MENU_PERMISSIONS } = require('../constants');
4
4
 
5
- function getAddContentMenuItems(app, sectionKey) {
6
- return async addItem => {
5
+ function getAddContentMenuItems(app) {
6
+ return async ({ addConfig }) => {
7
7
  const client = app.getClient();
8
8
  const {
9
9
  data: { getEntitySchemas }
@@ -14,9 +14,51 @@ function getAddContentMenuItems(app, sectionKey) {
14
14
  canDoActions: MENU_PERMISSIONS
15
15
  }
16
16
  });
17
+
18
+ if (!getEntitySchemas || !getEntitySchemas.length) return; // no items so don't add section
19
+
20
+ const menuItems = {};
21
+ const sectionMenuItems = { content: {} };
22
+
23
+ getEntitySchemas.forEach(({ id, displayName, displayProperties }) => {
24
+ if (!displayProperties) return null;
25
+
26
+ const { adminMenu: { sectionKey = 'content' } = {} } = displayProperties;
27
+ const sectionItems = sectionMenuItems[sectionKey] || {};
28
+ sectionItems[id] = {
29
+ label: displayName,
30
+ uri: `/data-listing/${id}`
31
+ };
32
+ sectionMenuItems[sectionKey] = sectionItems;
33
+ });
34
+
35
+ const menuConfig = {
36
+ main: {
37
+ items: {
38
+ content: {
39
+ label: 'Content',
40
+ loadOpen: true,
41
+ order: 10,
42
+ items: menuItems
43
+ }
44
+ }
45
+ }
46
+ };
47
+
48
+ Object.entries(sectionMenuItems).forEach(([sectionKey, sectionItems]) => {
49
+ const sectionConfig = menuConfig.main.items[sectionKey] || {};
50
+ sectionConfig.items = sectionItems;
51
+ menuConfig.main.items[sectionKey] = sectionConfig;
52
+ });
53
+
17
54
  getEntitySchemas.forEach(({ id, displayName }) => {
18
- addItem({ name: displayName, uri: `/data-listing/${id}` }, sectionKey);
55
+ menuItems[id] = {
56
+ label: displayName,
57
+ uri: `/data-listing/${id}`
58
+ };
19
59
  });
60
+
61
+ addConfig(menuConfig);
20
62
  };
21
63
  }
22
64
 
@@ -1,13 +1,23 @@
1
1
  import { gql } from '@apollo/client';
2
2
  import { BlazeError } from '@blaze-cms/core-errors';
3
+ import { getDynamicQuery } from '@blaze-cms/admin-ui-utils';
3
4
 
4
- function buildListingQuery(entitySchema) {
5
+ const buildAdminSearchQuery = entitySchema => {
6
+ const { listingProperties = [] } = entitySchema || {};
7
+ const parsedProperties = `id, ${listingProperties.join(' ') || 'id name'}`;
8
+
9
+ return getDynamicQuery('ADMIN_SEARCH')([entitySchema], parsedProperties, true);
10
+ };
11
+
12
+ function buildListingQuery(entitySchema, isSearchQuery) {
5
13
  if (!entitySchema.actions || !entitySchema.actions.getAll || !entitySchema.listingProperties) {
6
14
  throw new BlazeError(
7
15
  'Listing query requires getAll action and listingProperties from entity schema'
8
16
  );
9
17
  }
10
18
 
19
+ if (isSearchQuery) return buildAdminSearchQuery(entitySchema);
20
+
11
21
  const sortType =
12
22
  entitySchema.actions.getAll[0].toUpperCase() + entitySchema.actions.getAll.substr(1);
13
23
 
@@ -1,4 +1,4 @@
1
- const getDefaultQueryParams = ({ schema }) => {
1
+ const getDefaultQueryParams = schema => {
2
2
  const updated = schema.properties && schema.properties.updated;
3
3
  const { adminDefaultListingFilter: where } = schema.displayProperties || {};
4
4