@gpa-gemstone/react-forms 1.1.99 → 1.1.100

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.
@@ -1,6 +1,6 @@
1
1
  import { IProps as ISearchableSelectProps } from './SearchableSelect';
2
2
  import { Gemstone } from '@gpa-gemstone/application-typings';
3
- interface IProps<T> extends Omit<ISearchableSelectProps<T>, 'Valid' | 'Feedback' | 'GetLabel'> {
3
+ interface IProps<T> extends Omit<ISearchableSelectProps<T>, 'Valid' | 'Feedback' | 'GetLabel' | 'Setter'> {
4
4
  /**
5
5
  * Default value to use when adding an item and when value is null
6
6
  * @type {number}
@@ -30,6 +30,11 @@ interface IProps<T> extends Omit<ISearchableSelectProps<T>, 'Valid' | 'Feedback'
30
30
  * Flag to disable all input fields
31
31
  */
32
32
  Disabled?: boolean;
33
+ /**
34
+ * Setter function to update the Record
35
+ * @param record - Updated Record
36
+ */
37
+ Setter: (record: T, selectedOption?: Gemstone.TSX.Interfaces.ILabelValue<string | number>) => void;
33
38
  }
34
39
  declare function MultiSearchableSelect<T>(props: IProps<T>): JSX.Element;
35
40
  export default MultiSearchableSelect;
@@ -68,22 +68,20 @@ function MultiSearchableSelect(props) {
68
68
  : null,
69
69
  React.createElement("button", { className: 'btn', onClick: function () {
70
70
  var _a;
71
- return props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = [props.DefaultValue], _a)));
71
+ return props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = [props.DefaultValue], _a)), { Label: props.DefaultValue.toString(), Value: props.DefaultValue });
72
72
  } },
73
- " ",
74
- React.createElement(gpa_symbols_1.ReactIcons.CirclePlus, null),
75
- " ")),
73
+ React.createElement(gpa_symbols_1.ReactIcons.CirclePlus, null))),
76
74
  React.createElement(ToolTip_1.default, { Show: showHelp && props.Help != null, Target: guid, Class: "info", Position: "top" }, props.Help))
77
75
  : null,
