-
Notifications
You must be signed in to change notification settings - Fork 73
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
Events v2: Implement optimistic file upload and FILE type input #8246
Merged
Merged
Changes from 9 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
edbe07a
implement optimistic file upload and FILE type input
rikukissa 8593948
Merge branch 'develop' of github.com:opencrvs/opencrvs-core into even…
rikukissa 6df0b40
fix broken offline record creation
rikukissa 03d7be3
fix one type error
rikukissa 1ea0f11
fix: update tests, add missing license header
makelicious 7b0d269
fix: explicitly throw if cache not found
makelicious 45a9879
fix type errors
rikukissa 61c7c75
fix eslint errors
rikukissa 45dab8e
fix review page
rikukissa 78f2056
add signing for files fetched from events service
rikukissa 3ed265f
Merge branch 'develop' of github.com:opencrvs/opencrvs-core into even…
rikukissa 1561e2e
cleanup
rikukissa 981a6f0
cleanup
rikukissa 434293b
use undefined instead of null in FileInput as the default value of se…
rikukissa 157cc71
remove default empty string value
rikukissa f850846
remove fallback output
rikukissa afc741a
fix linter error
rikukissa f935e7d
fix: clean up types and lint issues
makelicious 67bd36c
fix review page exception
rikukissa 5aee2e4
fix: add missing flush
makelicious 23b8027
fix: update test mock name
makelicious 3223186
Merge branch 'develop' into events-v2-file-input
makelicious 125c78d
move debugger to top level of events v2
rikukissa f1f3527
Merge branch 'events-v2-file-input' of github.com:opencrvs/opencrvs-c…
rikukissa a6ad8f0
fix: add mock for files service call
makelicious a58902d
chore: add msw, mock documents api call
makelicious 425bcef
fix: add missing license header
makelicious dfea202
refactor react query logic a bit
rikukissa 3f2adc8
Merge branch 'events-v2-file-input' of github.com:opencrvs/opencrvs-c…
rikukissa 048c7a6
fix: remove unused export
makelicious 02550e7
fix: change cache invalidation order
makelicious c74bd85
Merge branch 'develop' into events-v2-file-input
makelicious 9a46b31
fix: add flushPromises
makelicious 095b2a1
fix: add flushPromises to top-level
makelicious 6d5a048
Merge branch 'develop' of github.com:opencrvs/opencrvs-core into even…
rikukissa 3958a5c
fix merge
rikukissa 65abcd5
add types back
rikukissa 6a54760
improve knip diff output
rikukissa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
96 changes: 96 additions & 0 deletions
96
packages/client/src/v2-events/components/forms/inputs/FileInput/DocumentListPreview.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
* | ||
* OpenCRVS is also distributed under the terms of the Civil Registration | ||
* & Healthcare Disclaimer located at http://opencrvs.org/license. | ||
* | ||
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS. | ||
*/ | ||
import * as React from 'react' | ||
import styled from 'styled-components' | ||
import { FieldValue, FileFieldValue } from '@opencrvs/commons/client' | ||
import { Button } from '@opencrvs/components/lib/Button/Button' | ||
import { Icon } from '@opencrvs/components/lib/Icon/Icon' | ||
import { Link } from '@opencrvs/components/lib/Link/Link' | ||
import { ISelectOption } from '@opencrvs/components/lib/Select' | ||
|
||
const Wrapper = styled.div` | ||
max-width: 100%; | ||
& > *:last-child { | ||
margin-bottom: 8px; | ||
border-bottom: 1.5px solid ${({ theme }) => theme.colors.grey100}; | ||
} | ||
` | ||
const Container = styled.div` | ||
width: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
gap: 4px; | ||
border-top: 1.5px solid ${({ theme }) => theme.colors.grey100}; | ||
height: 48px; | ||
padding: 0px 10px; | ||
` | ||
|
||
const Label = styled.div` | ||
display: flex; | ||
align-items: center; | ||
justify-content: flex-start; | ||
gap: 8px; | ||
text-overflow: ellipsis; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
svg { | ||
flex-shrink: 0; | ||
} | ||
` | ||
|
||
interface Props { | ||
id?: string | ||
attachment?: FileFieldValue | ||
label?: string | ||
onSelect: (document: FieldValue | FileFieldValue) => void | ||
dropdownOptions?: ISelectOption[] | ||
onDelete?: (image: FieldValue | FileFieldValue) => void | ||
} | ||
|
||
export function DocumentListPreview({ | ||
id, | ||
attachment, | ||
label, | ||
onSelect, | ||
dropdownOptions, | ||
onDelete | ||
}: Props) { | ||
function getFormattedLabelForDocType(docType: string) { | ||
const matchingOptionForDocType = | ||
dropdownOptions && | ||
dropdownOptions.find((option) => option.value === docType) | ||
return matchingOptionForDocType && matchingOptionForDocType.label | ||
} | ||
return ( | ||
<Wrapper id={`preview-list-${id}`}> | ||
{attachment && label && ( | ||
<Container> | ||
<Label> | ||
<Icon color="grey600" name="Paperclip" size="medium" /> | ||
<Link onClick={(_) => onSelect(attachment)}> | ||
<span>{getFormattedLabelForDocType(label) || label}</span> | ||
</Link> | ||
</Label> | ||
<Button | ||
aria-label="Delete attachment" | ||
id="preview_delete" | ||
size="small" | ||
type="icon" | ||
onClick={() => onDelete && onDelete(attachment)} | ||
> | ||
<Icon color="red" name="Trash" size="small" /> | ||
</Button> | ||
</Container> | ||
)} | ||
</Wrapper> | ||
) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's document this very carefully why we do this, it's so annoying :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup :D