@blaze-cms/plugin-data-ui 0.128.0-alpha.2 → 0.128.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 (47) hide show
  1. package/CHANGELOG.md +13 -16
  2. package/lib/components/EntityManager/Entity/Entity.js +29 -18
  3. package/lib/components/EntityManager/Entity/Entity.js.map +1 -1
  4. package/lib/components/EntityManager/Entity/SideBarRelations/index.js +12 -6
  5. package/lib/components/EntityManager/Entity/SideBarRelations/index.js.map +1 -1
  6. package/lib/components/InfoBoxes/InfoBoxes.js +36 -0
  7. package/lib/components/InfoBoxes/InfoBoxes.js.map +1 -0
  8. package/lib/components/InfoBoxes/container/InfoBoxContainer.js +44 -0
  9. package/lib/components/InfoBoxes/container/InfoBoxContainer.js.map +1 -0
  10. package/lib/components/InfoBoxes/helpers/build-dynamic-query.js +25 -0
  11. package/lib/components/InfoBoxes/helpers/build-dynamic-query.js.map +1 -0
  12. package/lib/components/InfoBoxes/hooks/useData.js +42 -0
  13. package/lib/components/InfoBoxes/hooks/useData.js.map +1 -0
  14. package/lib/components/InfoBoxes/hooks/useInfoBox.js +26 -0
  15. package/lib/components/InfoBoxes/hooks/useInfoBox.js.map +1 -0
  16. package/lib/components/InfoBoxes/index.js +12 -0
  17. package/lib/components/InfoBoxes/index.js.map +1 -0
  18. package/lib/components/InfoBoxes/presentational/InfoBox.js +46 -0
  19. package/lib/components/InfoBoxes/presentational/InfoBox.js.map +1 -0
  20. package/lib-es/components/EntityManager/Entity/Entity.js +29 -18
  21. package/lib-es/components/EntityManager/Entity/Entity.js.map +1 -1
  22. package/lib-es/components/EntityManager/Entity/SideBarRelations/index.js +13 -7
  23. package/lib-es/components/EntityManager/Entity/SideBarRelations/index.js.map +1 -1
  24. package/lib-es/components/InfoBoxes/InfoBoxes.js +28 -0
  25. package/lib-es/components/InfoBoxes/InfoBoxes.js.map +1 -0
  26. package/lib-es/components/InfoBoxes/container/InfoBoxContainer.js +30 -0
  27. package/lib-es/components/InfoBoxes/container/InfoBoxContainer.js.map +1 -0
  28. package/lib-es/components/InfoBoxes/helpers/build-dynamic-query.js +25 -0
  29. package/lib-es/components/InfoBoxes/helpers/build-dynamic-query.js.map +1 -0
  30. package/lib-es/components/InfoBoxes/hooks/useData.js +37 -0
  31. package/lib-es/components/InfoBoxes/hooks/useData.js.map +1 -0
  32. package/lib-es/components/InfoBoxes/hooks/useInfoBox.js +19 -0
  33. package/lib-es/components/InfoBoxes/hooks/useInfoBox.js.map +1 -0
  34. package/lib-es/components/InfoBoxes/index.js +3 -0
  35. package/lib-es/components/InfoBoxes/index.js.map +1 -0
  36. package/lib-es/components/InfoBoxes/presentational/InfoBox.js +31 -0
  37. package/lib-es/components/InfoBoxes/presentational/InfoBox.js.map +1 -0
  38. package/package.json +10 -9
  39. package/src/components/EntityManager/Entity/Entity.js +65 -59
  40. package/src/components/EntityManager/Entity/SideBarRelations/index.js +23 -9
  41. package/src/components/InfoBoxes/InfoBoxes.js +24 -0
  42. package/src/components/InfoBoxes/container/InfoBoxContainer.js +22 -0
  43. package/src/components/InfoBoxes/helpers/build-dynamic-query.js +25 -0
  44. package/src/components/InfoBoxes/hooks/useData.js +20 -0
  45. package/src/components/InfoBoxes/hooks/useInfoBox.js +13 -0
  46. package/src/components/InfoBoxes/index.js +3 -0
  47. package/src/components/InfoBoxes/presentational/InfoBox.js +34 -0
