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

Jerricodelacruz/issue83 #88

Merged
merged 8 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
13 changes: 0 additions & 13 deletions clean-room-demo/webapp/frontend/components/ScreenChecker.tsx

This file was deleted.

37 changes: 2 additions & 35 deletions clean-room-demo/webapp/frontend/components/document/IconItem.tsx
Original file line number Diff line number Diff line change
@@ -1,52 +1,19 @@
import React, { useState } from "react";
import { DocumentIcon, ImageIcon, PdfIcon, PowerpointIcon, ExcelIcon, IconProps } from "./Icon";
import IconType from "./IconType";

interface ItemProps {
name : string,
extension : string,
selected : boolean
}

interface Extension {
excel : string[],
powerPoint : string[],
document : string[],
image : string[],
pdf : string[]
}

const extensions : Extension = {
document : ['doc', 'dot', 'wbk', 'docx', 'docm', 'dotx', 'dotm', 'docb', 'wll', 'wwl'],
excel : ['xls', 'xlt', 'xlm', 'xll_', 'xla_', 'xla5', 'xla8', 'xlsx', 'xlsm', 'xltx', 'xltm', 'xlsb', 'xla', 'xlam', 'xll', 'xlw'],
image : ['apng', 'avig', 'gif', 'jpg', 'jpeg', 'jfif', 'pjpeg', 'pjp', 'png', 'svg', 'webp', 'bmp', 'ico', 'tiff'],
pdf : ['pdf'],
powerPoint : ['pptx', 'pptm', 'potx', 'potm', 'ppam', 'ppsx', 'ppsm', 'sldx', 'sldm', 'pa']
};

const Icon = (props : IconProps & { extension : string } ) => {
if(extensions.document.includes(props.extension)){
return <DocumentIcon {...props} />;
}
else if(extensions.excel.includes(props.extension)){
return <ExcelIcon {...props} />;
}
else if(extensions.image.includes(props.extension)){
return <ImageIcon {...props} />;
}
else if(extensions.pdf.includes(props.extension)){
return <PdfIcon {...props} />;
}
else if(extensions.powerPoint.includes(props.extension)){
return <PowerpointIcon {...props} />;
}
}

