diff --git a/server/app/export.go b/server/app/export.go index d1de4798a..9135e3e0b 100644 --- a/server/app/export.go +++ b/server/app/export.go @@ -184,19 +184,8 @@ func (a *App) writeArchiveFile(zw *zip.Writer, filename string, boardID string, return err } -// getBoardsForArchive fetches all the specified boards, or all boards in the workspace/team -// if `boardIDs` is empty. +// getBoardsForArchive fetches all the specified boards. func (a *App) getBoardsForArchive(boardIDs []string) ([]model.Board, error) { - if len(boardIDs) == 0 { - // TODO: implement this - // boards, err := a.GetAllBoards("", "board") - // if err != nil { - // return nil, fmt.Errorf("could not fetch all boards: %w", err) - // } - // return boards, nil - return []model.Board{}, nil - } - boards := make([]model.Board, 0, len(boardIDs)) for _, id := range boardIDs { diff --git a/webapp/src/archiver.ts b/webapp/src/archiver.ts index 5d57cf444..c1b313b65 100644 --- a/webapp/src/archiver.ts +++ b/webapp/src/archiver.ts @@ -11,11 +11,11 @@ declare let window: IAppWindow class Archiver { static async exportBoardArchive(board: Board): Promise { - this.exportArchive(mutator.exportArchive(board.id)) + this.exportArchive(mutator.exportBoardArchive(board.id)) } - static async exportFullArchive(): Promise { - this.exportArchive(mutator.exportArchive()) + static async exportFullArchive(teamID: string): Promise { + this.exportArchive(mutator.exportFullArchive(teamID)) } private static exportArchive(prom: Promise): void { diff --git a/webapp/src/components/globalHeader/globalHeaderSettingsMenu.tsx b/webapp/src/components/globalHeader/globalHeaderSettingsMenu.tsx index 44a658507..e75450373 100644 --- a/webapp/src/components/globalHeader/globalHeaderSettingsMenu.tsx +++ b/webapp/src/components/globalHeader/globalHeaderSettingsMenu.tsx @@ -76,8 +76,10 @@ const GlobalHeaderSettingsMenu = (props: Props) => { id='export' name={intl.formatMessage({id: 'Sidebar.export-archive', defaultMessage: 'Export archive'})} onClick={async () => { - TelemetryClient.trackEvent(TelemetryCategory, TelemetryActions.ExportArchive) - Archiver.exportFullArchive() + if (currentTeam) { + TelemetryClient.trackEvent(TelemetryCategory, TelemetryActions.ExportArchive) + Archiver.exportFullArchive(currentTeam.id) + } }} /> { const intl = useIntl() const dispatch = useAppDispatch() + const currentTeam = useAppSelector(getCurrentTeam) // we need this as the sidebar doesn't always need to re-render // on theme change. This can cause props and the actual @@ -114,8 +116,10 @@ const SidebarSettingsMenu = (props: Props) => { id='export' name={intl.formatMessage({id: 'Sidebar.export-archive', defaultMessage: 'Export archive'})} onClick={async () => { - TelemetryClient.trackEvent(TelemetryCategory, TelemetryActions.ExportArchive) - Archiver.exportFullArchive() + if (currentTeam) { + TelemetryClient.trackEvent(TelemetryCategory, TelemetryActions.ExportArchive) + Archiver.exportFullArchive(currentTeam.id) + } }} /> { - return octoClient.exportArchive(boardID) + async exportBoardArchive(boardID: string): Promise { + return octoClient.exportBoardArchive(boardID) + } + + // Not a mutator, but convenient to put here since Mutator wraps OctoClient + async exportFullArchive(teamID: string): Promise { + return octoClient.exportFullArchive(teamID) } // Not a mutator, but convenient to put here since Mutator wraps OctoClient diff --git a/webapp/src/octoClient.test.ts b/webapp/src/octoClient.test.ts index dea8e06a9..e4a3239c5 100644 --- a/webapp/src/octoClient.test.ts +++ b/webapp/src/octoClient.test.ts @@ -24,7 +24,11 @@ test('OctoClient: get blocks', async () => { expect(boards.length).toBe(blocks.length) FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify(blocks))) - const response = await octoClient.exportArchive() + let response = await octoClient.exportBoardArchive('board') + expect(response.status).toBe(200) + + FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify(blocks))) + response = await octoClient.exportFullArchive('team') expect(response.status).toBe(200) FetchMock.fn.mockReturnValueOnce(FetchMock.jsonResponse(JSON.stringify(blocks))) diff --git a/webapp/src/octoClient.ts b/webapp/src/octoClient.ts index 1cd92acad..d409ff1bc 100644 --- a/webapp/src/octoClient.ts +++ b/webapp/src/octoClient.ts @@ -201,12 +201,16 @@ class OctoClient { return (await this.getJson(response, {})) as Record } - // If no boardID is provided, it will export the entire archive - async exportArchive(boardID = ''): Promise { + async exportBoardArchive(boardID: string): Promise { const path = `/api/v1/boards/${boardID}/archive/export` return fetch(this.getBaseURL() + path, {headers: this.headers()}) } + async exportFullArchive(teamID: string): Promise { + const path = `/api/v1/teams/${teamID}/archive/export` + return fetch(this.getBaseURL() + path, {headers: this.headers()}) + } + async importFullArchive(file: File): Promise { const formData = new FormData() formData.append('file', file)