@@ -0,0 +1,37 @@
1
+ import { useQuery, gql } from '@apollo/client';
2
+ import useInfoBoxData from './useInfoBox';
3
+ function useData({
4
+ id,
5
+ schema,
6
+ infoBox
7
+ }) {
8
+ const {
9
+ query
10
+ } = useInfoBoxData({
11
+ id,
12
+ schema,
13
+ infoBox
14
+ });
15
+ const infoBoxQuery = query || gql`
16
+ query {
17
+ __typename
18
+ }
19
+ `;
20
+ const {
21
+ data = {},
22
+ loading,
23
+ error
24
+ } = useQuery(infoBoxQuery, {
25
+ variables: {
26
+ id
27
+ },
28
+ skip: !query
29
+ });
30
+ return {
31
+ data: data.__typename !== 'Query' ? data : null,
32
+ loading,
33
+ error
34
+ };
35
+ }
36
+ export default useData;
37
+ //# sourceMappingURL=useData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useData.js","names":["useQuery","gql","useInfoBoxData","useData","id","schema","infoBox","query","infoBoxQuery","data","loading","error","variables","skip","__typename"],"sources":["../../../../src/components/InfoBoxes/hooks/useData.js"],"sourcesContent":["import { useQuery, gql } from '@apollo/client';\nimport useInfoBoxData from './useInfoBox';\n\nfunction useData({ id, schema, infoBox }) {\n const { query } = useInfoBoxData({ id, schema, infoBox });\n\n const infoBoxQuery =\n query ||\n gql`\n query {\n __typename\n }\n `;\n\n const { data = {}, loading, error } = useQuery(infoBoxQuery, { variables: { id }, skip: !query });\n\n return { data: data.__typename !== 'Query' ? data : null, loading, error };\n}\n\nexport default useData;\n"],"mappings":"AAAA,SAASA,QAAQ,EAAEC,GAAG,QAAQ,gBAAgB;AAC9C,OAAOC,cAAc,MAAM,cAAc;AAEzC,SAASC,OAAOA,CAAC;EAAEC,EAAE;EAAEC,MAAM;EAAEC;AAAQ,CAAC,EAAE;EACxC,MAAM;IAAEC;EAAM,CAAC,GAAGL,cAAc,CAAC;IAAEE,EAAE;IAAEC,MAAM;IAAEC;EAAQ,CAAC,CAAC;EAEzD,MAAME,YAAY,GAChBD,KAAK,IACLN,GAAI;AACR;AACA;AACA;AACA,KAAK;EAEH,MAAM;IAAEQ,IAAI,GAAG,CAAC,CAAC;IAAEC,OAAO;IAAEC;EAAM,CAAC,GAAGX,QAAQ,CAACQ,YAAY,EAAE;IAAEI,SAAS,EAAE;MAAER;IAAG,CAAC;IAAES,IAAI,EAAE,CAACN;EAAM,CAAC,CAAC;EAEjG,OAAO;IAAEE,IAAI,EAAEA,IAAI,CAACK,UAAU,KAAK,OAAO,GAAGL,IAAI,GAAG,IAAI;IAAEC,OAAO;IAAEC;EAAM,CAAC;AAC5E;AAEA,eAAeR,OAAO"}
@@ -0,0 +1,19 @@
1
+ import buildDynamicQuery from '../helpers/build-dynamic-query';
2
+ function useInfoBox({
3
+ id,
4
+ schema,
5
+ infoBox
6
+ }) {
7
+ const {
8
+ query
9
+ } = buildDynamicQuery({
10
+ id,
11
+ schema,
12
+ infoBox
13
+ });
14
+ return {
15
+ query: query || null
16
+ };
17
+ }
18
+ export default useInfoBox;
19
+ //# sourceMappingURL=useInfoBox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useInfoBox.js","names":["buildDynamicQuery","useInfoBox","id","schema","infoBox","query"],"sources":["../../../../src/components/InfoBoxes/hooks/useInfoBox.js"],"sourcesContent":["import buildDynamicQuery from '../helpers/build-dynamic-query';\n\nfunction useInfoBox({ id, schema, infoBox }) {\n const { query } = buildDynamicQuery({\n id,\n schema,\n infoBox\n });\n\n return { query: query || null };\n}\n\nexport default useInfoBox;\n"],"mappings":"AAAA,OAAOA,iBAAiB,MAAM,gCAAgC;AAE9D,SAASC,UAAUA,CAAC;EAAEC,EAAE;EAAEC,MAAM;EAAEC;AAAQ,CAAC,EAAE;EAC3C,MAAM;IAAEC;EAAM,CAAC,GAAGL,iBAAiB,CAAC;IAClCE,EAAE;IACFC,MAAM;IACNC;EACF,CAAC,CAAC;EAEF,OAAO;IAAEC,KAAK,EAAEA,KAAK,IAAI;EAAK,CAAC;AACjC;AAEA,eAAeJ,UAAU"}
@@ -0,0 +1,3 @@
1
+ import InfoBoxes from './InfoBoxes';
2
+ export default InfoBoxes;
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["InfoBoxes"],"sources":["../../../src/components/InfoBoxes/index.js"],"sourcesContent":["import InfoBoxes from './InfoBoxes';\n\nexport default InfoBoxes;\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,aAAa;AAEnC,eAAeA,SAAS"}
@@ -0,0 +1,31 @@
1
+ import PropTypes from 'prop-types';
2
+ import React from 'react';
3
+ const InfoBox = ({
4
+ items,
5
+ infoBoxKey
6
+ }) => {
7
+ if (!items) return null;
8
+ const infoBoxItems = items.map(item => Object.values(item).map(info => {
9
+ if (!info.label || !info.value) return null;
10
+ return /*#__PURE__*/React.createElement("div", {
11
+ className: "info-box--item",
12
+ key: `${infoBoxKey}-${info.label.toLowerCase()}`
13
+ }, /*#__PURE__*/React.createElement("div", {
14
+ className: "info-box--label"
15
+ }, info.label, ": "), /*#__PURE__*/React.createElement("div", {
16
+ className: "info-box--value"
17
+ }, info.value));
18
+ }).filter(Boolean));
19
+ return /*#__PURE__*/React.createElement("div", {
20
+ className: "info-box",
21
+ key: infoBoxKey
22
+ }, /*#__PURE__*/React.createElement("div", {
23
+ className: "info-box--container"
24
+ }, infoBoxItems));
25
+ };
26
+ export default InfoBox;
27
+ InfoBox.propTypes = {
28
+ infoBoxKey: PropTypes.string.isRequired,
29
+ items: PropTypes.array.isRequired
30
+ };
31
+ //# sourceMappingURL=InfoBox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InfoBox.js","names":["PropTypes","React","InfoBox","items","infoBoxKey","infoBoxItems","map","item","Object","values","info","label","value","createElement","className","key","toLowerCase","filter","Boolean","propTypes","string","isRequired","array"],"sources":["../../../../src/components/InfoBoxes/presentational/InfoBox.js"],"sourcesContent":["import PropTypes from 'prop-types';\nimport React from 'react';\n\nconst InfoBox = ({ items, infoBoxKey }) => {\n if (!items) return null;\n\n const infoBoxItems = items.map(item =>\n Object.values(item)\n .map(info => {\n if (!info.label || !info.value) return null;\n\n return (\n <div className=\"info-box--item\" key={`${infoBoxKey}-${info.label.toLowerCase()}`}>\n <div className=\"info-box--label\">{info.label}: </div>\n <div className=\"info-box--value\">{info.value}</div>\n </div>\n );\n })\n .filter(Boolean)\n );\n\n return (\n <div className=\"info-box\" key={infoBoxKey}>\n <div className=\"info-box--container\">{infoBoxItems}</div>\n </div>\n );\n};\n\nexport default InfoBox;\n\nInfoBox.propTypes = {\n infoBoxKey: PropTypes.string.isRequired,\n items: PropTypes.array.isRequired\n};\n"],"mappings":"AAAA,OAAOA,SAAS,MAAM,YAAY;AAClC,OAAOC,KAAK,MAAM,OAAO;AAEzB,MAAMC,OAAO,GAAGA,CAAC;EAAEC,KAAK;EAAEC;AAAW,CAAC,KAAK;EACzC,IAAI,CAACD,KAAK,EAAE,OAAO,IAAI;EAEvB,MAAME,YAAY,GAAGF,KAAK,CAACG,GAAG,CAACC,IAAI,IACjCC,MAAM,CAACC,MAAM,CAACF,IAAI,CAAC,CAChBD,GAAG,CAACI,IAAI,IAAI;IACX,IAAI,CAACA,IAAI,CAACC,KAAK,IAAI,CAACD,IAAI,CAACE,KAAK,EAAE,OAAO,IAAI;IAE3C,oBACEX,KAAA,CAAAY,aAAA;MAAKC,SAAS,EAAC,gBAAgB;MAACC,GAAG,EAAG,GAAEX,UAAW,IAAGM,IAAI,CAACC,KAAK,CAACK,WAAW,EAAG;IAAE,gBAC/Ef,KAAA,CAAAY,aAAA;MAAKC,SAAS,EAAC;IAAiB,GAAEJ,IAAI,CAACC,KAAK,EAAC,IAAE,CAAM,eACrDV,KAAA,CAAAY,aAAA;MAAKC,SAAS,EAAC;IAAiB,GAAEJ,IAAI,CAACE,KAAK,CAAO,CAC/C;EAEV,CAAC,CAAC,CACDK,MAAM,CAACC,OAAO,CAAC,CACnB;EAED,oBACEjB,KAAA,CAAAY,aAAA;IAAKC,SAAS,EAAC,UAAU;IAACC,GAAG,EAAEX;EAAW,gBACxCH,KAAA,CAAAY,aAAA;IAAKC,SAAS,EAAC;EAAqB,GAAET,YAAY,CAAO,CACrD;AAEV,CAAC;AAED,eAAeH,OAAO;AAEtBA,OAAO,CAACiB,SAAS,GAAG;EAClBf,UAAU,EAAEJ,SAAS,CAACoB,MAAM,CAACC,UAAU;EACvClB,KAAK,EAAEH,SAAS,CAACsB,KAAK,CAACD;AACzB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaze-cms/plugin-data-ui",
3
- "version": "0.128.0-alpha.2",
3
+ "version": "0.128.0-project-admin-customisations.0",
4
4
  "description": "Blaze plugin data ui",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-es/index.js",
