@blaze-cms/plugin-data-ui 0.133.0 → 0.134.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 +45 -0
  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 +32 -17
  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 +23 -7
  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 +32 -17
  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 +24 -8
  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 +68 -57
  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 +51 -19
  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,6 +3,7 @@ import React, { useEffect, useState, useRef } from 'react';
3
3
  import { withRouter, Prompt } from 'react-router-dom';
4
4
  import { useApolloClient } from '@apollo/client';
5
5
  import PropTypes from 'prop-types';
6
+ import { RenderHook } from '@blaze-cms/plugin-render-hooks-ui';
6
7
  import { getQuery, GET_CURRENT_TAB_ID } from '@blaze-cms/admin-ui-utils';
7
8
  import { FormBuilder, parseFormValues } from '@blaze-cms/react-form-builder';
8
9
  import { DeleteAction, CopyDataFromAction } from '@blaze-cms/admin';
@@ -34,6 +35,7 @@ import {
34
35
  checkFulfilConditions
35
36
  } from '../utils/entity';
36
37
  import useToggle from '../../../utils/hooks/useToggle';
38
+ import InfoBoxes from '../../InfoBoxes/InfoBoxes';
37
39
 
38
40
  const Entity = ({
39
41
  formData,
@@ -403,68 +405,77 @@ const Entity = ({
403
405
 
404
406
  return (
405
407
  <div className="page">
406
- <Prompt when={hasToDisplayPrompt} message={LEAVE_PAGE_MESSAGE} />
407
- {showModal && (
408
- <DeleteAction
409
- onClose={setModalStatus}
410
- deleteAction={onDelete}
411
- itemName={formData.values.name}
412
- />
413
- )}
414
- {copyModalStatus && (
415
- <CopyDataFromAction
416
- onClose={handleCopyDataFromClose}
417
- copyAction={onCopy}
418
- getFormData={getFormData}
419
- />
420
- )}
421
-
422
- <div className="row row--display-row">
423
- <div className="column column--three-quarters">
424
- <EntityHeader
425
- entityData={entityData}
426
- entityIdentifier={entityIdentifier}
427
- pageTitle={pageTitle}
428
- pageName={pageName}
429
- onSubmit={onSubmit}
430
- handlePublishAndUnpublish={handlePublishAndUnpublish}
431
- isSaveButtonAvailable={isSaveButtonAvailable}
432
- isEnablePublishButton={isEnablePublishButton}
433
- isEnablePreviewButton={isEnablePreviewButton}
434
- toggleCopyModal={setCopyModalStatus}
435
- toggleModal={setModalStatus}
436
- formData={formData}
437
- onViewUrl={onViewUrlHandler}
438
- saveButtonText={saveButtonText}
439
- />
440
-
441
- <div className="page__content">
442
- <div className="content">
443
- <Tabs
444
- enabled={showPageBuilderTabs}
445
- onTabChange={tabId => {
446
- client.writeQuery({
447
- query: GET_CURRENT_TAB_ID,
448
- data: { currentTabId: tabId }
449
- });
450
- setCurrentTabId(tabId);
451
- }}>
452
- <FormBuilder
453
- getIsFormValid={setIsFormValid}
454
- getFormValues={getFormValues}
408
+ <EntityHeader
409
+ entityData={entityData}
410
+ entityIdentifier={entityIdentifier}
411
+ pageTitle={pageTitle}
412
+ pageName={pageName}
413
+ onSubmit={onSubmit}
414
+ handlePublishAndUnpublish={handlePublishAndUnpublish}
415
+ isSaveButtonAvailable={isSaveButtonAvailable}
416
+ isEnablePublishButton={isEnablePublishButton}
417
+ isEnablePreviewButton={isEnablePreviewButton}
418
+ toggleCopyModal={setCopyModalStatus}
419
+ toggleModal={setModalStatus}
420
+ formData={formData}
421
+ onViewUrl={onViewUrlHandler}
422
+ saveButtonText={saveButtonText}
423
+ />
424
+ <div className="page-wrapper__content">
425
+ <div className="tabs-wrapper tabs-wrapper__tab">
426
+ <Prompt when={hasToDisplayPrompt} message={LEAVE_PAGE_MESSAGE} />
427
+ {showModal && (
428
+ <DeleteAction
429
+ onClose={setModalStatus}
430
+ deleteAction={onDelete}
431
+ itemName={formData.values.name}
432
+ />
433
+ )}
434
+ {copyModalStatus && (
435
+ <CopyDataFromAction
436
+ onClose={handleCopyDataFromClose}
437
+ copyAction={onCopy}
438
+ getFormData={getFormData}
439
+ />
440
+ )}
441
+
442
+ <div className="page__content--fixed">
443
+ <div className="page__content">
444
+ <div className="content">
445
+ <RenderHook hookKey={`entity:${action}:main:top`} entity={entity} schema={schema} />
446
+ <InfoBoxes id={entity.id} schema={schema} />
447
+ <Tabs
448
+ enabled={showPageBuilderTabs}
449
+ onTabChange={tabId => {
450
+ client.writeQuery({
451
+ query: GET_CURRENT_TAB_ID,
452
+ data: { currentTabId: tabId }
453
+ });
454
+ setCurrentTabId(tabId);
455
+ }}>
456
+ <FormBuilder
457
+ getIsFormValid={setIsFormValid}
458
+ getFormValues={getFormValues}
459
+ schema={schema}
460
+ data={clonedFormData}
461
+ onChange={onChangeFormValues}
462
+ shouldCopyData={shouldCopyData}
463
+ updateCopyData={updateCopyData}
464
+ formValues={formValues}
465
+ isNewEntity={isNewEntity}
466
+ />
467
+ </Tabs>
468
+ <RenderHook
469
+ hookKey={`entity:${action}:main:bottom`}
470
+ entity={entity}
455
471
  schema={schema}
456
- data={clonedFormData}
457
- onChange={onChangeFormValues}
458
- shouldCopyData={shouldCopyData}
459
- updateCopyData={updateCopyData}
460
- formValues={formValues}
461
- isNewEntity={isNewEntity}
462
472
  />
463
- </Tabs>
473
+ </div>
464
474
  </div>
465
475
  </div>
466
476
  </div>
467
- <div className="column column--one-third">
477
+
478
+ <div className="column column--one-third page-sidebar page-sidebar--relations">
468
479
  {showSideBarRelations && (
469
480
  <SideBarRelations
470
481
  entity={entity}
@@ -0,0 +1,22 @@
1
+ import PropTypes from 'prop-types';
2
+ import React from 'react';
3
+ import useCustomSidebarData from '../hooks/useCustomSidebarData';
4
+ import CustomSidebarInfo from '../presentational/CustomSidebarInfo';
5
+
6
+ const CustomSibebarInfoContainer = ({ id, schema, displayProperties }) => {
7
+ const { data } = useCustomSidebarData({ id, schema, displayProperties });
8
+
9
+ if (!data || !Object.keys(data) || Object.keys(data).length === 0) return null;
10
+
11
+ const items = Object.values(data).flatMap(item => Object.values(item));
12
+
13
+ return <CustomSidebarInfo items={items} customSidebarInfoKey={displayProperties.key} />;
14
+ };
15
+
16
+ export default CustomSibebarInfoContainer;
17
+
18
+ CustomSibebarInfoContainer.propTypes = {
19
+ id: PropTypes.string.isRequired,
20
+ displayProperties: PropTypes.object.isRequired,
21
+ schema: PropTypes.object.isRequired
22
+ };
@@ -0,0 +1,33 @@
1
+ import { gql } from '@apollo/client';
2
+ import { BlazeError } from '@blaze-cms/core-errors';
3
+
4
+ export default function buildDynamicQuery({ id, schema, displayProperties }) {
5
+ if (!schema || !schema.actions || !schema.actions.get || !schema.properties) {
6
+ throw new BlazeError(
7
+ 'DataEntity query requires get action, properties and fields from entity schema'
8
+ );
9
+ }
10
+
11
+ if (
12
+ displayProperties.adminMainInfoProperty &&
13
+ Array.isArray(displayProperties.adminMainInfoProperty)
14
+ ) {
15
+ const fields = displayProperties.adminMainInfoProperty.map(
16
+ infoProperty =>
17
+ `${infoProperty} {
18
+ label
19
+ value
20
+ }`
21
+ );
22
+
23
+ return gql`query getInfoBoxData($id: String!){
24
+ ${schema.actions.get}( id: $id ) {
25
+ id
26
+ ${fields.map(field => field)}
27
+ __typename
28
+ }
29
+ }`;
30
+ }
31
+
32
+ return null;
33
+ }
@@ -0,0 +1,28 @@
1
+ import ProptTypes from 'prop-types';
2
+ import { useQuery, gql } from '@apollo/client';
3
+ import buildDynamicQuery from '../helpers/build-dynamic-query';
4
+
5
+ const useCustomSidebarData = ({ id, schema, displayProperties }) => {
6
+ const query = buildDynamicQuery({ id, schema, displayProperties });
7
+
8
+ const customSidebarInfoQuery =
9
+ query ||
10
+ gql`
11
+ query {
12
+ __typename
13
+ }
14
+ `;
15
+
16
+ const { data = {}, loading, error } = useQuery(customSidebarInfoQuery, {
17
+ variables: { id },
18
+ skip: !query
19
+ });
20
+
21
+ return { data: data.__typename !== 'Query' ? data : null, loading, error };
22
+ };
23
+
24
+ export default useCustomSidebarData;
25
+
26
+ useCustomSidebarData.propTypes = {
27
+ displayProperties: ProptTypes.object.isRequired
28
+ };
@@ -4,14 +4,23 @@ import uuidv1 from 'uuid/v1';
4
4
  import { useApolloClient } from '@apollo/client';
5
5
  import { getQuery } from '@blaze-cms/admin-ui-utils';
6
6
  import { formFieldTypes } from '@blaze-cms/react-form-builder';
7
- import Badge from '@blaze-react/badge';
7
+ import classnames from 'classnames';
8
8
  import { VersionsList } from '@blaze-cms/versioning-ui';
9
- import { PUBLISHED } from '../../../../constants';
9
+ import { PUBLISHED, UNPUBLISHED } from '../../../../constants';
10
+ import CustomSidebarInfoContainer from './container/CustomSidebarInfoContainer';
11
+ import EntityNavLinks from '../EntitiyNavLinks';
10
12
 
11
13
  const SideBarRelations = ({ schema, onChange, formData, entity }) => {
12
14
  const { relation: RelationComponent } = formFieldTypes;
13
- const { formattedStatus, formattedUpdated, formattedCreated, formattedPublished } = formData;
15
+ const {
16
+ formattedStatus,
17
+ formattedUpdated,
18
+ formattedCreated,
19
+ formattedPublished,
20
+ status
21
+ } = formData;
14
22
  const client = useApolloClient();
23
+
15
24
  const [relationsComponents, setRelationsComponents] = useState(null);
16
25
 
17
26
  useEffect(
@@ -51,27 +60,50 @@ const SideBarRelations = ({ schema, onChange, formData, entity }) => {
51
60
  const { id: itemId } = entity;
52
61
  const { identifier: itemEntity, interfaces } = schema;
53
62
 
63
+ const statusClassName = classnames('sidebar__status__badge', {
64
+ 'sidebar__status__badge--published': status === PUBLISHED,
65
+ 'sidebar__status__badge--unpublished': status === UNPUBLISHED
66
+ });
67
+
54
68
  return (
55
69
  <div className="sidebar" data-testid="sideBarRelations-main-div">
56
70
  <div className="sidebar__content">
57
- {formattedCreated && (
58
- <div className="sidebar__status">
59
- {formattedStatus && (
60
- <Badge type="status" modifiers={formattedStatus}>
61
- {formattedStatus}
62
- {formattedStatus === PUBLISHED && `: ${formattedPublished}`}
63
- </Badge>
64
- )}
65
- <p>
66
- Created: <span>{formattedCreated}</span>
67
- </p>
68
- <p>
69
- Updated: <span>{formattedUpdated}</span>
70
- </p>
71
- </div>
72
- )}
71
+ <div className="sidebar__status">
72
+ {formattedCreated && (
73
+ <div className="sidebar__top">
74
+ <div className="sidebar__status__wrapper">
75
+ <b>Status</b>
76
+ <span className={statusClassName}>{formattedStatus}</span>
77
+ </div>
78
+ {formattedStatus === PUBLISHED && (
79
+ <p>
80
+ {formattedStatus} on: <span> {formattedPublished}</span>
81
+ </p>
82
+ )}
83
+ </div>
84
+ )}
85
+
86
+ {!schema.displayProperties.adminMainInfoProperty && (
87
+ <>
88
+ <p>
89
+ Created: <span>{formattedCreated}</span>
90
+ </p>
91
+ <p>
92
+ Updated: <span>{formattedUpdated}</span>
93
+ </p>
94
+ </>
95
+ )}
96
+
97
+ <CustomSidebarInfoContainer
98
+ id={itemId}
99
+ schema={schema}
100
+ displayProperties={schema.displayProperties}
101
+ />
102
+ </div>
73
103
 
74
104
  <VersionsList itemEntity={itemEntity} itemId={itemId} interfaces={interfaces} />
105
+ <EntityNavLinks schema={schema} />
106
+
75
107
  {relationsComponents &&
76
108
  relationsComponents.map(({ id, staticData, schema: entitySchema }) => (
77
109
  <RelationComponent
@@ -0,0 +1,33 @@
1
+ import PropTypes from 'prop-types';
2
+ import React from 'react';
3
+
4
+ const CustomSidebarInfo = ({ items, customSidebarInfoKey }) => {
5
+ if (!items) return null;
6
+
7
+ const customSidebarInfoItems = items.map(item =>
8
+ Object.values(item)
9
+ .map(info => {
10
+ if (!info.label || !info.value) return null;
11
+
12
+ return (
13
+ <p>
14
+ {info.label}: <span>{info.value}</span>
15
+ </p>
16
+ );
17
+ })
18
+ .filter(Boolean)
19
+ );
20
+
21
+ return (
22
+ <div className="custom-sidebar-info" key={customSidebarInfoKey}>
23
+ <div className="custom-sidebar-info--container">{customSidebarInfoItems}</div>
24
+ </div>
25
+ );
26
+ };
27
+
28
+ export default CustomSidebarInfo;
29
+
30
+ CustomSidebarInfo.propTypes = {
31
+ customSidebarInfoKey: PropTypes.string.isRequired,
32
+ items: PropTypes.array.isRequired
33
+ };
@@ -0,0 +1,24 @@
1
+ import PropTypes from 'prop-types';
2
+ import React from 'react';
3
+ import InfoBoxContainer from './container/InfoBoxContainer';
4
+
5
+ const InfoBoxes = ({ id, schema }) => {
6
+ const {
7
+ displayProperties: { adminInfoBoxes = [] }
8
+ } = schema;
9
+
10
+ if (adminInfoBoxes.length <= 0) {
11
+ return null;
12
+ }
13
+
14
+ return adminInfoBoxes.map(infoBox => (
15
+ <InfoBoxContainer id={id} schema={schema} key={infoBox.key} infoBox={infoBox} />
16
+ ));
17
+ };
18
+
19
+ export default InfoBoxes;
20
+
21
+ InfoBoxes.propTypes = {
22
+ id: PropTypes.string.isRequired,
23
+ schema: PropTypes.object.isRequired
24
+ };
@@ -0,0 +1,22 @@
1
+ import PropTypes from 'prop-types';
2
+ import React from 'react';
3
+ import useData from '../hooks/useData';
4
+ import InfoBox from '../presentational/InfoBox';
5
+
6
+ const InfoBoxContainer = ({ id, schema, infoBox }) => {
7
+ const { data } = useData({ id, schema, infoBox });
8
+
9
+ if (!data || !Object.keys(data) || Object.keys(data).length === 0) return null;
10
+
11
+ const items = Object.values(data).flatMap(item => Object.values(item));
12
+
13
+ return <InfoBox items={items} infoBoxKey={infoBox.key} />;
14
+ };
15
+
16
+ export default InfoBoxContainer;
17
+
18
+ InfoBoxContainer.propTypes = {
19
+ id: PropTypes.string.isRequired,
20
+ infoBox: PropTypes.object.isRequired,
21
+ schema: PropTypes.object.isRequired
22
+ };
@@ -0,0 +1,25 @@
1
+ import { gql } from '@apollo/client';
2
+ import { BlazeError } from '@blaze-cms/core-errors';
3
+
4
+ export default function buildDynamicQuery({ id, schema, infoBox }) {
5
+ if (!schema || !schema.actions || !schema.actions.get || !schema.properties) {
6
+ throw new BlazeError(
7
+ 'DataEntity query requires get action, properties and fields from entity schema'
8
+ );
9
+ }
10
+
11
+ const fields = `${infoBox.property} {
12
+ label
13
+ value
14
+ }`;
15
+
16
+ return {
17
+ query: gql`query getInfoBoxData($id: String!){
18
+ ${schema.actions.get}( id: $id ) {
19
+ id
20
+ ${fields}
21
+ __typename
22
+ }
23
+ }`
24
+ };
25
+ }
@@ -0,0 +1,20 @@
1
+ import { useQuery, gql } from '@apollo/client';
2
+ import useInfoBoxData from './useInfoBox';
3
+
4
+ function useData({ id, schema, infoBox }) {
5
+ const { query } = useInfoBoxData({ id, schema, infoBox });
6
+
7
+ const infoBoxQuery =
8
+ query ||
9
+ gql`
10
+ query {
11
+ __typename
12
+ }
13
+ `;
14
+
15
+ const { data = {}, loading, error } = useQuery(infoBoxQuery, { variables: { id }, skip: !query });
16
+
17
+ return { data: data.__typename !== 'Query' ? data : null, loading, error };
18
+ }
19
+
20
+ export default useData;
@@ -0,0 +1,13 @@
1
+ import buildDynamicQuery from '../helpers/build-dynamic-query';
2
+
3
+ function useInfoBox({ id, schema, infoBox }) {
4
+ const { query } = buildDynamicQuery({
5
+ id,
6
+ schema,
7
+ infoBox
8
+ });
9
+
10
+ return { query: query || null };
11
+ }
12
+
13
+ export default useInfoBox;
@@ -0,0 +1,3 @@
1
+ import InfoBoxes from './InfoBoxes';
2
+
3
+ export default InfoBoxes;
@@ -0,0 +1,34 @@
1
+ import PropTypes from 'prop-types';
2
+ import React from 'react';
3
+
4
+ const InfoBox = ({ items, infoBoxKey }) => {
5
+ if (!items) return null;
6
+
7
+ const infoBoxItems = items.map(item =>
8
+ Object.values(item)
9
+ .map(info => {
10
+ if (!info.label || !info.value) return null;
11
+
12
+ return (
13
+ <div className="info-box--item" key={`${infoBoxKey}-${info.label.toLowerCase()}`}>
14
+ <div className="info-box--label">{info.label}: </div>
15
+ <div className="info-box--value">{info.value}</div>
16
+ </div>
17
+ );
18
+ })
19
+ .filter(Boolean)
20
+ );
21
+
22
+ return (
23
+ <div className="info-box" key={infoBoxKey}>
24
+ <div className="info-box--container">{infoBoxItems}</div>
25
+ </div>
26
+ );
27
+ };
28
+
29
+ export default InfoBox;
30
+
31
+ InfoBox.propTypes = {
32
+ infoBoxKey: PropTypes.string.isRequired,
33
+ items: PropTypes.array.isRequired
34
+ };