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

Improved UX for editing page headers & dashboard title #743

Merged
merged 1 commit into from
Jan 9, 2024
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
5 changes: 2 additions & 3 deletions src/chart/graph/GraphChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ const NeoGraphChart = (props: ChartProps) => {
});

const pageNames = getPageNumbersAndNamesList();

const chartProps: GraphChartVisualizationProps = {
data: {
nodes: data.nodes,
Expand All @@ -142,12 +141,12 @@ const NeoGraphChart = (props: ChartProps) => {
style: {
width: width,
height: height,
backgroundColor: settings.backgroundColor,
backgroundColor: theme == 'dark' && settings.backgroundColor == '#fafafa' ? '#040404' : settings.backgroundColor, // Temporary fix for default color adjustment in dark mode
linkDirectionalParticles: linkDirectionalParticles,
linkDirectionalArrowLength: arrowLengthProp,
linkDirectionalParticleSpeed: settings.linkDirectionalParticleSpeed,
nodeLabelFontSize: settings.nodeLabelFontSize,
nodeLabelColor: settings.nodeLabelColor,
nodeLabelColor: theme == 'dark' && settings.nodeLabelColor == 'black' ? 'white' : settings.nodeLabelColor, // Temporary fix for default color adjustment in dark mode
relLabelFontSize: settings.relLabelFontSize,
relLabelColor: settings.relLabelColor,
defaultNodeSize: settings.defaultNodeSize,
Expand Down
66 changes: 44 additions & 22 deletions src/dashboard/header/DashboardHeaderPageTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import debounce from 'lodash/debounce';
import { setPageTitle } from '../../page/PageActions';
import { removePageThunk } from '../DashboardThunks';
import { Tab, Menu, MenuItems, MenuItem, IconButton, TextInput } from '@neo4j-ndl/react';
import { Tab, Menu, MenuItems, MenuItem, IconButton } from '@neo4j-ndl/react';
import { EllipsisHorizontalIconOutline, PencilIconOutline, TrashIconOutline } from '@neo4j-ndl/react/icons';
import { NeoDeletePageModal } from '../../modal/DeletePageModal';
import { useSortable } from '@dnd-kit/sortable';
Expand All @@ -17,12 +17,9 @@
const menuOpen = Boolean(anchorEl);
const [deleteModalOpen, setDeleteModalOpen] = React.useState(false);
const [editing, setEditing] = React.useState(false);

const [inputWidth, setInputWidth] = React.useState(125);
const handleMenuEditClick = (event: MenuEditEvent) => {
event.preventDefault();
if (editing) {
debouncedSetPageTitle(tabIndex, titleText);
}
setEditing(!editing);
setAnchorEl(null);
};
Expand All @@ -49,7 +46,7 @@
transition,
};

const debouncedSetPageTitle = useCallback(debounce(setPageTitle, 250), []);
const debouncedSetPageTitle = useCallback(debounce(setPageTitle, 200), []);

const [titleText, setTitleText] = React.useState(title);
useEffect(() => {
Expand All @@ -69,24 +66,46 @@
'(no title)'
)
) : (
<TextInput
data-no-dnd='true'
autoFocus={true}
value={titleText}
onChange={(event) => {
if (disabled) {
return;
<form
onSubmit={(event) => {

Check warning on line 70 in src/dashboard/header/DashboardHeaderPageTitle.tsx

View check run for this annotation

Codecov / codecov/patch

src/dashboard/header/DashboardHeaderPageTitle.tsx#L69-L70

Added lines #L69 - L70 were not covered by tests
if (editing) {
handleMenuEditClick(event);

Check warning on line 72 in src/dashboard/header/DashboardHeaderPageTitle.tsx

View check run for this annotation

Codecov / codecov/patch

src/dashboard/header/DashboardHeaderPageTitle.tsx#L72

Added line #L72 was not covered by tests
}
setTitleText(event.target.value);
}}
style={{
textAlign: 'center',
height: '1.9rem',
}}
placeholder='Page name...'
/>
>
<input
data-no-dnd='true'
autoFocus={true}
value={titleText}
className=''
onBlur={(event) => {

Check warning on line 81 in src/dashboard/header/DashboardHeaderPageTitle.tsx

View check run for this annotation

Codecov / codecov/patch

src/dashboard/header/DashboardHeaderPageTitle.tsx#L81

Added line #L81 was not covered by tests
if (editing) {
handleMenuEditClick(event);

Check warning on line 83 in src/dashboard/header/DashboardHeaderPageTitle.tsx

View check run for this annotation

Codecov / codecov/patch

src/dashboard/header/DashboardHeaderPageTitle.tsx#L83

Added line #L83 was not covered by tests
}
}}
onChange={(event) => {
const {target} = event;
target.style.width = '125px';
setInputWidth(target.scrollWidth);

Check warning on line 89 in src/dashboard/header/DashboardHeaderPageTitle.tsx

View check run for this annotation

Codecov / codecov/patch

src/dashboard/header/DashboardHeaderPageTitle.tsx#L86-L89

Added lines #L86 - L89 were not covered by tests

if (disabled) {
return;

Check warning on line 92 in src/dashboard/header/DashboardHeaderPageTitle.tsx

View check run for this annotation

Codecov / codecov/patch

src/dashboard/header/DashboardHeaderPageTitle.tsx#L92

Added line #L92 was not covered by tests
}
setTitleText(event.target.value);
debouncedSetPageTitle(tabIndex, event.target.value);

Check warning on line 95 in src/dashboard/header/DashboardHeaderPageTitle.tsx

View check run for this annotation

Codecov / codecov/patch

src/dashboard/header/DashboardHeaderPageTitle.tsx#L94-L95

Added lines #L94 - L95 were not covered by tests
}}
style={{
height: '1.9rem',
marginBottom: -5,
width: inputWidth,
paddingLeft: 5,
paddingRight: 5,
}}
placeholder='Page name...'
/>
</form>
)}
{!disabled && (
{!disabled && !editing && (
<>
<IconButton
aria-label='Page actions'
Expand All @@ -107,9 +126,12 @@
<MenuItems>
<MenuItem
icon={<PencilIconOutline />}
title={editing ? 'Stop Editing' : 'Edit name'}
title={'Edit name'}
onClick={(e) => {
e.stopPropagation();
if (editing) {
debouncedSetPageTitle(tabIndex, titleText);

Check warning on line 133 in src/dashboard/header/DashboardHeaderPageTitle.tsx

View check run for this annotation

Codecov / codecov/patch

src/dashboard/header/DashboardHeaderPageTitle.tsx#L133

Added line #L133 was not covered by tests
}
!disabled && handleMenuEditClick(e);
}}
/>
Expand Down
56 changes: 40 additions & 16 deletions src/dashboard/header/DashboardTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
import { getDashboardIsEditable } from '../../settings/SettingsSelectors';
import { updateDashboardSetting } from '../../settings/SettingsActions';
import { Typography, IconButton, Menu, MenuItems, TextInput } from '@neo4j-ndl/react';
import { CheckBadgeIconOutline, EllipsisHorizontalIconOutline, PencilSquareIconOutline } from '@neo4j-ndl/react/icons';
import {
CheckBadgeIconOutline,
CheckIconOutline,
EllipsisHorizontalIconOutline,
PencilSquareIconOutline,
} from '@neo4j-ndl/react/icons';
import NeoSettingsModal from '../../settings/SettingsModal';
import NeoExtensionsModal from '../../extensions/ExtensionsModal';
import { EXTENSIONS_DRAWER_BUTTONS } from '../../extensions/ExtensionConfig';
Expand All @@ -31,7 +36,7 @@
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
const [editing, setEditing] = React.useState(false);
const debouncedDashboardTitleUpdate = useCallback(debounce(setDashboardTitle, 250), []);

const [inputWidth, setInputWidth] = React.useState(350);
const handleSettingsMenuOpen = (event: SettingsMenuOpenEvent) => {
setAnchorEl(event.currentTarget);
};
Expand Down Expand Up @@ -69,21 +74,40 @@
{/* only allow edit title if dashboard is not standalone - here we are in Title edit mode*/}
{editing && !standaloneSettings.standalone ? (
<div className={'n-flex n-flex-row n-flex-wrap n-justify-between n-items-center'}>
<TextInput
autoFocus={true}
value={dashboardTitleText}
style={{
textAlign: 'center',
height: '1.9rem',
}}
placeholder='Dashboard name...'
onChange={(event) => {
if (editable) {
setDashboardTitleText(event.target.value);
debouncedDashboardTitleUpdate(event.target.value);
<form
onSubmit={() => {

Check warning on line 78 in src/dashboard/header/DashboardTitle.tsx

View check run for this annotation

Codecov / codecov/patch

src/dashboard/header/DashboardTitle.tsx#L78

Added line #L78 was not covered by tests
if (editing) {
setEditing(false);

Check warning on line 80 in src/dashboard/header/DashboardTitle.tsx

View check run for this annotation

Codecov / codecov/patch

src/dashboard/header/DashboardTitle.tsx#L80

Added line #L80 was not covered by tests
}
}}
/>
>
<input
autoFocus={true}
value={dashboardTitleText}
style={{
height: '1.9rem',
fontSize: '1.875rem', // h3
fontWeight: 700, // h3
padding: 10,
width: inputWidth,
}}
placeholder='Dashboard name...'
onBlur={() => {

Check warning on line 95 in src/dashboard/header/DashboardTitle.tsx

View check run for this annotation

Codecov / codecov/patch

src/dashboard/header/DashboardTitle.tsx#L95

Added line #L95 was not covered by tests
if (editing) {
setEditing(false);

Check warning on line 97 in src/dashboard/header/DashboardTitle.tsx

View check run for this annotation

Codecov / codecov/patch

src/dashboard/header/DashboardTitle.tsx#L97

Added line #L97 was not covered by tests
}
}}
onChange={(event) => {

Check warning on line 100 in src/dashboard/header/DashboardTitle.tsx

View check run for this annotation

Codecov / codecov/patch

src/dashboard/header/DashboardTitle.tsx#L100

Added line #L100 was not covered by tests
if (editable) {
const {target} = event;
target.style.width = '350px';
setInputWidth(target.scrollWidth);
setDashboardTitleText(event.target.value);
debouncedDashboardTitleUpdate(event.target.value);

Check warning on line 106 in src/dashboard/header/DashboardTitle.tsx

View check run for this annotation

Codecov / codecov/patch

src/dashboard/header/DashboardTitle.tsx#L102-L106

Added lines #L102 - L106 were not covered by tests
}
}}
/>
</form>
<Tooltip title={'Stop Editing'} disableInteractive>
<IconButton
className='logo-btn n-p-1'
Expand All @@ -92,7 +116,7 @@
onClick={() => setEditing(false)}
clean
>
<CheckBadgeIconOutline className='header-icon' type='outline' />
<CheckIconOutline className='header-icon' type='outline' />
</IconButton>
</Tooltip>
</div>
Expand Down
Loading