diff --git a/packages/app/src/app/graphql/types.ts b/packages/app/src/app/graphql/types.ts index b7184576868..e6c4c220bce 100644 --- a/packages/app/src/app/graphql/types.ts +++ b/packages/app/src/app/graphql/types.ts @@ -5580,32 +5580,6 @@ export type SidebarCollectionFragment = { path: string; }; -export type SandboxFragment = { - __typename?: 'Sandbox'; - id: string; - alias: string | null; - title: string | null; - description: string | null; - insertedAt: string; - updatedAt: string; - removedAt: string | null; - privacy: number; - screenshotUrl: string | null; - teamId: any | null; - source: { __typename?: 'Source'; template: string | null }; - customTemplate: { __typename?: 'Template'; id: any | null } | null; - forkedTemplate: { - __typename?: 'Template'; - id: any | null; - color: string | null; - } | null; - collection: { - __typename?: 'Collection'; - path: string; - teamId: any | null; - } | null; -}; - export type TeamFragment = { __typename?: 'Team'; id: any; @@ -5736,156 +5710,6 @@ export type RenameSandboxMutation = { renameSandbox: { __typename?: 'Sandbox'; id: string }; }; -export type PermanentlyDeleteSandboxesMutationVariables = Exact<{ - sandboxIds: Array | Scalars['ID']; -}>; - -export type PermanentlyDeleteSandboxesMutation = { - __typename?: 'RootMutationType'; - permanentlyDeleteSandboxes: Array<{ __typename?: 'Sandbox'; id: string }>; -}; - -export type PathedSandboxesQueryVariables = Exact<{ - path: Scalars['String']; - teamId: InputMaybe; -}>; - -export type PathedSandboxesQuery = { - __typename?: 'RootQueryType'; - me: { - __typename?: 'CurrentUser'; - id: any; - collections: Array<{ - __typename?: 'Collection'; - id: any | null; - path: string; - }>; - collection: { - __typename?: 'Collection'; - id: any | null; - path: string; - sandboxes: Array<{ - __typename?: 'Sandbox'; - id: string; - alias: string | null; - title: string | null; - description: string | null; - insertedAt: string; - updatedAt: string; - removedAt: string | null; - privacy: number; - screenshotUrl: string | null; - teamId: any | null; - source: { __typename?: 'Source'; template: string | null }; - customTemplate: { __typename?: 'Template'; id: any | null } | null; - forkedTemplate: { - __typename?: 'Template'; - id: any | null; - color: string | null; - } | null; - collection: { - __typename?: 'Collection'; - path: string; - teamId: any | null; - } | null; - }>; - } | null; - } | null; -}; - -export type RecentSandboxFragment = { - __typename?: 'Sandbox'; - id: string; - alias: string | null; - title: string | null; - lastAccessedAt: any; - screenshotUrl: string | null; - privacy: number; - teamId: any | null; - source: { __typename?: 'Source'; template: string | null }; - customTemplate: { __typename?: 'Template'; id: any | null } | null; - forkedTemplate: { - __typename?: 'Template'; - id: any | null; - color: string | null; - } | null; - collection: { - __typename?: 'Collection'; - path: string; - teamId: any | null; - } | null; -}; - -export type RecentSandboxesQueryVariables = Exact<{ - orderField: Scalars['String']; - orderDirection: Direction; -}>; - -export type RecentSandboxesQuery = { - __typename?: 'RootQueryType'; - me: { - __typename?: 'CurrentUser'; - id: any; - sandboxes: Array<{ - __typename?: 'Sandbox'; - id: string; - alias: string | null; - title: string | null; - lastAccessedAt: any; - screenshotUrl: string | null; - privacy: number; - teamId: any | null; - source: { __typename?: 'Source'; template: string | null }; - customTemplate: { __typename?: 'Template'; id: any | null } | null; - forkedTemplate: { - __typename?: 'Template'; - id: any | null; - color: string | null; - } | null; - collection: { - __typename?: 'Collection'; - path: string; - teamId: any | null; - } | null; - }>; - } | null; -}; - -export type DeletedSandboxesQueryVariables = Exact<{ [key: string]: never }>; - -export type DeletedSandboxesQuery = { - __typename?: 'RootQueryType'; - me: { - __typename?: 'CurrentUser'; - id: any; - sandboxes: Array<{ - __typename?: 'Sandbox'; - id: string; - alias: string | null; - title: string | null; - description: string | null; - insertedAt: string; - updatedAt: string; - removedAt: string | null; - privacy: number; - screenshotUrl: string | null; - teamId: any | null; - source: { __typename?: 'Source'; template: string | null }; - customTemplate: { __typename?: 'Template'; id: any | null } | null; - forkedTemplate: { - __typename?: 'Template'; - id: any | null; - color: string | null; - } | null; - collection: { - __typename?: 'Collection'; - path: string; - teamId: any | null; - } | null; - }>; - } | null; -}; - export type TeamQueryVariables = Exact<{ id: Scalars['UUID4']; }>; diff --git a/packages/app/src/app/pages/Dashboard/Components/Selection/ContextMenus/SandboxMenu.tsx b/packages/app/src/app/pages/Dashboard/Components/Selection/ContextMenus/SandboxMenu.tsx index 5d133d1ec28..5cb7bde2567 100644 --- a/packages/app/src/app/pages/Dashboard/Components/Selection/ContextMenus/SandboxMenu.tsx +++ b/packages/app/src/app/pages/Dashboard/Components/Selection/ContextMenus/SandboxMenu.tsx @@ -54,7 +54,9 @@ export const SandboxMenu: React.FC = ({ const hasWriteAccess = isInActiveTeam && hasEditorAccess; - if (location.pathname.includes('deleted') && hasWriteAccess) { + // For deleted page, we can trust that sandboxes belong to the active team + // since they're already filtered by team in the query, so we only need hasEditorAccess + if (location.pathname.includes('deleted') && hasEditorAccess) { return ( ({ - mutation: ADD_SANDBOXES_TO_FOLDER_MUTATION, - variables: { - sandboxIds: selectedSandboxes, - teamId, - collectionPath: path, - }, - optimisticResponse: { - __typename: 'RootMutationType', - addToCollectionOrTeam: [], - }, - - refetchQueries: ['PathedSandboxes'], - }); -} - -export function undeleteSandboxes(selectedSandboxes) { - client.mutate({ - mutation: ADD_SANDBOXES_TO_FOLDER_MUTATION, - // @ts-ignore - variables: { - sandboxIds: selectedSandboxes.toJS - ? selectedSandboxes.toJS() - : selectedSandboxes, - collectionPath: '/', - }, - optimisticResponse: { - __typename: 'RootMutationType', - addToCollectionOrTeam: [], - }, - - refetchQueries: ['DeletedSandboxes'], - }); -} - -export function permanentlyDeleteSandboxes(selectedSandboxes: string[]) { - return client.mutate< - PermanentlyDeleteSandboxesMutation, - PermanentlyDeleteSandboxesMutationVariables - >({ - mutation: PERMANENTLY_DELETE_SANDBOXES_MUTATION, - variables: { - sandboxIds: selectedSandboxes, - }, - update: cache => { - try { - const oldDeleteCache = cache.readQuery< - DeletedSandboxesQuery, - DeletedSandboxesQueryVariables - >({ - query: DELETED_SANDBOXES_CONTENT_QUERY, - }); - - const newDeleteCache = { - ...oldDeleteCache, - me: { - ...(oldDeleteCache && oldDeleteCache.me ? oldDeleteCache.me : null), - sandboxes: (oldDeleteCache?.me?.sandboxes || []).filter( - x => !selectedSandboxes.includes(x.id) - ), - }, - }; - - cache.writeQuery({ - query: DELETED_SANDBOXES_CONTENT_QUERY, - data: newDeleteCache, - }); - } catch (e) { - // cache doesn't exist, no biggie! - } - }, - }); -} - -export function deleteSandboxes(selectedSandboxes, collections = []) { - client.mutate({ - mutation: DELETE_SANDBOXES_MUTATION, - variables: { - sandboxIds: selectedSandboxes.toJS - ? selectedSandboxes.toJS() - : selectedSandboxes, - }, - refetchQueries: [ - 'DeletedSandboxes', - 'PathedSandboxes', - 'RecentSandboxes', - ], - update: cache => { - if (collections) { - collections.forEach(({ path, teamId }) => { - try { - const variables = { - path, - teamId, - }; - - const oldFolderCacheData = cache.readQuery< - PathedSandboxesQuery, - PathedSandboxesQueryVariables - >({ - query: PATHED_SANDBOXES_CONTENT_QUERY, - variables, - }); - - const data = immer(oldFolderCacheData, draft => { - if ( - !draft?.me?.collection || - !oldFolderCacheData?.me?.collection?.sandboxes - ) { - return; - } - draft.me.collection.sandboxes = oldFolderCacheData.me.collection.sandboxes.filter( - x => !selectedSandboxes.includes(x?.id) - ); - }); - - if (data) { - cache.writeQuery< - PathedSandboxesQuery, - PathedSandboxesQueryVariables - >({ - query: PATHED_SANDBOXES_CONTENT_QUERY, - variables, - data, - }); - } - } catch (e) { - // cache doesn't exist, no biggie! - } - }); - } - }, - }); -} - export function setSandboxesPrivacy( selectedSandboxes: string[], privacy: 0 | 1 | 2 diff --git a/packages/app/src/app/pages/common/Modals/EmptyTrash/index.tsx b/packages/app/src/app/pages/common/Modals/EmptyTrash/index.tsx index e8c7088c45b..abd7223b7b9 100644 --- a/packages/app/src/app/pages/common/Modals/EmptyTrash/index.tsx +++ b/packages/app/src/app/pages/common/Modals/EmptyTrash/index.tsx @@ -2,11 +2,9 @@ import React, { FunctionComponent } from 'react'; import { useAppState, useActions } from 'app/overmind'; import { Alert } from '../Common/Alert'; -import { permanentlyDeleteSandboxes } from '../../../Dashboard/queries'; - export const EmptyTrash: FunctionComponent = () => { const { trashSandboxIds } = useAppState().dashboard; - const { modalClosed } = useActions(); + const { modalClosed, dashboard } = useActions(); return ( { description="Are you sure you want to permanently delete all the items in the trash?" onCancel={modalClosed} onPrimaryAction={async () => { - await permanentlyDeleteSandboxes(trashSandboxIds); + await dashboard.permanentlyDeleteSandboxes(trashSandboxIds); modalClosed(); }} diff --git a/packages/app/src/app/pages/common/Modals/MoveSandboxFolderModal/DirectoryPicker/SandboxesItem/FolderEntry/index.tsx b/packages/app/src/app/pages/common/Modals/MoveSandboxFolderModal/DirectoryPicker/SandboxesItem/FolderEntry/index.tsx index 882dc8bedf8..05b1d635f3a 100644 --- a/packages/app/src/app/pages/common/Modals/MoveSandboxFolderModal/DirectoryPicker/SandboxesItem/FolderEntry/index.tsx +++ b/packages/app/src/app/pages/common/Modals/MoveSandboxFolderModal/DirectoryPicker/SandboxesItem/FolderEntry/index.tsx @@ -38,7 +38,6 @@ import { CreateFolderEntry } from './CreateFolderEntry'; import { PATHED_SANDBOXES_FOLDER_QUERY, - PATHED_SANDBOXES_CONTENT_QUERY, DELETE_FOLDER_MUTATION, RENAME_FOLDER_MUTATION, } from '../queries'; @@ -180,13 +179,6 @@ class FolderEntry extends React.Component { client.mutate({ mutation: DELETE_FOLDER_MUTATION, variables: params, - - refetchQueries: [ - { - query: PATHED_SANDBOXES_CONTENT_QUERY, - variables: { path: '/', teamId }, - }, - ], update: (cache, { data: { deleteCollection } }) => { const variables: PathedSandboxesFoldersQueryVariables = { teamId, diff --git a/packages/app/src/app/pages/common/Modals/MoveSandboxFolderModal/DirectoryPicker/SandboxesItem/queries.ts b/packages/app/src/app/pages/common/Modals/MoveSandboxFolderModal/DirectoryPicker/SandboxesItem/queries.ts index 504ea6614f4..0752460bfc9 100644 --- a/packages/app/src/app/pages/common/Modals/MoveSandboxFolderModal/DirectoryPicker/SandboxesItem/queries.ts +++ b/packages/app/src/app/pages/common/Modals/MoveSandboxFolderModal/DirectoryPicker/SandboxesItem/queries.ts @@ -20,61 +20,6 @@ export const PATHED_SANDBOXES_FOLDER_QUERY = gql` ${SIDEBAR_COLLECTION_FRAGMENT} `; -export const SANDBOX_FRAGMENT = gql` - fragment Sandbox on Sandbox { - id - alias - title - description - insertedAt - updatedAt - removedAt - privacy - screenshotUrl - - source { - template - } - - customTemplate { - id - } - - forkedTemplate { - id - color - } - - teamId - - collection { - path - teamId - } - } -`; - -export const PATHED_SANDBOXES_CONTENT_QUERY = gql` - query PathedSandboxes($path: String!, $teamId: ID) { - me { - id - - collections(teamId: $teamId) { - ...SidebarCollection - } - collection(path: $path, teamId: $teamId) { - id - path - sandboxes { - ...Sandbox - } - } - } - } - ${SANDBOX_FRAGMENT} - ${SIDEBAR_COLLECTION_FRAGMENT} -`; - export const CREATE_FOLDER_MUTATION = gql` mutation createCollection($path: String!, $teamId: UUID4) { createCollection(path: $path, teamId: $teamId) {