Skip to content

Commit

Permalink
fix: remove s3 dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia committed Dec 13, 2021
1 parent 30cf578 commit 905753c
Show file tree
Hide file tree
Showing 9 changed files with 348 additions and 412 deletions.
12 changes: 6 additions & 6 deletions cypress/fixtures/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ export const IMAGE_ITEM_S3 = {
createdAt: '2021-03-16T16:00:50.968Z',
updatedAt: '2021-03-16T16:00:52.655Z',
extra: buildS3FileExtra({
key: 'files/icon.png', // for testing
path: 'files/icon.png', // for testing
size: 32439,
contenttype: 'image/png',
mimetype: 'image/png',
}),
settings: {
isPinned: false,
Expand All @@ -107,9 +107,9 @@ export const VIDEO_ITEM_S3 = {
createdAt: '2021-03-16T16:00:50.968Z',
updatedAt: '2021-03-16T16:00:52.655Z',
extra: buildS3FileExtra({
key: 'files/video.mp4', // for testing
path: 'files/video.mp4', // for testing
size: 52345,
contenttype: MIME_TYPES.VIDEO[0],
mimetype: MIME_TYPES.VIDEO[0],
}),
settings: {
isPinned: false,
Expand All @@ -127,9 +127,9 @@ export const PDF_ITEM_S3 = {
createdAt: '2021-03-16T16:00:50.968Z',
updatedAt: '2021-03-16T16:00:52.655Z',
extra: buildS3FileExtra({
key: 'files/doc.pdf', // for testing
path: 'files/doc.pdf', // for testing
size: 54321,
contenttype: MIME_TYPES.PDF[0],
mimetype: MIME_TYPES.PDF[0],
}),
settings: {
isPinned: false,
Expand Down
1 change: 1 addition & 0 deletions cypress/integration/ws.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '../support/server';

function beforeWs(visitRoute, wsClientStub) {
cy.setCookie('session', 'somecookie');
cy.visit(visitRoute, {
onBeforeLoad: (win) => {
cy.stub(win, 'WebSocket', () => wsClientStub);
Expand Down
8 changes: 4 additions & 4 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ module.exports = (on, config) => {
...config,
env: {
API_HOST: process.env.REACT_APP_API_HOST,
S3_FILES_HOST:
// calls to this host are mocked, but still should be reachable
// set an s3 host or fake it by using the same host as the api's
process.env.REACT_APP_S3_FILES_HOST || process.env.REACT_APP_API_HOST,
// S3_FILES_HOST:
// calls to this host are mocked, but still should be reachable
// set an s3 host or fake it by using the same host as the api's
// process.env.REACT_APP_S3_FILES_HOST || process.env.REACT_APP_API_HOST,
},
};
require('@cypress/code-coverage/task')(on, newConfig);
Expand Down
5 changes: 2 additions & 3 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
mockGetCurrentMember,
mockGetItem,
mockGetMemberBy,
mockGetS3Metadata,
} from './server';

Cypress.Commands.add(
Expand All @@ -31,6 +30,8 @@ Cypress.Commands.add(
const cachedItems = JSON.parse(JSON.stringify(items));
const cachedMembers = JSON.parse(JSON.stringify(members));

cy.setCookie('session', currentMember ? 'somecookie' : null);

mockGetItem(
{ items: cachedItems, currentMember },
getItemError || getCurrentMemberError,
Expand All @@ -43,7 +44,5 @@ Cypress.Commands.add(
mockGetCurrentMember(currentMember, getCurrentMemberError);

mockDefaultDownloadFile(cachedItems);

mockGetS3Metadata(cachedItems);
},
);
2 changes: 1 addition & 1 deletion cypress/support/integrationUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const expectAppViewScreenLayout = ({ id, name, extra }) => {

export const expectFileViewScreenLayout = ({ id, name, extra }) => {
const mimetype =
getFileExtra(extra)?.mimetype || getS3FileExtra(extra)?.contenttype;
getFileExtra(extra)?.mimetype || getS3FileExtra(extra)?.mimetype;

// embedded element
let selector = null;
Expand Down
22 changes: 0 additions & 22 deletions cypress/support/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import { getItemById, isChild } from '../../src/utils/item';
import { MEMBERS } from '../fixtures/members';
import { ID_FORMAT, parseStringToRegExp, EMAIL_FORMAT } from './utils';
import { DEFAULT_GET } from '../../src/api/utils';
import { getS3FileExtra } from '../../src/utils/itemExtra';

const {
buildGetChildrenRoute,
buildGetItemRoute,
buildGetMemberBy,
GET_CURRENT_MEMBER_ROUTE,
buildDownloadFilesRoute,
buildGetS3MetadataRoute,
} = API_ROUTES;

const API_HOST = Cypress.env('API_HOST');
Expand Down Expand Up @@ -127,24 +125,4 @@ export const mockDefaultDownloadFile = (items, shouldThrowError) => {
).as('downloadFile');
};

export const mockGetS3Metadata = (items, shouldThrowError) => {
cy.intercept(
{
method: DEFAULT_GET.method,
url: new RegExp(`${API_HOST}/${buildGetS3MetadataRoute(ID_FORMAT)}$`),
},
({ reply, url }) => {
if (shouldThrowError) {
reply({ statusCode: StatusCodes.BAD_REQUEST });
return;
}

const id = url.slice(API_HOST.length).split('/')[2];
const { extra } = items.find(({ id: thisId }) => id === thisId);

reply(getS3FileExtra(extra));
},
).as('getS3Metadata');
};

// bug: mockGetS3FileContent intercept static/js/bundle.js which fails tests
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"private": true,
"dependencies": {
"@graasp/chatbox": "git://github.com/graasp/graasp-chatbox.git#main",
"@graasp/query-client": "git://github.com/graasp/graasp-query-client.git",
"@graasp/query-client": "git://github.com/graasp/graasp-query-client.git#72/axios",
"@graasp/ui": "git://github.com/graasp/graasp-ui.git",
"@material-ui/core": "4.11.4",
"@material-ui/icons": "5.0.0-beta.4",
Expand Down Expand Up @@ -43,6 +43,7 @@
"start:ci": "react-scripts -r @cypress/instrument-cra start",
"build": "react-scripts build",
"dist": "env-cmd -f ./.env.production react-scripts build",
"dist:dev": "env-cmd -f ./.env.development react-scripts build",
"eject": "react-scripts eject",
"lint": "eslint .",
"prettier:check": "prettier --check src/**/*.js",
Expand Down
43 changes: 8 additions & 35 deletions src/components/common/Item.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import React from 'react';
import { Container, makeStyles, Typography } from '@material-ui/core';
import {
Loader,
FileItem,
DocumentItem,
LinkItem,
AppItem,
S3FileItem,
} from '@graasp/ui';
import { Loader, FileItem, DocumentItem, LinkItem, AppItem } from '@graasp/ui';
import Alert from '@material-ui/lab/Alert';
import { useTranslation } from 'react-i18next';
import PropTypes from 'prop-types';
Expand All @@ -23,13 +16,7 @@ import {
} from '../../config/selectors';
import { API_HOST, SCREEN_MAX_HEIGHT } from '../../config/constants';

const {
useItem,
useChildren,
useFileContent,
useS3FileContent,
useCurrentMember,
} = hooks;
const { useItem, useChildren, useFileContent, useCurrentMember } = hooks;

const useStyles = makeStyles((theme) => ({
container: {
Expand All @@ -53,22 +40,16 @@ const Item = ({ id, isChildren, showPinnedOnly }) => {

// fetch file content if type is file
const { data: content, isError: isFileError } = useFileContent(id, {
enabled: Boolean(item && item.get('type') === ITEM_TYPES.FILE),
enabled: Boolean(
item && [ITEM_TYPES.FILE, ITEM_TYPES.S3_FILE].includes(item.get('type')),
),
});

// fetch file content if type is s3File
const { data: s3Content, isError: isS3FileError } = useS3FileContent(
item?.get('id'),
{
enabled: Boolean(item?.get('type') === ITEM_TYPES.S3_FILE),
},
);

if (isLoading || isChildrenLoading) {
return <Loader />;
}

if (isError || !item || isFileError || isS3FileError) {
if (isError || !item || isFileError) {
return <Alert severity="error">{t('An unexpected error occured.')}</Alert>;
}

Expand Down Expand Up @@ -99,7 +80,8 @@ const Item = ({ id, isChildren, showPinnedOnly }) => {
);
case ITEM_TYPES.LINK:
return <LinkItem item={item} height={SCREEN_MAX_HEIGHT} />;
case ITEM_TYPES.FILE: {
case ITEM_TYPES.FILE:
case ITEM_TYPES.S3_FILE: {
return (
<FileItem
id={buildFileId(id)}
Expand All @@ -109,15 +91,6 @@ const Item = ({ id, isChildren, showPinnedOnly }) => {
/>
);
}
case ITEM_TYPES.S3_FILE: {
return (
<S3FileItem
item={item}
content={s3Content}
maxHeight={SCREEN_MAX_HEIGHT}
/>
);
}
case ITEM_TYPES.DOCUMENT: {
return <DocumentItem id={buildDocumentId(id)} item={item} readOnly />;
}
Expand Down
Loading

0 comments on commit 905753c

Please sign in to comment.