Skip to content

Commit

Permalink
feat: add field to edit folder's description
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia committed Oct 21, 2021
1 parent e23e526 commit 9ce4bcb
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 29 deletions.
2 changes: 1 addition & 1 deletion cypress/integration/item/create/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const createItem = (payload, options) => {
break;
case ITEM_TYPES.FOLDER:
default:
cy.fillSpaceModal(payload, options);
cy.fillFolderModal(payload, options);
break;
}
};
6 changes: 4 additions & 2 deletions cypress/integration/item/edit/editFolder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,27 @@ describe('Edit Folder', () => {
}

const itemToEdit = SAMPLE_ITEMS.items[0];

const newDescription = 'new description';
// edit
editItem(
{
...itemToEdit,
...EDITED_FIELDS,
description: newDescription,
},
ITEM_LAYOUT_MODES.LIST,
);

cy.wait('@editItem').then(
({
response: {
body: { id, name },
body: { id, name, description },
},
}) => {
// check item is edited and updated
expect(id).to.equal(itemToEdit.id);
expect(name).to.equal(EDITED_FIELDS.name);
expect(description).to.contain(newDescription);
cy.wait(EDIT_ITEM_PAUSE);
cy.wait('@getOwnItems');
},
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/item/edit/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const editItem = (payload, mode = DEFAULT_ITEM_LAYOUT_MODE) => {
break;
case ITEM_TYPES.FOLDER:
default:
cy.fillSpaceModal(payload);
cy.fillFolderModal(payload);
}
};

Expand Down
7 changes: 5 additions & 2 deletions cypress/support/commands/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ITEM_FORM_LINK_INPUT_ID,
ITEM_FORM_DOCUMENT_TEXT_SELECTOR,
ITEM_FORM_APP_URL_ID,
FOLDER_FORM_DESCRIPTION_ID,
} from '../../../src/config/selectors';

