diff --git a/.circleci/config.yml b/.circleci/config.yml index c495fa1..0d2aa83 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,9 +6,32 @@ orbs: queue: eddiewebb/queue@1.6.4 datacamp-deploy-branch: datacamp/deploy-branch@1 datacamp-artifactory: datacamp/artifactory@1 - + +jobs: + lint: + executor: node + steps: + - checkout + - run: + name: Install all dependencies + command: yarn + - run: + name: Lint all files + command: yarn lint + +executors: + node: + docker: + - image: cimg/node:16.18.0 workflows: -# BEGIN ANSIBLE MANAGED BLOCK + test_pr: + jobs: + - lint: + filters: + branches: + ignore: + - master + # BEGIN ANSIBLE MANAGED BLOCK build-and-deploy-eks: jobs: - queue/block_workflow: @@ -46,7 +69,7 @@ workflows: - datacamp-artifactory/build_and_push_image_to_artifactory: name: docker-build context: org-global - extra-docker-args: "--build-arg NPM_TOKEN=${NPM_TOKEN}" + extra-docker-args: '--build-arg NPM_TOKEN=${NPM_TOKEN}' dockerfile: Dockerfile docker-version: 20.10.2 executor: datacamp-artifactory/buildkit @@ -62,7 +85,7 @@ workflows: env: staging roles: terraform-role,k8s-role region: us-east-1 - extra-vars: "backstage=true" + extra-vars: 'backstage=true' filters: branches: only: @@ -93,35 +116,35 @@ workflows: requires: - testing-complete # END ANSIBLE MANAGED BLOCK - # build-and-deploy: - # jobs: - # - datacamp-ecr/build_and_push_image_to_ecr: - # name: build - # context: org-global - # aws-access-key-id: $OPS_AWS_ACCESS_KEY_ID - # aws-secret-access-key: $OPS_AWS_SECRET_ACCESS_KEY - # account-url: $OPS_ECR_URL - # puller-account-ids: '["301258414863", "487088987264"]' - # docker-version: 20.10.2 - # - datacamp-deploy/deploy: # Staging - # environment: staging - # aws-access-key-id: $STAGING_AWS_ACCESS_KEY_ID - # aws-secret-access-key: $STAGING_AWS_SECRET_ACCESS_KEY - # context: org-global - # requires: - # - build - # filters: - # branches: - # only: - # - main - # - datacamp-deploy/deploy: # Production - # environment: prod - # context: org-global - # requires: - # - build - # aws-access-key-id: $PROD_AWS_ACCESS_KEY_ID - # aws-secret-access-key: $PROD_AWS_SECRET_ACCESS_KEY - # filters: - # branches: - # only: - # - main +# build-and-deploy: +# jobs: +# - datacamp-ecr/build_and_push_image_to_ecr: +# name: build +# context: org-global +# aws-access-key-id: $OPS_AWS_ACCESS_KEY_ID +# aws-secret-access-key: $OPS_AWS_SECRET_ACCESS_KEY +# account-url: $OPS_ECR_URL +# puller-account-ids: '["301258414863", "487088987264"]' +# docker-version: 20.10.2 +# - datacamp-deploy/deploy: # Staging +# environment: staging +# aws-access-key-id: $STAGING_AWS_ACCESS_KEY_ID +# aws-secret-access-key: $STAGING_AWS_SECRET_ACCESS_KEY +# context: org-global +# requires: +# - build +# filters: +# branches: +# only: +# - main +# - datacamp-deploy/deploy: # Production +# environment: prod +# context: org-global +# requires: +# - build +# aws-access-key-id: $PROD_AWS_ACCESS_KEY_ID +# aws-secret-access-key: $PROD_AWS_SECRET_ACCESS_KEY +# filters: +# branches: +# only: +# - main diff --git a/components/Autocomplete.tsx b/components/Autocomplete.tsx index f0e076c..5610a34 100644 --- a/components/Autocomplete.tsx +++ b/components/Autocomplete.tsx @@ -1,127 +1,120 @@ -import { Heading, Paragraph } from "@datacamp/waffles-text"; -import router from "next/router"; -import { useEffect, useState } from "react"; -import { API_URL } from "../lib/utils"; +/* eslint-disable filenames/match-exported */ +import { Heading, Paragraph } from '@datacamp/waffles-text'; +import router from 'next/router'; +import { useEffect, useState } from 'react'; + +import { API_URL } from '../lib/utils'; type Props = { - searchInput: string + searchInput: string; }; export default function AutoComplete({ searchInput }: Props) { - const [packageSuggestions, setPackageSuggestions] = useState([]); const [topicSuggestions, setTopicSuggestions] = useState([]); - function onClick(query) { - router.push(`/search?q=${encodeURIComponent(query)}`); - }; + function onClick(query) { + router.push(`/search?q=${encodeURIComponent(query)}`); + } + + async function autoComplete(query) { + try { + // fetch the data + const [resPackages, resTopics] = await Promise.all([ + fetch(`${API_URL}/search_packages?q=${query}&page=1&latest=1`, { + headers: { + Accept: 'application/json', + }, + }), + fetch(`${API_URL}/search_functions?q=${query}&page=1&latest=1`, { + headers: { + Accept: 'application/json', + }, + }), + ]); - async function autoComplete(query) { - try { - // fetch the data - const [resPackages, resTopics] = await Promise.all([ - fetch( - `${API_URL}/search_packages?q=${query}&page=1&latest=1`, - { - headers: { - Accept: 'application/json', - }, - }, - ), - fetch( - `${API_URL}/search_functions?q=${query}&page=1&latest=1`, - { - headers: { - Accept: 'application/json', - }, - }, - ) - ]); - - const { packages } = await resPackages?.json(); - const functions = await resTopics?.json(); - const topics = functions?.functions; - const relevantPackages = packages?.filter((p)=>(p?.score>1)); - const relevantTopics = topics?.filter((p)=>(p?.score>1)); - setPackageSuggestions(relevantPackages?.slice(0, Math.min(relevantPackages?.length, 5))); - setTopicSuggestions(relevantTopics?.slice(0, Math.min(relevantTopics?.length, 5))); - - } catch (err) { - console.error(err); - } - }; + const { packages } = await resPackages?.json(); + const functions = await resTopics?.json(); + const topics = functions?.functions; + const relevantPackages = packages?.filter((p) => p?.score > 1); + const relevantTopics = topics?.filter((p) => p?.score > 1); + setPackageSuggestions( + relevantPackages?.slice(0, Math.min(relevantPackages?.length, 5)), + ); + setTopicSuggestions( + relevantTopics?.slice(0, Math.min(relevantTopics?.length, 5)), + ); + } catch (err) { + // eslint-disable-next-line no-console + console.error(err); + } + } - useEffect(()=>{ - autoComplete(searchInput); - }, [searchInput]) + useEffect(() => { + autoComplete(searchInput); + }, [searchInput]); - return ( -
- { - searchInput - && -
onClick(searchInput)} - className="flex items-center px-4 py-4 cursor-pointer hover:bg-dc-beige200 hover:opacity-0.5" - > - {`View results for "${searchInput}"`} -
- } -
- { - packageSuggestions?.length>0 - && - searchInput - && - + )} +
+
+ ); +} diff --git a/components/Html.tsx b/components/Html.tsx index f9492bc..d99d63d 100644 --- a/components/Html.tsx +++ b/components/Html.tsx @@ -1,4 +1,4 @@ -import { MathJax, MathJaxContext } from "better-react-mathjax"; +import { MathJax, MathJaxContext } from 'better-react-mathjax'; type Props = { children: string; diff --git a/components/PackageReadMePlaceholder.tsx b/components/PackageReadMePlaceholder.tsx index 46ade4b..2d25928 100644 --- a/components/PackageReadMePlaceholder.tsx +++ b/components/PackageReadMePlaceholder.tsx @@ -1,23 +1,17 @@ import Html from './Html'; type Props = { - packageName: string, - version: string, - title: string, - description: string -} + description: string; + packageName: string; + title: string; + version: string; +}; export default function PackageReadMePlaceholder(data: Props) { - const { - packageName, - version, - title, - description - } = data; + const { description, packageName, title, version } = data; return ( -
+
@@ -25,25 +19,17 @@ export default function PackageReadMePlaceholder(data: Props) { {`${packageName} (version ${version})`}
- { - title - && - ( + {title && (
-

{title}

+

{title}

- ) - } - { - description - && - ( + )} + {description && (

Description

{description}
- ) - } + )}
diff --git a/lib/utils.ts b/lib/utils.ts index d0f5392..2f1193c 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -41,4 +41,4 @@ export function copyTextToClipboard(text: string) { navigator.clipboard.writeText(text); } -export const API_URL = 'https://api.rdocumentation.org'; \ No newline at end of file +export const API_URL = 'https://api.rdocumentation.org'; diff --git a/pages/_document.tsx b/pages/_document.tsx index 6829c2c..8f462f1 100644 --- a/pages/_document.tsx +++ b/pages/_document.tsx @@ -20,7 +20,10 @@ class MyDocument extends Document { - +