@abgov/jsonforms-components 1.22.1 → 1.22.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.
package/index.esm.js CHANGED
@@ -4,7 +4,7 @@ import { GoAFormItem, GoAInput, GoATextArea, GoACallout, GoAInputDate, GoAInputD
4
4
  import styled from 'styled-components';
5
5
  import axios from 'axios';
6
6
  import get$1 from 'lodash/get';
7
- import { rankWith, isStringControl, and, optionIs, uiTypeIs, isDateControl, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, getAjv, isVisible, isEnabled, deriveLabelForUISchemaElement, schemaTypeIs, formatIs, createDefaultValue, Paths, or, isObjectArrayControl, isPrimitiveArrayControl, scopeEndsWith, withIncreasedRank, hasType, isControl as isControl$1, isCategorization, isLayout as isLayout$1 } from '@jsonforms/core';
7
+ import { rankWith, isStringControl, and, optionIs, uiTypeIs, isDateControl, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, getAjv, isVisible, isEnabled, deriveLabelForUISchemaElement, schemaTypeIs, formatIs, createDefaultValue, Paths, or, isObjectArrayControl, isPrimitiveArrayControl, withIncreasedRank, hasType, isControl as isControl$1, isCategorization, isLayout as isLayout$1 } from '@jsonforms/core';
8
8
  import { withJsonFormsControlProps, withJsonFormsRendererProps, withJsonFormsEnumProps, withTranslateProps, useJsonForms, JsonFormsDispatch, withJsonFormsLayoutProps, withJsonFormsArrayLayoutProps, withJsonFormsCellProps } from '@jsonforms/react';
9
9
  import merge from 'lodash/merge';
10
10
  import isEmpty$1 from 'lodash/isEmpty';
@@ -5763,72 +5763,6 @@ const GoAArrayControlTester = rankWith(3, or(isObjectArrayControl, isPrimitiveAr
5763
5763
  const GoAArrayControlRenderer = withJsonFormsArrayLayoutProps(ArrayControl);
5764
5764
  const GoAListWithDetailsTester = rankWith(3, and(uiTypeIs('ListWithDetail')));
5765
5765
 
5766
- const linkLength = 40;
5767
- const invalidExtensions = ['exe'];
5768
- const LinkSelect = props => {
5769
- var _a, _b;
5770
- const componentProps = (_b = (_a = props === null || props === void 0 ? void 0 : props.uischema) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.componentProps;
5771
- const {
5772
- link,
5773
- label,
5774
- heading,
5775
- description
5776
- } = componentProps;
5777
- const [linkValid, setLinkValid] = useState(null);
5778
- let error = undefined;
5779
- let linkLabel = (link === null || link === void 0 ? void 0 : link.length) > linkLength ? `${link === null || link === void 0 ? void 0 : link.slice(0, linkLength)}...` : link;
5780
- let linkUrl = link;
5781
- if (label) {
5782
- linkLabel = label;
5783
- }
5784
- const count = link === null || link === void 0 ? void 0 : link.split('.').length;
5785
- const extension = link === null || link === void 0 ? void 0 : link.split('.')[count - 1];
5786
- if (invalidExtensions.includes(extension)) {
5787
- linkUrl = null;
5788
- linkLabel = '';
5789
- error = `Invalid extension: ${extension}`;
5790
- }
5791
- useEffect(() => {
5792
- function validateLink(linkUrl) {
5793
- return __awaiter(this, void 0, void 0, function* () {
5794
- if (linkUrl) {
5795
- const response = yield validateUrl({
5796
- url: linkUrl
5797
- });
5798
- setLinkValid(response);
5799
- }
5800
- });
5801
- }
5802
- validateLink(linkUrl);
5803
- }, [linkUrl]);
5804
- if (!linkLabel && !error) {
5805
- linkLabel = 'Link';
5806
- }
5807
- if (linkValid === false) {
5808
- linkLabel = '';
5809
- error = 'Invalid Link';
5810
- }
5811
- return jsx(GoAFormItem, {
5812
- error: error,
5813
- label: heading,
5814
- children: jsxs("div", {
5815
- "data-testid": "link-jsonform",
5816
- children: [description && jsx("div", {
5817
- children: description
5818
- }), linkUrl && linkValid ? jsx("a", {
5819
- href: link,
5820
- target: "_blank",
5821
- rel: "noreferrer",
5822
- children: linkLabel
5823
- }) : linkLabel]
5824
- })
5825
- });
5826
- };
5827
- const linkControl = props => {
5828
- return jsx(LinkSelect, Object.assign({}, props));
5829
- };
5830
- const GoALinkControlTester = rankWith(2, scopeEndsWith('link'));
5831
-
5832
5766
  const GoATextCell = props => jsx(GoAInputText, Object.assign({}, props));
5833
5767
  const GoATextCellTester = rankWith(1, isStringControl);
5834
5768
  withJsonFormsCellProps(GoATextCell);
@@ -5989,8 +5923,65 @@ const HelpContentDiv = styled.div(_t || (_t = _`
5989
5923
  }
5990
5924
  `));
5991
5925
 
5926
+ const linkLength = 40;
5927
+ const invalidExtensions = ['exe'];
5928
+ const RenderLink = props => {
5929
+ var _a;
5930
+ const {
5931
+ link,
5932
+ help
5933
+ } = props;
5934
+ const [linkValid, setLinkValid] = useState(null);
5935
+ let error = undefined;
5936
+ let linkLabel = link && (link === null || link === void 0 ? void 0 : link.length) > linkLength ? `${link === null || link === void 0 ? void 0 : link.slice(0, linkLength)}...` : link;
5937
+ let linkUrl = link;
5938
+ if (help) {
5939
+ linkLabel = help;
5940
+ }
5941
+ const count = ((_a = link === null || link === void 0 ? void 0 : link.split('.')) === null || _a === void 0 ? void 0 : _a.length) || 0;
5942
+ const extension = link === null || link === void 0 ? void 0 : link.split('.')[count - 1];
5943
+ if (invalidExtensions.includes(extension || '')) {
5944
+ linkUrl = '';
5945
+ linkLabel = '';
5946
+ error = `Invalid extension: ${extension}`;
5947
+ }
5948
+ useEffect(() => {
5949
+ function validateLink(linkUrl) {
5950
+ return __awaiter(this, void 0, void 0, function* () {
5951
+ if (linkUrl) {
5952
+ const response = yield validateUrl({
5953
+ url: linkUrl
5954
+ });
5955
+ setLinkValid(response);
5956
+ }
5957
+ });
5958
+ }
5959
+ validateLink(linkUrl);
5960
+ }, [linkUrl]);
5961
+ if (!linkLabel && !error) {
5962
+ linkLabel = 'Link';
5963
+ }
5964
+ if (linkValid === false) {
5965
+ linkLabel = '';
5966
+ error = 'Invalid Link';
5967
+ }
5968
+ return jsx(GoAFormItem, {
5969
+ error: error,
5970
+ label: "",
5971
+ children: jsx("div", {
5972
+ "data-testid": "link-jsonform",
5973
+ children: linkUrl && linkValid ? jsx("a", {
5974
+ href: link,
5975
+ target: "_blank",
5976
+ rel: "noreferrer",
5977
+ children: linkLabel
5978
+ }) : linkLabel
5979
+ })
5980
+ });
5981
+ };
5982
+
5992
5983
  const HelpContentComponent = _a => {
5993
- var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
5984
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
5994
5985
  var {
5995
5986
  isParent = true
5996
5987
  } = _a,
@@ -6003,6 +5994,7 @@ const HelpContentComponent = _a => {
6003
5994
  visible,
6004
5995
  label
6005
5996
  } = props;
5997
+ const link = (_b = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _b === void 0 ? void 0 : _b.link;
6006
5998
  const renderHelp = () => {
6007
5999
  var _a, _b, _c;
6008
6000
  return Array.isArray((_a = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _a === void 0 ? void 0 : _a.help) ? jsx("ul", {
@@ -6030,21 +6022,21 @@ const HelpContentComponent = _a => {
6030
6022
  return jsx(Visible, {
6031
6023
  visible: visible,
6032
6024
  children: jsx(HelpContentDiv, {
6033
- "aria-label": (_b = uischema.options) === null || _b === void 0 ? void 0 : _b.ariaLabel,
6025
+ "aria-label": (_c = uischema.options) === null || _c === void 0 ? void 0 : _c.ariaLabel,
6034
6026
  children: jsxs("div", {
6035
6027
  className: marginClass,
6036
- children: [label && !((_c = uischema.options) === null || _c === void 0 ? void 0 : _c.variant) && ((_d = uischema.options) === null || _d === void 0 ? void 0 : _d.variant) !== 'details' && jsxs("div", {
6028
+ children: [label && !((_d = uischema.options) === null || _d === void 0 ? void 0 : _d.variant) && ((_e = uischema.options) === null || _e === void 0 ? void 0 : _e.variant) !== 'details' && jsxs("div", {
6037
6029
  className: labelClass,
6038
6030
  "data-testid": label,
6039
6031
  children: [label, jsx("br", {})]
6040
- }), ((_e = uischema.options) === null || _e === void 0 ? void 0 : _e.img) && ((_f = uischema.options) === null || _f === void 0 ? void 0 : _f.img) !== '' && renderImage(uischema.options), (!((_g = uischema.options) === null || _g === void 0 ? void 0 : _g.variant) || ((_h = uischema.options) === null || _h === void 0 ? void 0 : _h.variant) !== 'details') && renderHelp(), ((_j = uischema.options) === null || _j === void 0 ? void 0 : _j.variant) && ((_k = uischema.options) === null || _k === void 0 ? void 0 : _k.variant) === 'details' && jsxs(GoADetails, {
6032
+ }), ((_f = uischema.options) === null || _f === void 0 ? void 0 : _f.img) && ((_g = uischema.options) === null || _g === void 0 ? void 0 : _g.img) !== '' && renderImage(uischema.options), ((_h = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _h === void 0 ? void 0 : _h.link) && link !== '' && RenderLink(uischema === null || uischema === void 0 ? void 0 : uischema.options), (!((_j = uischema.options) === null || _j === void 0 ? void 0 : _j.variant) || ((_k = uischema.options) === null || _k === void 0 ? void 0 : _k.variant) !== 'details') && !link && renderHelp(), ((_l = uischema.options) === null || _l === void 0 ? void 0 : _l.variant) && ((_m = uischema.options) === null || _m === void 0 ? void 0 : _m.variant) === 'details' && jsxs(GoADetails, {
6041
6033
  heading: label ? label : '',
6042
6034
  mt: "3xs",
6043
6035
  mb: "none",
6044
- children: [renderHelp(), (uischema === null || uischema === void 0 ? void 0 : uischema.elements) && ((_l = uischema === null || uischema === void 0 ? void 0 : uischema.elements) === null || _l === void 0 ? void 0 : _l.length) > 0 && jsx(HelpContents, {
6036
+ children: [renderHelp(), (uischema === null || uischema === void 0 ? void 0 : uischema.elements) && ((_o = uischema === null || uischema === void 0 ? void 0 : uischema.elements) === null || _o === void 0 ? void 0 : _o.length) > 0 && jsx(HelpContents, {
6045
6037
  elements: uischema === null || uischema === void 0 ? void 0 : uischema.elements
6046
6038
  })]
6047
- }), (uischema === null || uischema === void 0 ? void 0 : uischema.elements) && (uischema === null || uischema === void 0 ? void 0 : uischema.elements.length) > 0 && ((_m = uischema.options) === null || _m === void 0 ? void 0 : _m.variant) !== 'details' && jsx(HelpContents, {
6039
+ }), (uischema === null || uischema === void 0 ? void 0 : uischema.elements) && (uischema === null || uischema === void 0 ? void 0 : uischema.elements.length) > 0 && ((_p = uischema.options) === null || _p === void 0 ? void 0 : _p.variant) !== 'details' && jsx(HelpContents, {
6048
6040
  elements: uischema.elements,
6049
6041
  isParent: false
6050
6042
  })]
@@ -6255,9 +6247,6 @@ const GoABaseRenderers = [
6255
6247
  {
6256
6248
  tester: GoAEnumControlTester,
6257
6249
  renderer: GoAEnumControl
6258
- }, {
6259
- tester: GoALinkControlTester,
6260
- renderer: linkControl
6261
6250
  }, {
6262
6251
  tester: GoAIntegerControlTester,
6263
6252
  renderer: GoAInputIntegerControl
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "1.22.1",
3
+ "version": "1.22.2",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Government of Alberta - React renderers for JSON Forms based on the design system.",
6
6
  "repository": "https://github.com/GovAlta/adsp-monorepo",
@@ -9,6 +9,7 @@ interface OptionProps {
9
9
  alt?: string;
10
10
  height?: string;
11
11
  width?: string;
12
+ link?: string;
12
13
  }
13
14
  interface CustomControlElement extends ControlElement {
14
15
  options?: OptionProps;
@@ -0,0 +1,11 @@
1
+ export interface OptionProps {
2
+ ariaLabel?: string;
3
+ help?: string | string[];
4
+ variant?: string;
5
+ img?: string;
6
+ alt?: string;
7
+ height?: string;
8
+ width?: string;
9
+ link?: string;
10
+ }
11
+ export declare const RenderLink: (props: OptionProps) => JSX.Element;
@@ -1,9 +0,0 @@
1
- import { ControlProps, RankedTester } from '@jsonforms/core';
2
- import { TranslateProps } from '@jsonforms/react';
3
- import { WithInputProps } from '../Inputs/type';
4
- import { WithOptionLabel } from '../../util';
5
- import { WithClassname } from '@jsonforms/core';
6
- export type LinkSelectProps = WithClassname & TranslateProps & WithInputProps & ControlProps;
7
- export declare const LinkSelect: (props: LinkSelectProps) => JSX.Element;
8
- export declare const linkControl: (props: ControlProps & WithOptionLabel & TranslateProps) => import("react/jsx-runtime").JSX.Element;
9
- export declare const GoALinkControlTester: RankedTester;