@@ -27,12 +27,13 @@
27
27
  },
28
28
  "license": "GPL-3.0",
29
29
  "dependencies": {
30
- "@blaze-cms/admin-ui-utils": "0.128.0-alpha.0",
31
- "@blaze-cms/core-errors": "^0.127.0",
32
- "@blaze-cms/react-form-builder": "0.128.0-alpha.0",
33
- "@blaze-cms/react-page-builder": "0.128.0-alpha.2",
34
- "@blaze-cms/setup-ui": "0.128.0-alpha.0",
35
- "@blaze-cms/versioning-ui": "0.128.0-alpha.0",
30
+ "@blaze-cms/admin-ui-utils": "0.128.0-project-admin-customisations.0",
31
+ "@blaze-cms/core-errors": "0.128.0-project-admin-customisations.0",
32
+ "@blaze-cms/plugin-render-hooks-ui": "0.128.0-project-admin-customisations.0",
33
+ "@blaze-cms/react-form-builder": "0.128.0-project-admin-customisations.0",
34
+ "@blaze-cms/react-page-builder": "0.128.0-project-admin-customisations.0",
35
+ "@blaze-cms/setup-ui": "0.128.0-project-admin-customisations.0",
36
+ "@blaze-cms/versioning-ui": "0.128.0-project-admin-customisations.0",
36
37
  "@blaze-react/button": "0.5.19",
37
38
  "@blaze-react/more": "0.5.19",
38
39
  "@blaze-react/multiselect": "0.6.6",
@@ -53,7 +54,7 @@
53
54
  "uuid": "^3.3.3"
54
55
  },
