From 7655bcd6f316e5fba04ce309b99d4dfb5be0e3be Mon Sep 17 00:00:00 2001
From: lingdocs <71590811+lingdocs@users.noreply.github.com>
Date: Sat, 9 Apr 2022 17:45:07 +0500
Subject: [PATCH] fix select option creating bug
---
package.json | 2 +-
src/components/np-picker/NPNounPicker.tsx | 1 +
.../np-picker/NPParticiplePicker.tsx | 1 +
src/components/np-picker/NPPronounPicker.tsx | 4 +++-
src/components/np-picker/picker-tools.tsx | 20 +++++++++++++++----
5 files changed, 22 insertions(+), 6 deletions(-)
diff --git a/package.json b/package.json
index 8c0de20..4022a95 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "@lingdocs/pashto-inflector",
- "version": "1.8.1",
+ "version": "1.8.2",
"author": "lingdocs.com",
"description": "A Pashto inflection and verb conjugation engine, inculding React components for displaying Pashto text, inflections, and conjugations",
"homepage": "https://verbs.lingdocs.com",
diff --git a/src/components/np-picker/NPNounPicker.tsx b/src/components/np-picker/NPNounPicker.tsx
index 10f6b2e..b849a8b 100644
--- a/src/components/np-picker/NPNounPicker.tsx
+++ b/src/components/np-picker/NPNounPicker.tsx
@@ -103,6 +103,7 @@ function NPNounPicker(props: ({
handleChange={setPatternFilter}
/>
} */}
+
Noun
{!(props.noun && props.noun.dynamicComplement) ?
{props.clearButton}
+ Participle
handlePronounTypeChange(g as "far" | "near")}
/>
-
+
diff --git a/src/components/np-picker/picker-tools.tsx b/src/components/np-picker/picker-tools.tsx
index 30ba8d2..47fec06 100644
--- a/src/components/np-picker/picker-tools.tsx
+++ b/src/components/np-picker/picker-tools.tsx
@@ -66,14 +66,26 @@ export function makeSelectOption(
e: T.DictionaryEntry | T.VerbEntry | T.NounEntry | T.AdjectiveEntry | T.LocativeAdverbEntry,
opts: T.TextOptions,
): { value: string, label: string } {
+ function truncateEnglish(s: string) {
+ const maxLength = 16;
+ return s.length <= maxLength
+ ? maxLength
+ : s.slice(0, maxLength) + "…";
+ }
const entry = "entry" in e ? e.entry : e;
- const eng = (isVerbEntry(e))
- ? (getEnglishParticiple(e.entry))
- : getEnglishWord(e);
+ const eng = (() => {
+ try {
+ return (isVerbEntry(e))
+ ? (getEnglishParticiple(e.entry))
+ : getEnglishWord(e);
+ } catch(err) {
+ return "";
+ }
+ })();
const english = typeof eng === "string"
? eng
: !eng
- ? ""
+ ? truncateEnglish(entry.e)
: ("singular" in eng && eng.singular !== undefined)
? eng.singular
: eng.plural;