Skip to content

Commit

Permalink
Merge pull request #1256 from stakwork/feature/merge-modal
Browse files Browse the repository at this point in the history
Feature/merge modal
  • Loading branch information
Rassl authored Apr 16, 2024
2 parents 16846b6 + 1081900 commit f17035a
Show file tree
Hide file tree
Showing 20 changed files with 469 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const DropdownSearch: React.FC<Props> = ({ onSelect, selectedTopic }) =>

const handleSearch = async (val: string) => {
const filters = {
muted: 'False',
is_muted: 'False',
sort_by: ALPHABETICALLY,
search: val,
skip: '0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const DropdownSearch: React.FC<Props> = ({ onSelect, selectedTopic }) =>

const handleSearch = async (val: string) => {
const filters = {
muted: 'False',
is_muted: 'False',
sort_by: ALPHABETICALLY,
search: val,
skip: '0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const TableRowComponent: FC<TTableRaw> = ({ topic, onClick }) => {
setLoading(true)

try {
await putNodeData(refId, { muted_topic: shouldMute })
await putNodeData(refId, { is_muted: shouldMute })
useTopicsStore.setState({ ids: ids.filter((i) => i !== refId), total: total - 1 })
} catch (error) {
console.warn(error)
Expand All @@ -50,7 +50,7 @@ const TableRowComponent: FC<TTableRaw> = ({ topic, onClick }) => {
<ClipLoader color={colors.white} size={16} />
) : (
<>
{topic.muted_topic ? (
{topic.is_muted ? (
<IconWrapper className="centered" onClick={() => handleMute(topic.ref_id, false)}>
<MdCheckCircle color={colors.primaryGreen} fontSize={24} />
</IconWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ export const TopicSources = () => {
<Wrapper direction="column" justify="flex-end">
<Heading align="flex-start" direction="row" justify="space-between">
<Text className="title">Topics</Text>
<Button disabled={loading} onClick={() => setFilters({ muted: !filters.muted })} size="medium">
{filters.muted ? 'Show Unmuted' : 'Show Muted'}
<Button disabled={loading} onClick={() => setFilters({ is_muted: !filters.is_muted })} size="medium">
{filters.is_muted ? 'Show Unmuted' : 'Show Muted'}
{loading && <ClipLoader color={colors.BLUE_PRESS_STATE} size={10} />}
</Button>
</Heading>
Expand All @@ -123,7 +123,7 @@ export const TopicSources = () => {
<ClipLoader color={colors.white} />
) : (
<>
<Table onTopicEdit={onTopicEdit} showMuted={filters.muted} />
<Table onTopicEdit={onTopicEdit} showMuted={filters.is_muted} />
{total > ids.length ? (
<Button className="load-more" disabled={loading} onClick={handleLoadMore}>
Load more
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const ToNode: FC<Props> = ({ onSelect, selectedValue }) => {

const handleSearch = async (val: string) => {
const filters = {
muted: 'False',
is_muted: 'False',
sort_by: ALPHABETICALLY,
search: val,
skip: '0',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const DropdownSearch: React.FC<Props> = ({ onSelect, selectedTopic }) =>

const handleSearch = async (val: string) => {
const filters = {
muted: 'False',
is_muted: 'False',
sort_by: ALPHABETICALLY,
search: val,
skip: '0',
Expand Down
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}
/>
)
}
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}
/>
)
}
Loading

0 comments on commit f17035a

Please sign in to comment.