Skip to content

Commit

Permalink
Merge pull request #59 from pantheon-systems/PCC-555-adjust-nextjs-st…
Browse files Browse the repository at this point in the history
…arter-kit-tests-js-ts

Make nextjs starter kit tests more useful. Solve some SDK typescript problems.
  • Loading branch information
kevinstubbs authored Sep 13, 2023
2 parents 980fb0b + 00e3424 commit 3b97d98
Show file tree
Hide file tree
Showing 64 changed files with 132 additions and 5,710 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
node_modules/
yarn.lock
yarn-error.log
package-lock.json

.env.local
.env.development
.env.production

.turbo
.DS_Store
yarn-error.log
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@pantheon-systems/pcc-cli",
"author": "@pantheon-systems",
"description": "Pantheon Content Cloud CLI",
"version": "2.0.1",
"version": "2.0.2",
"type": "module",
"license": "MIT",
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@pantheon-systems/pcc-sdk-core",
"author": "@pantheon-systems",
"description": "Pantheon Content Cloud SDK Core",
"version": "2.0.1",
"version": "2.0.2",
"license": "MIT",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
46 changes: 29 additions & 17 deletions packages/core/src/helpers/articles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,39 @@ export interface ArticleQueryArgs {
}

type FilterableFields = "body" | "tag" | "title";
export type ArticleSearchArgs = { [key in FilterableFields]: string };

export type ArticleSearchArgs = {
bodyContains?: string;
tagContains?: string;
titleContains?: string;
};

type ConvertedArticleSearchArgs = {
[key in FilterableFields]: { contains: string };
[key in FilterableFields]: { contains: string } | undefined;
};

export function convertSearchParamsToGQL(
searchParams?: ArticleSearchArgs,
): { filter: ConvertedArticleSearchArgs } | null {
if (!searchParams) return null;

// Cast empty object to workaround Typescript bug
// https://stackoverflow.com/questions/15877362/declare-and-initialize-a-dictionary-in-typescript
const convertedObject: ConvertedArticleSearchArgs =
{} as ConvertedArticleSearchArgs;

Object.keys(searchParams).forEach(
(k) =>
(convertedObject[k.replace("Contains", "") as FilterableFields] = {
contains: searchParams[k as FilterableFields],
}),
);
const convertedObject: ConvertedArticleSearchArgs = {
body: searchParams.bodyContains
? {
contains: searchParams.bodyContains,
}
: undefined,
tag: searchParams.tagContains
? {
contains: searchParams.tagContains,
}
: undefined,
title: searchParams.titleContains
? {
contains: searchParams.titleContains,
}
: undefined,
};

return Object.keys(convertedObject).length
? { filter: convertedObject }
Expand All @@ -60,12 +72,12 @@ export async function getArticles(

export async function getArticle(
client: PantheonClient,
id: string,
id: number | string,
args?: ArticleQueryArgs,
) {
const article = await client.apolloClient.query({
query: GET_ARTICLE_QUERY,
variables: { id, ...args },
variables: { id: id.toString(), ...args },
});

return article.data.article as Article;
Expand All @@ -86,13 +98,13 @@ export async function getArticleBySlug(

export async function getArticleBySlugOrId(
client: PantheonClient,
slugOrId: string,
slugOrId: number | string,
args?: ArticleQueryArgs,
) {
// First attempt to retrieve by slug, and fallback to by id if the matching slug
// couldn't be found.
try {
const article = await getArticleBySlug(client, slugOrId, args);
const article = await getArticleBySlug(client, slugOrId.toString(), args);

if (article) {
return article;
Expand Down
2 changes: 1 addition & 1 deletion packages/react-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@pantheon-systems/pcc-react-sdk",
"author": "@pantheon-systems",
"description": "Pantheon Content Cloud React SDK",
"version": "2.0.1",
"version": "2.0.2",
"license": "MIT",
"keywords": [
"pcc",
Expand Down
2 changes: 2 additions & 0 deletions packages/react-sdk/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export type { PantheonClientConfig } from "@pantheon-systems/pcc-sdk-core";
export { PantheonClient } from "@pantheon-systems/pcc-sdk-core";

export {
getArticles,
getArticle,
Expand Down
2 changes: 1 addition & 1 deletion packages/vue-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@pantheon-systems/pcc-vue-sdk",
"author": "@pantheon-systems",
"description": "Pantheon Content Cloud Vue SDK",
"version": "2.0.1",
"version": "2.0.2",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
Expand Down
3 changes: 3 additions & 0 deletions starters/gatsby-starter/src/components/seo.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import React from 'react';

const defaultMeta = {
type: "website",
robots: "follow, index",
Expand All @@ -12,6 +14,7 @@ export default function Seo({ title, description, tags, authors, date }) {
tags,
date,
};

return (
<head>
<title>{meta.title}</title>
Expand Down
10 changes: 0 additions & 10 deletions starters/nextjs-starter-ts/__tests__/data/article.json

This file was deleted.

20 changes: 0 additions & 20 deletions starters/nextjs-starter-ts/__tests__/data/articles.json

This file was deleted.

Loading

0 comments on commit 3b97d98

Please sign in to comment.