Skip to content

Commit

Permalink
feat: add preventUserRemoving prop for menu item and add callbacks fo…
Browse files Browse the repository at this point in the history
…r aside header
  • Loading branch information
jenshenJ committed Sep 30, 2024
1 parent 8f9b6cf commit 537cfa0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const AllPagesListItem: React.FC<AllPagesListItemProps> = (props) => {
<Icon className={b('icon')} data={item.icon} size={item.iconSize} />
) : null}
<span className={b('text')}>{item.title}</span>
{editMode && (
{editMode && !item.preventUserRemoving && (
<Button
onClick={onPinButtonClick}
view={item.hidden ? 'flat-secondary' : 'flat-action'}
Expand Down
15 changes: 14 additions & 1 deletion src/components/AllPagesPanel/AllPagesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ interface AllPagesPanelProps {

export const AllPagesPanel: React.FC<AllPagesPanelProps> = (props) => {
const {startEditIcon, onEditModeChanged, className} = props;
const {menuItems, onMenuItemsChanged} = useAsideHeaderInnerContext();
const {
menuItems,
onMenuItemsChanged,
onOpenEditMode,
onResetSettingsToDefault,
onToggleMenuItem,
} = useAsideHeaderInnerContext();

const menuItemsRef = useRef(menuItems);
menuItemsRef.current = menuItems;

Expand All @@ -37,6 +44,10 @@ export const AllPagesPanel: React.FC<AllPagesPanelProps> = (props) => {

useEffect(() => {
onEditModeChanged?.(isEditMode);

if (isEditMode) {
onOpenEditMode?.();
}
}, [isEditMode, onEditModeChanged]);

Check warning on line 51 in src/components/AllPagesPanel/AllPagesPanel.tsx

View workflow job for this annotation

GitHub Actions / Verify Files

React Hook useEffect has a missing dependency: 'onOpenEditMode'. Either include it or remove the dependency array

const onItemClick = useCallback((item: ListItemData<MenuItem>) => {
Expand All @@ -54,6 +65,7 @@ export const AllPagesPanel: React.FC<AllPagesPanelProps> = (props) => {
const originItems = menuItemsRef.current.filter(
(menuItem) => menuItem.id !== ALL_PAGES_ID,
);
onToggleMenuItem?.(changedItem);
onMenuItemsChanged(
originItems.map((menuItem) => {
if (menuItem.id !== changedItem.id) {
Expand Down Expand Up @@ -81,6 +93,7 @@ export const AllPagesPanel: React.FC<AllPagesPanelProps> = (props) => {
if (!onMenuItemsChanged) {
return;
}
onResetSettingsToDefault?.();
const originItems = menuItemsRef.current.filter((item) => item.id !== ALL_PAGES_ID);
onMenuItemsChanged(
originItems.map((item) => ({
Expand Down
3 changes: 3 additions & 0 deletions src/components/AsideHeader/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export interface AsideHeaderGeneralProps extends QAProps {
}) => React.ReactNode;
onClosePanel?: () => void;
onChangeCompact?: (compact: boolean) => void;
onOpenEditMode?: () => void;
onToggleMenuItem?: (changedItem: MenuItem) => void;
onResetSettingsToDefault?: () => void;
openModalSubscriber?: (subscriber: OpenModalSubscriber) => void;
}

Expand Down
1 change: 1 addition & 0 deletions src/components/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface MenuItem extends QAProps {
ref: React.RefObject<HTMLElement>;
},
) => React.ReactNode;
preventUserRemoving?: boolean;
rightAdornment?: React.ReactNode;
type?: MenuItemType;
afterMoreButton?: boolean;
Expand Down

0 comments on commit 537cfa0

Please sign in to comment.