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

Display a count of 0 when the prep count has not been defined instead of NaN #4006

Merged
merged 6 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ export function PrepDialogRow({
readonly selected: number;
readonly onChange: (newSelected: number) => void;
}): JSX.Element {
const unavailableCount = preparation.countAmount - preparation.available;
const unavailableCount = Number.isNaN(preparation.available)
? 0
: preparation.countAmount - preparation.available;

const available = Math.max(0, preparation.available);
const checked = selected !== 0;
Expand Down Expand Up @@ -99,7 +101,9 @@ export function PrepDialogRow({
onValueChange={handleChange}
/>
</td>
<td className="justify-end tabular-nums">{preparation.available}</td>
<td className="justify-end tabular-nums">
{Number.isNaN(preparation.available) ? 0 : preparation.available}
</td>
<td className="justify-end tabular-nums">
{
/* If unavailable items, link to related interactions */
Expand All @@ -125,7 +129,6 @@ export function PrepDialogRow({
);
const count =
loans.length + gifts.length + exchangeOuts.length;

setState(
count === 1
? {
Expand Down
14 changes: 11 additions & 3 deletions specifyweb/frontend/js_src/lib/components/QueryBuilder/Results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ import { commonText } from '../../localization/common';
import { interactionsText } from '../../localization/interactions';
import { queryText } from '../../localization/query';
import { f } from '../../utils/functools';
import { filterArray, type GetOrSet, type GetSet, type IR, type R, type RA } from '../../utils/types';
import {
type GetOrSet,
type GetSet,
type IR,
type R,
type RA,
filterArray,
} from '../../utils/types';
import { removeKey } from '../../utils/utils';
import { Container, H3 } from '../Atoms';
import { Button } from '../Atoms/Button';
Expand Down Expand Up @@ -202,7 +209,7 @@ export function QueryResults(props: Props): JSX.Element {
Array.isArray(results) &&
Array.isArray(loadedResults) &&
results.length > 0 &&
typeof fetchResults === 'function'? (
typeof fetchResults === 'function' ? (
<>
{hasPermission('/record/replace', 'update') &&
hasTablePermission(model.name, 'update') && (
Expand Down Expand Up @@ -393,7 +400,8 @@ export function useFetchQueryResults({
const resultsRef = React.useRef(results);
const handleSetResults = React.useCallback(
(results: RA<QueryResultRow | undefined> | undefined) => {
const filteredResults = results !== undefined ? filterArray(results) : undefined
const filteredResults =
results === undefined ? undefined : filterArray(results);
setResults(filteredResults);
resultsRef.current = results;
},
Expand Down
2 changes: 1 addition & 1 deletion specifyweb/frontend/js_src/lib/localization/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1819,7 +1819,7 @@ export const preferencesText = createDictionary({
},
detailedView: {
'en-us': 'Detailed view',
},
},
attachmentPreviewMode: {
'en-us': 'Attachment preview mode',
'de-ch': 'Anhang-Vorschaumodus',
Expand Down