@abgov/jsonforms-components 1.21.1 → 1.22.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.
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, 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, scopeEndsWith, 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';
@@ -2871,6 +2871,20 @@ const fetchRegister = props => __awaiter(void 0, void 0, void 0, function* () {
2871
2871
  }
2872
2872
  return undefined;
2873
2873
  });
2874
+ const validateUrl = props => __awaiter(void 0, void 0, void 0, function* () {
2875
+ const {
2876
+ url
2877
+ } = props;
2878
+ if (url) {
2879
+ try {
2880
+ yield axios.get(url);
2881
+ return true;
2882
+ } catch (err) {
2883
+ console.warn(`Error in fetching data from remote: ${err}`);
2884
+ return false;
2885
+ }
2886
+ } else return false;
2887
+ });
2874
2888
 
2875
2889
  const JsonFormsRegisterContext = /*#__PURE__*/createContext(undefined);
2876
2890
  const JsonFormRegisterProvider = ({
@@ -5749,6 +5763,72 @@ const GoAArrayControlTester = rankWith(3, or(isObjectArrayControl, isPrimitiveAr
5749
5763
  const GoAArrayControlRenderer = withJsonFormsArrayLayoutProps(ArrayControl);
5750
5764
  const GoAListWithDetailsTester = rankWith(3, and(uiTypeIs('ListWithDetail')));
5751
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
+
5752
5832
  const GoATextCell = props => jsx(GoAInputText, Object.assign({}, props));
5753
5833
  const GoATextCellTester = rankWith(1, isStringControl);
5754
5834
  withJsonFormsCellProps(GoATextCell);
@@ -6180,6 +6260,9 @@ const GoABaseRenderers = [
6180
6260
  {
6181
6261
  tester: GoAEnumControlTester,
6182
6262
  renderer: GoAEnumControl
6263
+ }, {
6264
+ tester: GoALinkControlTester,
6265
+ renderer: linkControl
6183
6266
  }, {
6184
6267
  tester: GoAIntegerControlTester,
6185
6268
  renderer: GoAInputIntegerControl
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "1.21.1",
3
+ "version": "1.22.0",
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",
@@ -1,2 +1,7 @@
1
1
  import { RegisterConfig } from './actions';
2
2
  export declare const fetchRegister: (props: RegisterConfig) => Promise<any[] | undefined>;
3
+ interface Validate {
4
+ url?: string;
5
+ }
6
+ export declare const validateUrl: (props: Validate) => Promise<boolean>;
7
+ export {};
@@ -0,0 +1,9 @@
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;