export default function IconItem(props : ItemProps) {
const { name, extension, selected } = props;

return (<div className={`w-24 ${selected ? 'text-blue-800' : 'text-black'}`}>
<div className={`relative h-24 flex justify-center ${selected ? 'bg-blue-100' : ' bg-gray-200 '}`}>
<div className="m-auto"><Icon extension={extension} color={selected ? '#0759a7' : '#59595C'} /></div>
<div className="m-auto"><IconType extension={extension} color={selected ? '#0759a7' : '#59595C'} /></div>
</div>
<p className="relative truncate text-xs">{name}</p>
</div>);
Expand Down
37 changes: 37 additions & 0 deletions clean-room-demo/webapp/frontend/components/document/IconType.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { DocumentIcon, ExcelIcon, IconProps, ImageIcon, PdfIcon, PowerpointIcon } from "./Icon";

interface Extension {
excel : string[],
powerPoint : string[],
document : string[],
image : string[],
pdf : string[]
}

const extensions : Extension = {
document : ['doc', 'dot', 'wbk', 'docx', 'docm', 'dotx', 'dotm', 'docb', 'wll', 'wwl'],
Sealjay marked this conversation as resolved.
Show resolved Hide resolved
excel : ['xls', 'xlt', 'xlm', 'xll_', 'xla_', 'xla5', 'xla8', 'xlsx', 'xlsm', 'xltx', 'xltm', 'xlsb', 'xla', 'xlam', 'xll', 'xlw'],
image : ['apng', 'avig', 'gif', 'jpg', 'jpeg', 'jfif', 'pjpeg', 'pjp', 'png', 'svg', 'webp', 'bmp', 'ico', 'tiff'],
pdf : ['pdf'],
powerPoint : ['pptx', 'pptm', 'potx', 'potm', 'ppam', 'ppsx', 'ppsm', 'sldx', 'sldm', 'pa']
};

const IconType = (props : IconProps & { extension : string } ) => {
if(extensions.document.includes(props.extension)){
return <DocumentIcon {...props} />;
}
else if(extensions.excel.includes(props.extension)){
return <ExcelIcon {...props} />;
}
else if(extensions.image.includes(props.extension)){
return <ImageIcon {...props} />;
}
else if(extensions.pdf.includes(props.extension)){
return <PdfIcon {...props} />;
}
else if(extensions.powerPoint.includes(props.extension)){
return <PowerpointIcon {...props} />;
}
}

export default IconType;
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import Item from "./IconItem";

interface Item {
id : number;
fileName : string;
}

interface Props {
items : { id:number, fileName:string }[]
items : Item[]
selectedId? : number,
handleSelect? : any
}
Expand All @@ -15,7 +20,7 @@ const IconView = (props : Props) => {
const { items, selectedId, handleSelect } = { ...defaultProps, ...props };

return (<>
<div className="grid bg-green-300 grid-cols-2 sm:grid-cols-4 gap-3 md:grid-cols-5 lg:grid-cols-8">
<div className="grid grid-cols-2 sm:grid-cols-4 gap-3 md:grid-cols-5 lg:grid-cols-8">
{items.map(({id, fileName}) => {
const [name, extension] = fileName.split('.');
return <div key={id} onClick={() => handleSelect(id)}>
Expand Down
54 changes: 54 additions & 0 deletions clean-room-demo/webapp/frontend/components/document/ListView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { DocumentIcon, ExcelIcon, IconProps, ImageIcon, PdfIcon, PowerpointIcon } from "./Icon";
import IconType from "./IconType";

interface Item {
id : number;
fileName : string;
creationDate : Date;
active : boolean;
}

interface Props {
items : Item[]
selectedId? : number,
handleSelect? : any
}

const defaultProps = {
items : [],
selectedId : 10
}

const ListView = (props : Props) => {
const { items, selectedId, handleSelect } = { ...defaultProps, ...props };

return <div className="overflow-auto">
<table className="table-auto w-full text-left">
<thead className="text-gray-600 border-b-2 border-dotted border-gray-100">
<tr>
<th className="pb-3">ID</th>
<th className="pb-3">TYPE</th>
<th className="pb-3">DOCUMENT NAME</th>
<th className="pb-3">CREATION DATE</th>
<th className="pb-3">ACTIVE</th>
</tr>
</thead>
<tbody>
{items.map(({id, fileName, creationDate, active} : Item) => {
const [name, extension] = fileName.split('.');
return <tr key={id} className={`${selectedId == id ? 'bg-blue-50 text-blue-800' : 'text-gray-500'} border-b border-gray-100 border-dotted`} onClick={() => handleSelect(id)}>
<td className="py-1 align-middle">{id}</td>
<td className="py-1 align-middle">
<IconType extension={extension} width={30} height={30} />
</td>
<td className="py-1 align-middle">{name}</td>
<td className="py-1 align-middle">{`${('0' + creationDate.getMonth() + 1).slice(-2)}/${creationDate.getDate()}/${creationDate.getFullYear()}`}</td>
<td className="py-1 align-middle">{active ? 'YES' : 'NO'}</td>
</tr>
})}
</tbody>
</table>
</div>;
}

export default ListView;
93 changes: 58 additions & 35 deletions clean-room-demo/webapp/frontend/pages/document.tsx
Original file line number Diff line number Diff line change
@@ -1,60 +1,83 @@
import { AddIcon, ItemIcon, ListIcon } from "@/components/document/Icon";
import ListView from "@/components/document/ListView";
import IconView from "@/components/document/IconView";
import ScreenChecker from "@/components/ScreenChecker";
import { useState } from "react";

export default function Index() {
interface Item {
id : number;
fileName : string;
creationDate : Date;
active : boolean;
}

export default function Document() {
// SAMPLE DATA FOR LATEST DOCUMENTS
const latestItems = [
{id : 1, fileName : 'First.doc', creationDate : new Date(), active : false, },
{id : 2, fileName : 'Second.xls', creationDate : new Date(), active : false}
]

// SAMPLE DATA FOR DOCUMENTS
const items = [
{id : 1, fileName : 'First.doc'},
{id : 2, fileName : 'Second.xls'},
{id : 3, fileName : 'Third.png'},
{id : 4, fileName : 'Fourth.pdf'},
{id : 5, fileName : 'Fifth.pdf'},
{id : 6, fileName : 'Sixth.pdf'},
{id : 7, fileName : 'Seventh.pptx'},
{id : 8, fileName : 'Eigth.doc'},
{id : 9, fileName : 'Ninth.xlsm'},
{id : 10, fileName : 'Tenth.jpeg'},
{id : 11, fileName : 'Eleventh.doc'},
{id : 12, fileName : 'Twelfth.docx'},
{id : 13, fileName : 'Thirteenth.pdf'},
{id : 14, fileName : 'Fourteenth.png'},
{id : 15, fileName : 'Fifthteenth.doc'},
{id : 16, fileName : 'Sixteenth.pdf'},
{id : 17, fileName : 'Seventeenth.pdf'},
{id : 18, fileName : 'Eigteenth.pptx'},
{id : 19, fileName : 'Nineteenth.png'},
{id : 20, fileName : 'Twentieth.xlm'},
{id : 1, fileName : 'First.doc', creationDate : new Date(), active : false},
{id : 2, fileName : 'Second.xls', creationDate : new Date(), active : false},
{id : 3, fileName : 'Third.png', creationDate : new Date(), active : true},
{id : 4, fileName : 'Fourth.pdf', creationDate : new Date(), active : false},
{id : 5, fileName : 'Fifth.pdf', creationDate : new Date(), active : false},
{id : 6, fileName : 'Sixth.pdf', creationDate : new Date(), active : false},
{id : 7, fileName : 'Seventh.pptx', creationDate : new Date(), active : true},
{id : 8, fileName : 'Eigth.doc', creationDate : new Date(), active : false},
{id : 9, fileName : 'Ninth.xlsm', creationDate : new Date(), active : false},
{id : 10, fileName : 'Tenth.jpeg', creationDate : new Date(), active : false},
{id : 11, fileName : 'Eleventh.doc', creationDate : new Date(), active : false},
{id : 12, fileName : 'Twelfth.docx', creationDate : new Date(), active : true},
{id : 13, fileName : 'Thirteenth.pdf', creationDate : new Date(), active : false},
{id : 14, fileName : 'Fourteenth.png', creationDate : new Date(), active : false},
{id : 15, fileName : 'Fifthteenth.doc', creationDate : new Date(), active : false},
{id : 16, fileName : 'Sixteenth.pdf', creationDate : new Date(), active : true},
{id : 17, fileName : 'Seventeenth.pdf', creationDate : new Date(), active : false},
{id : 18, fileName : 'Eigteenth.pptx', creationDate : new Date(), active : false},
{id : 19, fileName : 'Nineteenth.png', creationDate : new Date(), active : false},
{id : 20, fileName : 'Twentieth.xlm', creationDate : new Date(), active : true}
];

const [selectedId, setSelectedId] = useState(0);
const [selectedId, setSelectedId] = useState<number>(0);
const [selectedView, setSelectedView] = useState<'Icon' | 'List'>('Icon');

const handleSelect = (id : number) => {
setSelectedId(id);
}

const selectView = (view) => {
setSelectedView(view);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you using an off the shelf PDF viewer or creating one that can support other office document types?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of now we are still looking for the package for pdf viewer and other types of documents. Do you have any suggestion package that we can use?

Issue #81 Document viewer page - @dennisdelamida

}

const View = ({viewType, items, selectedId, handleSelect} : {viewType : 'Icon' | 'List', items : Item[], selectedId? : number, handleSelect? : any}) => {
switch (viewType) {
case 'Icon':
return <IconView items={items} selectedId={selectedId} handleSelect={handleSelect}/>
case 'List':
return <ListView items={items} selectedId={selectedId} handleSelect={handleSelect}/>
}
}

return (<>
<ScreenChecker />
<div className="p-10">{/* <<<<--- PARENT */}
<div className="p-10">{/* <<<<--- PARENT CONTAINER */}
<div className="relative w-full">
<div className="flex justify-end space-x-1 absolute right-0">
<ListIcon />
<ItemIcon />
<div onClick={() => selectView('List')}><ListIcon fill="#0759a7" color={selectedView == 'List' ? 'white' : '#0759a7'} fillOpacity={selectedView == 'List' ? '1' : '0.1'} /></div>
<div onClick={() => selectView('Icon')}><ItemIcon fill="#0759a7" color={selectedView == 'Icon' ? 'white' : '#0759a7'} fillOpacity={selectedView == 'Icon' ? '1' : '0.1'} /></div>
</div>
<div>
<span className="text-2xl text-blue-800">Latest</span>
<span className="relative text-2xl text-blue-800">Latest</span>
<div className="mt-5">
{/* ITEM */}
{/* <IconView items={items} selectedId={6} /> */}
{/* LIST */}
<View viewType={selectedView} items={latestItems} />
</div>
</div>
<div className="mt-10">
<div className="flex space-x-5"><span className="text-2xl text-blue-800">Documents</span><AddIcon /></div>
<div className="flex space-x-5"><span className="text-2xl text-blue-800">Documents</span><AddIcon color="#0759A7" fill="#0759a7" fillOpacity="0.1"/></div>
<div className="mt-5">
{/* ITEM */}
<IconView items={items} selectedId={selectedId} handleSelect={handleSelect} />
{/* LIST */}
<View viewType={selectedView} items={items} selectedId={selectedId} handleSelect={handleSelect}/>
</div>
</div>
</div>
Expand Down