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

Properly lint repo #131

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
95 changes: 59 additions & 36 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,32 @@ orbs:
queue: eddiewebb/[email protected]
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:
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
221 changes: 107 additions & 114 deletions components/Autocomplete.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<div className="my-2 bg-white rounded-2xl shadow-lg">
{
searchInput
&&
<div
onClick={()=>onClick(searchInput)}
className="flex items-center px-4 py-4 cursor-pointer hover:bg-dc-beige200 hover:opacity-0.5"
>
<Paragraph className="pl-2 py-2">{`View results for "${searchInput}"`}</Paragraph>
</div>
}
<div>
{
packageSuggestions?.length>0
&&
searchInput
&&
<ul>
<li className="my-2 ml-2 pl-4 text-dc-grey200 flex justify-between">
<Heading as="h3" size={300}>PACKAGES</Heading>
return (
<div className="my-2 bg-white rounded-2xl shadow-lg">
{searchInput && (
<div
className="flex items-center px-4 py-4 cursor-pointer hover:bg-dc-beige200 hover:opacity-0.5"
onClick={() => onClick(searchInput)}
>
<Paragraph className="pl-2 py-2">{`View results for "${searchInput}"`}</Paragraph>
</div>
)}
<div>
{packageSuggestions?.length > 0 && searchInput && (
<ul>
<li className="my-2 ml-2 pl-4 text-dc-grey200 flex justify-between">
<Heading as="h3" size={300}>
PACKAGES
</Heading>
</li>
{packageSuggestions?.map((p) => {
return (
<li
className="flex items-center px-4 py-2 cursor-pointer hover:bg-dc-beige200 hover:opacity-0.5"
key={p?.fields?.package_name}
onClick={() => onClick(p?.fields?.package_name)}
>
<Paragraph className="pl-2 text-lg">
{p?.fields?.package_name}
</Paragraph>
</li>
{
packageSuggestions?.map((p)=>{
return (
<li
key={p?.fields?.package_name}
onClick={()=>onClick(p?.fields?.package_name)}
className="flex items-center px-4 py-2 cursor-pointer hover:bg-dc-beige200 hover:opacity-0.5"
>
<Paragraph className="pl-2 text-lg">{p?.fields?.package_name}</Paragraph>
</li>
)
})}
</ul>
}
</div>
<div>
{
topicSuggestions?.length>0
&&
searchInput
&&
<ul>
<li className="my-2 ml-2 pl-4 text-dc-grey200 flex justify-between">
<Heading as="h3" size={300}>FUNCTIONS</Heading>
);
})}
</ul>
)}
</div>
<div>
{topicSuggestions?.length > 0 && searchInput && (
<ul>
<li className="my-2 ml-2 pl-4 text-dc-grey200 flex justify-between">
<Heading as="h3" size={300}>
FUNCTIONS
</Heading>
</li>
{topicSuggestions?.map((t) => {
return (
<li
className="flex items-center px-4 py-2 cursor-pointer hover:bg-dc-beige200 hover:opacity-0.5"
key={t?.fields?.package_name + t?.fields?.name}
onClick={() => onClick(t?.fields?.name)}
>
<div>
<Paragraph className="px-2 text-lg">{`${t?.fields?.name}`}</Paragraph>
</div>
<div>
<Paragraph className="text-lg text-dc-red">{`(${t?.fields?.package_name})`}</Paragraph>
</div>
</li>
{
topicSuggestions?.map((t)=>{
return (
<li
key={t?.fields?.package_name+t?.fields?.name}
onClick={()=>onClick(t?.fields?.name)}
className="flex items-center px-4 py-2 cursor-pointer hover:bg-dc-beige200 hover:opacity-0.5"
>
<div>
<Paragraph className="px-2 text-lg">{`${t?.fields?.name}`}</Paragraph>
</div>
<div>
<Paragraph className="text-lg text-dc-red">{`(${t?.fields?.package_name})`}</Paragraph>
</div>
</li>
)
})}
</ul>
}
</div>
</div>
)
}
);
})}
</ul>
)}
</div>
</div>
);
}
2 changes: 1 addition & 1 deletion components/Html.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MathJax, MathJaxContext } from "better-react-mathjax";
import { MathJax, MathJaxContext } from 'better-react-mathjax';

type Props = {
children: string;
Expand Down
Loading