-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: progress bar in my sites #1189
Draft
luke-mcfarlane-rocketlab
wants to merge
5
commits into
main
Choose a base branch
from
feat/progress-bars-in-sites
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f340f73
Added progress bar to record table
luke-mcfarlane-rocketlab bb693f3
Fixed typo in JSDoc
luke-mcfarlane-rocketlab b35bf80
Some fixes to address PR comments
luke-mcfarlane-rocketlab 1b8bb5c
Linting fix
luke-mcfarlane-rocketlab 354f0f5
Merge branch 'main' into feat/progress-bars-in-sites
PeterBaker0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,14 +42,21 @@ | |
import { | ||
ProjectID, | ||
ProjectUIViewsets, | ||
Record, | ||
RecordMetadata, | ||
getFullRecordData, | ||
getMetadataForAllRecords, | ||
getRecordsWithRegex, | ||
} from '@faims3/data-model'; | ||
import {NotebookDataGridToolbar} from './datagrid_toolbar'; | ||
import RecordDelete from './delete'; | ||
import getLocalDate from '../../fields/LocalDate'; | ||
import {logError} from '../../../logging'; | ||
import ProgressBar from '../progress-bar'; | ||
import {percentComplete, requiredFields} from '../../../lib/form-utils'; | ||
import {getUiSpecForProject} from '../../../uiSpecification'; | ||
import {useQuery} from '@tanstack/react-query'; | ||
import {useGetUISpec} from '../../../lib/queries'; | ||
|
||
type RecordsTableProps = { | ||
project_id: ProjectID; | ||
|
@@ -72,6 +79,8 @@ | |
function RecordsTable(props: RecordsTableProps) { | ||
const {project_id, maxRows, rows, loading} = props; | ||
|
||
const {data: uiSpec} = useGetUISpec(project_id); | ||
|
||
// default for mobileView is on (collapsed table) | ||
const [mobileViewSwitchValue, setMobileViewSwitchValue] = | ||
React.useState(true); | ||
|
@@ -292,6 +301,16 @@ | |
{params.row.conflicts === true && ( | ||
<Alert severity={'warning'}>Record has conflicts</Alert> | ||
)} | ||
<ProgressBar | ||
percentage={ | ||
uiSpec && params.row.record | ||
? percentComplete( | ||
requiredFields(uiSpec.fields), | ||
params.row.record.data | ||
) | ||
: 0 | ||
} | ||
/> | ||
</Box> | ||
); | ||
}, | ||
|
@@ -431,29 +450,45 @@ | |
); | ||
} | ||
|
||
interface RecordMetaDataExtended extends RecordMetadata { | ||
record: Record; | ||
} | ||
|
||
export function RecordsBrowseTable(props: RecordsBrowseTableProps) { | ||
const [query, setQuery] = React.useState(''); | ||
const [pouchData, setPouchData] = React.useState( | ||
undefined as RecordMetadata[] | undefined | ||
); | ||
const [pouchData, setPouchData] = React.useState< | ||
RecordMetaDataExtended[] | undefined | ||
>(undefined); | ||
|
||
useEffect(() => { | ||
const getData = async () => { | ||
try { | ||
if (query.length === 0) { | ||
const ma = await getMetadataForAllRecords( | ||
props.project_id, | ||
props.filter_deleted | ||
); | ||
setPouchData(ma); | ||
} else { | ||
const ra = await getRecordsWithRegex( | ||
props.project_id, | ||
query, | ||
props.filter_deleted | ||
const records = ( | ||
query.length === 0 | ||
? await getMetadataForAllRecords( | ||
props.project_id, | ||
props.filter_deleted | ||
) | ||
: await getRecordsWithRegex( | ||
props.project_id, | ||
query, | ||
props.filter_deleted | ||
) | ||
) as RecordMetaDataExtended[]; | ||
|
||
for (const record of records) { | ||
const data = await getFullRecordData( | ||
record.project_id, | ||
record.record_id, | ||
record.revision_id | ||
); | ||
setPouchData(ra); | ||
|
||
if (!data) continue; | ||
|
||
record.record = data; | ||
} | ||
|
||
setPouchData(records); | ||
Comment on lines
463
to
+491
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this is probably going to conflict with my pending PR #1199 which moves this into a react query - but that's okay we can fix it up |
||
} catch (err) { | ||
logError(err); // unable to load records | ||
setPouchData(undefined); | ||
|
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,9 @@ | ||
import {useQuery} from '@tanstack/react-query'; | ||
import {getUiSpecForProject} from '../uiSpecification'; | ||
|
||
export const useGetUISpec = (project_id: string) => { | ||
return useQuery({ | ||
queryKey: ['uiSpec', project_id], | ||
queryFn: () => getUiSpecForProject(project_id), | ||
}); | ||
}; |
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.
Performance concerns here possibly - but we'll see.
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.
For the PR to display summary fields in the record table we'll be grabbing the whole record data so this would not be necessary. A few interacting changes going on here. Can this be deferred?
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.
Yes, we can defer this one