@tellescope/react-components 1.232.0 → 1.232.1

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 (40) hide show
  1. package/lib/cjs/Forms/forms.v2.d.ts +1 -1
  2. package/lib/cjs/Forms/hooks.d.ts.map +1 -1
  3. package/lib/cjs/Forms/hooks.js +24 -0
  4. package/lib/cjs/Forms/hooks.js.map +1 -1
  5. package/lib/cjs/Forms/inputs.d.ts +4 -1
  6. package/lib/cjs/Forms/inputs.d.ts.map +1 -1
  7. package/lib/cjs/Forms/inputs.js +100 -26
  8. package/lib/cjs/Forms/inputs.js.map +1 -1
  9. package/lib/cjs/Forms/inputs.v2.d.ts +5 -7
  10. package/lib/cjs/Forms/inputs.v2.d.ts.map +1 -1
  11. package/lib/cjs/Forms/inputs.v2.js +7 -234
  12. package/lib/cjs/Forms/inputs.v2.js.map +1 -1
  13. package/lib/esm/CMS/components.d.ts +0 -1
  14. package/lib/esm/CMS/components.d.ts.map +1 -1
  15. package/lib/esm/Forms/form_responses.d.ts +0 -1
  16. package/lib/esm/Forms/form_responses.d.ts.map +1 -1
  17. package/lib/esm/Forms/forms.d.ts +3 -3
  18. package/lib/esm/Forms/forms.v2.d.ts +4 -4
  19. package/lib/esm/Forms/hooks.d.ts +0 -1
  20. package/lib/esm/Forms/hooks.d.ts.map +1 -1
  21. package/lib/esm/Forms/hooks.js +24 -0
  22. package/lib/esm/Forms/hooks.js.map +1 -1
  23. package/lib/esm/Forms/inputs.d.ts +5 -2
  24. package/lib/esm/Forms/inputs.d.ts.map +1 -1
  25. package/lib/esm/Forms/inputs.js +101 -27
  26. package/lib/esm/Forms/inputs.js.map +1 -1
  27. package/lib/esm/Forms/inputs.v2.d.ts +6 -8
  28. package/lib/esm/Forms/inputs.v2.d.ts.map +1 -1
  29. package/lib/esm/Forms/inputs.v2.js +7 -234
  30. package/lib/esm/Forms/inputs.v2.js.map +1 -1
  31. package/lib/esm/controls.d.ts +2 -2
  32. package/lib/esm/inputs.d.ts +1 -1
  33. package/lib/esm/inputs.native.d.ts +0 -1
  34. package/lib/esm/inputs.native.d.ts.map +1 -1
  35. package/lib/esm/state.d.ts +315 -315
  36. package/lib/tsconfig.tsbuildinfo +1 -1
  37. package/package.json +9 -9
  38. package/src/Forms/hooks.tsx +33 -5
  39. package/src/Forms/inputs.tsx +151 -29
  40. package/src/Forms/inputs.v2.tsx +9 -299
@@ -3,7 +3,7 @@ import { SxProps, TextFieldProps } from "@mui/material";
3
3
  import { FormInputProps } from "./types";
4
4
  import { Enduser, FormResponseValue } from "@tellescope/types-models";
5
5
  import { FileBlob, Styled } from "..";
