-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1256 from stakwork/feature/merge-modal
Feature/merge modal
- Loading branch information
Showing
20 changed files
with
469 additions
and
107 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
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
40 changes: 40 additions & 0 deletions
40
...nts/SourcesTableModal/SourcesView/Topics/AddEdgeTopicModal/Title/ConnectionType/index.tsx
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,40 @@ | ||
import { FC, useEffect, useState } from 'react' | ||
import { AutoComplete, TAutocompleteOption } from '~/components/common/AutoComplete' | ||
import { getEdgeTypes } from '~/network/fetchSourcesData' | ||
|
||
type Props = { | ||
selectedType: string | ||
setSelectedType: (option: string) => void | ||
} | ||
|
||
export const ConnectionType: FC<Props> = ({ selectedType, setSelectedType }) => { | ||
const [options, setOptions] = useState<string[]>([]) | ||
|
||
useEffect(() => { | ||
const init = async () => { | ||
try { | ||
const { data } = await getEdgeTypes() | ||
|
||
setOptions(data.edge_types) | ||
} catch (error) { | ||
console.warn(error) | ||
} | ||
} | ||
|
||
init() | ||
}, [setOptions]) | ||
|
||
const resolveOption = (i: string) => ({ label: i, value: i }) | ||
|
||
const handleSelectChange = (option: TAutocompleteOption | null) => { | ||
setSelectedType(option?.value || '') | ||
} | ||
|
||
return ( | ||
<AutoComplete | ||
onSelect={handleSelectChange} | ||
options={options.map(resolveOption)} | ||
selectedValue={selectedType ? resolveOption(selectedType) : null} | ||
/> | ||
) | ||
} |
83 changes: 83 additions & 0 deletions
83
src/components/SourcesTableModal/SourcesView/Topics/AddEdgeTopicModal/Title/ToNode/index.tsx
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,83 @@ | ||
import { IconButton } from '@mui/material' | ||
import { debounce } from 'lodash' | ||
import { FC, useMemo, useState } from 'react' | ||
import { OPTIONS } from '~/components/AddItemModal/SourceTypeStep/constants' | ||
import ClearIcon from '~/components/Icons/ClearIcon' | ||
import { ALPHABETICALLY } from '~/components/SourcesTableModal/SourcesView/constants' | ||
import { AutoComplete, TAutocompleteOption } from '~/components/common/AutoComplete' | ||
import { Flex } from '~/components/common/Flex' | ||
import { getEdges } from '~/network/fetchSourcesData' | ||
import { FetchEdgesResponse, TEdge } from '~/types' | ||
|
||
type Props = { | ||
onSelect: (topic: TEdge | null) => void | ||
selectedValue: TEdge | null | ||
} | ||
|
||
export const ToNode: FC<Props> = ({ onSelect, selectedValue }) => { | ||
const [options, setOptions] = useState<TEdge[]>([]) | ||
const [optionsIsLoading, setOptionsIsLoading] = useState(false) | ||
|
||
const handleSearch = async (val: string) => { | ||
const filters = { | ||
is_muted: 'False', | ||
sort_by: ALPHABETICALLY, | ||
search: val, | ||
skip: '0', | ||
limit: '1000', | ||
} | ||
|
||
setOptionsIsLoading(true) | ||
|
||
try { | ||
const responseData: FetchEdgesResponse = await getEdges(filters.search) | ||
|
||
setOptions(responseData.data) | ||
} catch (error) { | ||
setOptions([]) | ||
} finally { | ||
setOptionsIsLoading(false) | ||
} | ||
} | ||
|
||
const debouncedSearch = useMemo(() => debounce(handleSearch, 300), []) | ||
|
||
const handleChange = (e: string) => { | ||
if (!e) { | ||
setOptions([]) | ||
|
||
return | ||
} | ||
|
||
if (e.length > 2) { | ||
debouncedSearch(e) | ||
} | ||
} | ||
|
||
const handleSelect = (val: TAutocompleteOption | null) => { | ||
const option = val ? options.find((i) => i.ref_id === val.value) : null | ||
|
||
onSelect(option || null) | ||
} | ||
|
||
const resolveOption = (i: TEdge) => ({ label: i.search_value, value: i.ref_id, type: i.node_type }) | ||
|
||
const resolveOptions = (values: TEdge[]) => values.map(resolveOption) | ||
|
||
return selectedValue ? ( | ||
<Flex align="center" basis="100%" direction="row" grow={1} shrink={1}> | ||
<span>{selectedValue.search_value}</span> | ||
<IconButton onClick={() => onSelect(null)} size="small"> | ||
<ClearIcon /> | ||
</IconButton> | ||
</Flex> | ||
) : ( | ||
<AutoComplete | ||
handleInputChange={handleChange} | ||
isLoading={optionsIsLoading} | ||
onSelect={handleSelect} | ||
options={resolveOptions(options) || OPTIONS} | ||
selectedValue={selectedValue ? resolveOption(selectedValue) : null} | ||
/> | ||
) | ||
} |
Oops, something went wrong.