Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed file download, updated preview port #182

Merged
merged 2 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/src/common/components/DataTable/DataTable.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
}

.tableContainer {
max-height: 600px;
max-height: 800px;
}

.table {
Expand Down
6 changes: 1 addition & 5 deletions ui/src/common/components/DownloadMenu/DownloadMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ import { useAppDispatch } from 'store/useAppDispatch';
import { Menu } from '@mantine/core';
import { DownloadIcon } from 'common/icons';
import classes from './DownloadMenu.module.scss';

export interface DownloadMenuOptions {
label: string;
format: string;
}
import type { DownloadMenuOptions } from 'common/types/downloadMenuOptions';

interface DownloadMenuProps {
options: DownloadMenuOptions[];
Expand Down
7 changes: 7 additions & 0 deletions ui/src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* limitations under the License.
*/
import type { Pagination } from './types';
import type { DownloadMenuOptions } from './types/downloadMenuOptions';

export const isDev = !import.meta.env.PROD;

Expand All @@ -26,3 +27,9 @@ export const auth0Scope = import.meta.env.VITE_AUTH0_SCOPE as string;
export const domain = window.location.origin;

export const emptyPagination: Pagination = { page: 1, size: 10, total: 0, pages: 0 };

export const fileDownloadOptions: DownloadMenuOptions[] = [
{ label: '.binpb', format: 'binpb' },
{ label: '.txtpb', format: 'txtpb' },
{ label: '.json', format: 'json' },
];
4 changes: 3 additions & 1 deletion ui/src/common/store/util.thunks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,16 @@ export const downloadFile =
});

const blob = new Blob([response.data], { type: response.headers['content-type'] });
const header = response.headers['content-disposition'];
const fileName = header.replace(/^.*filename="(.*)"/, '$1');

const link = document.createElement('a');
fileUrl = URL.createObjectURL(blob);

link.href = fileUrl;
// We need content-disposition value to get filename from BE.
// Waiting to be exposed by CORS
link.setAttribute('download', 'test.txt');
link.setAttribute('download', fileName);

document.body.appendChild(link);
link.click();
Expand Down
19 changes: 19 additions & 0 deletions ui/src/common/types/downloadMenuOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2024 Open Reaction Database Project Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export interface DownloadMenuOptions {
label: string;
format: string;
}
12 changes: 3 additions & 9 deletions ui/src/pages/DatasetPage/DatasetHeader/DatasetHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { UserField } from 'common/components/UserField/UserField';
import { ActionIcon, Button, Flex, Paper, Title } from '@mantine/core';
import { CopyButton, type CopyButtonOptions } from 'common/components/CopyButton/CopyButton';
import { formatDate } from 'common/utils';
import { DownloadMenu, type DownloadMenuOptions } from 'common/components/DownloadMenu/DownloadMenu';
import { DownloadMenu } from 'common/components/DownloadMenu/DownloadMenu';
import { ChevronDownIcon, EditIcon } from 'common/icons';
import type { Dataset } from 'store/datasets/datasets.types';
import { useCallback, useMemo } from 'react';
Expand All @@ -29,18 +29,12 @@ import { useSelector } from 'react-redux';
import { selectIsDatasetOpened } from 'store/datasets/datasets.selectors';
import { setDatasetEditOpenedAction } from 'store/datasets/datasets.actions';
import { useAppDispatch } from 'store/useAppDispatch';
import { domain } from 'common/constants';
import { domain, fileDownloadOptions } from 'common/constants';

interface DatasetHeaderProps {
dataset: Dataset;
}

const datasetDownloadOptions: DownloadMenuOptions[] = [
{ label: '.pb', format: 'binpb' },
{ label: '.pbtxt', format: 'txtpb' },
{ label: '.json', format: 'json' },
];

export function DatasetHeader({ dataset }: Readonly<DatasetHeaderProps>) {
const [location] = useLocation();
const dispatch = useAppDispatch();
Expand Down Expand Up @@ -108,7 +102,7 @@ export function DatasetHeader({ dataset }: Readonly<DatasetHeaderProps>) {

<div className={classes.buttonContainer}>
<DownloadMenu
options={datasetDownloadOptions}
options={fileDownloadOptions}
url={`/datasets/${dataset.id}/download`}
target={
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,19 @@
*/
import { Button, Flex, Paper } from '@mantine/core';
import { Link, useParams } from 'wouter';
import { CopyButton, type CopyButtonOptions } from '../../../../common/components/CopyButton/CopyButton';
import { CopyButton, type CopyButtonOptions } from 'common/components/CopyButton/CopyButton';
import { CheckListIcon, ChevronDownIcon, DotsIcon, DownloadIcon } from 'common/icons';
import { DownloadMenu, type DownloadMenuOptions } from '../../../../common/components/DownloadMenu/DownloadMenu';
import { DownloadMenu } from 'common/components/DownloadMenu/DownloadMenu';
import classes from './ReactionCard.module.scss';
import { useSelector } from 'react-redux';
import { selectReactionById } from 'store/reactions/reactions.selectors';
import { fileDownloadOptions } from 'common/constants';

interface ReactionCardProps {
id: number;
index: number;
}

const reactionDownloadOptions: DownloadMenuOptions[] = [
{ label: '.pb', format: 'binpb' },
{ label: '.pbtxt', format: 'txtpb' },
];

export function ReactionCard({ id, index }: Readonly<ReactionCardProps>) {
const { datasetId } = useParams();
const reaction = useSelector(selectReactionById(id));
Expand Down Expand Up @@ -83,7 +79,7 @@ export function ReactionCard({ id, index }: Readonly<ReactionCardProps>) {
</Button>

<DownloadMenu
options={reactionDownloadOptions}
options={fileDownloadOptions}
url={`/datasets/${datasetId}/reactions/${id}/download`}
target={
<Button
Expand Down
11 changes: 3 additions & 8 deletions ui/src/pages/ReactionPage/ReactionHeader/ReactionHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,15 @@ import { useSelector } from 'react-redux';
import { CopyButton } from 'common/components/CopyButton/CopyButton';
import { CheckListIcon, ChevronDownIcon, DownloadIcon, EditIcon, TrashIcon } from 'common/icons';
import { useCallback, useMemo } from 'react';
import { DownloadMenu, type DownloadMenuOptions } from 'common/components/DownloadMenu/DownloadMenu';
import { DownloadMenu } from 'common/components/DownloadMenu/DownloadMenu';
import { useLocation } from 'wouter';
import { domain } from 'common/constants';
import { domain, fileDownloadOptions } from 'common/constants';
import classes from './reactionHeader.module.scss';
import { useDisclosure } from '@mantine/hooks';
import { useAppDispatch } from 'store/useAppDispatch';
import { InputModal } from '../../../common/components/InputModal/InputModal';
import { renameReaction } from '../../../store/reactions/reactions.thunks';

const reactionDownloadOptions: DownloadMenuOptions[] = [
{ label: '.pb', format: 'binpb' },
{ label: '.pbtxt', format: 'txtpb' },
];

interface ReactionHeaderProps {
datasetId: number;
reactionId: number;
Expand Down Expand Up @@ -110,7 +105,7 @@ export function ReactionHeader({ datasetId, reactionId }: Readonly<ReactionHeade
Save as Template
</Button>
<DownloadMenu
options={reactionDownloadOptions}
options={fileDownloadOptions}
url={`/datasets/${datasetId}/reactions/${reactionId}/download`}
target={
<Button
Expand Down
3 changes: 3 additions & 0 deletions ui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ export default defineConfig({
test: {
globals: true,
},
preview: {
port: 5173,
},
});
Loading