Skip to content

Commit

Permalink
changes for capability page type
Browse files Browse the repository at this point in the history
  • Loading branch information
Trombach committed Nov 28, 2022
1 parent f12d3ee commit ab1732e
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 14 deletions.
2 changes: 2 additions & 0 deletions graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ClientAPI, createClient, Entry, Environment, Space } from "contentful-m

type ContentType
= 'article'
| 'capability'
| 'caseStudy'
| 'equipment'
| 'event'
Expand All @@ -13,6 +14,7 @@ type ContentType
const defaultSelectQuery = 'sys.id,fields.title,fields.slug,sys.contentType,fields.relatedItems';
const queryMap: Map<ContentType, string> = new Map([
['article', defaultSelectQuery],
['capability', defaultSelectQuery],
['caseStudy', defaultSelectQuery],
['equipment', defaultSelectQuery],
['event', defaultSelectQuery],
Expand Down
47 changes: 40 additions & 7 deletions reports/contentOverview.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getApolloClient } from "../apolloClient";
import { ApolloClient, NormalizedCacheObject } from "@apollo/client/core";
import { CurrentReportDoc, DataOverTimeDoc } from "../googleDocsWrapper";
import { GetAllArticlesDocument, GetAllArticlesQuery, GetAllCaseStudiesDocument, GetAllCaseStudiesQuery, GetAllCategoriesDocument, GetAllCategoriesQuery, GetAllEquipmentDocument, GetAllEquipmentQuery, GetAllEventsDocument, GetAllEventsQuery, GetAllFundingPagesDocument, GetAllFundingPagesQuery, GetAllLinkCardsDocument, GetAllLinkCardsQuery, GetAllOfficialDocumentsDocument, GetAllOfficialDocumentsQuery, GetAllPersonsDocument, GetAllPersonsQuery, GetAllServicesDocument, GetAllServicesQuery, GetAllSoftwaresDocument, GetAllSoftwaresQuery, GetAllSubHubsDocument, GetAllSubHubsQuery, GetAllVideosDocument, GetAllVideosQuery } from "./types";
import { GetAllArticlesDocument, GetAllArticlesQuery, GetAllCapabilitiesDocument, GetAllCapabilitiesQuery, GetAllCaseStudiesDocument, GetAllCaseStudiesQuery, GetAllCategoriesDocument, GetAllCategoriesQuery, GetAllEquipmentDocument, GetAllEquipmentQuery, GetAllEventsDocument, GetAllEventsQuery, GetAllFundingPagesDocument, GetAllFundingPagesQuery, GetAllLinkCardsDocument, GetAllLinkCardsQuery, GetAllOfficialDocumentsDocument, GetAllOfficialDocumentsQuery, GetAllPersonsDocument, GetAllPersonsQuery, GetAllServicesDocument, GetAllServicesQuery, GetAllSoftwaresDocument, GetAllSoftwaresQuery, GetAllSubHubsDocument, GetAllSubHubsQuery, GetAllVideosDocument, GetAllVideosQuery } from "./types";
import { uploadCsv } from "../csvUpload";
import { ResultOf } from "@graphql-typed-document-node/core";

Expand All @@ -15,20 +15,20 @@ let GRAPHQL_CHUNK_SIZE = 50;
* this is ugly, but there dosn't seem to be a way to turn a union type into an array of all possible values
* add new titles to both this array and the union type HeaderTitle
*/
const overviewSheetHeaderFields: ContentOverviewSummaryTitle[] = ['Date', 'SubHubs', 'Articles', 'Software', 'Official Documents', 'Link Cards', 'Events', 'Persons', 'Services', 'Videos', 'Categories', 'Equipment', 'CaseStudies', 'Funding Pages'];
const overviewSheetHeaderFields: ContentOverviewSummaryTitle[] = ['Date', 'SubHubs', 'Articles', 'Software', 'Official Documents', 'Link Cards', 'Events', 'Persons', 'Services', 'Videos', 'Categories', 'Equipment', 'CaseStudies', 'Funding Pages', 'Capabilities'];
const sheetHeaderFields: ContentOverviewHeaderTitle[] = ['ID', 'Title', 'Slug', 'Last Updated', 'Next Review', 'First Published', 'Owner', 'Publisher', 'Content Type', 'Related Orgs', 'Related Orgs 1', 'Related Orgs 2', 'Related Orgs 3', 'Linked Entries', 'Is SSO Protected', 'Is Searchable'];


type ContentOverviewRow = { [key in ContentOverviewHeaderTitle]: string | number | boolean };
type ContentOverviewHeaderTitle = 'ID' | 'Title' | 'Slug' | 'Last Updated' | 'Next Review' | 'First Published' | 'Owner' | 'Publisher' | 'Content Type' | 'Related Orgs' | 'Related Orgs 1' | 'Related Orgs 2' | 'Related Orgs 3' | 'Linked Entries' | 'Is SSO Protected' | 'Is Searchable';

type ContentOverviewSummaryRow = { [key in ContentOverviewSummaryTitle]: string | number | boolean };
type ContentOverviewSummaryTitle = 'Date' | 'SubHubs' | 'Articles' | 'Software' | 'Official Documents' | 'Link Cards' | 'Events' | 'Persons' | 'Services' | 'Videos' | 'Categories' | 'Equipment' | 'CaseStudies' | 'Funding Pages';
type ContentOverviewSummaryTitle = 'Date' | 'SubHubs' | 'Articles' | 'Software' | 'Official Documents' | 'Link Cards' | 'Events' | 'Persons' | 'Services' | 'Videos' | 'Categories' | 'Equipment' | 'CaseStudies' | 'Funding Pages' | 'Capabilities';

type ContentfulDocumentType = typeof GetAllArticlesDocument | typeof GetAllCaseStudiesDocument | typeof GetAllCategoriesDocument | typeof GetAllEquipmentDocument | typeof GetAllEventsDocument | typeof GetAllFundingPagesDocument | typeof GetAllLinkCardsDocument | typeof GetAllOfficialDocumentsDocument | typeof GetAllPersonsDocument | typeof GetAllServicesDocument | typeof GetAllSoftwaresDocument | typeof GetAllSubHubsDocument | typeof GetAllVideosDocument;
type ContentfulDocumentType = typeof GetAllArticlesDocument | typeof GetAllCapabilitiesDocument | typeof GetAllCaseStudiesDocument | typeof GetAllCategoriesDocument | typeof GetAllEquipmentDocument | typeof GetAllEventsDocument | typeof GetAllFundingPagesDocument | typeof GetAllLinkCardsDocument | typeof GetAllOfficialDocumentsDocument | typeof GetAllPersonsDocument | typeof GetAllServicesDocument | typeof GetAllSoftwaresDocument | typeof GetAllSubHubsDocument | typeof GetAllVideosDocument;
type ContentfulQueryType = ResultOf<ContentfulDocumentType>;

type ContentType = 'SubHub' | 'Article' | 'Software' | 'OfficialDocuments' | 'LinkCard' | 'Event' | 'Person' | 'Service' | 'Video' | 'Category' | 'Equipment' | 'CaseStudy' | 'Funding';
type ContentType = 'SubHub' | 'Article' | 'Software' | 'OfficialDocuments' | 'LinkCard' | 'Event' | 'Person' | 'Service' | 'Video' | 'Category' | 'Equipment' | 'CaseStudy' | 'Funding' | 'Capability';

interface ContentOverviewData {
id: string;
Expand Down Expand Up @@ -64,6 +64,7 @@ interface ContentOverviewSummaryData {
equipment: number;
caseStudies: number;
fundingPages: number;
capabilities: number
}

// export function to run report
Expand Down Expand Up @@ -113,7 +114,8 @@ export async function runContentOverview(chunkSize?: number): Promise<void> {
Categories: row.Categories ?? 0,
Equipment: row.Equipment ?? 0,
CaseStudies: row.CaseStudies ?? 0,
"Funding Pages": row["Funding Pages"] ?? 0
"Funding Pages": row["Funding Pages"] ?? 0,
Capabilities: row.Capabilities ?? 0
}

return summaryRow;
Expand Down Expand Up @@ -145,6 +147,7 @@ function getTotal(query: ContentfulQueryType): number {
if ('equipmentCollection' in query) return query.equipmentCollection?.total ?? 0;
if ('caseStudyCollection' in query) return query.caseStudyCollection?.total ?? 0;
if ('fundingCollection' in query) return query.fundingCollection?.total ?? 0;
if ('capabilityCollection' in query) return query.capabilityCollection?.total ?? 0;

throw new Error(`Unknown query type: ${query}`);
}
Expand All @@ -165,6 +168,7 @@ function mapReportData(query: ContentfulQueryType): Partial<ContentOverviewData>
if ('equipmentCollection' in query) return mapReportDataEquipment(query);
if ('caseStudyCollection' in query) return mapReportDataCaseStudies(query);
if ('fundingCollection' in query) return mapReportDataFundingPages(query);
if ('capabilityCollection' in query) return mapReportDataCapabilityPages(query);

throw new Error(`Unknown query type: ${query}`);
}
Expand Down Expand Up @@ -442,6 +446,31 @@ function mapReportDataFundingPages(queryData: GetAllFundingPagesQuery): Partial<
});
}