78
76
  fieldArray.map(function (r, index) {
79
77
  var _a, _b, _c, _d, _e, _f;
80
78
  return (React.createElement("div", { className: 'row align-items-center', key: index },
81
79
  React.createElement("div", { className: 'col-10' },
82
- React.createElement(SearchableSelect_1.default, { Record: fieldArray, Field: index, Label: index === 0 ? props.Label : '', Help: index === 0 ? props.Help : undefined, Feedback: (_b = (_a = props.ItemFeedback) === null || _a === void 0 ? void 0 : _a.call(props, r, index, fieldArray)) !== null && _b !== void 0 ? _b : undefined, Valid: function () { var _a, _b; return (_b = (_a = props.ItemValid) === null || _a === void 0 ? void 0 : _a.call(props, r, index, fieldArray)) !== null && _b !== void 0 ? _b : true; }, Style: props.Style, Disabled: props.Disabled, Setter: function (record) {
80
+ React.createElement(SearchableSelect_1.default, { Record: fieldArray, Field: index, Label: index === 0 ? props.Label : '', Help: index === 0 ? props.Help : undefined, Feedback: (_b = (_a = props.ItemFeedback) === null || _a === void 0 ? void 0 : _a.call(props, r, index, fieldArray)) !== null && _b !== void 0 ? _b : undefined, Valid: function () { var _a, _b; return (_b = (_a = props.ItemValid) === null || _a === void 0 ? void 0 : _a.call(props, r, index, fieldArray)) !== null && _b !== void 0 ? _b : true; }, Style: props.Style, Disabled: props.Disabled, Setter: function (record, option) {
83
81
  var _a;
84
82
  var newArray = __spreadArray([], fieldArray, true);
85
83
  newArray[index] = record[index];
86
- props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = newArray, _a)));
84
+ props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = newArray, _a)), option);
87
85
  }, Search: props.Search, BtnStyle: props.BtnStyle, GetLabel: props.GetLabel != null ? function () { return props.GetLabel(fieldArray[index], index); } : undefined, ResetSearchOnSelect: props.ResetSearchOnSelect, AllowCustom: props.AllowCustom })),
88
86
  React.createElement("div", { className: "col-".concat(index === __spreadArray([], fieldArray, true).length - 1 ? 1 : 2, " ").concat(index === 0 ? 'd-flex align-items-center' : '') },
89
87
  React.createElement("button", { className: 'btn', style: ((_c = props.Disabled) !== null && _c !== void 0 ? _c : false) ? { display: 'none' } : undefined, onClick: function () {
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { Gemstone } from '@gpa-gemstone/application-typings';
3
- export interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
3
+ export interface IProps<T> extends Omit<Gemstone.TSX.Interfaces.IBaseFormProps<T>, 'Setter'> {
4
4
  /**
5
5
  * Function to determine the validity of a field
6
6
  * @param field - Field of the record to check
@@ -42,5 +42,10 @@ export interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
42
42
  * Flag to reset search text to an empty string when a user selects an option or when the element loses focus. Defaulting to false
43
43
  */
44
44
  ResetSearchOnSelect?: boolean;
45
+ /**
46
+ * Setter function to update the Record
47
+ * @param record - Updated Record
48
+ */
49
+ Setter: (record: T, selectedOption: Gemstone.TSX.Interfaces.ILabelValue<string | number>) => void;
45
50
  }
46
51
  export default function SearchableSelect<T>(props: IProps<T>): JSX.Element;
@@ -35,7 +35,7 @@ function SearchableSelect(props) {
35
35
  var _c = React.useState(false), loading = _c[0], setLoading = _c[1];
36
36
  var setter = React.useCallback(function (record, selectedOption) {
37
37
  handleSetSearch(selectedOption);
38
- props.Setter(record);
38
+ props.Setter(record, { Label: selectedOption.Element, Value: selectedOption.Value }); //we know Element is a string as we set this ourselves
39
39
  }, [props.Setter, props.Field]);
40
40
  var handleSetSearch = React.useCallback(function (selectedOption) {
41
41
  var _a, _b, _c;
package/lib/Select.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Gemstone } from '@gpa-gemstone/application-typings';
2
- interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
2
+ interface IProps<T> extends Omit<Gemstone.TSX.Interfaces.IBaseFormProps<T>, 'Setter'> {
3
3
  /**
4
4
  * Options for the select dropdown
5
5
  * @type {{ Value: string; Label: string }[]}
@@ -17,6 +17,11 @@ interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
17
17
  * @optional
18
18
  */
19
19
  EmptyLabel?: string;
20
+ /**
21
+ * Setter function to update the Record
22
+ * @param record - Updated Record
23
+ */
24
+ Setter: (record: T, selectedOption: Gemstone.TSX.Interfaces.ILabelValue<string | number>) => void;
20
25
  }
21
26
  export default function Select<T>(props: IProps<T>): JSX.Element;
22
27
  export {};
package/lib/Select.js CHANGED
@@ -49,13 +49,14 @@ function Select(props) {
49
49
  var _a;
50
50
  var currentValue = GetRecordValue();
51
51
  if (!((_a = props.EmptyOption) !== null && _a !== void 0 ? _a : false) && props.Options.length > 0 && props.Options.findIndex(function (option) { return option.Value == currentValue; }) === -1) {
52
- SetRecord(props.Options[0].Value);
52
+ var option = props.Options[0];
53
+ SetRecord(option.Value, option);
53
54
  // tslint:disable-next-line
54
55
  console.warn("The current value is not available as an option. Specify EmptyOption=true if the value should be allowed.");
55
56
  }
56
57
  }, [props.Options]);
57
58
  // Update the parent component's state with the new value.
58
- function SetRecord(value) {
59
+ function SetRecord(value, option) {
59
60
  var _a, _b;
60
61
  var record = __assign({}, props.Record);
61
62
  if (value !== '') {
@@ -65,7 +66,7 @@ function Select(props) {
65
66
  else
66
67
  record[props.Field] = null;
67
68
  if (record[props.Field] != props.Record[props.Field])
68
- props.Setter(record);
69
+ props.Setter(record, option);
69
70
  }
70
71
  // Rretrieve the current value of the select field from the record.
71
72
  function GetRecordValue() {
@@ -85,7 +86,11 @@ function Select(props) {
85
86
  showHelpIcon ?
86
87
  React.createElement(ToolTip_1.default, { Show: showHelp, Target: guid, Class: "info", Position: "top" }, props.Help)
87
88
  : null,
88
- React.createElement("select", { className: "form-control", onChange: function (evt) { return SetRecord(evt.target.value); }, value: GetRecordValue(), disabled: props.Disabled == null ? false : props.Disabled },
89
+ React.createElement("select", { className: "form-control", onChange: function (evt) {
90
+ var val = evt.target.value;
91
+ var option = props.Options.find(function (op) { return op.Value == val; });
92
+ SetRecord(val, option);
93
+ }, value: GetRecordValue(), disabled: props.Disabled == null ? false : props.Disabled },
89
94
  ((_a = props.EmptyOption) !== null && _a !== void 0 ? _a : false) ? React.createElement("option", { value: "" }, props.EmptyLabel !== undefined ? props.EmptyLabel : '') : null,
90
95
  props.Options.map(function (a, i) { return (React.createElement("option", { key: i, value: a.Value }, a.Label)); }))));
91
96
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gpa-gemstone/react-forms",
3
- "version": "1.1.99",
3
+ "version": "1.1.100",
4
4
  "description": "React Form modules for gpa webapps",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -46,7 +46,7 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "@gpa-gemstone/application-typings": "0.0.88",
49
- "@gpa-gemstone/gpa-symbols": "0.0.55",
49
+ "@gpa-gemstone/gpa-symbols": "0.0.56",
50
50
  "@gpa-gemstone/helper-functions": "0.0.46",
51
51
  "@types/react": "^17.0.14",
52
52
  "@types/styled-components": "^5.1.11",