Skip to content
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

Add visibility attribute to AppData type #69

Merged
merged 2 commits into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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?
swouf marked this conversation as resolved.
Show resolved Hide resolved
}),
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