Skip to content

Commit

Permalink
fix: add visibility attribute to AppData type
Browse files Browse the repository at this point in the history
refactor: use PermissionLevel from @graasp/sdk
  • Loading branch information
Jérémy La Scala committed Jan 20, 2023
1 parent bb68d9c commit c5a567d
Show file tree
Hide file tree
Showing 4 changed files with 14 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

0 comments on commit c5a567d

Please sign in to comment.