forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add filters/sorting for the libraries v2 tab on studio home (op…
- Loading branch information
1 parent
8cf26e1
commit 83489b0
Showing
11 changed files
with
535 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { camelCaseObject, snakeCaseObject, getConfig } from '@edx/frontend-platform'; | ||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | ||
|
||
export const getApiBaseUrl = () => getConfig().STUDIO_BASE_URL; | ||
|
||
export interface LibraryV2 { | ||
id: string, | ||
type: string, | ||
org: string, | ||
slug: string, | ||
title: string, | ||
description: string, | ||
numBlocks: number, | ||
version: number, | ||
lastPublished: string | null, | ||
allowLti: boolean, | ||
allowPublicLearning: boolean, | ||
allowPublicRead: boolean, | ||
hasUnpublishedChanges: boolean, | ||
hasUnpublishedDeletes: boolean, | ||
license: string, | ||
} | ||
|
||
export interface LibrariesV2Response { | ||
next: string | null, | ||
previous: string | null, | ||
count: number, | ||
numPages: number, | ||
currentPage: number, | ||
start: number, | ||
results: LibraryV2[], | ||
} | ||
|
||
/* Additional custom parameters for the API request. */ | ||
export interface GetLibrariesV2CustomParams { | ||
/* (optional) Library type, default `complex` */ | ||
type?: string, | ||
/* (optional) Page number of results */ | ||
page?: number, | ||
/* (optional) The number of results on each page, default `50` */ | ||
pageSize?: number, | ||
/* (optional) Whether pagination is supported, default `true` */ | ||
pagination?: boolean, | ||
/* (optional) Library field to order results by. Prefix with '-' for descending */ | ||
order?: string, | ||
/* (optional) Search query to filter v2 Libraries by */ | ||
search?: string, | ||
} | ||
|
||
/** | ||
* Get's studio home v2 Libraries. | ||
*/ | ||
export async function getStudioHomeLibrariesV2(customParams: GetLibrariesV2CustomParams): Promise<LibrariesV2Response> { | ||
// Set default params if not passed in | ||
const customParamsDefaults = { | ||
type: customParams.type || 'complex', | ||
page: customParams.page || 1, | ||
pageSize: customParams.pageSize || 50, | ||
pagination: customParams.pagination !== undefined ? customParams.pagination : true, | ||
order: customParams.order || 'title', | ||
textSearch: customParams.search, | ||
}; | ||
const customParamsFormat = snakeCaseObject(customParamsDefaults); | ||
const { data } = await getAuthenticatedHttpClient().get(`${getApiBaseUrl()}/api/libraries/v2/`, { params: customParamsFormat }); | ||
return camelCaseObject(data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 3 additions & 2 deletions
5
src/studio-home/data/apiHooks.js → src/studio-home/data/apiHooks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.