Skip to content

Commit

Permalink
feat: redesign 'add text' modal (#1117)
Browse files Browse the repository at this point in the history
* feat: modify 'add text' title text

* feat: add helper text

* Revert "feat: modify 'add text' title text"

This reverts commit 8d34688.

* feat: change 'add text' title

* feat: add helper text in NameForm

* feat: change 'add text' tab text

* feat: change 'add text' title style

* feat: add clear button to name form

* feat: add display name form

* feat: change helper text wording

* feat: autocomplete displayName

* feat: change document form ui

* feat: add tests

* fix: update comment

Co-authored-by: Basile Spaenlehauer <[email protected]>

* fix: update DocumentForm

Co-authored-by: Basile Spaenlehauer <[email protected]>

* fix: update yarn.lock

* fix: code matches

* feat: change document form select styles

* fix: add comment

* fix: menu item background color

* fix: helper text and style

* feat: add tooltip

* fix: disable DisplayNameForm autofocus

* feat: add geolocation modal (#1112)

* refactor: add geolocation modal

* refactor: add translations

* refactor: update fr trans

* refactor: upgrade query client

* fix: update yarn.lock

* feat: update yarn.lock

* fix: add select of flavors

* fix: update styles

* fix: display name was erased in edit

* fix: make new item modal the same and udpate deps

* fix: update deps

* fix: remove semi-colon

---------

Co-authored-by: Basile Spaenlehauer <[email protected]>
Co-authored-by: Kim Lan Phan Hoang <[email protected]>
  • Loading branch information
3 people authored Apr 5, 2024
1 parent 23bb83d commit 514fbaf
Show file tree
Hide file tree
Showing 22 changed files with 913 additions and 187 deletions.
23 changes: 22 additions & 1 deletion cypress/e2e/item/create/createDocument.cy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { ITEM_FORM_CONFIRM_BUTTON_ID } from '@/config/selectors';
import {
CREATE_ITEM_BUTTON_ID,
CREATE_ITEM_DOCUMENT_ID,
ITEM_FORM_CONFIRM_BUTTON_ID,
ITEM_FORM_DISPLAY_NAME_INPUT_ID,
ITEM_FORM_NAME_INPUT_ID,
} from '@/config/selectors';

import { HOME_PATH, buildItemPath } from '../../../../src/config/paths';
import ItemLayoutMode from '../../../../src/enums/itemLayoutMode';
Expand Down Expand Up @@ -56,4 +62,19 @@ describe('Create Document', () => {
true,
);
});

it('autoComplete document displayName', () => {
cy.setUpApi();
cy.visit(HOME_PATH);

cy.switchMode(ItemLayoutMode.List);

cy.get(`#${CREATE_ITEM_BUTTON_ID}`).click();
cy.get(`#${CREATE_ITEM_DOCUMENT_ID}`).click();
cy.get(`#${ITEM_FORM_NAME_INPUT_ID}`).type('Test Name');
cy.get(`#${ITEM_FORM_DISPLAY_NAME_INPUT_ID}`).should(
'have.value',
'Test Name',
);
});
});
1 change: 1 addition & 0 deletions cypress/support/editUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const editItem = (
id: string;
type: DiscriminatedItem['type'] | string;
name: string;
displayName: string;
description: string;
},
mode = DEFAULT_ITEM_LAYOUT_MODE,
Expand Down
6 changes: 5 additions & 1 deletion cypress/support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ declare global {
options?: { confirm?: boolean },
): void;
fillDocumentModal(
payload: { name: string; extra?: DocumentItemExtra },
payload: {
name: string;
displayName: string;
extra?: DocumentItemExtra;
},
options?: { confirm?: boolean },
): void;
fillAppModal(
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
"@emotion/styled": "11.11.0",
"@graasp/chatbox": "3.1.0",
"@graasp/map": "1.5.0",
"@graasp/query-client": "3.2.0",
"@graasp/sdk": "4.3.1",
"@graasp/query-client": "3.3.0",
"@graasp/sdk": "4.6.0",
"@graasp/translations": "1.25.3",
"@graasp/ui": "4.14.0",
"@graasp/ui": "4.14.1",
"@mui/icons-material": "5.15.11",
"@mui/lab": "5.0.0-alpha.166",
"@mui/material": "5.15.11",
Expand Down
1 change: 1 addition & 0 deletions src/components/Root.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import './styles.css';
import '@ag-grid-community/styles/ag-grid.min.css';
import '@ag-grid-community/styles/ag-theme-material.min.css';
import '@uppy/core/dist/style.css';
Expand Down
3 changes: 0 additions & 3 deletions src/components/file/FileDashboardUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ const FileDashboardUploader = ({ onComplete }: Props): JSX.Element => {

return (
<>
<Typography variant="h6">
{translateBuilder(BUILDER.UPLOAD_FILE_TITLE)}
</Typography>
<Typography variant="body1" paragraph>
{translateBuilder(BUILDER.UPLOAD_FILE_INFORMATIONS)}
</Typography>
Expand Down
142 changes: 72 additions & 70 deletions src/components/item/form/AppForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ const AppForm = ({ onChange, updatedProperties = {} }: Props): JSX.Element => {
// there is no new value to use
if (!newValue) {
// unset the name and the url in the extra
onChange({ name: undefined, extra: undefined });
onChange({
name: undefined,
extra: undefined,
});
}
};

Expand All @@ -127,78 +130,77 @@ const AppForm = ({ onChange, updatedProperties = {} }: Props): JSX.Element => {
handleAppSelection(null);
};

if (isCustomApp) {
return (
<Stack direction="column" alignItems="start" mt={1} spacing={2}>
<Button
startIcon={<ArrowBack fontSize="small" />}
variant="text"
onClick={() => {
setIsCustomApp(false);
handleAppSelection(null);
}}
>
{translateBuilder(BUILDER.CREATE_NEW_APP_BACK_TO_APP_LIST_BUTTON)}
</Button>
<Typography>
{translateBuilder(BUILDER.CREATE_CUSTOM_APP_HELPER_TEXT)}
</Typography>
<TextField
id={CUSTOM_APP_URL_ID}
fullWidth
variant="standard"
autoFocus
label={translateBuilder(BUILDER.APP_URL)}
onChange={(e) =>
// todo: use better type here (partial of discriminated item is not a good type)

onChange({ extra: buildAppExtra({ url: e.target.value }) })
}
value={currentUrl}
/>
<NameForm
setChanges={onChange}
updatedProperties={updatedProperties}
autoFocus={false}
/>
</Stack>
);
}
return (
<Stack direction="column" height="100%" spacing={2}>
<Typography variant="h6">
{translateBuilder(BUILDER.CREATE_NEW_ITEM_APP_TITLE)}
</Typography>

{isCustomApp ? (
<Stack direction="column" alignItems="start" mt={1} spacing={2}>
<Button
startIcon={<ArrowBack fontSize="small" />}
variant="text"
onClick={() => {
setIsCustomApp(false);
handleAppSelection(null);
}}
>
{translateBuilder(BUILDER.CREATE_NEW_APP_BACK_TO_APP_LIST_BUTTON)}
</Button>
<Typography>
{translateBuilder(BUILDER.CREATE_CUSTOM_APP_HELPER_TEXT)}
</Typography>
<TextField
id={CUSTOM_APP_URL_ID}
fullWidth
variant="standard"
autoFocus
label={translateBuilder(BUILDER.APP_URL)}
onChange={(e) =>
// todo: use better type here (partial of discriminated item is not a good type)

onChange({ extra: buildAppExtra({ url: e.target.value }) })
}
value={currentUrl}
<Stack direction="column" height="100%" spacing={2} minHeight="0px">
<TextField
fullWidth
placeholder={translateBuilder('Search for an app')}
variant="outlined"
autoFocus
size="small"
onChange={searchAnApp}
/>
<Box display="flex" flexGrow={1} minHeight="0px" overflow="scroll" p={1}>
<Grid2
container
spacing={2}
height="max-content"
maxHeight={400}
alignItems="stretch"
>
<AppGrid
currentUrl={currentUrl}
handleSelection={handleAppSelection}
searchQuery={searchQuery}
/>
</Stack>
) : (
<>
<TextField
fullWidth
placeholder={translateBuilder('Search for an app')}
variant="outlined"
autoFocus
size="small"
onChange={searchAnApp}
<AppCard
id={CUSTOM_APP_CYPRESS_ID}
name={translateBuilder(BUILDER.CREATE_CUSTOM_APP)}
description={translateBuilder(
BUILDER.CREATE_CUSTOM_APP_DESCRIPTION,
)}
image={addNewImage}
onClick={addCustomApp}
/>
<Box display="flex" flexGrow={1}>
<Grid2
container
spacing={2}
height="max-content"
maxHeight={400}
alignItems="stretch"
overflow="auto"
>
<AppGrid
currentUrl={currentUrl}
handleSelection={handleAppSelection}
searchQuery={searchQuery}
/>
<AppCard
id={CUSTOM_APP_CYPRESS_ID}
name={translateBuilder(BUILDER.CREATE_CUSTOM_APP)}
description={translateBuilder(
BUILDER.CREATE_CUSTOM_APP_DESCRIPTION,
)}
image={addNewImage}
onClick={addCustomApp}
/>
</Grid2>
</Box>
</>
)}
</Grid2>
</Box>
<NameForm
setChanges={onChange}
updatedProperties={updatedProperties}
Expand Down
4 changes: 2 additions & 2 deletions src/components/item/form/BaseItemForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const BaseItemForm = ({
updatedProperties,
setChanges,
}: EditModalContentPropType): JSX.Element => (
<>
<Box overflow="auto">
<NameForm
setChanges={setChanges}
item={item}
Expand All @@ -26,7 +26,7 @@ const BaseItemForm = ({
setChanges={setChanges}
/>
</Box>
</>
</Box>
);

export default BaseItemForm;
80 changes: 80 additions & 0 deletions src/components/item/form/DisplayNameForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { ChangeEvent } from 'react';

import ClearIcon from '@mui/icons-material/Clear';
import InfoIcon from '@mui/icons-material/Info';
import {
IconButton,
Stack,
TextField,
Tooltip,
useMediaQuery,
useTheme,
} from '@mui/material';

import { useBuilderTranslation } from '../../../config/i18n';
import { ITEM_FORM_DISPLAY_NAME_INPUT_ID } from '../../../config/selectors';
import { BUILDER } from '../../../langs/constants';
import type { EditModalContentPropType } from './EditModalWrapper';

export type DisplayNameFormProps = EditModalContentPropType;

const DisplayNameForm = ({
updatedProperties,
setChanges,
}: DisplayNameFormProps): JSX.Element => {
const { t: translateBuilder } = useBuilderTranslation();
const theme = useTheme();
// when the screen is large, use only half of the width for the input.
const largeScreen = useMediaQuery(theme.breakpoints.up('sm'));

const handleDisplayNameInput = (event: ChangeEvent<{ value: string }>) => {
setChanges({ displayName: event.target.value });
};

const handleClearClick = () => {
setChanges({ displayName: '' });
};

return (
<TextField
variant="standard"
id={ITEM_FORM_DISPLAY_NAME_INPUT_ID}
label={
<Stack direction="row" alignItems="center">
{translateBuilder(BUILDER.CREATE_NEW_ITEM_DISPLAY_NAME_LABEL)}
<Tooltip
title={translateBuilder(
BUILDER.CREATE_NEW_ITEM_DISPLAY_NAME_HELPER_TEXT,
)}
>
<IconButton size="small">
<InfoIcon fontSize="small" color="primary" />
</IconButton>
</Tooltip>
</Stack>
}
value={updatedProperties?.displayName}
onChange={handleDisplayNameInput}
// always shrink because setting name from defined app does not shrink automatically
InputLabelProps={{ shrink: true }}
// add a clear icon button
InputProps={{
endAdornment: (
<IconButton
onClick={handleClearClick}
sx={{
visibility: updatedProperties?.displayName ? 'visible' : 'hidden',
}}
>
<ClearIcon fontSize="small" />
</IconButton>
),
}}
// only take full width when on small screen size
fullWidth={!largeScreen}
sx={{ my: 1, width: largeScreen ? '50%' : undefined }}
/>
);
};

export default DisplayNameForm;
Loading

0 comments on commit 514fbaf

Please sign in to comment.