55
56
  "devDependencies": {
56
- "@blaze-cms/core-ui": "0.128.0-alpha.0"
57
+ "@blaze-cms/core-ui": "0.128.0-project-admin-customisations.0"
57
58
  },
58
59
  "peerDependencies": {
59
60
  "@apollo/client": "3.x",
@@ -65,5 +66,5 @@
65
66
  "lib/*",
66
67
  "lib-es/*"
67
68
  ],
68
- "gitHead": "c2d83b0701dc4e4db0d93143f7383779d1e3627d"
69
+ "gitHead": "e980a4e631f7e2d3a8939a754d87167f48da315f"
69
70
  }
@@ -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,72 @@ 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}
455
- schema={schema}
456
- data={clonedFormData}
457
- onChange={onChangeFormValues}
458
- shouldCopyData={shouldCopyData}
459
- updateCopyData={updateCopyData}
460
- formValues={formValues}
461
- isNewEntity={isNewEntity}
462
- />
463
- </Tabs>
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
+ </div>
464
469
  </div>
465
470
  </div>
466
471
  </div>
467
- <div className="column column--one-third">
472
+
473
+ <div className="column column--one-third page-sidebar">
468
474
  {showSideBarRelations && (
469
475
  <SideBarRelations
470
476
  entity={entity}
@@ -4,16 +4,21 @@ 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
10
 
11
11
  const SideBarRelations = ({ schema, onChange, formData, entity }) => {
12
12
  const { relation: RelationComponent } = formFieldTypes;
13
- const { formattedStatus, formattedUpdated, formattedCreated, formattedPublished } = formData;
13
+ const {
14
+ formattedStatus,
15
+ formattedUpdated,
16
+ formattedCreated,
17
+ formattedPublished,
18
+ status
19
+ } = formData;
14
20
  const client = useApolloClient();
15
21
  const [relationsComponents, setRelationsComponents] = useState(null);
16
-
17
22
  useEffect(
18
23
  () => {
19
24
  (async () => {
@@ -51,17 +56,26 @@ const SideBarRelations = ({ schema, onChange, formData, entity }) => {
51
56
  const { id: itemId } = entity;
52
57
  const { identifier: itemEntity, interfaces } = schema;
53
58
 
59
+ const statusClassName = classnames('sidebar__status__badge', {
60
+ 'sidebar__status__badge--published': status === PUBLISHED,
61
+ 'sidebar__status__badge--unpublished': status === UNPUBLISHED
62
+ });
63
+
54
64
  return (
55
65
  <div className="sidebar" data-testid="sideBarRelations-main-div">
56
66
  <div className="sidebar__content">
57
67
  {formattedCreated && (
58
68
  <div className="sidebar__status">
59
- {formattedStatus && (
60
- <Badge type="status" modifiers={formattedStatus}>
61
- {formattedStatus}
62
- {formattedStatus === PUBLISHED && `: ${formattedPublished}`}
63
- </Badge>
69
+ <div className="sidebar__status__wrapper">
70
+ <b>Status</b>
71
+ <span className={statusClassName}>{formattedStatus}</span>
72
+ </div>
73
+ {formattedStatus === PUBLISHED && (
74
+ <p>
75
+ {formattedStatus} on: <span> {formattedPublished}</span>
76
+ </p>
64
77
  )}
78
+
65
79
  <p>
66
80
  Created: <span>{formattedCreated}</span>
67
81
  </p>
@@ -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
+ };