Skip to content

Commit

Permalink
fixes #190 - fixed some issues with whitespace treatment
Browse files Browse the repository at this point in the history
  • Loading branch information
replaysMike committed May 4, 2023
1 parent db55c5d commit 729b307
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ export function PartMediaMemoized({ infoResponse, datasheet, part, loadingPartMe

PartMediaMemoized.propTypes = {
/** part metadata info */
infoResponse: PropTypes.object.isRequired,
infoResponse: PropTypes.object,
part: PropTypes.object,
datasheet: PropTypes.object,
loadingPartMetadata: PropTypes.bool.isRequired
Expand Down
14 changes: 14 additions & 0 deletions Binner/Binner.Web/ClientApp/src/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -840,4 +840,18 @@ div:has(.popup),div:has(.Toastify>*) {

.error.small {
font-size: 0.9em;
}

.suggested-part {
font-size: 0.8em;
height: 19px;
}

.suggested-part span {
font-style: italic;
}

.suggested-part button {
font-weight: 500;
font-style: normal;
}
6 changes: 3 additions & 3 deletions Binner/Binner.Web/ClientApp/src/pages/Datasheets.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function Datasheets (props) {
Datasheets.abortController = new AbortController();
setLoading(true);
try {
const response = await fetchApi(`api/part/info?partNumber=${part.partNumber}&partType=${part.partType}&mountingType=${part.mountingType}`, {
const response = await fetchApi(`api/part/info?partNumber=${part.partNumber.trim()}&partType=${part.partType}&mountingType=${part.mountingType}`, {
signal: Datasheets.abortController.signal
});
const responseData = response.data;
Expand Down Expand Up @@ -108,14 +108,14 @@ export function Datasheets (props) {
const handlePartTypeChange = (e, partType) => {
const newPart = {...part, partTypeId: partType.partTypeId, partType: partType.name };
setPart(newPart);
if (newPart.partNumber.length > 0)
if (newPart.partNumber.trim().length > 0)
searchDebounced(newPart);
}

const handleChange = (e, control) => {
part[control.name] = control.value;
const newPart = {...part};
if (newPart.partNumber.length > 0)
if (newPart.partNumber.trim().length > 0)
searchDebounced(newPart);
setPart(newPart);
};
Expand Down
14 changes: 0 additions & 14 deletions Binner/Binner.Web/ClientApp/src/pages/Inventory.css
Original file line number Diff line number Diff line change
Expand Up @@ -179,20 +179,6 @@
margin: 0.3em 0 1em 0;
}

.inventory .suggested-part {
font-size: 0.8em;
height: 19px;
}

.inventory .suggested-part span {
font-style: italic;
}

.inventory .suggested-part button {
font-weight: 500;
font-style: normal;
}

.inventory .ui.dropdown .menu>.item {
display: flex;
flex-direction: column-reverse;
Expand Down
41 changes: 24 additions & 17 deletions Binner/Binner.Web/ClientApp/src/pages/Inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function Inventory(props) {
rememberLast: true
};
const [viewPreferences, setViewPreferences] = useState(defaultViewPreferences);
const pageHasParameters = (props.params && props.params.partNumber !== undefined && props.params.partNumber.length > 0);
const pageHasParameters = props.params?.partNumber?.length > 0;
const defaultPart = {
partId: 0,
partNumber: props.params.partNumber || "",
Expand Down Expand Up @@ -126,15 +126,17 @@ export function Inventory(props) {

useEffect(() => {
const partNumberStr = props.params.partNumber;
setIsEditing((props.params && props.params.partNumber !== undefined && props.params.partNumber.length > 0));
const newIsEditing = partNumberStr?.length > 0;
setIsEditing(newIsEditing);
const fetchData = async () => {
setPartMetadataIsSubscribed(false);
setPartMetadataError(null);
await fetchPartTypes();
await fetchRecentRows();
if (partNumberStr) {
var loadedPart = await fetchPart(partNumberStr);
if (isEditing) setInputPartNumber(partNumberStr);
if (newIsEditing) setInputPartNumber(partNumberStr);
setInputPartNumber(partNumberStr);
await fetchPartMetadataAndInventory(partNumberStr, loadedPart || part);
} else if (props.params.partNumberToAdd) {
const { data } = await doFetchPartMetadata(props.params.partNumberToAdd, loadedPart || part, false);
Expand All @@ -150,15 +152,16 @@ export function Inventory(props) {
};
}, [props.params.partNumber]);

useEffect(() => {
if (!props.params.partNumberToAdd)
/*useEffect(() => {
if (!props.params.partNumberToAdd) {
resetForm();
}, [props.params.partNumberToAdd]);
}
}, [props.params.partNumberToAdd]);*/

const fetchPartMetadataAndInventory = async (input, localPart) => {
if (partTypesRef.current.length === 0)
console.error("There are no partTypes! This shouldn't happen and is a bug.");
if (input.length < MinSearchKeywordLength)
if (input.trim().length < MinSearchKeywordLength)
return;
Inventory.infoAbortController.abort();
Inventory.infoAbortController = new AbortController();
Expand Down Expand Up @@ -226,7 +229,7 @@ export function Inventory(props) {
Inventory.infoAbortController.abort();
Inventory.infoAbortController = new AbortController();
try {
const response = await fetchApi(`api/part/info?partNumber=${partNumber}&supplierPartNumbers=digikey:${part.digiKeyPartNumber || ""},mouser:${part.mouserPartNumber || ""},arrow:${part.arrowPartNumber}`, {
const response = await fetchApi(`api/part/info?partNumber=${partNumber.trim()}&supplierPartNumbers=digikey:${part.digiKeyPartNumber || ""},mouser:${part.mouserPartNumber || ""},arrow:${part.arrowPartNumber}`, {
signal: Inventory.infoAbortController.signal
});

Expand Down Expand Up @@ -265,7 +268,7 @@ export function Inventory(props) {
const doInventoryPartSearch = async (partNumber) => {
if (partNumber.length < MinSearchKeywordLength)
return { exists: false, data: null, error: `Ignoring search as keywords are less than the minimum required (${MinSearchKeywordLength}).` };
const existsResponse = await fetchApi(`api/part/search?keywords=${partNumber}&exactMatch=true`, {
const existsResponse = await fetchApi(`api/part/search?keywords=${partNumber.trim()}&exactMatch=true`, {
signal: Inventory.infoAbortController.signal,
catchErrors: true
});
Expand Down Expand Up @@ -393,7 +396,7 @@ export function Inventory(props) {
Inventory.partAbortController = new AbortController();
setLoadingPartMetadata(true);
try {
const response = await fetchApi(`api/part?partNumber=${partNumber}`, {
const response = await fetchApi(`api/part?partNumber=${partNumber.trim()}`, {
signal: Inventory.partAbortController.signal
});
const { data } = response;
Expand Down Expand Up @@ -495,14 +498,19 @@ export function Inventory(props) {
const isExisting = part.partId > 0;

const request = { ...part };
request.partNumber = inputPartNumber;
request.partNumber = inputPartNumber.trim();
request.partTypeId = (parseInt(part.partTypeId) || 0) + "";
request.mountingTypeId = (parseInt(part.mountingTypeId) || 0) + "";
request.quantity = parseInt(part.quantity) || 0;
request.lowStockThreshold = parseInt(part.lowStockThreshold) || 0;
request.cost = parseFloat(part.cost) || 0.0;
request.projectId = parseInt(part.projectId) || null;

if (request.partNumber.length === 0) {
toast.error("Part Number is empty!");
return;
}

const saveMethod = isExisting ? "PUT" : "POST";
const response = await fetchApi("api/part", {
method: saveMethod,
Expand Down Expand Up @@ -698,7 +706,7 @@ export function Inventory(props) {
const printLabel = async (e) => {
e.preventDefault();
e.stopPropagation();
await fetchApi(`api/part/print?partNumber=${part.partNumber}&generateImageOnly=false`, { method: "POST" });
await fetchApi(`api/part/print?partNumber=${part.partNumber.trim()}&generateImageOnly=false`, { method: "POST" });
};

const setPartFromMetadata = (metadataParts, suggestedPart) => {
Expand Down Expand Up @@ -933,6 +941,9 @@ export function Inventory(props) {
};

/* RENDER */
const title = isEditing
? t('page.inventory.edittitle', "Edit Inventory")
: t('page.inventory.addtitle', "Add Inventory");

/*<MatchingPartsMemoized part={part} metadataParts={metadataParts} partTypes={partTypes} setPartFromMetadata={setPartFromMetadata} />*/
const renderForm = useMemo(() => {
Expand Down Expand Up @@ -1353,11 +1364,7 @@ export function Inventory(props) {


</>);
}, [inputPartNumber, part, viewPreferences.rememberLast, loadingPartMetadata, partMetadataError, disableRendering.current]);

const title = isEditing
? t('page.inventory.edittitle', "Edit Inventory")
: t('page.inventory.addtitle', "Add Inventory");
}, [inputPartNumber, part, viewPreferences.rememberLast, loadingPartMetadata, partMetadataError, disableRendering.current, isEditing, allPartTypes]);

return (
<div className="inventory mask">
Expand Down
4 changes: 4 additions & 0 deletions Binner/Binner.Web/ClientApp/src/pages/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ export function Search(props) {
else
newData = [...parts, ...pageOfData];
}
if (newData.length > 0)
setShowPartNotFound(false);
else
setShowPartNotFound(true);
setParts(newData);
setPage(page);
setTotalPages(totalPages);
Expand Down

0 comments on commit 729b307

Please sign in to comment.