@evoke-platform/ui-components 1.10.0-dev.31 → 1.10.0-dev.32

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.
@@ -42,7 +42,8 @@ export const Document = (props) => {
42
42
  if (canUpdateProperty) {
43
43
  apiServices
44
44
  .get(getPrefixedUrl(`/objects/${objectId}/instances/${instance.id}/documents/checkAccess?action=update`))
45
- .then((accessCheck) => setHasUpdatePermission(accessCheck.result));
45
+ .then((accessCheck) => setHasUpdatePermission(accessCheck.result))
46
+ .catch(() => setHasUpdatePermission(false));
46
47
  }
47
48
  };
48
49
  const handleUpload = async (files) => {
@@ -70,9 +70,8 @@ function FormRendererContainer(props) {
70
70
  }
71
71
  else {
72
72
  if (instanceId) {
73
- objectStore.getInstance(instanceId).then((instance) => {
74
- setInstance(instance);
75
- });
73
+ const instance = await objectStore.getInstance(instanceId);
74
+ setInstance(instance);
76
75
  }
77
76
  const object = await apiServices.get(getPrefixedUrl(`/objects/${form?.objectId || objectId}${instanceId ? `/instances/${instanceId}/object` : '/effective'}`), { params: { sanitizedVersion: true } });
78
77
  setSanitizedObject(object);
@@ -42,6 +42,12 @@ export const Document = (props) => {
42
42
  [`${id}UpdatePermission`]: accessCheck.result,
43
43
  });
44
44
  setHasUpdatePermission(accessCheck.result);
45
+ })
46
+ .catch(() => {
47
+ setFetchedOptions({
48
+ [`${id}UpdatePermission`]: false,
49
+ });
50
+ setHasUpdatePermission(false);
45
51
  });
46
52
  }
47
53
  }, [canUpdateProperty, fetchedOptions, instance, object]);
@@ -631,6 +631,325 @@ describe('FormRendererContainer', () => {
631
631
  await user.click(discardButton);
632
632
  await waitFor(() => expect(firstNameInput).toHaveValue(''));
633
633
  });
634
+ it('should show a not found error if the instance cannot be found', async () => {
635
+ const form = {
636
+ id: 'simpleForm',
637
+ name: 'Simple Form',
638
+ entries: [
639
+ {
640
+ type: 'inputField',
641
+ input: {
642
+ id: 'name',
643
+ type: 'string',
644
+ },
645
+ display: {
646
+ label: 'Name',
647
+ },
648
+ },
649
+ ],
650
+ actionId: '_update',
651
+ objectId: 'simpleObject',
652
+ };
653
+ const simpleObject = {
654
+ id: 'simpleObject',
655
+ name: 'Simple Object',
656
+ actions: [
657
+ {
658
+ id: '_update',
659
+ name: 'Update',
660
+ type: 'update',
661
+ parameters: [
662
+ {
663
+ id: 'name',
664
+ name: 'Name',
665
+ type: 'string',
666
+ },
667
+ ],
668
+ outputEvent: 'updated',
669
+ },
670
+ ],
671
+ properties: [
672
+ {
673
+ id: 'name',
674
+ name: 'Name',
675
+ type: 'string',
676
+ },
677
+ ],
678
+ };
679
+ server.use(http.get(`/api/data/objects/simpleObject/effective`, () => HttpResponse.json(simpleObject)), http.get(`/api/data/forms/simpleForm`, () => HttpResponse.json(form)), http.get('/api/data/objects/simpleObject/instances/123', () => HttpResponse.json({
680
+ message: 'Not Found',
681
+ }, { status: 404 })), http.get('/api/data/objects/simpleObject/instances/123/object', () => HttpResponse.json({
682
+ message: 'Not Found',
683
+ }, { status: 404 })));
684
+ render(React.createElement(FormRendererContainer, { formId: form.id, actionId: "_update", objectId: "simpleObject", instanceId: '123', dataType: "objectInstances" }));
685
+ await screen.findByText('The requested content could not be found.');
686
+ });
687
+ it('should show an unauthorized error if the instance access is unauthorized', async () => {
688
+ const form = {
689
+ id: 'simpleForm',
690
+ name: 'Simple Form',
691
+ entries: [
692
+ {
693
+ type: 'inputField',
694
+ input: {
695
+ id: 'name',
696
+ type: 'string',
697
+ },
698
+ display: {
699
+ label: 'Name',
700
+ },
701
+ },
702
+ ],
703
+ actionId: '_create',
704
+ objectId: 'simpleObject',
705
+ };
706
+ const simpleObject = {
707
+ id: 'simpleObject',
708
+ name: 'Simple Object',
709
+ actions: [
710
+ {
711
+ id: '_create',
712
+ name: 'Create',
713
+ type: 'create',
714
+ parameters: [
715
+ {
716
+ id: 'name',
717
+ name: 'Name',
718
+ type: 'string',
719
+ },
720
+ ],
721
+ outputEvent: 'created',
722
+ },
723
+ ],
724
+ properties: [
725
+ {
726
+ id: 'name',
727
+ name: 'Name',
728
+ type: 'string',
729
+ },
730
+ ],
731
+ };
732
+ server.use(http.get(`/api/data/objects/simpleObject/effective`, () => HttpResponse.json(simpleObject)), http.get(`/api/data/forms/simpleForm`, () => HttpResponse.json(form)), http.get('/api/data/objects/simpleObject/instances/123', () => HttpResponse.json({
733
+ message: 'Unauthorized',
734
+ }, { status: 403 })), http.get('/api/data/objects/simpleObject/instances/123/object', () => HttpResponse.json({
735
+ message: 'Unauthorized',
736
+ }, { status: 403 })));
737
+ render(React.createElement(FormRendererContainer, { formId: form.id, actionId: "_create", objectId: "simpleObject", instanceId: '123', dataType: "objectInstances" }));
738
+ await screen.findByText('You do not have permission to view this content.');
739
+ });
740
+ it('should show a misconfiguration error when action with actionId does not exist', async () => {
741
+ const simpleObject = {
742
+ id: 'simpleObject',
743
+ name: 'Simple Object',
744
+ actions: [],
745
+ properties: [],
746
+ };
747
+ server.use(http.get(`/api/data/objects/simpleObject/effective`, () => HttpResponse.json(simpleObject)));
748
+ render(React.createElement(FormRendererContainer, { objectId: "simpleObject", actionId: "_create", dataType: "objectInstances" }));
749
+ await screen.findByText('It looks like something is missing.');
750
+ });
751
+ it('should show a not found error when object cannot be found', async () => {
752
+ server.use(http.get(`/api/data/objects/simpleObject/effective`, () => HttpResponse.json({ error: 'Not Found' }, { status: 404 })));
753
+ render(React.createElement(FormRendererContainer, { objectId: "simpleObject", dataType: "objectInstances" }));
754
+ await screen.findByText('The requested content could not be found.');
755
+ });
756
+ describe('when trying to show a specific form', () => {
757
+ it("should not show the action's default form", async () => {
758
+ const form = {
759
+ id: 'simpleForm',
760
+ name: 'Simple Form',
761
+ entries: [],
762
+ actionId: '_create',
763
+ objectId: 'simpleObject',
764
+ };
765
+ const simpleObject = {
766
+ id: 'simpleObject',
767
+ name: 'Simple Object',
768
+ actions: [
769
+ {
770
+ id: '_create',
771
+ name: 'Create',
772
+ type: 'create',
773
+ parameters: [],
774
+ outputEvent: 'created',
775
+ defaultFormId: 'notSimpleForm',
776
+ },
777
+ ],
778
+ properties: [],
779
+ };
780
+ server.use(http.get(`/api/data/objects/simpleObject/effective`, () => HttpResponse.json(simpleObject)), http.get(`/api/data/forms/simpleForm`, () => HttpResponse.json(form)));
781
+ render(React.createElement(FormRendererContainer, { formId: form.id, objectId: "simpleObject", dataType: "objectInstances" }));
782
+ await screen.findByText('Simple Form');
783
+ });
784
+ it('should show a not found error when the form cannot be found', async () => {
785
+ const simpleObject = {
786
+ id: 'simpleObject',
787
+ name: 'Simple Object',
788
+ actions: [
789
+ {
790
+ id: '_create',
791
+ name: 'Create',
792
+ type: 'create',
793
+ parameters: [],
794
+ outputEvent: 'created',
795
+ },
796
+ ],
797
+ properties: [],
798
+ };
799
+ server.use(http.get(`/api/data/objects/simpleObject/effective`, () => HttpResponse.json(simpleObject)), http.get(`/api/data/forms/notAForm`, () => HttpResponse.json({ error: 'Not Found' }, { status: 404 })));
800
+ render(React.createElement(FormRendererContainer, { formId: 'notAForm', objectId: "simpleObject", dataType: "objectInstances" }));
801
+ await screen.findByText('The requested content could not be found.');
802
+ });
803
+ it("should show a misconfiguration error when the form's action does not exist", async () => {
804
+ const form = {
805
+ id: 'simpleForm',
806
+ name: 'Simple Form',
807
+ entries: [],
808
+ actionId: '_create',
809
+ objectId: 'simpleObject',
810
+ };
811
+ const simpleObject = {
812
+ id: 'simpleObject',
813
+ name: 'Simple Object',
814
+ actions: [
815
+ {
816
+ id: 'notTheRightAction',
817
+ name: 'Create',
818
+ type: 'create',
819
+ parameters: [],
820
+ outputEvent: 'created',
821
+ },
822
+ ],
823
+ properties: [],
824
+ };
825
+ server.use(http.get(`/api/data/objects/simpleObject/effective`, () => HttpResponse.json(simpleObject)), http.get(`/api/data/forms/simpleForm`, () => HttpResponse.json(form)));
826
+ render(React.createElement(FormRendererContainer, { formId: form.id, objectId: "simpleObject", dataType: "objectInstances" }));
827
+ await screen.findByText('It looks like something is missing.');
828
+ });
829
+ it("should show a misconfiguration error when actionId doesn't match form's action id", async () => {
830
+ const form = {
831
+ id: 'simpleForm',
832
+ name: 'Simple Form',
833
+ entries: [],
834
+ actionId: '_notCreate',
835
+ objectId: 'simpleObject',
836
+ };
837
+ const simpleObject = {
838
+ id: 'simpleObject',
839
+ name: 'Simple Object',
840
+ actions: [
841
+ {
842
+ id: '_create',
843
+ name: 'Create',
844
+ type: 'create',
845
+ parameters: [],
846
+ outputEvent: 'created',
847
+ },
848
+ ],
849
+ properties: [],
850
+ };
851
+ server.use(http.get(`/api/data/objects/simpleObject/effective`, () => HttpResponse.json(simpleObject)), http.get(`/api/data/forms/simpleForm`, () => HttpResponse.json(form)));
852
+ render(React.createElement(FormRendererContainer, { formId: form.id, objectId: "simpleObject", actionId: "_create", dataType: "objectInstances" }));
853
+ await screen.findByText('It looks like something is missing.');
854
+ });
855
+ });
856
+ describe('when trying to show a default form', () => {
857
+ // object id and action id are provided, but form id is not => use default form
858
+ it('should use the default form when provided with an object and action with a default form id', async () => {
859
+ const form = {
860
+ id: 'simpleForm',
861
+ name: 'Simple Form',
862
+ entries: [],
863
+ actionId: '_create',
864
+ objectId: 'simpleObject',
865
+ };
866
+ const simpleObject = {
867
+ id: 'simpleObject',
868
+ name: 'Simple Object',
869
+ actions: [
870
+ {
871
+ id: '_create',
872
+ name: 'Create',
873
+ type: 'create',
874
+ parameters: [],
875
+ outputEvent: 'created',
876
+ defaultFormId: 'simpleForm',
877
+ },
878
+ ],
879
+ properties: [],
880
+ };
881
+ server.use(http.get(`/api/data/objects/simpleObject/effective`, () => HttpResponse.json(simpleObject)), http.get(`/api/data/forms/simpleForm`, () => HttpResponse.json(form)));
882
+ render(React.createElement(FormRendererContainer, { objectId: "simpleObject", actionId: "_create", dataType: "objectInstances" }));
883
+ await screen.findByText('Simple Form');
884
+ });
885
+ // object id and action id are provided, and defaultFormId is defined but the form doesn't exist
886
+ it('should show a not found error when the default form cannot be found', async () => {
887
+ const simpleObject = {
888
+ id: 'simpleObject',
889
+ name: 'Simple Object',
890
+ actions: [
891
+ {
892
+ id: '_create',
893
+ name: 'Create',
894
+ type: 'create',
895
+ parameters: [],
896
+ outputEvent: 'created',
897
+ defaultFormId: 'notAForm',
898
+ },
899
+ ],
900
+ properties: [],
901
+ };
902
+ server.use(http.get(`/api/data/objects/simpleObject/effective`, () => HttpResponse.json(simpleObject)), http.get(`/api/data/forms/notAForm`, () => HttpResponse.json({ error: 'Not Found' }, { status: 404 })));
903
+ render(React.createElement(FormRendererContainer, { objectId: "simpleObject", actionId: "_create", dataType: "objectInstances" }));
904
+ await screen.findByText('The requested content could not be found.');
905
+ });
906
+ it('should show a misconfiguration error when the default form is not defined', async () => {
907
+ const simpleObject = {
908
+ id: 'simpleObject',
909
+ name: 'Simple Object',
910
+ actions: [
911
+ {
912
+ id: '_create',
913
+ name: 'Create',
914
+ type: 'create',
915
+ parameters: [],
916
+ outputEvent: 'created',
917
+ },
918
+ ],
919
+ properties: [],
920
+ };
921
+ server.use(http.get(`/api/data/objects/simpleObject/effective`, () => HttpResponse.json(simpleObject)));
922
+ render(React.createElement(FormRendererContainer, { objectId: "simpleObject", actionId: "_create", dataType: "objectInstances" }));
923
+ await screen.findByText('It looks like something is missing.');
924
+ });
925
+ it("should show a misconfiguration error if actionId doesn't match the form's actionId", async () => {
926
+ const form = {
927
+ id: 'simpleForm',
928
+ name: 'Simple Form',
929
+ entries: [],
930
+ actionId: 'notCreate',
931
+ objectId: 'simpleObject',
932
+ };
933
+ const simpleObject = {
934
+ id: 'simpleObject',
935
+ name: 'Simple Object',
936
+ actions: [
937
+ {
938
+ id: '_create',
939
+ name: 'Create',
940
+ type: 'create',
941
+ parameters: [],
942
+ outputEvent: 'created',
943
+ defaultFormId: 'simpleForm',
944
+ },
945
+ ],
946
+ properties: [],
947
+ };
948
+ server.use(http.get(`/api/data/objects/simpleObject/effective`, () => HttpResponse.json(simpleObject)), http.get(`/api/data/forms/simpleForm`, () => HttpResponse.json(form)));
949
+ render(React.createElement(FormRendererContainer, { objectId: "simpleObject", actionId: "_create", dataType: "objectInstances" }));
950
+ await screen.findByText('It looks like something is missing.');
951
+ });
952
+ });
634
953
  describe('when submitting a form with validation', () => {
635
954
  const form = {
636
955
  id: 'validationTestForm',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evoke-platform/ui-components",
3
- "version": "1.10.0-dev.31",
3
+ "version": "1.10.0-dev.32",
4
4
  "description": "",
5
5
  "main": "dist/published/index.js",
6
6
  "module": "dist/published/index.js",