function mapReportDataCapabilityPages(queryData: GetAllCapabilitiesQuery): Partial<ContentOverviewData>[] | undefined {
return queryData.capabilityCollection?.items.map((item) => {
const rowData: Partial<ContentOverviewData> = {
contentType: item?.__typename,
id: item?.sys?.id,
isSearchable: item?.searchable,
isSsoProtected: item?.ssoProtected,
lastUpdated: item?.sys?.publishedAt ? new Date(item.sys.publishedAt) : null,
nextReview: item?.nextReview ? new Date(item.nextReview) : null,
owner: item?.owner?.name ? item.owner.name : '',
publisher: item?.publisher?.name ? item.publisher.name : '',
slug: item?.slug ? item.slug : '',
title: item?.title ? item.title : '',
relatedOrgs: item?.relatedOrgsCollection?.total,
relatedOrgs1: item?.relatedOrgsCollection?.items[0]?.name,
relatedOrgs2: item?.relatedOrgsCollection?.items[1]?.name,
relatedOrgs3: item?.relatedOrgsCollection?.items[2]?.name,
linkedEntries: item?.relatedItemsCollection?.total,
firstPublishedAt: item?.sys.firstPublishedAt ? new Date(item.sys.firstPublishedAt) : null
}

return rowData;
})
}

