Unverified Commit 77d3853f authored by Maximilian Krauß's avatar Maximilian Krauß Committed by GitHub

fix: inherits memo visibility for default comment visibility (#4728)

parent a317f9e6
...@@ -40,6 +40,8 @@ export interface Props { ...@@ -40,6 +40,8 @@ export interface Props {
memoName?: string; memoName?: string;
// The name of the parent memo if the memo is a comment. // The name of the parent memo if the memo is a comment.
parentMemoName?: string; parentMemoName?: string;
// The visibility of the parent memo for preset when commenting
parentMemoVisibility?: Visibility;
autoFocus?: boolean; autoFocus?: boolean;
onConfirm?: (memoName: string) => void; onConfirm?: (memoName: string) => void;
onCancel?: () => void; onCancel?: () => void;
...@@ -57,12 +59,12 @@ interface State { ...@@ -57,12 +59,12 @@ interface State {
} }
const MemoEditor = observer((props: Props) => { const MemoEditor = observer((props: Props) => {
const { className, cacheKey, memoName, parentMemoName, autoFocus, onConfirm, onCancel } = props; const { className, cacheKey, memoName, parentMemoName, parentMemoVisibility, autoFocus, onConfirm, onCancel } = props;
const t = useTranslate(); const t = useTranslate();
const { i18n } = useTranslation(); const { i18n } = useTranslation();
const currentUser = useCurrentUser(); const currentUser = useCurrentUser();
const [state, setState] = useState<State>({ const [state, setState] = useState<State>({
memoVisibility: Visibility.PRIVATE, memoVisibility: parentMemoVisibility ?? Visibility.PRIVATE,
resourceList: [], resourceList: [],
relationList: [], relationList: [],
location: undefined, location: undefined,
...@@ -96,7 +98,7 @@ const MemoEditor = observer((props: Props) => { ...@@ -96,7 +98,7 @@ const MemoEditor = observer((props: Props) => {
}, [autoFocus]); }, [autoFocus]);
useEffect(() => { useEffect(() => {
let visibility = userSetting.memoVisibility; let visibility = parentMemoVisibility ?? userSetting.memoVisibility;
if (workspaceMemoRelatedSetting.disallowPublicVisibility && visibility === "PUBLIC") { if (workspaceMemoRelatedSetting.disallowPublicVisibility && visibility === "PUBLIC") {
visibility = "PRIVATE"; visibility = "PRIVATE";
} }
...@@ -104,7 +106,7 @@ const MemoEditor = observer((props: Props) => { ...@@ -104,7 +106,7 @@ const MemoEditor = observer((props: Props) => {
...prevState, ...prevState,
memoVisibility: convertVisibilityFromString(visibility), memoVisibility: convertVisibilityFromString(visibility),
})); }));
}, [userSetting.memoVisibility, workspaceMemoRelatedSetting.disallowPublicVisibility]); }, [parentMemoVisibility, userSetting.memoVisibility, workspaceMemoRelatedSetting.disallowPublicVisibility]);
useAsyncEffect(async () => { useAsyncEffect(async () => {
if (!memoName) { if (!memoName) {
......
...@@ -160,6 +160,7 @@ const MemoDetail = observer(() => { ...@@ -160,6 +160,7 @@ const MemoDetail = observer(() => {
cacheKey={`${memo.name}-${memo.updateTime}-comment`} cacheKey={`${memo.name}-${memo.updateTime}-comment`}
placeholder={t("editor.add-your-comment-here")} placeholder={t("editor.add-your-comment-here")}
parentMemoName={memo.name} parentMemoName={memo.name}
parentMemoVisibility={memo.visibility}
autoFocus autoFocus
onConfirm={handleCommentCreated} onConfirm={handleCommentCreated}
onCancel={() => setShowCommentEditor(false)} onCancel={() => setShowCommentEditor(false)}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment