-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: mappable fields with static values version 2 (#53)
Demo: https://www.loom.com/share/79a23c05d0984ced80d6bddc9bc0fe1e?sid=eb855a66-4130-4034-a3a2-ed445235cbe6 --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
745fcb1
commit 3dfe038
Showing
12 changed files
with
225 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6800,7 +6800,7 @@ Apache-2.0 | |
|
||
The following npm package may be included in this product: | ||
|
||
- [email protected].30001660 | ||
- [email protected].30001663 | ||
|
||
This package contains the following license and notice below: | ||
|
||
|
@@ -8135,7 +8135,7 @@ distributed under the terms of the MIT license above. | |
|
||
The following npm package may be included in this product: | ||
|
||
- [email protected].25 | ||
- [email protected].28 | ||
|
||
This package contains the following license and notice below: | ||
|
||
|
@@ -12403,7 +12403,7 @@ THE SOFTWARE. | |
The following npm packages may be included in this product: | ||
|
||
- [email protected] | ||
- [email protected].0 | ||
- [email protected].1 | ||
- [email protected] | ||
|
||
These packages each contain the following license and notice below: | ||
|
@@ -13893,7 +13893,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
|
||
The following npm package may be included in this product: | ||
|
||
- browserslist@4.23.3 | ||
- browserslist@4.24.0 | ||
|
||
This package contains the following license and notice below: | ||
|
||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { renderEntityFields } from "./renderEntityFields.tsx"; | ||
export { resolveVisualEditorData } from "./resolveVisualEditorData.ts"; | ||
export { resolveProp } from "./resolveProp.ts"; | ||
export { resolveYextEntityField } from "./resolveYextEntityField.ts"; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { EntityFieldType } from "../components/YextEntityFieldSelector.tsx"; | ||
|
||
export const resolveYextEntityField = <T>( | ||
document: any, | ||
entityField: EntityFieldType | ||
): T => { | ||
// return static value if fieldName is not set | ||
if (entityField.fieldName === "") { | ||
return entityField.staticValue as T; | ||
} | ||
|
||
try { | ||
// check for the entity field in the document | ||
const steps: string[] = entityField.fieldName.split("."); | ||
let missedStep = false; | ||
let current = document; | ||
for (let i = 0; i < steps.length; i++) { | ||
if (current?.[steps[i]] !== undefined) { | ||
current = current[steps[i]]; | ||
} else { | ||
missedStep = true; | ||
break; | ||
} | ||
} | ||
if (!missedStep) { | ||
return current; | ||
} | ||
} catch (e) { | ||
console.error("Error in resolveYextEntityField:", e); | ||
} | ||
|
||
// if field not found, return static value as a fallback | ||
console.warn( | ||
`The field ${entityField.fieldName} was not found in the document, defaulting to static value ${entityField.staticValue}.` | ||
); | ||
return entityField.staticValue as T; | ||
}; |
Oops, something went wrong.