From a88fc392de41d9e3e7cf8a01f4645e26accf5bac Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Mon, 1 Jan 2024 20:01:45 -0500 Subject: [PATCH] stash --- app/actions/definitions/documents.tsx | 3 +- .../Document => }/components/Combobox.tsx | 0 app/components/InputSelect.tsx | 1 + app/components/InputSelectPermission.tsx | 9 ++- .../Sharing/DocumentMemberList.tsx} | 61 +++++--------- .../Sharing}/MemberListItem.tsx | 11 +-- .../Sharing}/SharePopover.tsx | 80 ++++++++++++------- app/components/Sharing/index.tsx | 3 + .../CollectionGroupMemberListItem.tsx | 2 +- .../components/MemberListItem.tsx | 2 +- .../Document/components/ShareButton.tsx | 4 +- 11 files changed, 92 insertions(+), 84 deletions(-) rename app/{scenes/Document => }/components/Combobox.tsx (100%) rename app/{scenes/Document/components/InviteTeamMembers.tsx => components/Sharing/DocumentMemberList.tsx} (82%) rename app/{scenes/Document/components => components/Sharing}/MemberListItem.tsx (97%) rename app/{scenes/Document/components => components/Sharing}/SharePopover.tsx (90%) create mode 100644 app/components/Sharing/index.tsx diff --git a/app/actions/definitions/documents.tsx b/app/actions/definitions/documents.tsx index 24c71205b8..b958145c2b 100644 --- a/app/actions/definitions/documents.tsx +++ b/app/actions/definitions/documents.tsx @@ -32,13 +32,13 @@ import { toast } from "sonner"; import { ExportContentType, TeamPreference } from "@shared/types"; import MarkdownHelper from "@shared/utils/MarkdownHelper"; import { getEventFiles } from "@shared/utils/files"; -import SharePopover from "~/scenes/Document/components/SharePopover"; import DocumentDelete from "~/scenes/DocumentDelete"; import DocumentMove from "~/scenes/DocumentMove"; import DocumentPermanentDelete from "~/scenes/DocumentPermanentDelete"; import DocumentPublish from "~/scenes/DocumentPublish"; import DocumentTemplatizeDialog from "~/components/DocumentTemplatizeDialog"; import DuplicateDialog from "~/components/DuplicateDialog"; +import SharePopover from "~/components/Sharing"; import { createAction } from "~/actions"; import { DocumentSection } from "~/actions/sections"; import env from "~/env"; @@ -952,4 +952,5 @@ export const rootDocumentActions = [ openDocumentComments, openDocumentHistory, openDocumentInsights, + shareDocument, ]; diff --git a/app/scenes/Document/components/Combobox.tsx b/app/components/Combobox.tsx similarity index 100% rename from app/scenes/Document/components/Combobox.tsx rename to app/components/Combobox.tsx diff --git a/app/components/InputSelect.tsx b/app/components/InputSelect.tsx index 718eb1751b..82d976adbe 100644 --- a/app/components/InputSelect.tsx +++ b/app/components/InputSelect.tsx @@ -163,6 +163,7 @@ const InputSelect = (props: Props) => { topAnchor={topAnchor} rightAnchor={rightAnchor} hiddenScrollbars + maxWidth={400} style={ maxHeight && topAnchor ? { diff --git a/app/components/InputSelectPermission.tsx b/app/components/InputSelectPermission.tsx index 5f108bacc7..1ecff92705 100644 --- a/app/components/InputSelectPermission.tsx +++ b/app/components/InputSelectPermission.tsx @@ -2,6 +2,7 @@ import * as React from "react"; import { useTranslation } from "react-i18next"; import { $Diff } from "utility-types"; import { CollectionPermission } from "@shared/types"; +import { EmptySelectValue } from "~/types"; import InputSelect, { Props, Option } from "./InputSelect"; export default function InputSelectPermission( @@ -17,7 +18,7 @@ export default function InputSelectPermission( const { t } = useTranslation(); const handleChange = React.useCallback( (value) => { - if (value === "no_access") { + if (value === EmptySelectValue) { value = null; } @@ -31,7 +32,7 @@ export default function InputSelectPermission( label={t("Default access")} options={[ { - label: t("View and edit"), + label: t("Can edit"), value: CollectionPermission.ReadWrite, }, { @@ -40,11 +41,11 @@ export default function InputSelectPermission( }, { label: t("No access"), - value: "no_access", + value: EmptySelectValue, }, ]} ariaLabel={t("Default access")} - value={value || "no_access"} + value={value || EmptySelectValue} onChange={handleChange} {...rest} /> diff --git a/app/scenes/Document/components/InviteTeamMembers.tsx b/app/components/Sharing/DocumentMemberList.tsx similarity index 82% rename from app/scenes/Document/components/InviteTeamMembers.tsx rename to app/components/Sharing/DocumentMemberList.tsx index 1bf2b95559..347924663b 100644 --- a/app/scenes/Document/components/InviteTeamMembers.tsx +++ b/app/components/Sharing/DocumentMemberList.tsx @@ -1,6 +1,6 @@ import { t } from "i18next"; -import { orderBy } from "lodash"; import isNil from "lodash/isNil"; +import orderBy from "lodash/orderBy"; import { observer } from "mobx-react"; import * as React from "react"; import { toast } from "sonner"; @@ -11,6 +11,7 @@ import User from "~/models/User"; import UserMembership from "~/models/UserMembership"; import Avatar from "~/components/Avatar"; import { AvatarSize } from "~/components/Avatar/Avatar"; +import Combobox from "~/components/Combobox"; import Flex from "~/components/Flex"; import LoadingIndicator from "~/components/LoadingIndicator"; import PaginatedList from "~/components/PaginatedList"; @@ -18,7 +19,6 @@ import useCurrentUser from "~/hooks/useCurrentUser"; import useRequest from "~/hooks/useRequest"; import useStores from "~/hooks/useStores"; import useThrottledCallback from "~/hooks/useThrottledCallback"; -import Combobox from "./Combobox"; import MemberListItem from "./MemberListItem"; type Props = { @@ -26,38 +26,31 @@ type Props = { document: Document; }; -function InviteTeamMembers({ document }: Props) { +function DocumentMembersList({ document }: Props) { const { users, userMemberships } = useStores(); const [query, setQuery] = React.useState(""); const [selectedUser, setSelectedUser] = React.useState(null); const [invitedInSession, setInvitedInSession] = React.useState([]); const user = useCurrentUser(); - const { - data: teamMembers, - loading: loadingTeamMembers, - request: fetchTeamMembers, - } = useRequest( + const { loading: loadingTeamMembers, request: fetchTeamMembers } = useRequest( React.useCallback( () => users.fetchPage({ limit: Pagination.defaultLimit }), [users] ) ); - const { - data: documentMembers, - loading: loadingDocumentMembers, - request: fetchDocumentMembers, - } = useRequest( - React.useCallback( - () => - userMemberships.fetchDocumentMemberships({ - id: document.id, - limit: Pagination.defaultLimit, - }), - [userMemberships, document.id] - ) - ); + const { loading: loadingDocumentMembers, request: fetchDocumentMembers } = + useRequest( + React.useCallback( + () => + userMemberships.fetchDocumentMemberships({ + id: document.id, + limit: Pagination.defaultLimit, + }), + [userMemberships, document.id] + ) + ); React.useEffect(() => { void fetchTeamMembers(); @@ -85,20 +78,8 @@ function InviteTeamMembers({ document }: Props) { const nonMembers = React.useMemo( () => - teamMembers && documentMembers - ? users - .notInDocument(document.id, query) - .filter((u) => u.id !== user.id) - : [], - [ - users, - document.id, - document.members, - teamMembers, - documentMembers, - user.id, - query, - ] + users.notInDocument(document.id, query).filter((u) => u.id !== user.id), + [users, users.orderedData, document.id, document.members, user.id, query] ); React.useEffect(() => { @@ -178,10 +159,6 @@ function InviteTeamMembers({ document }: Props) { return ; } - if (!teamMembers && !documentMembers) { - return null; - } - return ( } border={false} style={{ marginRight: -8 }} + small actions={ {onUpdate && ( - {!hideTitle && ( + {/* {!hideTitle && ( {isPubliclyShared ? ( @@ -230,7 +232,7 @@ function SharePopover({ )} {t("Share this document")} - )} + )} */} {sharedParent && !document.isDraft && ( @@ -246,9 +248,53 @@ function SharePopover({ )} - {canPublish && !sharedParent?.published && ( + {/* {canPublish && !sharedParent?.published && ( - )} + )} */} + +

People with access

+ + + +

Link access

+ + + + + {t("No public access")} + + ), + value: EmptySelectValue, + }, + { + label: ( + + + {t("Anyone with link can view")} + + ), + value: "public", + }, + ]} + // value={value || EmptySelectValue} + // onChange={handleChange} + /> + + + +
{canPublish && share && !document.isDraft && ( @@ -270,24 +316,11 @@ function SharePopover({ )} - {canPublish ? ( - <> - - - - - - ) : null} - {expandedOptions && ( <> {canPublish && sharedParent?.published && ( - <> - - - + )} - )} - - - ); diff --git a/app/components/Sharing/index.tsx b/app/components/Sharing/index.tsx new file mode 100644 index 0000000000..757dd58d66 --- /dev/null +++ b/app/components/Sharing/index.tsx @@ -0,0 +1,3 @@ +import SharePopover from "./SharePopover"; + +export default SharePopover; diff --git a/app/scenes/CollectionPermissions/components/CollectionGroupMemberListItem.tsx b/app/scenes/CollectionPermissions/components/CollectionGroupMemberListItem.tsx index 953d2ad4ab..55c118ea41 100644 --- a/app/scenes/CollectionPermissions/components/CollectionGroupMemberListItem.tsx +++ b/app/scenes/CollectionPermissions/components/CollectionGroupMemberListItem.tsx @@ -37,7 +37,7 @@ const CollectionGroupMemberListItem = ({ value: CollectionPermission.Read, }, { - label: t("View and edit"), + label: t("Can edit"), value: CollectionPermission.ReadWrite, }, { diff --git a/app/scenes/CollectionPermissions/components/MemberListItem.tsx b/app/scenes/CollectionPermissions/components/MemberListItem.tsx index e7ea9890d1..e453b2d30f 100644 --- a/app/scenes/CollectionPermissions/components/MemberListItem.tsx +++ b/app/scenes/CollectionPermissions/components/MemberListItem.tsx @@ -60,7 +60,7 @@ const MemberListItem = ({ value: CollectionPermission.Read, }, { - label: t("View and edit"), + label: t("Can edit"), value: CollectionPermission.ReadWrite, }, { diff --git a/app/scenes/Document/components/ShareButton.tsx b/app/scenes/Document/components/ShareButton.tsx index 677ef41935..1b0fc249d4 100644 --- a/app/scenes/Document/components/ShareButton.tsx +++ b/app/scenes/Document/components/ShareButton.tsx @@ -6,10 +6,10 @@ import { usePopoverState, PopoverDisclosure } from "reakit/Popover"; import Document from "~/models/Document"; import Button from "~/components/Button"; import Popover from "~/components/Popover"; +import SharePopover from "~/components/Sharing"; import Tooltip from "~/components/Tooltip"; import useCurrentTeam from "~/hooks/useCurrentTeam"; import useStores from "~/hooks/useStores"; -import SharePopover from "./SharePopover"; type Props = { document: Document; @@ -61,7 +61,7 @@ function ShareButton({ document }: Props) { )} - +