Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

Project view components to ts

kruzhambus6a2dc9184633
diff --git a/src/pages/Project/View/components/CCRow.jsx b/src/pages/Project/View/components/CCRow.tsx
similarity index 87%
rename from src/pages/Project/View/components/CCRow.jsx
rename to src/pages/Project/View/components/CCRow.tsx
index 2f9452b2b..bed9f85f1 100644
--- a/src/pages/Project/View/components/CCRow.jsx
+++ b/src/pages/Project/View/components/CCRow.tsx
@@ -10,7 +10,10 @@ import PropTypes from 'prop-types'
* @param {string} language - Language to use for country name.
* @returns {JSX.Element}
*/
-const CCRow = ({ rowName, language }) => (
+const CCRow = ({ rowName, language }: {
+ rowName: string
+ language: string
+}): JSX.Element => (
<>
<Flag
className='rounded-sm'
diff --git a/src/pages/Project/View/components/Filters.jsx b/src/pages/Project/View/components/Filters.tsx
similarity index 81%
rename from src/pages/Project/View/components/Filters.jsx
rename to src/pages/Project/View/components/Filters.tsx
index 2eb6158db..9793fbada 100644
--- a/src/pages/Project/View/components/Filters.jsx
+++ b/src/pages/Project/View/components/Filters.tsx
@@ -12,7 +12,18 @@ import countries from 'utils/isoCountries'
*/
const Filter = ({
column, filter, isExclusive, onRemoveFilter, onChangeExclusive, tnMapping, language, t,
-}) => {
+}: {
+ column: string
+ filter: string
+ isExclusive: boolean
+ // eslint-disable-next-line no-shadow
+ onRemoveFilter: (column: string, filter: string) => void
+ // eslint-disable-next-line no-shadow
+ onChangeExclusive: (column: string, filter: string, isExclusive: boolean) => void
+ tnMapping: Record<string, string>
+ language: string
+ t: (key: string) => string
+}): JSX.Element => {
const displayColumn = tnMapping[column]
let displayFilter = filter
@@ -58,6 +69,17 @@ const Filter = ({
*/
const Filters = ({
filters, onRemoveFilter, onChangeExclusive, tnMapping,
+}: {
+ filters: {
+ column: string
+ filter: string
+ isExclusive: boolean
+ }[]
+ // eslint-disable-next-line no-shadow
+ onRemoveFilter: (column: string, filter: string) => void
+ // eslint-disable-next-line no-shadow
+ onChangeExclusive: (column: string, filter: string, isExclusive: boolean) => void
+ tnMapping: Record<string, string>
}) => {
const { t, i18n: { language } } = useTranslation('common')
diff --git a/src/pages/Project/View/components/InteractiveMap.jsx b/src/pages/Project/View/components/InteractiveMap.tsx
similarity index 85%
rename from src/pages/Project/View/components/InteractiveMap.jsx
rename to src/pages/Project/View/components/InteractiveMap.tsx
index ec078aee3..807cc1de6 100644
--- a/src/pages/Project/View/components/InteractiveMap.jsx
+++ b/src/pages/Project/View/components/InteractiveMap.tsx
@@ -5,21 +5,38 @@ import { useTranslation } from 'react-i18next'
import PropTypes from 'prop-types'
import countries from 'utils/isoCountries'
import { PROJECT_TABS } from 'redux/constants'
+import { StateType } from 'redux/store'
import { getTimeFromSeconds, getStringFromTime } from 'utils/generic'
import countriesList from 'utils/countries'
import { useSelector } from 'react-redux'
-const InteractiveMap = ({ data, onClickCountry, total }) => {
+const InteractiveMap = ({ data, onClickCountry, total }: {
+ data: Record<string, number>
+ onClickCountry: (country: string) => void
+ total: number
+}) => {
const { t, i18n: { language } } = useTranslation('common')
- const [hoverShow, setHoverShow] = useState(false)
- const [dataHover, setDataHover] = useState(null)
- const [cursorPosition, setCursorPosition] = useState(null)
+ const [hoverShow, setHoverShow] = useState<boolean>(false)
+ const [dataHover, setDataHover] = useState<{
+ countries: string
+ data: number
+ }>({} as {
+ countries: string
+ data: number
+ })
+ const [cursorPosition, setCursorPosition] = useState<{
+ pageX: number
+ pageY: number
+ }>({} as {
+ pageX: number
+ pageY: number
+ })
- const projectTab = useSelector((state) => state.ui.projects.projectTab)
+ const projectTab = useSelector((state: StateType) => state.ui.projects.projectTab)
const isTrafficTab = projectTab === PROJECT_TABS.traffic
- const onMouseMove = (e) => {
+ const onMouseMove = (e: React.MouseEvent<SVGSVGElement, MouseEvent>) => {
const rect = e.currentTarget.getBoundingClientRect()
const pageX = e.clientX - rect.left
const pageY = e.clientY - rect.top
diff --git a/src/pages/Project/View/components/LiveVisitorsDropdown.jsx b/src/pages/Project/View/components/LiveVisitorsDropdown.tsx
similarity index 88%
rename from src/pages/Project/View/components/LiveVisitorsDropdown.jsx
rename to src/pages/Project/View/components/LiveVisitorsDropdown.tsx
index bdcdd240b..dbf934a2e 100644
--- a/src/pages/Project/View/components/LiveVisitorsDropdown.jsx
+++ b/src/pages/Project/View/components/LiveVisitorsDropdown.tsx
@@ -1,19 +1,23 @@
import React, { useState, useEffect } from 'react'
import _map from 'lodash/map'
import { useTranslation } from 'react-i18next'
+// @ts-ignore
import OutsideClickHandler from 'react-outside-click-handler'
import {
ChevronDownIcon, ChevronUpIcon, XMarkIcon,
} from '@heroicons/react/24/outline'
import Flag from 'react-flagkit'
-import { getLiveVisitorsInfo } from 'api'
+import { getLiveVisitorsInfo, IGetLiveVisitorsInfo } from 'api'
-const LiveVisitorsDropdown = ({ live, projectId }) => {
+const LiveVisitorsDropdown = ({ live, projectId }: {
+ live: number
+ projectId: string
+}): JSX.Element => {
const { t } = useTranslation()
- const [show, setShow] = useState(false)
- const [liveInfo, setLiveInfo] = useState([])
- const [loading, setLoading] = useState(true)
+ const [show, setShow] = useState<boolean>(false)
+ const [liveInfo, setLiveInfo] = useState<IGetLiveVisitorsInfo[]>([])
+ const [loading, setLoading] = useState<boolean>(true)
const getLiveVisitors = async () => {
await getLiveVisitorsInfo(projectId)
diff --git a/src/pages/Project/View/components/NoEvents.jsx b/src/pages/Project/View/components/NoEvents.jsx
deleted file mode 100644
index b89ef0282..000000000
--- a/src/pages/Project/View/components/NoEvents.jsx
+++ /dev/null
@@ -1,123 +0,0 @@
-import React, {
- memo, useEffect, useState, useRef,
-} from 'react'
-import { useTranslation, Trans } from 'react-i18next'
-import Prism from 'prismjs'
-import { ClipboardDocumentIcon } from '@heroicons/react/24/outline'
-import _isEmpty from 'lodash/isEmpty'
-import PropTypes from 'prop-types'
-
-import Code from 'ui/Code'
-import Button from 'ui/Button'
-import { getUMDBuildExample } from 'pages/Docs/examples'
-import { DOCS_URL } from 'redux/constants'
-
-/**
- * This component is used to display text if the data is not available.
- *
- * @param {array} filters - Active filters.
- * @param {function} resetFilters - Callback to reset all filters.
- * @param {string} pid - Project ID.
- * @returns {JSX.Element}
- */
-const NoEvents = ({
- filters, resetFilters, pid,
-}) => {
- const { t } = useTranslation('common')
- const [copied, setCopied] = useState(false)
- const umdBuildExample = getUMDBuildExample(pid)
-
- const copyTimerRef = useRef(null)
-
- const setToClipboard = (value) => {
- if (!copied) {
- navigator.clipboard.writeText(value)
- setCopied(true)
- copyTimerRef.current = setTimeout(() => {
- setCopied(false)
- }, 2000)
- }
- }
-
- useEffect(() => {
- Prism.highlightAll()
-
- return () => {
- clearTimeout(copyTimerRef.current)
- }
- }, [])
-
- return (
- <div className='flex flex-col py-6 sm:px-6 lg:px-8 mt-5'>
- <div className='max-w-7xl w-full mx-auto text-gray-900 dark:text-gray-50'>
- <h2 className='text-4xl text-center leading-tight my-3'>
- {t('project.noEvTitle')}
- </h2>
- <h2 className='text-2xl mb-8 text-center leading-snug'>
- <Trans
- t={t}
- i18nKey='project.noEvContent'
- components={{
- // eslint-disable-next-line jsx-a11y/anchor-has-content
- url: <a href={DOCS_URL} className='hover:underline text-blue-600' target='_blank' rel='noreferrer noopener' />,
- }}
- />
- </h2>
- {!_isEmpty(filters) && (
- <div className='!flex !mx-auto'>
- <Button
- onClick={resetFilters}
- className='!flex !mx-auto'
- primary
- giant
- >
- {t('project.resetFilters')}
- </Button>
- </div>
- )}
- {_isEmpty(filters) && (
- <>
- <hr className='mt-3 mb-2 border-gray-200 dark:border-gray-600' />
- <h2 className='text-2xl mb-2 text-center leading-snug'>
- {t('project.codeExample')}
- </h2>
- <div className='relative'>
- <Code text={umdBuildExample} language='html' />
- <div className='absolute top-3 right-5'>
- <Button
- type='button'
- onClick={() => setToClipboard(umdBuildExample)}
- className='opacity-80 hover:opacity-100'
- noBorder
- >
- <ClipboardDocumentIcon className='w-6 h-6 text-gray-100' />
- {copied && (
- <div className='animate-appear cursor-auto rounded p-1 absolute sm:top-0 top-0.5 right-8 text-xs text-green-500'>
- {t('common.copied')}
- </div>
- )}
- </Button>
- </div>
- </div>
- </>
- )}
- </div>
- </div>
- )
-}
-
-NoEvents.propTypes = {
- filters: PropTypes.arrayOf(PropTypes.shape({
- column: PropTypes.string,
- filter: PropTypes.string,
- isExclusive: PropTypes.bool,
- })),
- resetFilters: PropTypes.func.isRequired,
- pid: PropTypes.string.isRequired,
-}
-
-NoEvents.defaultProps = {
- filters: [],
-}
-
-export default memo(NoEvents)
diff --git a/src/pages/Project/View/components/NoEvents.tsx b/src/pages/Project/View/components/NoEvents.tsx
new file mode 100644
index 000000000..ddc5ac585
--- /dev/null
+++ b/src/pages/Project/View/components/NoEvents.tsx
@@ -0,0 +1,80 @@
+import React, {
+ memo,
+} from 'react'
+import { useTranslation, Trans } from 'react-i18next'
+import _isEmpty from 'lodash/isEmpty'
+import PropTypes from 'prop-types'
+
+import Button from 'ui/Button'
+import { DOCS_CAPTCHA_URL } from 'redux/constants'
+
+/**
+ * This component is used to display text if the data is not available.
+ *
+ * @param {array} filters - Active filters.
+ * @param {function} resetFilters - Callback to reset all filters.
+ * @param {string} pid - Project ID.
+ * @returns {JSX.Element}
+ */
+const NoEvents = ({
+ filters, resetFilters,
+}: {
+ filters: {
+ column: string
+ filter: string
+ isExclusive: boolean
+ }[]
+ resetFilters: () => void
+}): JSX.Element => {
+ const { t }: {
+ t: (key: string) => string
+ } = useTranslation('common')
+
+ return (
+ <div className='flex flex-col py-6 sm:px-6 lg:px-8 mt-5'>
+ <div className='max-w-7xl w-full mx-auto text-gray-900 dark:text-gray-50'>
+ <h2 className='text-4xl text-center leading-tight my-3'>
+ {t('project.noEvTitle')}
+ </h2>
+ <h2 className='text-2xl mb-8 text-center leading-snug'>
+ <Trans
+ // @ts-ignore
+ t={t}
+ i18nKey='project.noCaptchaEv'
+ components={{
+ // eslint-disable-next-line jsx-a11y/anchor-has-content
+ url: <a href={DOCS_CAPTCHA_URL} className='hover:underline text-blue-600' target='_blank' rel='noreferrer noopener' />,
+ }}
+ />
+ </h2>
+ {!_isEmpty(filters) && (
+ <div className='!flex !mx-auto'>
+ <Button
+ onClick={resetFilters}
+ className='!flex !mx-auto'
+ primary
+ giant
+ >
+ {t('project.resetFilters')}
+ </Button>
+ </div>
+ )}
+ </div>
+ </div>
+ )
+}
+
+NoEvents.propTypes = {
+ filters: PropTypes.arrayOf(PropTypes.shape({
+ column: PropTypes.string,
+ filter: PropTypes.string,
+ isExclusive: PropTypes.bool,
+ })),
+ resetFilters: PropTypes.func.isRequired,
+}
+
+NoEvents.defaultProps = {
+ filters: [],
+}
+
+export default memo(NoEvents)
diff --git a/src/pages/Project/View/components/RefRow.jsx b/src/pages/Project/View/components/RefRow.tsx
similarity index 79%
rename from src/pages/Project/View/components/RefRow.jsx
rename to src/pages/Project/View/components/RefRow.tsx
index 9847c7956..bee34ee08 100644
--- a/src/pages/Project/View/components/RefRow.jsx
+++ b/src/pages/Project/View/components/RefRow.tsx
@@ -9,22 +9,25 @@ import PropTypes from 'prop-types'
* @param {boolean} showIcons - Whether to show favicon icons near links or not.
* @returns {JSX.Element}
*/
-const RefRow = ({ rowName, showIcons }) => {
- let isUrl = true
- let url = rowName
+const RefRow = ({ rowName, showIcons }: {
+ rowName: string
+ showIcons: boolean
+}): JSX.Element => {
+ let isUrl: boolean = true
+ let url: URL | null = null
try {
- url = new URL(rowName)
+ url = new URL(rowName) as URL
} catch {
isUrl = false
}
return (
<div>
- {showIcons && isUrl && !_isEmpty(url.hostname) && (
+ {showIcons && isUrl && !_isEmpty(url?.hostname) && (
<img
className='w-5 h-5 mr-1.5 float-left'
- src={`https://icons.duckduckgo.com/ip3/${url.hostname}.ico`}
+ src={`https://icons.duckduckgo.com/ip3/${url?.hostname}.ico`}
alt=''
aria-hidden='true'
/>