Skip to content

Commit

Permalink
Merge pull request #69 from graasp/68-visibility-AppData-type
Browse files Browse the repository at this point in the history
Add visibility attribute to AppData type
  • Loading branch information
swouf authored Jan 23, 2023
2 parents e61b48a + 09b6c07 commit f6636d0
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/config/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { StatusCodes } from 'http-status-codes';
import { PermissionLevel } from '@graasp/sdk';
// React Query Configs

// time during which cache entry is never refetched
Expand All @@ -21,12 +22,13 @@ export const THUMBNAIL_SIZES = {
};
export const DEFAULT_THUMBNAIL_SIZES = THUMBNAIL_SIZES.SMALL;

export const PERMISSION_LEVELS = {
WRITE: 'write',
READ: 'read',
ADMIN: 'admin',
};
export const DEFAULT_PERMISSION = PERMISSION_LEVELS.READ;
export const DEFAULT_PERMISSION = PermissionLevel.Read;

// Has to match with https://github.com/graasp/graasp-apps/blob/main/src/interfaces/app-details.ts
export enum AppDataVisibility {
ITEM = 'item',
MEMBER = 'member',
}

export const DEFAULT_CONTEXT = 'standalone';
export const DEFAULT_LANG = 'en';
Expand Down
4 changes: 2 additions & 2 deletions src/mockServer/fixtures.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PERMISSION_LEVELS } from '../config/constants';
import { PermissionLevel } from '@graasp/sdk';
import { buildContext } from '../hooks/postMessage';
import { LocalContext, Member } from '../types';
import { Context } from '@graasp/sdk';
Expand All @@ -18,7 +18,7 @@ export const buildMockLocalContext = (appContext = {}) => {
memberId: MOCK_SERVER_MEMBER.id,
offline: false,
apiHost: 'http://localhost:3000',
permission: PERMISSION_LEVELS.READ,
permission: PermissionLevel.Read,
context: Context.PLAYER,
dev: true,
...appContext,
Expand Down
2 changes: 2 additions & 0 deletions src/mockServer/mockServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { createServer, Model, Factory, RestSerializer, Response } from 'miragejs
import { API_ROUTES } from '../api/routes';
import { AppAction, AppData, AppSetting, Database, LocalContext, Member } from '../types';
import { buildMockLocalContext, MOCK_SERVER_ITEM, MOCK_SERVER_MEMBER } from './fixtures';
import { AppDataVisibility } from '../config/constants';

const {
buildGetAppDataRoute,
Expand Down Expand Up @@ -80,6 +81,7 @@ export const mockServer = ({
itemId: currentItemId,
memberId: currentMemberId,
creator: currentMemberId,
visibility: () => AppDataVisibility.MEMBER, // TODO: Is it right?
}),
appActionResource: Factory.extend<AppAction>({
id: () => v4(),
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { List, Record } from 'immutable';
import { Context, PermissionLevel } from '@graasp/sdk';
import { AppDataVisibility } from './config/constants';

// generic type
type EnumToUnionType<T> = T extends `${infer R}` ? R : never;
Expand Down Expand Up @@ -63,6 +64,7 @@ export type AppData = {
updatedAt: string;
memberId: UUID;
itemId: UUID;
visibility: AppDataVisibility;
};

export type AppAction = {
Expand Down
2 changes: 2 additions & 0 deletions test/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { v4 } from 'uuid';
import { AppDataVisibility } from '../src/config/constants';
import { AppData, AppSetting, LocalContext, Member } from '../src/types';

export const API_HOST = 'http://localhost:3000';
Expand Down Expand Up @@ -63,6 +64,7 @@ export const buildAppData = ({ id = v4(), data = {} }: Partial<AppData> = {}): A
updatedAt: Date.now().toString(),
memberId: 'memberId',
itemId: 'itemId',
visibility: AppDataVisibility.MEMBER,
});

export const FIXTURE_APP_DATA: AppData[] = [buildAppData(), buildAppData(), buildAppData()];
Expand Down

0 comments on commit f6636d0

Please sign in to comment.