fixed accountsItemTitle context options button

This commit is contained in:
mushka 2022-11-01 14:06:23 +03:00
parent ef8af2739a
commit d4b2901d6b
3 changed files with 40 additions and 18 deletions

View File

@ -6,16 +6,25 @@ const excludeOptionsIntoFolder = ["open", "separator0", "separator1"];
class ContextHelper {
constructor(props) {
this.t = props.t;
this.isUser = props.isUser;
this.selection = props.selection;
this.setSelection = props.setSelection;
this.reloadSelection = props.reloadSelection;
this.getContextOptions = props.getContextOptions;
this.getUserContextOptions = props.getUserContextOptions;
this.getContextOptionActions = props.getContextOptionActions;
if (this.selection) this.fixItemContextOptions();
}
fixItemContextOptions = () => {
if (this.isUser) {
const newOptions = this.selection.options.filter(
(option) => option !== "details"
);
this.selection.options = newOptions;
return;
}
const options = this.getContextOptions(this.selection, false);
excludeGeneralOptions.forEach((excludeOption) => {
@ -72,7 +81,17 @@ class ContextHelper {
};
getItemContextOptions = () => {
return this.getContextOptionActions(this.selection, this.t);
return this.isUser
? this.getUserContextOptions(
this.t,
this.selection.options,
this.selection
)
: this.getContextOptionActions(this.selection, this.t);
};
getUserContextOptions = () => {
console.log(this.selection);
};
}

View File

@ -1,13 +1,13 @@
import React from "react";
import React, { useRef } from "react";
import { withTranslation } from "react-i18next";
import Text from "@docspace/components/text";
import ContextMenuButton from "@docspace/components/context-menu-button";
import { Avatar } from "@docspace/components";
import Badges from "@docspace/client/src/pages/AccountsHome/Section/Body/Badges";
import { StyledAccountsItemTitle } from "../../styles/accounts";
import { StyledTitle } from "../../styles/common";
import ItemContextOptions from "./ItemContextOptions";
const AccountsItemTitle = ({
t,
@ -16,16 +16,11 @@ const AccountsItemTitle = ({
getUserContextOptions,
selectionLength,
}) => {
const itemTitleRef = useRef();
const isPending =
selection.statusType === "pending" || selection.statusType === "disabled";
const getData = () => {
const newOptions = selection.options.filter(
(option) => option !== "details"
);
return getUserContextOptions(t, newOptions, selection);
};
if (isSeveralItems) {
return (
<StyledTitle>
@ -38,7 +33,7 @@ const AccountsItemTitle = ({
}
return (
<StyledAccountsItemTitle isPending={isPending}>
<StyledAccountsItemTitle isPending={isPending} ref={itemTitleRef}>
<Avatar
className="avatar"
role={selection.role ? selection.role : "user"}
@ -67,7 +62,12 @@ const AccountsItemTitle = ({
<Badges withoutPaid={true} statusType={selection.statusType} />
)}
</div>
<ContextMenuButton className="context-button" getData={getData} />
<ItemContextOptions
t={t}
isUser
itemTitleRef={itemTitleRef}
selection={selection}
/>
</StyledAccountsItemTitle>
);
};

View File

@ -14,12 +14,12 @@ const ItemContextOptions = ({
t,
selection,
setSelection,
reloadSelection,
getContextOptions,
getContextOptionActions,
getUserContextOptions,
setBufferSelection,
isUser = false,
itemTitleRef,
}) => {
if (!selection) return null;
@ -28,14 +28,16 @@ const ItemContextOptions = ({
const contextHelper = new ContextHelper({
t,
isUser,
selection,
setSelection,
reloadSelection,
getContextOptions,
getContextOptionActions,
getUserContextOptions,
});
if (!selection) return null;
const setItemAsBufferSelection = () => setBufferSelection(selection);
const onContextMenu = (e) => {
@ -48,6 +50,8 @@ const ItemContextOptions = ({
contextMenuRef.current.hide();
}, [selection]);
console.log(selection);
return (
<StyledItemContextOptions onClick={setItemAsBufferSelection}>
<ContextMenu
@ -69,7 +73,7 @@ const ItemContextOptions = ({
export default inject(
({ auth, filesStore, peopleStore, contextOptionsStore }) => {
const { setSelection, reloadSelection } = auth.infoPanelStore;
const { setSelection } = auth.infoPanelStore;
const { getUserContextOptions } = peopleStore.contextOptionsStore;
const {
setBufferSelection,
@ -81,7 +85,6 @@ export default inject(
return {
setSelection,
reloadSelection,
setBufferSelection,
getContextOptions,
getContextOptionActions,