import {
Expand Down Expand Up @@ -77,12 +78,14 @@ Cypress.Commands.add(
);

Cypress.Commands.add(
'fillSpaceModal',
({ name = '', extra = {} }, { confirm = true } = {}) => {
'fillFolderModal',
({ name = '', extra = {}, description = '' }, { confirm = true } = {}) => {
cy.fillBaseItemModal({ name }, { confirm: false });

cy.get(`#${ITEM_FORM_IMAGE_INPUT_ID}`).type(`{selectall}${extra.image}`);

cy.get(`#${FOLDER_FORM_DESCRIPTION_ID}`).type(`{selectall}${description}`);

if (confirm) {
cy.get(`#${ITEM_FORM_CONFIRM_BUTTON_ID}`).click();
}
Expand Down
23 changes: 20 additions & 3 deletions src/components/item/form/FolderForm.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React from 'react';
import { useTranslation } from 'react-i18next';
import PropTypes from 'prop-types';
import { TextEditor } from '@graasp/ui';
import TextField from '@material-ui/core/TextField';
import Typography from '@material-ui/core/Typography';
import { ITEM_FORM_IMAGE_INPUT_ID } from '../../../config/selectors';
import {
FOLDER_FORM_DESCRIPTION_ID,
ITEM_FORM_IMAGE_INPUT_ID,
} from '../../../config/selectors';
import BaseItemForm from './BaseItemForm';

const FolderForm = ({ onChange, item, updatedProperties }) => {
Expand All @@ -12,16 +15,29 @@ const FolderForm = ({ onChange, item, updatedProperties }) => {
const handleImageUrlInput = (event) => {
onChange({ ...updatedProperties, extra: { image: event.target.value } });
};
const onCaptionChange = (content) => {
onChange({
...updatedProperties,
description: content,
});
};

return (
<>
<Typography variant="h6">{t('Create a Folder')}</Typography>
<BaseItemForm
onChange={onChange}
item={item}
updatedProperties={updatedProperties}
/>

<TextEditor
id={FOLDER_FORM_DESCRIPTION_ID}
value={updatedProperties?.description || item?.description}
edit
onChange={onCaptionChange}
showSaveButton={false}
/>

<TextField
id={ITEM_FORM_IMAGE_INPUT_ID}
margin="dense"
Expand All @@ -39,6 +55,7 @@ FolderForm.propTypes = {
extra: PropTypes.shape({
image: PropTypes.string,
}),
description: PropTypes.string,
}),
onChange: PropTypes.func.isRequired,
item: PropTypes.shape({
Expand Down
22 changes: 7 additions & 15 deletions src/components/main/ItemsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'ag-grid-community/dist/styles/ag-grid.css';
import 'ag-grid-community/dist/styles/ag-theme-material.css';
import { useTranslation } from 'react-i18next';
import { MUTATION_KEYS } from '@graasp/query-client';
import { TextEditor } from '@graasp/ui';
import { useHistory, useParams } from 'react-router';
import Typography from '@material-ui/core/Typography';
import { makeStyles } from '@material-ui/core/styles';
Expand Down Expand Up @@ -73,19 +74,6 @@ const ItemsTable = ({

const mutation = useMutation(MUTATION_KEYS.EDIT_ITEM);

const mappedRows = rows.map((item) => {
const { id, updatedAt, name, createdAt, type, extra, settings } = item;
return {
id,
name,
type,
updatedAt,
createdAt,
extra,
settings
};
});

const isFolder = () => Boolean(itemId);
const canDrag = () => isFolder() && !isSearching;

Expand Down Expand Up @@ -151,7 +139,7 @@ const ItemsTable = ({
const itemRowDragText = (params) => params.rowNode.data.name;

const NoRowsComponent = () => <Typography>{t('No items')}</Typography>;

const parentDescription = parentItem?.get('description');
return (
<div className={classes.root}>
<TableToolbar
Expand All @@ -161,13 +149,17 @@ const ItemsTable = ({
headerElements={headerElements}
actions={toolbarActions}
/>

{/* description */}
{parentDescription && <TextEditor value={parentDescription} />}

<div
className="ag-theme-material"
style={{ height: ITEMS_TABLE_CONTAINER_HEIGHT, width: '100%' }}
id={tableId}
>
<AgGridReact
rowData={mappedRows}
rowData={rows}
rowSelection="multiple"
suppressRowClickSelection
suppressCellSelection
Expand Down
14 changes: 9 additions & 5 deletions src/components/main/NewItemModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next';
import PropTypes from 'prop-types';
import { Box, makeStyles } from '@material-ui/core';
import Button from '@material-ui/core/Button';
import Typography from '@material-ui/core/Typography';
import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
import DialogContent from '@material-ui/core/DialogContent';
Expand Down Expand Up @@ -91,11 +92,14 @@ const NewItemModal = ({ open, handleClose }) => {
switch (selectedItemType) {
case ITEM_TYPES.FOLDER:
return (
<FolderForm
onChange={updateItem}
item={initialItem}
updatedProperties={updatedPropertiesPerType[ITEM_TYPES.FOLDER]}
/>
<>
<Typography variant="h6">{t('Create a Folder')}</Typography>
<FolderForm
onChange={updateItem}
item={initialItem}
updatedProperties={updatedPropertiesPerType[ITEM_TYPES.FOLDER]}
/>
</>
);
case ITEM_TYPES.FILE:
return <FileDashboardUploader />;
Expand Down
1 change: 1 addition & 0 deletions src/config/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,4 @@ export const SETTINGS_CHATBOX_TOGGLE_ID = 'settingsChatboxToggle';

export const ITEMS_TABLE_RESTORE_SELECTED_ITEMS_ID =
'itemsTableRestoreSelectedItems';
export const FOLDER_FORM_DESCRIPTION_ID = 'folderFormDescription';

0 comments on commit 9ce4bcb

Please sign in to comment.