Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/swarm UI url #2316

Merged
merged 4 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/components/Auth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

export const AuthGuard = ({ children }: PropsWithChildren) => {
const [unAuthorized, setUnauthorized] = useState(false)
const { setBudget, setIsAdmin, setPubKey, setIsAuthenticated } = useUserStore((s) => s)
const { setBudget, setIsAdmin, setPubKey, setIsAuthenticated, setSwarmUiUrl } = useUserStore((s) => s)
const { splashDataLoading } = useDataStore((s) => s)
const [renderMainPage, setRenderMainPage] = useState(false)

Expand Down Expand Up @@ -67,9 +67,15 @@
const res = await getIsAdmin()

if (res.data) {
localStorage.setItem('admin', JSON.stringify({ isAdmin: res.data.isAdmin }))
const isAdmin = !!res.data.isAdmin

setIsAdmin(!!res.data.isAdmin)
localStorage.setItem('admin', JSON.stringify({ isAdmin }))

if (isAdmin && res.data.swarmUiUrl) {
setSwarmUiUrl(res.data.swarmUiUrl)
}

setIsAdmin(isAdmin)
setTrendingTopicsFeatureFlag(res.data.trendingTopics)
setQueuedSourcesFeatureFlag(res.data.queuedSources)
setCustomSchemaFeatureFlag(res.data.customSchema)
Expand All @@ -91,6 +97,7 @@
setCustomSchemaFeatureFlag,
setRealtimeGraphFeatureFlag,
setChatInterfaceFeatureFlag,
setSwarmUiUrl,
])

// auth checker
Expand All @@ -105,7 +112,7 @@

await handleAuth()
} catch (error) {
console.log(error)

Check warning on line 115 in src/components/Auth/index.tsx

View workflow job for this annotation

GitHub Actions / craco-build-run

Unexpected console statement

Check warning on line 115 in src/components/Auth/index.tsx

View workflow job for this annotation

GitHub Actions / eslint-run

Unexpected console statement

Check warning on line 115 in src/components/Auth/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/admin/signin.cy.ts)

Unexpected console statement

Check warning on line 115 in src/components/Auth/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/checkEnv.cy.ts)

Unexpected console statement

Check warning on line 115 in src/components/Auth/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/createGeneratedEdges/createGeneratedEdges.cy.ts)

Unexpected console statement

Check warning on line 115 in src/components/Auth/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/admin/topics.cy.ts)

Unexpected console statement

Check warning on line 115 in src/components/Auth/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/seeLatest/latest.cy.ts)

Unexpected console statement

Check warning on line 115 in src/components/Auth/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addWebpage.cy.ts)

Unexpected console statement

Check warning on line 115 in src/components/Auth/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addYoutube.cy.ts)

Unexpected console statement

Check warning on line 115 in src/components/Auth/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/curationTable/curation.cy.ts)

Unexpected console statement

Check warning on line 115 in src/components/Auth/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addTweet.cy.ts)

Unexpected console statement

Check warning on line 115 in src/components/Auth/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addContent/addSource.cy.ts)

Unexpected console statement

Check warning on line 115 in src/components/Auth/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/trendingTopics/trendingTopics.cy.ts)

Unexpected console statement

Check warning on line 115 in src/components/Auth/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/sourcesTable/sourcesTable.cy.ts)

Unexpected console statement

Check warning on line 115 in src/components/Auth/index.tsx

View workflow job for this annotation

GitHub Actions / cypress-run (cypress/e2e/addNode/addNodeType.cy.ts)

Unexpected console statement
}
}

Expand Down
43 changes: 36 additions & 7 deletions src/components/SettingsModal/SettingsView/General/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { FC, useState } from 'react'
import { Button } from '@mui/material'
import { FC, useState } from 'react'
import { FormProvider, useForm } from 'react-hook-form'
import { MdError } from 'react-icons/md'
import { ClipLoader } from 'react-spinners'
import styled from 'styled-components'
import { Flex } from '~/components/common/Flex'
import { SuccessNotify } from '~/components/common/SuccessToast'
import { TextInput } from '~/components/common/TextInput'
import { NODE_ADD_ERROR, requiredRule } from '~/constants'
import { TAboutParams, postAboutData } from '~/network/fetchSourcesData'
import { postAboutData, TAboutParams } from '~/network/fetchSourcesData'
import { useAppStore } from '~/stores/useAppStore'
import { useUserStore } from '~/stores/useUserStore'
import { colors } from '~/utils/colors'
import { SuccessNotify } from '~/components/common/SuccessToast'
import { MdError } from 'react-icons/md'

type Props = {
initialValues: TAboutParams
Expand All @@ -21,6 +22,7 @@ export const General: FC<Props> = ({ initialValues, onClose }) => {
const form = useForm<TAboutParams>({ defaultValues: initialValues, mode: 'onSubmit' })
const { isSubmitting } = form.formState
const setAppMetaData = useAppStore((s) => s.setAppMetaData)
const { swarmUiUrl } = useUserStore((s) => s)
const [error, setError] = useState<string>('')

const onSubmit = form.handleSubmit(async (data) => {
Expand Down Expand Up @@ -56,8 +58,14 @@ export const General: FC<Props> = ({ initialValues, onClose }) => {
return (
<FormProvider {...form}>
<StyledForm id="add-node-form" onSubmit={handleSubmit}>
<>
<FormBody>
<Flex>
{swarmUiUrl && (
<SwarmLinkContainer>
<Link href={swarmUiUrl}>View Swarm UI</Link>
</SwarmLinkContainer>
)}

<Flex pt={20}>
<TextInput
id="cy-about-title-id"
Expand All @@ -81,7 +89,7 @@ export const General: FC<Props> = ({ initialValues, onClose }) => {
</Flex>
</Flex>

<Flex mt={210} py={error ? 0 : 24}>
<Flex py={error ? 0 : 24}>
<Button
color="secondary"
disabled={isSubmitting}
Expand All @@ -108,14 +116,15 @@ export const General: FC<Props> = ({ initialValues, onClose }) => {
</StyledError>
) : null}
</Flex>
</>
</FormBody>
</StyledForm>
</FormProvider>
)
}

const StyledForm = styled.form`
padding: 36px;
height: 100%;
`

const IconWrapper = styled.span`
Expand All @@ -130,6 +139,26 @@ const IconWrapper = styled.span`
}
`

const SwarmLinkContainer = styled(Flex)`
display: flex;
align-items: flex-end;
`

const FormBody = styled(Flex)`
display: flex;
direction: column;
justify-content: space-between;
height: 100%;
`

const Link = styled.a`
font-family: 'Barlow';
font-size: 16px;
color: ${colors.PRIMARY_BLUE};
text-decoration: underline;
font-weight: 500;
`

const StyledError = styled(Flex)`
display: flex;
align-items: center;
Expand Down
5 changes: 5 additions & 0 deletions src/stores/useUserStore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ export type UserStore = {
tribeUuid: string
setTribeUuid: (val: string) => void
tribeHost: string
swarmUiUrl: string
setTribeHost: (val: string) => void
setIsAuthenticated: (val: boolean) => void
setSignedToken: (val: string) => void
setSwarmUiUrl: (val: string) => void
}

const defaultData: Omit<
Expand All @@ -31,6 +33,7 @@ const defaultData: Omit<
| 'setTribeHost'
| 'setIsAuthenticated'
| 'setSignedToken'
| 'setSwarmUiUrl'
> = {
isAdmin: false,
isAuthenticated: false,
Expand All @@ -40,6 +43,7 @@ const defaultData: Omit<
tribeHost: '',
tribeUuid: '',
signedToken: '',
swarmUiUrl: '',
}

export const useUserStore = create<UserStore>((set) => ({
Expand All @@ -59,4 +63,5 @@ export const useUserStore = create<UserStore>((set) => ({
setTribeHost: (tribeHost) => set({ tribeHost }),
setIsAuthenticated: (isAuthenticated) => set({ isAuthenticated }),
setSignedToken: (signedToken) => set({ signedToken }),
setSwarmUiUrl: (swarmUiUrl) => set({ swarmUiUrl }),
}))
1 change: 1 addition & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ export type IsAdminResponse = {
customSchema: boolean
realtimeGraph: boolean
chatInterface: boolean
swarmUiUrl: string
}
success: boolean
message: string
Expand Down
Loading