6
- import { DatabaseRecord, FormField } from "@tellescope/types-client";
6
+ import { FormField } from "@tellescope/types-client";
7
7
  export declare const LanguageSelect: ({ value, ...props }: {
8
8
  value: string;
9
9
  onChange: (s: string) => void;
@@ -52,13 +52,11 @@ export declare const Progress: ({ numerator, denominator, style, color }: {
52
52
  color?: string | undefined;
53
53
  } & Styled) => JSX.Element;
54
54
  export declare const DropdownInput: ({ field, value, onChange }: FormInputProps<'Dropdown'>) => JSX.Element;
55
- export interface AddToDatabaseProps {
56
- databaseId: string;
57
- onAdd: (record: DatabaseRecord) => void;
58
- }
59
- export declare const DatabaseSelectInput: ({ AddToDatabase, field, value: _value, onChange, onDatabaseSelect, responses, size, disabled, enduser }: FormInputProps<"Database Select"> & {
55
+ import { AddToDatabaseProps as AddToDatabasePropsImported } from './inputs';
56
+ export type AddToDatabaseProps = AddToDatabasePropsImported;
57
+ export declare const DatabaseSelectInput: (props: FormInputProps<'Database Select'> & {
60
58
  responses: FormResponseValue[];
61
- AddToDatabase?: React.JSXElementConstructor<AddToDatabaseProps> | undefined;
59
+ AddToDatabase?: React.JSXElementConstructor<AddToDatabaseProps>;
62
60
  }) => JSX.Element;
63
61
  export declare const CanvasMedicationsInput: ({ field, value, onChange }: FormInputProps<'Medications'>) => JSX.Element;
64
62
  export declare const MedicationsInput: ({ field, value, onChange, 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AAC,gBAoK3H,CAAA;AAED,eAAO,MAAM,gBAAgB,MAAO,QAAQ,OAAO,CAAC,+FAkBnD,CAAA;AAED,eAAO,MAAM,oBAAoB,qEAAsE,eAAe,kBAAkB,CAAC,gBAiLxI,CAAA;AAED,eAAO,MAAM,uBAAuB,4HAA6H,eAAe,qBAAqB,CAAC,gBAyOrM,CAAA;AAED,eAAO,MAAM,WAAW,yCAAoD,eAAe,QAAQ,CAAC,gBAenG,CAAA;AAED,eAAO,MAAM,2CAA2C,QAAS,MAAM,WAetE,CAAA;AAED,eAAO,MAAM,aAAa,uIAAkJ,eAAe,UAAU,CAAC,uBAkGrM,CAAA;AAED,eAAO,MAAM,gBAAgB,4FAA6F,eAAe,OAAO,CAAC,gBA+ChJ,CAAA;AAED,eAAO,MAAM,WAAW,iGAAkG,eAAe,OAAO,CAAC,gBA8ChJ,CAAA;AAMD,eAAO,MAAM,cAAc,iGAAkG,eAAe,WAAW,CAAC,gBAqHvJ,CAAA;AAGD,eAAO,MAAM,eAAe,iGAAkG,eAAe,YAAY,CAAC,gBAsDzJ,CAAA;AAED,eAAO,MAAM,aAAa,+BAAgC,eAAe,WAAW,CAAC,gBAEpF,CAAA;AAED,eAAO,MAAM,eAAe;mBACX,MAAM,QAAQ,CAAC,MAAM,cAAc,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;iBA6CxE,CAAA"}
@@ -912,240 +912,13 @@ var DropdownInput = function (_a) {
912
912
  } }));
913
913
  };
914
914
  exports.DropdownInput = DropdownInput;
915
- var choicesForDatabase = {};
916
- var preventRefetch = {};
917
- var LOAD_CHOICES_LIMIT = 500;
918
- var useDatabaseChoices = function (_a) {
919
- var _b, _d, _e, _f;
920
- var _g = _a.databaseId, databaseId = _g === void 0 ? '' : _g, field = _a.field, otherAnswers = _a.otherAnswers;
921
- var session = (0, __1.useResolvedSession)();
922
- var _h = (0, react_1.useState)(0), renderCount = _h[0], setRenderCount = _h[1];
923
- // todo: make searchable, don't load all
924
- (0, react_1.useEffect)(function () {
925
- var _a, _b, _d, _e;
926
- if ((_a = choicesForDatabase[databaseId]) === null || _a === void 0 ? void 0 : _a.done)
927
- return;
928
- if (renderCount > 100)
929
- return; // limit to 50000 entries / prevent infinite looping
930
- var choices = (_d = (_b = choicesForDatabase[databaseId]) === null || _b === void 0 ? void 0 : _b.records) !== null && _d !== void 0 ? _d : [];
931
- var lastId = (_e = choicesForDatabase[databaseId]) === null || _e === void 0 ? void 0 : _e.lastId;
932
- if (preventRefetch[databaseId + field.id + lastId])
933
- return;
934
- preventRefetch[databaseId + field.id + lastId] = true;
935
- session.api.form_fields.load_choices_from_database({
936
- fieldId: field.id,
937
- lastId: lastId,
938
- limit: LOAD_CHOICES_LIMIT,
939
- databaseId: databaseId,
940
- })
941
- .then(function (_a) {
942
- var _b;
943
- var newChoices = _a.choices;
944
- choicesForDatabase[databaseId] = {
945
- lastId: (_b = newChoices === null || newChoices === void 0 ? void 0 : newChoices[newChoices.length - 1]) === null || _b === void 0 ? void 0 : _b.id,
946
- records: __spreadArray(__spreadArray([], choices, true), newChoices, true).sort(function (c1, c2) { return (label_for_database_record(field, c1)
947
- .localeCompare(label_for_database_record(field, c2))); }),
948
- done: newChoices.length < LOAD_CHOICES_LIMIT,
949
- };
950
- setRenderCount(function (r) { return r + 1; });
951
- })
952
- .catch(function (err) {
953
- console.error(err);
954
- preventRefetch[databaseId + field.id + lastId] = false;
955
- });
956
- }, [session, field, databaseId, renderCount]);
957
- var addChoice = (0, react_1.useCallback)(function (record) {
958
- if (!choicesForDatabase[databaseId]) {
959
- choicesForDatabase[databaseId] = {
960
- done: false,
961
- records: [],
962
- };
963
- }
964
- choicesForDatabase[databaseId].records.push(record);
965
- }, [choicesForDatabase, databaseId]);
966
- return {
967
- addChoice: addChoice,
968
- doneLoading: (_d = (_b = choicesForDatabase[databaseId]) === null || _b === void 0 ? void 0 : _b.done) !== null && _d !== void 0 ? _d : false,
969
- choices: __spreadArray(__spreadArray([], (_f = (_e = choicesForDatabase[databaseId]) === null || _e === void 0 ? void 0 : _e.records) !== null && _f !== void 0 ? _f : [], true), (otherAnswers || []).map(function (v) {
970
- var _a;
971
- return ({
972
- id: v.text,
973
- databaseId: databaseId,
974
- values: [{ label: ((_a = field.options) === null || _a === void 0 ? void 0 : _a.databaseLabel) || '', type: 'Text', value: v.text }],
975
- });
976
- }), true),
977
- renderCount: renderCount,
978
- };
979
- };
980
- var label_for_database_record = function (field, record) {
981
- var _a, _b, _d, _e;
982
- if (!record)
983
- return '';
984
- var addedLabels = ((((_a = field.options) === null || _a === void 0 ? void 0 : _a.databaseLabels) || [])
985
- .map(function (l) { var _a, _b; return (_b = (_a = record.values.find(function (v) { return v.label === l; })) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.toString(); })
986
- .filter(function (v) { return v === null || v === void 0 ? void 0 : v.trim(); }));
987
- return (((_e = (_d = (_b = record.values.find(function (v) { var _a; return v.label === ((_a = field.options) === null || _a === void 0 ? void 0 : _a.databaseLabel); })) === null || _b === void 0 ? void 0 : _b.value) === null || _d === void 0 ? void 0 : _d.toString()) !== null && _e !== void 0 ? _e : '')
988
- + (addedLabels.length
989
- ? " (".concat(addedLabels.join(', '), ")")
990
- : ''));
991
- };
992
- var get_other_answers = function (_value, typing) {
993
- try {
994
- var existing = ((_value || [])
995
- .filter(function (v) { return typeof v === 'string' || v.recordId === v.text; })
996
- .map(function (v) { return typeof v === 'string' ? { databaseId: '', recordId: v, text: v } : v; }));
997
- if (typing) {
998
- existing.push({ text: typing, databaseId: '', recordId: typing });
999
- }
1000
- return existing;
1001
- }
1002
- catch (err) {
1003
- console.error(err);
1004
- }
1005
- return [];
1006
- };
1007
- var DatabaseSelectInput = function (_a) {
1008
- var _b, _d, _e, _f, _g, _h, _j, _k;
1009
- var AddToDatabase = _a.AddToDatabase, field = _a.field, _value = _a.value, onChange = _a.onChange, onDatabaseSelect = _a.onDatabaseSelect, responses = _a.responses, size = _a.size, disabled = _a.disabled, enduser = _a.enduser;
1010
- var _l = (0, react_1.useState)(''), typing = _l[0], setTyping = _l[1];
1011
- var _m = useDatabaseChoices({
1012
- databaseId: (_b = field.options) === null || _b === void 0 ? void 0 : _b.databaseId,
1013
- field: field,
1014
- otherAnswers: get_other_answers(_value, ((_d = field === null || field === void 0 ? void 0 : field.options) === null || _d === void 0 ? void 0 : _d.other) ? typing : undefined),
1015
- }), addChoice = _m.addChoice, choices = _m.choices, doneLoading = _m.doneLoading;
1016
- var value = react_1.default.useMemo(function () {
1017
- var _a, _b;
1018
- try {
1019
- // if the value is a string (some single answer that was save), make sure we coerce to array
1020
- var __value = typeof _value === 'string' ? [_value] : _value;
1021
- return ((_b = (_a = __value === null || __value === void 0 ? void 0 : __value.map(function (v) {
1022
- return choices.find(function (c) {
1023
- return c.id === v.recordId || (typeof v === 'string' && label_for_database_record(field, c) === v);
1024
- });
1025
- })) === null || _a === void 0 ? void 0 : _a.filter(function (v) { return v; })) !== null && _b !== void 0 ? _b : []);
1026
- }
1027
- catch (err) {
1028
- console.error('Error resolving database answers for _value', err);
1029
- return [];
1030
- }
1031
- }, [_value, choices, field]);
1032
- var filterResponse = (0, react_1.useMemo)(function () {
1033
- var _a, _b, _d, _e;
1034
- return (((_b = (_a = field.options) === null || _a === void 0 ? void 0 : _a.databaseFilter) === null || _b === void 0 ? void 0 : _b.fieldId)
1035
- ? (_e = (_d = responses.find(function (r) { var _a, _b; return r.fieldId === ((_b = (_a = field.options) === null || _a === void 0 ? void 0 : _a.databaseFilter) === null || _b === void 0 ? void 0 : _b.fieldId); })) === null || _d === void 0 ? void 0 : _d.answer) === null || _e === void 0 ? void 0 : _e.value
1036
- : undefined);
1037
- }, [responses, (_e = field.options) === null || _e === void 0 ? void 0 : _e.databaseFilter]);
1038
- // State filtering logic similar to Insurance component
1039
- var addressQuestion = (0, react_1.useMemo)(function () { return responses === null || responses === void 0 ? void 0 : responses.find(function (r) {
1040
- var _a;
1041
- if (r.answer.type !== 'Address')
1042
- return false;
1043
- if (r.field.intakeField !== 'Address')
1044
- return false;
1045
- // make sure state is actually defined (in case of multiple address questions, where 1+ are blank)
1046
- if (!((_a = r.answer.value) === null || _a === void 0 ? void 0 : _a.state))
1047
- return false;
1048
- return true;
1049
- }); }, [responses]);
1050
- var state = (0, react_1.useMemo)(function () {
1051
- var _a, _b, _d, _e;
1052
- return (((_a = field.options) === null || _a === void 0 ? void 0 : _a.filterByEnduserState)
1053
- ? ((((_b = addressQuestion === null || addressQuestion === void 0 ? void 0 : addressQuestion.answer) === null || _b === void 0 ? void 0 : _b.type) === 'Address' ? (_e = (_d = addressQuestion === null || addressQuestion === void 0 ? void 0 : addressQuestion.answer) === null || _d === void 0 ? void 0 : _d.value) === null || _e === void 0 ? void 0 : _e.state : undefined) || (enduser === null || enduser === void 0 ? void 0 : enduser.state))
1054
- : undefined);
1055
- }, [enduser === null || enduser === void 0 ? void 0 : enduser.state, addressQuestion, (_f = field.options) === null || _f === void 0 ? void 0 : _f.filterByEnduserState]);
1056
- var filteredChoicesWithPotentialDuplicates = (0, react_1.useMemo)(function () {
1057
- var _a, _b;
1058
- if (!choices)
1059
- return [];
1060
- if (!filterResponse)
1061
- return choices;
1062
- if (!((_b = (_a = field === null || field === void 0 ? void 0 : field.options) === null || _a === void 0 ? void 0 : _a.databaseFilter) === null || _b === void 0 ? void 0 : _b.databaseLabel))
1063
- if (!value || value.length === 0)
1064
- return choices;
1065
- return (choices
1066
- .filter(function (c) {
1067
- var _a;
1068
- var v = (_a = c.values.find(function (_v) { var _a, _b; return _v.label === ((_b = (_a = field.options) === null || _a === void 0 ? void 0 : _a.databaseFilter) === null || _b === void 0 ? void 0 : _b.databaseLabel); })) === null || _a === void 0 ? void 0 : _a.value;
1069
- if (!v)
1070
- return true;
1071
- // use .text on r values to handle Database Select types as filter source (in addition to basic text and list of text)
1072
- if (typeof v === 'object') {
1073
- return !!(Object.values(v).find(function (oVal) { return (typeof oVal === 'string' || typeof oVal === 'number'
1074
- ? (Array.isArray(filterResponse)
1075
- ? filterResponse.find(function (r) { return r === oVal.toString() || (typeof r === 'object' && r.text === oVal); })
1076
- : (typeof filterResponse === 'string' || typeof filterResponse === 'number')
1077
- ? filterResponse.toString() === oVal.toString()
1078
- : false)
1079
- : false); }));
1080
- }
1081
- if (typeof v === 'string' || typeof v === 'number') {
1082
- return !!(Array.isArray(filterResponse)
1083
- ? filterResponse.find(function (r) { return r === v.toString() || (typeof r === 'object' && r.text === v); })
1084
- : (typeof filterResponse === 'string' || typeof filterResponse === 'number')
1085
- ? filterResponse.toString() === v.toString()
1086
- : (typeof filterResponse === 'object' && filterResponse.city === v.toString()) ? true
1087
- : (typeof filterResponse === 'object' && filterResponse.state === v.toString()) ? true
1088
- : (typeof filterResponse === 'object' && filterResponse.zipCode === v.toString()) ? true
1089
- : false);
1090
- }
1091
- return false;
1092
- }));
1093
- }, [choices, filterResponse, (_g = field.options) === null || _g === void 0 ? void 0 : _g.databaseFilter, value]);
1094
- // Apply state filtering as a secondary filter (doesn't modify existing logic)
1095
- var stateFilteredChoices = (0, react_1.useMemo)(function () {
1096
- var _a;
1097
- if (!((_a = field.options) === null || _a === void 0 ? void 0 : _a.filterByEnduserState) || !state) {
1098
- return filteredChoicesWithPotentialDuplicates;
1099
- }
1100
- return filteredChoicesWithPotentialDuplicates.filter(function (c) {
1101
- var _a, _b;
1102
- var recordState = ((_b = (_a = c.values.find(function (v) { var _a, _b; return ((_b = (_a = v.label) === null || _a === void 0 ? void 0 : _a.trim()) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'state'; })) === null || _a === void 0 ? void 0 : _a.value) === null || _b === void 0 ? void 0 : _b.toString()) || '';
1103
- return !recordState || recordState === state;
1104
- });
1105
- }, [filteredChoicesWithPotentialDuplicates, (_h = field.options) === null || _h === void 0 ? void 0 : _h.filterByEnduserState, state]);
1106
- var filteredChoices = (0, react_1.useMemo)(function () {
1107
- var filtered = [];
1108
- var uniques = new Set([]);
1109
- for (var _a = 0, stateFilteredChoices_1 = stateFilteredChoices; _a < stateFilteredChoices_1.length; _a++) {
1110
- var c = stateFilteredChoices_1[_a];
1111
- var text = label_for_database_record(field, c);
1112
- if (uniques.has(text))
1113
- continue; // duplicate found
1114
- uniques.add(text);
1115
- filtered.push(c);
1116
- }
1117
- return filtered;
1118
- }, [field, stateFilteredChoices]);
1119
- if (!doneLoading)
1120
- return (0, jsx_runtime_1.jsx)(LinearProgress_1.default, {});
1121
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(material_1.Autocomplete, { id: field.id, freeSolo: false, size: size, componentsProps: { popper: { sx: { wordBreak: "break-word" } } }, options: filteredChoices, multiple: true, getOptionLabel: function (o) { return (Array.isArray(o) // edge case
1122
- ? ''
1123
- : label_for_database_record(field, o)); }, value: value, disabled: disabled, onChange: function (_, v) {
1124
- var _a, _b, _d, _e, _f;
1125
- if (v.length && onDatabaseSelect) {
1126
- onDatabaseSelect(((_a = field.options) === null || _a === void 0 ? void 0 : _a.radio)
1127
- ? [v[v.length - 1]] // if radio, only last selected
1128
- : v);
1129
- }
1130
- return onChange((!((_b = field.options) === null || _b === void 0 ? void 0 : _b.radio)
1131
- ? v.map(function (_v) {
1132
- var _a;
1133
- return ({
1134
- databaseId: (_a = field.options) === null || _a === void 0 ? void 0 : _a.databaseId,
1135
- recordId: _v.id,
1136
- text: label_for_database_record(field, _v),
1137
- });
1138
- })
1139
- : [{
1140
- databaseId: (_d = field.options) === null || _d === void 0 ? void 0 : _d.databaseId,
1141
- recordId: (_f = (_e = v[v.length - 1]) === null || _e === void 0 ? void 0 : _e.id) !== null && _f !== void 0 ? _f : '',
1142
- text: label_for_database_record(field, v[v.length - 1]),
1143
- }]), field.id);
1144
- }, inputValue: typing, onInputChange: function (e, v) { return e && setTyping(v); }, renderInput: function (params) { return (0, jsx_runtime_1.jsx)(material_1.TextField, __assign({}, params, { InputProps: __assign(__assign({}, params.InputProps), { sx: exports.defaultInputProps.sx }) })); },
1145
- // use custom Chip to ensure very long entries break properly (whitespace: normal)
1146
- renderTags: function (value, getTagProps) {
1147
- return value.map(function (value, index) { return ((0, jsx_runtime_1.jsx)(material_1.Chip, __assign({ label: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ style: { whiteSpace: 'normal' } }, { children: Array.isArray(value) ? '' : label_for_database_record(field, value) })) }, getTagProps({ index: index }), { sx: { height: "100%", py: 0.5 } }))); });
1148
- } }), AddToDatabase && ((_j = field === null || field === void 0 ? void 0 : field.options) === null || _j === void 0 ? void 0 : _j.allowAddToDatabase) && ((0, jsx_runtime_1.jsx)(AddToDatabase, { databaseId: (_k = field.options) === null || _k === void 0 ? void 0 : _k.databaseId, onAdd: addChoice }))] }));
915
+ // DatabaseSelectInput logic is shared with inputs.tsx to avoid duplication
916
+ // Import the interface and component from the shared implementation
917
+ var inputs_2 = require("./inputs");
918
+ // Wrap the shared DatabaseSelectInput component with v2-specific props
919
+ var DatabaseSelectInput = function (props) {
920
+ // Pass all props plus v2-specific defaultInputProps to the shared component
921
+ return (0, jsx_runtime_1.jsx)(inputs_2.DatabaseSelectInput, __assign({}, props, { inputProps: exports.defaultInputProps }));
1149
922
  };
1150
923
  exports.DatabaseSelectInput = DatabaseSelectInput;
1151
924
  var displayTermsCache = undefined;