Skip to content

Commit

Permalink
feat: #87 - update search home page
Browse files Browse the repository at this point in the history
  • Loading branch information
eouin committed May 29, 2023
2 parents b593c14 + 7248288 commit 62574f4
Show file tree
Hide file tree
Showing 28 changed files with 351 additions and 367 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Setup pnpm
uses: pnpm/[email protected]
with:
version: 8.0.0
version: 8.5.1
run_install: true
- name: Cache pnpm modules
uses: actions/cache@v3
Expand Down Expand Up @@ -69,7 +69,7 @@ jobs:
- name: Setup pnpm
uses: pnpm/[email protected]
with:
version: 8.0.0
version: 8.5.1
run_install: true
- name: Cache pnpm modules
uses: actions/cache@v3
Expand Down Expand Up @@ -114,7 +114,7 @@ jobs:
- name: Setup pnpm
uses: pnpm/[email protected]
with:
version: 8.0.0
version: 8.5.1
run_install: true
- name: Cache pnpm modules
uses: actions/cache@v3
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"eslint-plugin-sonarjs": "0.19.0",
"husky": "8.0.3",
"jest": "29.5.0",
"jest-sonar": "0.2.15",
"jest-sonar": "0.2.16",
"lint-staged": "13.2.2",
"prettier": "2.8.8",
"pretty-quick": "3.1.3",
Expand All @@ -46,9 +46,10 @@
"engines": {
"npm": "please-use-pnpm",
"yarn": "please-use-pnpm",
"pnpm": ">=8.0.0",
"pnpm": "8",
"node": ">=16.1.0 < 17.0.0 || >=18.0.0 < 19.0.0"
},
"packageManager": "[email protected]",
"pnpm": {
"overrides": {
"[email protected]>ansi-regex": "^5.0.1"
Expand Down
10 changes: 3 additions & 7 deletions packages/core/src/api/blogs-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@ import type {
BlogsAPIOptions,
FetchResponse
} from '@sap/knowledge-hub-extension-types';

import { BLOGS_API_HOST, BLOGS_SEARCH_PATH } from '@sap/knowledge-hub-extension-types';
import asyncFetch from '../utils/asyncFetch';

const API_HOST = 'https://searchproxy.api.community.sap.com';
const VERSION = 'v1';
const SEARCH_PATH = `/external/api/${VERSION}/search?`;

/**
* Returns API to programmatically access community blogs.
*
* @param options - options like API host, node enhancements, or html enhancements
* @returns - API
*/
export function getCommunityBlogsApi(options?: BlogsAPIOptions): BlogsAPI {
const apiHost = options?.apiHost || API_HOST;
const apiHost = options?.apiHost ?? BLOGS_API_HOST;

return {
getBlogs: async (queryOptions?: BlogsSearchQuery | undefined): Promise<FetchResponse<BlogsSearchResult>> =>
Expand Down Expand Up @@ -63,7 +59,7 @@ export async function getBlogs(
queryOptions: BlogsSearchQuery | undefined
): Promise<FetchResponse<BlogsSearchResult>> {
const options = prepareQueryOptions(queryOptions);
const url = `${host}${SEARCH_PATH}${options}`;
const url = `${host}${BLOGS_SEARCH_PATH}${options}`;

return await asyncFetch<BlogsSearchResult>(url);
}
55 changes: 44 additions & 11 deletions packages/core/src/api/tags-api.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
import type { TagsSearchResult, TagsAPI, TagsAPIOptions, FetchResponse } from '@sap/knowledge-hub-extension-types';
import type {
BlogsTagsSearchResult,
TutorialsSearchResult,
TutorialsSearchQuery,
TagsAPI,
FetchResponse
} from '@sap/knowledge-hub-extension-types';
import {
TAGS_BLOGS_API_HOST,
TAGS_BLOGS_TAGS_PATH,
TAGS_TUTORIALS_API_HOST,
TAGS_TUTORIALS_SEARCH_PATH
} from '@sap/knowledge-hub-extension-types';

import asyncFetch from '../utils/asyncFetch';

const API_HOST = 'https://searchproxy.api.community.sap.com';
const VERSION = 'v1';
const TAGS_PATH = `/api/${VERSION}/tags`;

/**
* Returns API to programmatically access community tags.
*
* @param options - options like API host, node enhancements, or html enhancements
* @returns - API
*/
export function getCommunityTagsApi(options?: TagsAPIOptions): TagsAPI {
const apiHost = options?.apiHost || API_HOST;
export function getCommunityTagsApi(): TagsAPI {
const apiHostBlogs = TAGS_BLOGS_API_HOST;
const apiHostTutorials = TAGS_TUTORIALS_API_HOST;

return {
getTags: async (): Promise<FetchResponse<TagsSearchResult>> => getTags(apiHost)
getBlogsTags: async (): Promise<FetchResponse<BlogsTagsSearchResult>> => getBlogsTags(apiHostBlogs),
getTutorialsTags: async (): Promise<FetchResponse<TutorialsSearchResult>> => getTutorialsTags(apiHostTutorials)
};
}

Expand All @@ -26,8 +36,31 @@ export function getCommunityTagsApi(options?: TagsAPIOptions): TagsAPI {
* @param host - Tags API host
* @returns - Object of blogs result
*/
export async function getTags(host: string): Promise<FetchResponse<TagsSearchResult>> {
const url = `${host}${TAGS_PATH}`;
export async function getBlogsTags(host: string): Promise<FetchResponse<BlogsTagsSearchResult>> {
const url = `${host}${TAGS_BLOGS_TAGS_PATH}`;

return await asyncFetch<BlogsTagsSearchResult>(url);
}

/**
* Returns an object of tutorials search result.
*
* @param host - Developer tutorials API host
* @param queryOptions - options like query string, filters
* @returns - Object of tutorial entries
*/
export async function getTutorialsTags(host: string): Promise<FetchResponse<TutorialsSearchResult>> {
const queryOptions: TutorialsSearchQuery = {
rows: 10,
start: 0,
searchField: '',
pagePath: '/content/developers/website/languages/en/tutorial-navigator',
language: 'en_us',
addDefaultLanguage: true,
filters: []
};
const options = JSON.stringify(queryOptions);
const url = `${host}${TAGS_TUTORIALS_SEARCH_PATH}${options}`;

return await asyncFetch<TagsSearchResult>(url);
return await asyncFetch<TutorialsSearchResult>(url);
}
14 changes: 4 additions & 10 deletions packages/core/src/api/tutorials-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ import type {
TutorialsAPIOptions,
FetchResponse
} from '@sap/knowledge-hub-extension-types';
import { TUTORIALS_API_HOST, TUTORIALS_SEARCH_PATH, TUTORIALS_SOLR_TAG_ID } from '@sap/knowledge-hub-extension-types';
import asyncFetch from '../utils/asyncFetch';

const API_HOST = 'https://developers.sap.com';
const VERSION = 'v3';
const SEARCH_PATH = `/bin/sapdx/${VERSION}/solr/search?json=`;
const SOLR_TAG_ID = 'solrTagId';

/**
* Return a stringify version of all api options.
*
Expand All @@ -29,7 +25,7 @@ export function prepareQueyOptions(queryOptions: TutorialsSearchQuery | undefine
* @returns - a string of filters tagId options
*/
function formatFiltersTagIdOptions(tagId: string): string {
return `/${tagId}/${SOLR_TAG_ID}`;
return `/${tagId}/${TUTORIALS_SOLR_TAG_ID}`;
}

/**
Expand All @@ -39,7 +35,7 @@ function formatFiltersTagIdOptions(tagId: string): string {
* @returns - API
*/
export function getDeveloperTutorialsApi(options?: TutorialsAPIOptions): TutorialsAPI {
const apiHost = options?.apiHost || API_HOST;
const apiHost = options?.apiHost ?? TUTORIALS_API_HOST;

return {
getTutorials: async (
Expand All @@ -66,9 +62,7 @@ export async function getTutorials(
}

const options = prepareQueyOptions(queryOptions);
const url = `${host}${SEARCH_PATH}${options}`;

console.log('getTutorials: ', url);
const url = `${host}${TUTORIALS_SEARCH_PATH}${options}`;

return await asyncFetch<TutorialsSearchResult>(url);
}
41 changes: 32 additions & 9 deletions packages/ide-extension/src/knowledge-hub/actionsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import {
BLOGS_FETCH_BLOGS,
FILTERS_BLOGS_TAGS,
FILTERS_TUTORIALS_TAGS,
TAGS_FETCH_TAGS,
TAGS_FETCH_BLOGS_TAGS,
TAGS_FETCH_TUTORIALS_TAGS,
initialize,
fetchBlogs,
fetchHomeBlogs,
fetchTutorials,
fetchTags,
fetchTutorialsTags,
fetchBlogsTags,
fetchBlogsTotalCount,
fetchTutorialsTotalCount
} from '@sap/knowledge-hub-extension-types';
Expand Down Expand Up @@ -138,18 +140,36 @@ export class ActionHandler {
*
* @returns void
*/
private fetchTags = async (): Promise<void> => {
private fetchTagsBlogs = async (): Promise<void> => {
try {
await this.panel.webview.postMessage(fetchTags.pending(true));
const response = await this.communityTagsApi.getTags();
await this.panel.webview.postMessage(fetchBlogsTags.pending(true));
const response = await this.communityTagsApi.getBlogsTags();

if (response.status === 'fetched' && response.data) {
await this.panel.webview.postMessage(fetchTags.fulfilled(response.data));
await this.panel.webview.postMessage(fetchBlogsTags.fulfilled(response.data));
}

if (response.status === 'error') {
const errorMsg = (response.error ? response.error : 'error') as unknown as string;
await this.panel.webview.postMessage(fetchTags.rejected(errorMsg));
await this.panel.webview.postMessage(fetchBlogsTags.rejected(errorMsg));
}
} catch (error) {
console.error(error);
}
};

private fetchTagsTutorials = async (): Promise<void> => {
try {
await this.panel.webview.postMessage(fetchTutorialsTags.pending(true));
const response = await this.communityTagsApi.getTutorialsTags();

if (response.status === 'fetched' && response.data) {
await this.panel.webview.postMessage(fetchTutorialsTags.fulfilled(response.data));
}

if (response.status === 'error') {
const errorMsg = (response.error ? response.error : 'error') as unknown as string;
await this.panel.webview.postMessage(fetchTutorialsTags.rejected(errorMsg));
}
} catch (error) {
console.error(error);
Expand Down Expand Up @@ -182,8 +202,11 @@ export class ActionHandler {
[BLOGS_FETCH_BLOGS]: async (action: AnyAction): Promise<void> => {
await this.fetchBlogs(action);
},
[TAGS_FETCH_TAGS]: async (): Promise<void> => {
await this.fetchTags();
[TAGS_FETCH_BLOGS_TAGS]: async (): Promise<void> => {
await this.fetchTagsBlogs();
},
[TAGS_FETCH_TUTORIALS_TAGS]: async (): Promise<void> => {
await this.fetchTagsTutorials();
}
};
}
7 changes: 3 additions & 4 deletions packages/types/src/const/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {
AppState,
TutorialsSearchResult,
BlogsSearchResult,
TagsSearchResult,
BlogsTagsSearchResult,
BlogFiltersEntry,
TutorialsTagWithTitle
} from '../types';
Expand Down Expand Up @@ -141,9 +141,8 @@ export const createViewAction = createActionFactory(VIEW_PREFIX);
export const initialize = createCoreAction<AppState>('app/initialize');
export const fetchTutorials = createCoreAction<TutorialsSearchResult>('tutorials/fetch');
export const fetchBlogs = createCoreAction<BlogsSearchResult>('blogs/fetch');
export const fetchHomeTutorials = createCoreAction<TutorialsSearchResult>('home/tutorials/fetch');
export const fetchHomeBlogs = createCoreAction<BlogsSearchResult>('home/blogs/fetch');
export const fetchTags = createCoreAction<TagsSearchResult>('tags/fetch');
export const fetchBlogsTags = createCoreAction<BlogsTagsSearchResult>('tags/fetch/blogs-tags');
export const fetchTutorialsTags = createCoreAction<TutorialsSearchResult>('tags/fetch/tutorials-tags');
export const initBlogsQuery = createCoreAction<BlogFiltersEntry[]>('blogs/init/query');
export const initBlogsFilters = createCoreAction<BlogFiltersEntry[]>('blogs/init/filters');
export const initTutorialsFilters = createCoreAction<TutorialsTagWithTitle[]>('tutorials/init/filters');
Expand Down
21 changes: 21 additions & 0 deletions packages/types/src/const/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Blogs
export const BLOGS_API_HOST = 'https://searchproxy.api.community.sap.com';
export const BLOGS_VERSION = 'v1';
export const BLOGS_SEARCH_PATH = `/external/api/${BLOGS_VERSION}/search?`;

// Tutorials
export const TUTORIALS_API_HOST = 'https://developers.sap.com';
export const TUTORIALS_VERSION = 'v3';
export const TUTORIALS_SEARCH_PATH = `/bin/sapdx/${TUTORIALS_VERSION}/solr/search?json=`;
export const TUTORIALS_SOLR_TAG_ID = 'solrTagId';

// Blogs Tags
export const TAGS_BLOGS_API_HOST = 'https://searchproxy.api.community.sap.com';
export const TAGS_BLOGS_VERSION = 'v1';
export const TAGS_BLOGS_TAGS_PATH = `/api/${TAGS_BLOGS_VERSION}/tags`;

// Tutorials Tags
export const TAGS_TUTORIALS_API_HOST = 'https://developers.sap.com';
export const TAGS_TUTORIALS_VERSION = 'v3';
export const TAGS_TUTORIALS_SEARCH_PATH = `/bin/sapdx/${TUTORIALS_VERSION}/solr/search?json=`;
export const TAGS_TUTORIALS_SOLR_TAG_ID = 'solrTagId';
1 change: 1 addition & 0 deletions packages/types/src/const/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './actions';
export * from './api';
export * from './app';
export * from './blogsCategories';
export * from './blogsLanguages';
11 changes: 8 additions & 3 deletions packages/types/src/types/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export const RESTART_WEBVIEW = 'RESTART_WEBVIEW';
export const KNOWLEDGE_HUB_WEB_VIEW_READY = 'KNOWLEDGE_HUB_WEB_VIEW_READY';
export const TUTORIALS_FETCH_TUTORIALS = 'TUTORIALS_FETCH_TUTORIALS';
export const BLOGS_FETCH_BLOGS = 'BLOGS_FETCH_BLOGS';
export const TAGS_FETCH_TAGS = 'TAGS_FETCH_TAGS';
export const TAGS_FETCH_BLOGS_TAGS = 'TAGS_FETCH_BLOGS_TAGS';
export const TAGS_FETCH_TUTORIALS_TAGS = 'TAGS_FETCH_TUTORIALS_TAGS';
export const HOME_FETCH_TUTORIALS = 'HOME_FETCH_TUTORIALS';
export const HOME_FETCH_BLOGS = 'HOME_FETCH_BLOGS';

Expand All @@ -45,6 +46,10 @@ export interface BlogsFetchBlogs {
home: boolean;
}

export interface TagsFetchTags {
type: typeof TAGS_FETCH_TAGS;
export interface TagsFetchBlogsTags {
type: typeof TAGS_FETCH_BLOGS_TAGS;
}

export interface TagsFetchTutorialsTags {
type: typeof TAGS_FETCH_TUTORIALS_TAGS;
}
14 changes: 2 additions & 12 deletions packages/types/src/types/home.types.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import type { TutorialsState, TutorialsTags } from './tutorials.types';
import type { TutorialsState } from './tutorials.types';
import type { BlogsState } from './blogs.types';
import type { Tag } from './tags.types';

// export interface HomeBlogs {
// blogs: BlogsState;
// tags: Tag[];
// }

export interface HomeTutorials {
tutorials: TutorialsState;
tags: TutorialsTags;
}
export interface Home {
tutorials: HomeTutorials;
tutorials: TutorialsState;
blogs: BlogsState;
}
Loading

0 comments on commit 62574f4

Please sign in to comment.