-
Notifications
You must be signed in to change notification settings - Fork 8
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
base: main
Are you sure you want to change the base?
Changes from 2 commits
f340f73
bb693f3
b35bf80
1b8bb5c
354f0f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ | |
import { | ||
ProjectID, | ||
ProjectUIViewsets, | ||
Record, | ||
RecordMetadata, | ||
getFullRecordData, | ||
getMetadataForAllRecords, | ||
|
@@ -53,8 +54,9 @@ | |
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; | ||
|
@@ -77,10 +79,7 @@ | |
function RecordsTable(props: RecordsTableProps) { | ||
const {project_id, maxRows, rows, loading} = props; | ||
|
||
const {data: uiSpec} = useQuery({ | ||
queryKey: ['uiSpec', project_id], | ||
queryFn: () => getUiSpecForProject(project_id), | ||
}); | ||
const {data: uiSpec} = useGetUISpec(project_id); | ||
|
||
// default for mobileView is on (collapsed table) | ||
const [mobileViewSwitchValue, setMobileViewSwitchValue] = | ||
|
@@ -253,14 +252,6 @@ | |
minWidth: 150, | ||
filterable: true, | ||
renderCell: (params: GridCellParams) => { | ||
const {project_id, record_id, revision_id} = params.row; | ||
|
||
const {data: record} = useQuery({ | ||
queryKey: ['recordData', project_id, record_id, revision_id], | ||
queryFn: () => | ||
getFullRecordData(project_id, record_id, revision_id), | ||
}); | ||
|
||
return ( | ||
<Box sx={{width: '100%', my: 1}}> | ||
<Grid | ||
|
@@ -312,10 +303,10 @@ | |
)} | ||
<ProgressBar | ||
percentage={ | ||
uiSpec && record | ||
uiSpec && params.row.record | ||
? percentComplete( | ||
requiredFields(uiSpec.fields), | ||
record.data | ||
params.row.record.data | ||
) | ||
: 0 | ||
} | ||
|
@@ -448,29 +439,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); | ||
|
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. cool - I think there is a space for hooks already though |
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), | ||
}); | ||
}; |
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