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

feat: progress bar in my sites #1189

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
65 changes: 50 additions & 15 deletions app/src/gui/components/notebook/record_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Check warning on line 57 in app/src/gui/components/notebook/record_table.tsx

View workflow job for this annotation

GitHub Actions / Build and Test

'getUiSpecForProject' is defined but never used
import {useQuery} from '@tanstack/react-query';

Check warning on line 58 in app/src/gui/components/notebook/record_table.tsx

View workflow job for this annotation

GitHub Actions / Build and Test

'useQuery' is defined but never used
import {useGetUISpec} from '../../../lib/queries';

type RecordsTableProps = {
project_id: ProjectID;
Expand All @@ -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);
Expand Down Expand Up @@ -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>
);
},
Expand Down Expand Up @@ -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
);
Comment on lines +479 to 484
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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

setPouchData(ra);

if (!data) continue;

record.record = data;
}

setPouchData(records);
Comment on lines 463 to +491
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
Expand Down
6 changes: 3 additions & 3 deletions app/src/lib/form-utils.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {ProjectUIModel} from '@faims3/data-model/build/src/types';
import {ProjectUIFields} from '@faims3/data-model/build/src/types';

/**
* Retrieves the keys of fields that are marked as required from the given project UI model.
*
* @param {ProjectUIModel} fields - An object representing the project's UI model fields, where each field contains component parameters.
* @param {ProjectUIFields} fields - An object representing the project's UI model fields, where each field contains component parameters.
* @returns {string[]} An array of keys representing the fields that are marked as required.
*/
export const requiredFields = (fields: ProjectUIModel): string[] =>
export const requiredFields = (fields: ProjectUIFields): string[] =>
Object.entries(fields)
.filter(([, value]) => value['component-parameters'].required)
.map(([key]) => key);
Expand Down
9 changes: 9 additions & 0 deletions app/src/lib/queries.ts
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),
});
};
Loading