Skip to content

Commit

Permalink
Merge pull request #432 from l3vels/fix/more-design-changes
Browse files Browse the repository at this point in the history
Fix/more design changes
  • Loading branch information
Chkhikvadze authored Feb 12, 2024
2 parents 8d79d8a + 0806eb6 commit c67ac9b
Show file tree
Hide file tree
Showing 17 changed files with 672 additions and 392 deletions.
18 changes: 6 additions & 12 deletions apps/ui/src/Route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ import CreateCampaignForm from 'plugins/contact/pages/Campaign/CampaignForm/Crea
import EditCampaignForm from 'plugins/contact/pages/Campaign/CampaignForm/EditCampaignForm'
import TwilioPhoneNumberSidConfirmationModal from 'modals/TwilioPhoneNumberSidConfirmationModal'
import IntegrationListModal from 'modals/IntegrationListModal'
import DatasourceListModal from 'modals/DatasourceListModal'

const Route = () => {
const { loading } = useContext(AuthContext)
Expand Down Expand Up @@ -213,12 +214,8 @@ const Route = () => {
/>
</Router>

<Router
path={'datasources'}
element={<MainRouteLayout />}
key={document.location.href}
>
<Router index element={<Datasource />} key={document.location.href} />
<Router path={'datasources'} element={<Datasource />} key={document.location.href}>
{/* <Router index element={<Datasource />} key={document.location.href} /> */}
<Router
path={':datasourceId'}
element={<AgentView />}
Expand Down Expand Up @@ -258,12 +255,8 @@ const Route = () => {
/>
</Router>

<Router
path={'integrations'}
element={<MainRouteLayout />}
key={document.location.href}
>
<Router index element={<Integrations />} key={document.location.href} />
<Router path={'integrations'} element={<Integrations />} key={document.location.href}>
{/* <Router index element={<Integrations />} key={document.location.href} /> */}
<Router
path={'toolkit/:slug'}
element={<ToolView />}
Expand Down Expand Up @@ -420,6 +413,7 @@ const Route = () => {
<VideoModal />
<ContactListModal />
<IntegrationListModal />
<DatasourceListModal />
<TwilioPhoneNumberSidConfirmationModal />

<CommandMenu
Expand Down
131 changes: 131 additions & 0 deletions apps/ui/src/modals/DatasourceListModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import withRenderModal from 'hocs/withRenderModal'
import Modal from 'share-ui/components/Modal/Modal'
import { StyledFooter, StyledInnerWrapper, StyledModalBody } from './IntegrationListModal'
import {
StyledChatWrapper,
StyledDivider,
StyledHorizontalDivider,
StyledLeftColumn,
StyledMainWrapper,
} from 'routes/ChatRouteLayout'
import ListHeader from 'routes/components/ListHeader'
import { useModal } from 'hooks'
import { useDatasource } from 'pages/Datasource/useDatasource'
import { useDatasourcesService } from 'services/datasource/useDatasourcesService'
import { useEditAgent } from 'pages/Agents/useEditAgent'
import MiniToolCard from 'components/ChatCards/MiniToolCard'
import { DATA_LOADER_IMAGES } from 'pages/Datasource/constants'
import { useEffect, useState } from 'react'
import { ButtonPrimary } from 'components/Button/Button'
import { t } from 'i18next'

const DatasourceListModal = () => {
const { closeModal } = useModal()

const [pickedDatasource, setPickedDatasource] = useState(null as any)

const { data: datasources } = useDatasourcesService()

const { agentById, isLoading, formik } = useEditAgent()

const agentDatasources = agentById?.configs.datasources

const installedDatasources = datasources?.filter((datasource: any) =>
agentDatasources?.includes(datasource.id),
)
const notInstalledDatasources = datasources?.filter(
(datasource: any) => !agentDatasources?.includes(datasource.id),
)

const handleUpdateDatasource = async () => {
if (!agentDatasources) return
let updatedValues
if (agentDatasources.includes(pickedDatasource)) {
updatedValues = agentDatasources?.filter((toolId: string) => toolId !== pickedDatasource)
} else {
updatedValues = [...agentDatasources, pickedDatasource]
}

await formik.setFieldValue('agent_datasources', updatedValues)
formik.submitForm()
}

useEffect(() => {
if (installedDatasources?.length > 0) setPickedDatasource(installedDatasources?.[0]?.id)
else if (notInstalledDatasources?.length > 0)
setPickedDatasource(notInstalledDatasources?.[0]?.id)
}, [agentDatasources])

return (
<Modal
onClose={() => closeModal('datasource-list-modal')}
show
backgroundColor='light'
noOverlay
>
<StyledModalBody>
<StyledMainWrapper>
<StyledLeftColumn>
<ListHeader title={'Installed'} />
{installedDatasources?.map((datasource: any) => {
const filteredLogos = DATA_LOADER_IMAGES.filter(
loaderImages => loaderImages.sourceName === datasource.source_type,
)

const imageSrc = filteredLogos?.[0]?.imageSrc || ''

return (
<MiniToolCard
key={datasource.id}
onClick={() => setPickedDatasource(datasource.id)}
picked={pickedDatasource === datasource.id}
name={datasource.name}
logo={imageSrc}
/>
)
})}

<StyledHorizontalDivider />

<ListHeader title={'Marketplace'} />
{notInstalledDatasources?.map((datasource: any) => {
const filteredLogos = DATA_LOADER_IMAGES.filter(
loaderImages => loaderImages.sourceName === datasource.source_type,
)

const imageSrc = filteredLogos?.[0]?.imageSrc || ''

return (
<MiniToolCard
key={datasource.id}
onClick={() => setPickedDatasource(datasource.id)}
picked={pickedDatasource === datasource.id}
name={datasource.name}
logo={imageSrc}
/>
)
})}
</StyledLeftColumn>

<StyledDivider />

<StyledChatWrapper>
<StyledInnerWrapper>
<StyledFooter>
<ButtonPrimary
onClick={handleUpdateDatasource}
disabled={isLoading}
loading={isLoading}
>
{agentDatasources?.includes(pickedDatasource) ? t('remove') : t('install')}
</ButtonPrimary>
</StyledFooter>
</StyledInnerWrapper>
</StyledChatWrapper>
</StyledMainWrapper>
</StyledModalBody>
</Modal>
)
}

export default withRenderModal('datasource-list-modal')(DatasourceListModal)
12 changes: 6 additions & 6 deletions apps/ui/src/modals/IntegrationListModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const IntegrationListModal = () => {
<TabPanels>
<TabPanel>
{agentToolsData && (
<StyledInnerTabWrapper>
<StyledInnerWrapper>
<ToolView toolSlug={pickedTool?.slug} hideForm />

<StyledFooter>
Expand All @@ -181,7 +181,7 @@ const IntegrationListModal = () => {
{agentToolsData.includes(pickedTool?.id) ? t('remove') : t('install')}
</ButtonPrimary>
</StyledFooter>
</StyledInnerTabWrapper>
</StyledInnerWrapper>
)}
</TabPanel>
<TabPanel>
Expand All @@ -200,11 +200,11 @@ const IntegrationListModal = () => {

export default withRenderModal('integration-list-modal')(IntegrationListModal)

const StyledModalBody = styled.div`
export const StyledModalBody = styled.div`
width: 50vw;
height: 70vh;
`
const StyledFooter = styled.div`
export const StyledFooter = styled.div`
width: 100%;
display: flex;
Expand All @@ -216,10 +216,10 @@ const StyledFooter = styled.div`
bottom: 0;
`
const StyledTextFieldWrapper = styled.div`
export const StyledTextFieldWrapper = styled.div`
padding: 4px;
`
const StyledInnerTabWrapper = styled.div`
export const StyledInnerWrapper = styled.div`
position: relative;
height: 100%;
Expand Down
42 changes: 21 additions & 21 deletions apps/ui/src/pages/Agents/AgentForm/AgentForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,28 +237,28 @@ const AgentForm = ({ formik, isVoice = true }: AgentFormProps) => {
/> */}

{agentType === 'text' && (
<StyledCombinedFields>
<AgentDropdown
isMulti
label={t('datasources')}
fieldName={'agent_datasources'}
fieldValue={agent_datasources}
setFieldValue={setFieldValue}
options={datasourceOptions}
/>
// <StyledCombinedFields>
// <AgentDropdown
// isMulti
// label={t('datasources')}
// fieldName={'agent_datasources'}
// fieldValue={agent_datasources}
// setFieldValue={setFieldValue}
// options={datasourceOptions}
// />
// </StyledCombinedFields>

<AgentDropdown
label={'Data Process Flow'}
fieldName={'agent_source_flow'}
setFieldValue={setFieldValue}
fieldValue={agent_source_flow}
options={data_process_flow}
onChange={() => {
setFieldValue('agent_source_flow', '')
}}
optionSize={'small'}
/>
</StyledCombinedFields>
<AgentDropdown
label={'Data Process Flow'}
fieldName={'agent_source_flow'}
setFieldValue={setFieldValue}
fieldValue={agent_source_flow}
options={data_process_flow}
onChange={() => {
setFieldValue('agent_source_flow', '')
}}
optionSize={'small'}
/>
)}

<StyledCombinedFields>
Expand Down
4 changes: 2 additions & 2 deletions apps/ui/src/pages/Agents/AgentForm/components/CopyScript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ const CopyScript = () => {
<StyledAgentWrapper onClick={() => openLinkTab(import.meta.env.REACT_APP_MAIN_API_DOCS)}>
<Book />
<TypographyPrimary
value={'Main API integration'}
value={'Core API integration'}
type={Typography.types.LABEL}
size={Typography.sizes.xss}
/>
</StyledAgentWrapper>
<StyledAgentWrapper onClick={() => openLinkTab(import.meta.env.REACT_APP_PR_API_DOCS)}>
<Book />
<TypographyPrimary
value={'PR API integration'}
value={'Voice API integration'}
type={Typography.types.LABEL}
size={Typography.sizes.xss}
/>
Expand Down
Loading

0 comments on commit c67ac9b

Please sign in to comment.