-
Notifications
You must be signed in to change notification settings - Fork 21
Implements GAME-81 #293
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
Merged
Merged
Implements GAME-81 #293
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b3cb164
Implements GAME-81
kkartunov fe1153e
code review updates
kkartunov 126806e
switch to heroicon for sort column trigger
kkartunov c3ae18a
use _spacing whenever possible
kkartunov 40ef0de
GAME-107 and GAME-99
kkartunov 9f83312
GAME-107 #comment This commit refactors the SWR to be a generic hook …
brooketopcoder 95cefd1
GAME-107 clean-up
brooketopcoder 5ac9f54
GAMe-107 clean up
brooketopcoder 1eb9358
Merge pull request #300 from topcoder-platform/GAME-107_bjcs
kkartunov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,2 +1,5 @@ | ||
| export * from './infinite-page-dao.model' | ||
| export * from './infinite-page-handler.model' | ||
| export * from './page.model' | ||
| export * from './sort.model' | ||
| export * from './use-infinite-page.hook' |
This file contains hidden or 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,5 @@ | ||
| export interface InfinitePageDao<T> { | ||
| count: number | ||
| // TODO: rename this 'items' so it can be used in a grid/card view | ||
| rows: ReadonlyArray<T> | ||
| } |
This file contains hidden or 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,5 @@ | ||
| export interface InfinitePageHandler<T> { | ||
| data?: ReadonlyArray<T> | ||
| getAndSetNext: () => void | ||
| hasMore: boolean | ||
| } |
This file contains hidden or 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,25 @@ | ||
| import { flatten, map } from 'lodash' | ||
| // tslint:disable-next-line: no-submodule-imports | ||
| import useSWRInfinite, { SWRInfiniteResponse } from 'swr/infinite' | ||
|
|
||
| import { InfinitePageDao } from './infinite-page-dao.model' | ||
| import { InfinitePageHandler } from './infinite-page-handler.model' | ||
|
|
||
| export function useGetInfinitePage<T>(getKey: (index: number, previousPageData: InfinitePageDao<T>) => string | undefined): | ||
| InfinitePageHandler<T> { | ||
|
|
||
| const { data, setSize, size }: SWRInfiniteResponse<InfinitePageDao<T>> = useSWRInfinite(getKey, { revalidateFirstPage: false }) | ||
|
|
||
| // flatten version of badges paginated data | ||
| const outputData: ReadonlyArray<T> = flatten(map(data, dao => dao.rows)) | ||
|
|
||
| function getAndSetNext(): void { | ||
| setSize(size + 1) | ||
| } | ||
|
|
||
| return { | ||
| data: outputData, | ||
| getAndSetNext, | ||
| hasMore: outputData.length < (data?.[0]?.count || 0), | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| export * from './table-column.model' | ||
| export { tableGetDefaultSort } from './table-functions' | ||
| export { default as Table } from './Table' |
This file contains hidden or 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 hidden or 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
4 changes: 4 additions & 0 deletions
4
src-ts/tools/gamification-admin/game-config/gamification-config.model.ts
This file contains hidden or 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,4 @@ | ||
| export interface GamificationConfigModel { | ||
| ORG_ID: string | ||
| PAGE_SIZE: number | ||
| } |
27 changes: 27 additions & 0 deletions
27
src-ts/tools/gamification-admin/game-config/gamification.config.ts
This file contains hidden or 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,27 @@ | ||
| import { EnvironmentConfig } from '../../../config' | ||
|
|
||
| import { GamificationConfigModel } from './gamification-config.model' | ||
| import { GamificationConfigDefault } from './gamification.default.config' | ||
| import { GamificationConfigDev } from './gamification.dev.config' | ||
| import { GamificationConfigProd } from './gamification.prod.config' | ||
|
|
||
| function getConfig(): GamificationConfigModel { | ||
|
|
||
| switch (EnvironmentConfig.ENV) { | ||
|
|
||
| case 'dev': | ||
| return GamificationConfigDev | ||
|
|
||
| case 'prod': | ||
| return GamificationConfigProd | ||
|
|
||
| default: | ||
| return GamificationConfigDefault | ||
| } | ||
| } | ||
|
|
||
| const GamificationConfig: GamificationConfigModel = { | ||
| ...getConfig(), | ||
| } | ||
|
|
||
| export default GamificationConfig |
6 changes: 6 additions & 0 deletions
6
src-ts/tools/gamification-admin/game-config/gamification.default.config.ts
This file contains hidden or 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,6 @@ | ||
| import { GamificationConfigModel } from './gamification-config.model' | ||
|
|
||
| export const GamificationConfigDefault: GamificationConfigModel = { | ||
| ORG_ID: '6052dd9b-ea80-494b-b258-edd1331e27a3', | ||
| PAGE_SIZE: 12, | ||
| } |
6 changes: 6 additions & 0 deletions
6
src-ts/tools/gamification-admin/game-config/gamification.dev.config.ts
This file contains hidden or 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,6 @@ | ||
| import { GamificationConfigModel } from './gamification-config.model' | ||
| import { GamificationConfigDefault } from './gamification.default.config' | ||
|
|
||
| export const GamificationConfigDev: GamificationConfigModel = { | ||
| ...GamificationConfigDefault, | ||
| } |
7 changes: 7 additions & 0 deletions
7
src-ts/tools/gamification-admin/game-config/gamification.prod.config.ts
This file contains hidden or 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,7 @@ | ||
| import { GamificationConfigModel } from './gamification-config.model' | ||
| import { GamificationConfigDefault } from './gamification.default.config' | ||
|
|
||
| export const GamificationConfigProd: GamificationConfigModel = { | ||
| ...GamificationConfigDefault, | ||
| ORG_ID: 'e111f8df-6ac8-44d1-b4da-bb916f5e3425', | ||
| } |
This file contains hidden or 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 @@ | ||
| export { default as GamificationConfig } from './gamification.config' |
10 changes: 10 additions & 0 deletions
10
src-ts/tools/gamification-admin/game-lib/game-badge.model.ts
This file contains hidden or 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,10 @@ | ||
| // TODO: add factory to convert snake case property names to camel case | ||
| export interface GameBadge { | ||
| active: boolean | ||
| badge_description: string | ||
| badge_image_url: string | ||
| badge_name: string | ||
| badge_status: string | ||
| id: string | ||
| organization_id: string | ||
| } |
This file contains hidden or 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,3 @@ | ||
| export * from './game-badge.model' | ||
| export * from './use-get-game-badges-page.hook' | ||
| export * from './use-gamification-breadcrumb.hook' |
16 changes: 16 additions & 0 deletions
16
src-ts/tools/gamification-admin/game-lib/use-gamification-breadcrumb.hook.tsx
This file contains hidden or 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,16 @@ | ||
| import { BreadcrumbItemModel } from '../../../lib' | ||
| import { basePath } from '../gamification-admin.routes' | ||
| import { toolTitle } from '../GamificationAdmin' | ||
|
|
||
| export function useGamificationBreadcrumb(items: Array<BreadcrumbItemModel>): Array<BreadcrumbItemModel> { | ||
|
|
||
| const breadcrumb: Array<BreadcrumbItemModel> = [ | ||
| { | ||
| name: toolTitle, | ||
| url: basePath, | ||
| }, | ||
| ...items, | ||
| ] | ||
|
|
||
| return breadcrumb | ||
| } |
30 changes: 30 additions & 0 deletions
30
src-ts/tools/gamification-admin/game-lib/use-get-game-badges-page.hook.ts
This file contains hidden or 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,30 @@ | ||
| import { EnvironmentConfig } from '../../../config' | ||
| import { InfinitePageDao, InfinitePageHandler, Sort, useGetInfinitePage } from '../../../lib' | ||
| import { GamificationConfig } from '../game-config' | ||
|
|
||
| import { GameBadge } from './game-badge.model' | ||
|
|
||
| export function useGetGameBadgesPage(sort: Sort): InfinitePageHandler<GameBadge> { | ||
|
|
||
| function getKey(index: number, previousPageData: InfinitePageDao<GameBadge>): string | undefined { | ||
|
|
||
| // reached the end | ||
| if (!!previousPageData && !previousPageData.rows.length) { | ||
| return undefined | ||
| } | ||
|
|
||
| const params: Record<string, string> = { | ||
| limit: `${GamificationConfig.PAGE_SIZE}`, | ||
| offset: `${index * GamificationConfig.PAGE_SIZE}`, | ||
| order_by: sort.fieldName, | ||
| order_type: sort.direction, | ||
| organization_id: GamificationConfig.ORG_ID, | ||
| } | ||
|
|
||
| const badgeEndpointUrl: URL = new URL(`${EnvironmentConfig.API.V5}/gamification/badges?${new URLSearchParams(params)}`) | ||
|
|
||
| return badgeEndpointUrl.toString() | ||
| } | ||
|
|
||
| return useGetInfinitePage(getKey) | ||
| } |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.