From 1ddc07d640016244158d39222494de72db3b6ce8 Mon Sep 17 00:00:00 2001 From: Jake Prins Date: Fri, 27 Oct 2023 10:26:58 +0200 Subject: [PATCH 1/2] Add wayfinder to advanced custom mapping --- package.json | 1 + src/components/FieldSelector.tsx | 58 +++++++++++++++-- src/components/Vault.tsx | 80 ++++++++++++----------- src/styles/base.css | 2 +- src/styles/index.css | 2 + src/utils/useConnections.tsx | 21 ++++++ tailwind.config.js | 1 + yarn.lock | 107 ++++++++++++++++++++++++++++++- 8 files changed, 226 insertions(+), 46 deletions(-) diff --git a/package.json b/package.json index 634d901..462ac8c 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ }, "dependencies": { "@apideck/components": "^0.12.9", + "@apideck/wayfinder": "^0.1.9", "formik": "^2.2.9", "fuse.js": "^6.5.3", "jwt-decode": "^3.1.2", diff --git a/src/components/FieldSelector.tsx b/src/components/FieldSelector.tsx index 6529e6f..6d5f8f9 100644 --- a/src/components/FieldSelector.tsx +++ b/src/components/FieldSelector.tsx @@ -1,4 +1,5 @@ -import { Button, TextInput, useDebounce } from '@apideck/components'; +import { Button, TextInput, useDebounce, useModal } from '@apideck/components'; +import { WayFinder } from '@apideck/wayfinder'; import { Menu, Transition } from '@headlessui/react'; import classNames from 'classnames'; @@ -13,6 +14,8 @@ import React, { useRef, useState, } from 'react'; +import useSWR from 'swr'; +import { useConnections } from '../utils/useConnections'; interface Props { onSelect: (field: any) => void; @@ -50,9 +53,22 @@ const FieldSelector = ({ ); const [list, setList] = useState([]); const debouncedSearchTerm = useDebounce(searchTerm, 250); - const [fieldMappingString, setFieldMappingString] = useState(); + const [fieldMappingString, setFieldMappingString] = useState(); const [properties, setProperties] = useState(propertiesProps); const searchInputRef: any = useRef(); + const { addModal, removeModal } = useModal(); + + const { selectedConnection, fetchResourceExample } = useConnections(); + + const { data, error: exampleError } = useSWR( + selectedConnection && + selectedCustomMapping?.id && + mode === 'advanced' && ['example', selectedCustomMapping?.id], + () => fetchResourceExample(selectedCustomMapping?.id?.split('+')[1]), + { revalidateIfStale: false } + ); + + const exampleResponse = data?.data?.example_response; useEffect(() => { if (debouncedSearchTerm) { @@ -379,12 +395,46 @@ const FieldSelector = ({ setFieldMappingString(e.target.value) } /> -
+
+