// get contentful data

async function getData(): Promise<{ summary: ContentOverviewSummaryRow, report: ContentOverviewRow[] }> {
Expand All @@ -462,6 +491,7 @@ async function getData(): Promise<{ summary: ContentOverviewSummaryRow, report:
const equipmentRows = await getRows(client, GetAllEquipmentDocument);
const caseStudyRows = await getRows(client, GetAllCaseStudiesDocument);
const fundingRows = await getRows(client, GetAllFundingPagesDocument);
const capabilityRows = await getRows(client, GetAllCapabilitiesDocument);

subHubRows ? report.push(...subHubRows.data) : null;
articleRows ? report.push(...articleRows.data) : null;
Expand All @@ -476,6 +506,7 @@ async function getData(): Promise<{ summary: ContentOverviewSummaryRow, report:
equipmentRows ? report.push(...equipmentRows.data) : null;
caseStudyRows ? report.push(...caseStudyRows.data) : null;
fundingRows ? report.push(...fundingRows.data) : null;
capabilityRows ? report.push(...capabilityRows.data) : null;

const summary: ContentOverviewSummaryData = {
linkCards: linkCardRows?.total ?? 0,
Expand All @@ -492,6 +523,7 @@ async function getData(): Promise<{ summary: ContentOverviewSummaryRow, report:
equipment: equipmentRows?.total ?? 0,
caseStudies: caseStudyRows?.total ?? 0,
fundingPages: fundingRows?.total ?? 0,
capabilities: capabilityRows?.total ?? 0
};

return {
Expand Down Expand Up @@ -584,7 +616,8 @@ function makeOverviewSummaryRow(data: ContentOverviewSummaryData): ContentOvervi
Videos: data.videos,
Equipment: data.equipment,
CaseStudies: data.caseStudies,
"Funding Pages": data.fundingPages
"Funding Pages": data.fundingPages,
Capabilities: data.capabilities
};
}

10 changes: 6 additions & 4 deletions reports/pagesPerCategory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { CurrentReportDoc } from "../googleDocsWrapper";
import { GetPagesPerCategoryDocument, GetPagesPerCategoryQuery, GetPagesPerStageDocument, GetPagesPerStageQuery } from "./types";

type HeaderTitleRow = { [key in HeaderTitle]: string | number | boolean };
type HeaderTitle = 'Category/Stage' | 'Display Order' | 'SubHubs' | 'Articles' | 'Software' | 'Events' | 'Services' | 'CaseStudies' | 'Equipment' | 'Funding Pages';
type HeaderTitle = 'Category/Stage' | 'Display Order' | 'SubHubs' | 'Articles' | 'Software' | 'Events' | 'Services' | 'CaseStudies' | 'Equipment' | 'Funding Pages' | 'Capabilities';

const sheetHeaderFields: HeaderTitle[] = ['Category/Stage', 'Display Order', 'SubHubs', 'Articles', 'Software', 'Events', 'Services', 'CaseStudies', 'Equipment', 'Funding Pages'];
const sheetHeaderFields: HeaderTitle[] = ['Category/Stage', 'Display Order', 'SubHubs', 'Articles', 'Software', 'Events', 'Services', 'CaseStudies', 'Equipment', 'Funding Pages', 'Capabilities'];



Expand Down Expand Up @@ -63,7 +63,8 @@ function mapCategoryData(queryData: GetPagesPerCategoryQuery): HeaderTitleRow[]
SubHubs: item?.linkedFrom?.subHubCollection?.total ?? 0,
"CaseStudies": item?.linkedFrom?.caseStudyCollection?.total ?? 0,
Equipment: item?.linkedFrom?.equipmentCollection?.total ?? 0,
"Funding Pages": item?.linkedFrom?.fundingCollection?.total ?? 0
"Funding Pages": item?.linkedFrom?.fundingCollection?.total ?? 0,
Capabilities: item?.linkedFrom?.capabilityCollection?.total ?? 0
}

return row;
Expand All @@ -83,7 +84,8 @@ function mapStageData(queryData: GetPagesPerStageQuery): HeaderTitleRow[] {
SubHubs: item?.linkedFrom?.subHubCollection?.total ?? 0,
"CaseStudies": item?.linkedFrom?.caseStudyCollection?.total ?? 0,
Equipment: item?.linkedFrom?.equipmentCollection?.total ?? 0,
"Funding Pages": item?.linkedFrom?.fundingCollection?.total ?? 0
"Funding Pages": item?.linkedFrom?.fundingCollection?.total ?? 0,
Capabilities: item?.linkedFrom?.capabilityCollection?.total ?? 0
}

return row;
Expand Down
7 changes: 4 additions & 3 deletions reports/pagesPerOrgUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { GetPagesPerOrgUnitDocument, GetPagesPerOrgUnitQuery } from "./types";
let MAX_ITEMS = 10;

type HeaderTitleRow = { [key in HeaderTitle]: string | number | boolean };
type HeaderTitle = 'Org Unit' | 'SubHubs' | 'Articles' | 'Software' | 'Events' | 'Services' | 'CaseStudies' | 'Equipment' | 'Funding Pages';
type HeaderTitle = 'Org Unit' | 'SubHubs' | 'Articles' | 'Software' | 'Events' | 'Services' | 'CaseStudies' | 'Equipment' | 'Funding Pages' | 'Capabilities';

const sheetHeaderFields: HeaderTitle[] = ['Org Unit', 'SubHubs', 'Articles', 'Software', 'Events', 'Services', 'CaseStudies', 'Equipment', 'Funding Pages'];
const sheetHeaderFields: HeaderTitle[] = ['Org Unit', 'SubHubs', 'Articles', 'Software', 'Events', 'Services', 'CaseStudies', 'Equipment', 'Funding Pages', 'Capabilities'];


export async function runPagesPerOrgUnit(chunkSize?: number): Promise<void> {
Expand Down Expand Up @@ -81,7 +81,8 @@ function mapData(data: GetPagesPerOrgUnitQuery): HeaderTitleRow[] {
Services: item?.linkedFrom?.serviceCollection?.total ?? 0,
Software: item?.linkedFrom?.softwareCollection?.total ?? 0,
SubHubs: item?.linkedFrom?.subHubCollection?.total ?? 0,
"Funding Pages": item?.linkedFrom?.fundingCollection?.total ?? 0
"Funding Pages": item?.linkedFrom?.fundingCollection?.total ?? 0,
Capabilities: item?.linkedFrom?.fundingCollection?.total ?? 0
};

return row;
Expand Down
38 changes: 38 additions & 0 deletions reports/queries/contentOverview.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,44 @@ query GetAllArticles($limit: Int!, $skip: Int!) {
}
}

query GetAllCapabilities($limit: Int!, $skip: Int!) {
capabilityCollection(preview: true, limit: $limit, skip: $skip) {
total
items {
sys {
id
publishedAt
firstPublishedAt
}
nextReview
owner {
name
}
publisher {
name
}
ssoProtected
title
slug
relatedOrgsCollection(limit: 3) {
total
items {
name
}
}
searchable
stageCollection {
items {
name
}
}
relatedItemsCollection(limit: 1) {
total
}
}
}
}

query GetAllSoftwares($limit: Int!, $skip: Int!) {
softwareCollection(preview: true, limit: $limit, skip: $skip) {
total
Expand Down
6 changes: 6 additions & 0 deletions reports/queries/pagesPerCategory.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ query GetPagesPerCategory {
fundingCollection(limit: 1) {
total
}
capabilityCollection(limit: 1) {
total
}
caseStudyCollection(limit: 1) {
total
}
Expand Down Expand Up @@ -41,6 +44,9 @@ query GetPagesPerStage {
fundingCollection(limit: 1) {
total
}
capabilityCollection(limit: 1) {
total
}
caseStudyCollection(limit: 1) {
total
}
Expand Down
3 changes: 3 additions & 0 deletions reports/queries/pagesPerOrgUnits.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ query GetPagesPerOrgUnit($limit: Int!, $skip: Int) {
fundingCollection(limit: 1) {
total
}
capabilityCollection(limit: 1) {
total
}
caseStudyCollection(limit: 1) {
total
}
Expand Down

0 comments on commit ab1732e

Please sign in to comment.