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

Anusha/appeals 61519.1 #23409

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions app/controllers/reader/documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def documents
document.to_hash.tap do |object|
object[:opened_by_current_user] = read_documents_hash[document.id] || false
object[:tags] = tags_by_doc_id[document.id].to_a
object[:file_size] = document.file_size
end
end
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ def file_name
vbms_document_id.to_s
end

def file_size
File.size(default_path) || 0
end

def default_path
File.join(Rails.root, "tmp", "pdfs", file_name)
end
Expand Down
15 changes: 15 additions & 0 deletions client/app/reader/DocSizeIndicator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import PropTypes from 'prop-types';
import { filesize } from 'filesize';

const DocSizeIndicator = (props) => {
return (
<span>{filesize(props.docSize)}</span>
);
};

DocSizeIndicator.propTypes = {
docSize: PropTypes.number.isRequired
};

export default DocSizeIndicator;
12 changes: 12 additions & 0 deletions client/app/reader/DocumentsTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import TagTableColumn from './TagTableColumn';
import Table from '../components/Table';
import Button from '../components/Button';
import CommentIndicator from './CommentIndicator';
import DocSizeIndicator from './DocSizeIndicator';
import DropdownFilter from '../components/DropdownFilter';
import { bindActionCreators } from 'redux';
import Highlight from '../components/Highlight';
Expand Down Expand Up @@ -50,6 +51,8 @@ const receiptDateFilterStates = {

};



export const getRowObjects = (documents, annotationsPerDocument) => {
return documents.reduce((acc, doc) => {
acc.push(doc);
Expand Down Expand Up @@ -695,6 +698,15 @@ class DocumentsTable extends React.Component {
),
valueFunction: (doc) => <CommentIndicator docId={doc.id} />,
},
{
cellClass: 'comments-column',
header: (
<div id="comments-header" className="document-list-header-comments table-header-label">
File Size
</div>
),
valueFunction: (doc) => <DocSizeIndicator docSize={doc.file_size} />,
},
];
};

Expand Down
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"expose-loader": "^0.7.3",
"faker": "^4.1.0",
"file-loader": "^2.0.0",
"filesize": "^10.1.6",
"font-awesome": "^4.7.0",
"glamor": "^2.20.40",
"history": "^4.5.1",
Expand Down
20 changes: 20 additions & 0 deletions client/test/app/components/DocSizeIndicator.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import React from 'react';
import { render } from '@testing-library/react';
import DocSizeIndicator from '../../../app/reader/DocSizeIndicator';

it('shows file size', () => {
const { container } = render(<DocSizeIndicator docSize="1024" />);

expect(container).toHaveTextContent('1.02 kB');
});

it('handles empty strings', () => {
const { container } = render(<DocSizeIndicator docSize="" />);

expect(container).toHaveTextContent('0 B');
});
it('handles null', () => {
const { container } = render(<DocSizeIndicator docSize={null} />);

expect(container).toHaveTextContent('0 B');
});
4 changes: 3 additions & 1 deletion client/test/app/reader/DocumentsTable-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ describe('DocumentsTable', () => {
listComments: true,
isComment: true
},
{ id: 20 }
{
id: 20,
},
]);
}
);
Expand Down
5 changes: 5 additions & 0 deletions client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8993,6 +8993,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/filesize/-/filesize-6.1.0.tgz#e81bdaa780e2451d714d71c0d7a4f3238d37ad00"
integrity sha512-LpCHtPQ3sFx67z+uh2HnSyWSLLu5Jxo21795uRDuar/EOuYWXib5EmPaGIBuSnRqH2IODiKA2k5re/K9OnN/Yg==

filesize@^10.1.6:
version "10.1.6"
resolved "https://registry.yarnpkg.com/filesize/-/filesize-10.1.6.tgz#31194da825ac58689c0bce3948f33ce83aabd361"
integrity sha512-sJslQKU2uM33qH5nqewAwVB2QgR6w1aMNsYUp3aN5rMRyXEwJGmZvaWzeJFNTOXWlHQyBFCWrdj3fV/fsTOX8w==

fill-range@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-4.0.0.tgz#d544811d428f98eb06a63dc402d2403c328c38f7"
Expand Down
Loading