-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/compute-todos
- Loading branch information
Showing
5 changed files
with
109 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Table } from '@equinor/eds-core-react'; | ||
import styled from 'styled-components'; | ||
|
||
export const uploadCell = styled(Table.Cell)` | ||
alignitems: baseline; | ||
> form { | ||
> label { | ||
> input { | ||
width: 5%; | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export const filesizeCell = styled(Table.Cell)` | ||
width: 15%; | ||
`; | ||
export const deleteCell = styled(Table.Cell)` | ||
width: 10%; | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { Button, Table } from '@equinor/eds-core-react'; | ||
import { delete_to_trash as deleteIcon } from '@equinor/eds-icons'; | ||
import { ChangeEvent } from 'react'; | ||
import IconButton from '../../../components/IconButton/IconButton'; | ||
import { FileUploader } from '../FileUploader/FileUploader'; | ||
import * as Styled from './FileColumn.styled'; | ||
|
||
type FileDisplay = { isVisible: boolean; toggle: () => void }; | ||
|
||
interface FileColumnProps { | ||
onChange: (e: ChangeEvent<HTMLInputElement>) => void; | ||
onDelete: () => void; | ||
INI?: true; | ||
file?: File; | ||
fileDisplay?: FileDisplay; | ||
fileSize?: number; | ||
} | ||
export const FileColumn = ({ | ||
onChange, | ||
onDelete, | ||
INI, | ||
file, | ||
fileDisplay, | ||
fileSize, | ||
}: FileColumnProps) => { | ||
const DeleteButton = ({ onDelete }: { onDelete: () => void }) => ( | ||
<IconButton icon={deleteIcon} title="delete" onClick={onDelete} /> | ||
); | ||
|
||
function humanFileSize(bytes: number, si = true, dp = 2) { | ||
const thresh = si ? 1000 : 1024; | ||
|
||
if (Math.abs(bytes) < thresh) { | ||
return bytes + ' B'; | ||
} | ||
|
||
const units = si | ||
? ['kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'] | ||
: ['KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']; | ||
let u = -1; | ||
const r = 10 ** dp; | ||
|
||
do { | ||
bytes /= thresh; | ||
++u; | ||
} while ( | ||
Math.round(Math.abs(bytes) * r) / r >= thresh && | ||
u < units.length - 1 | ||
); | ||
|
||
return bytes.toFixed(dp) + ' ' + units[u]; | ||
} | ||
|
||
return ( | ||
<Table.Row className={`${INI ? 'ini' : 'nc'}-file`}> | ||
<Styled.uploadCell> | ||
<FileUploader | ||
onChange={onChange} | ||
file={file} | ||
acceptType={INI ? 'INI' : 'NC'} | ||
/> | ||
</Styled.uploadCell> | ||
<Table.Cell> | ||
{file && INI && ( | ||
<Button variant="outlined" onClick={fileDisplay?.toggle}> | ||
{fileDisplay?.isVisible ? 'Hide' : 'Show'} | ||
</Button> | ||
)} | ||
</Table.Cell> | ||
<Styled.filesizeCell> | ||
{fileSize ? humanFileSize(fileSize) : '-'} | ||
</Styled.filesizeCell> | ||
<Styled.deleteCell> | ||
{file && <DeleteButton onDelete={onDelete} />} | ||
</Styled.deleteCell> | ||
</Table.Row> | ||
); | ||
}; |
50 changes: 2 additions & 48 deletions
50
src/features/AddModel/ModelInputFilesTable/ModelInputFilesTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters