Skip to content

Commit

Permalink
Fixes a UI issue with Producing PCB's, sometimes the UI data wasn't g…
Browse files Browse the repository at this point in the history
…etting updated properly and it showed PCB could not be produced even though it had enough parts.

Also fixes an issue with migrating old data where there are duplicate partType entries which fails the upgrade process.
Thanks to @interbiznw for reporting both of these!
  • Loading branch information
replaysMike committed May 4, 2023
1 parent 0e497da commit ebaea33
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,8 @@
"addedPart": "Added part {{partNumber}}!",
"failedSavePart": "Failed to update, check Part Type and Mounting Type",
"noPartMetadata": "No part metadata found!",
"scanPartExists": "Part exists in inventory. You can edit it's details or remove it from your scan."
"scanPartExists": "Part exists in inventory. You can edit it's details or remove it from your scan.",
"noOutOfStockParts": "No out of stock parts."
},
"confirm": {
"deleteProject": "Are you sure you want to delete this project and your entire BOM?",
Expand Down
18 changes: 9 additions & 9 deletions Binner/Binner.Web/ClientApp/src/components/ProducePcbModal.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState, useEffect, useCallback } from "react";
import { useTranslation, Trans } from 'react-i18next';
import { useTranslation } from 'react-i18next';
import { Button, Form, Modal, Image, Header, Popup, Input, Table, Icon } from "semantic-ui-react";
import PropTypes from "prop-types";
import NumberPicker from "./NumberPicker";
Expand All @@ -15,7 +15,7 @@ export function ProducePcbModal(props) {
const [project, setProject] = useState({ parts:[], pcbs: []});
const [pcbOptions, setPcbOptions] = useState([]);

const canProducePcb = (pcb) => {
const canProducePcb = (project, pcb = null) => {
const formQuantity = parseInt(form.quantity) || 1;
if (pcb && pcb.pcbId > 0) {
const pcbParts = _.filter(project.parts, p => p.pcbId === pcb.pcbId);
Expand All @@ -30,12 +30,12 @@ export function ProducePcbModal(props) {
const createPcbOptions = (project) => {
const options = [
{ key: -1, text: t('comp.producePcbModal.options.all', "All"), description: t('comp.producePcbModal.options.allDescription', "Produce the entire BOM"), value: -1 },
{ key: 0, text: t('comp.producePcbModal.options.unassociated', "Unassociated"), description: t('comp.producePcbModal.options.unassociatedDescription', "Produce parts not associated to a PCB"), value: 0, icon: !canProducePcb() && "warning circle", disabled: getProducibleUnassociatedCount(project.parts) === 0 },
{ key: 0, text: t('comp.producePcbModal.options.unassociated', "Unassociated"), description: t('comp.producePcbModal.options.unassociatedDescription', "Produce parts not associated to a PCB"), value: 0, icon: !canProducePcb(project) && "warning circle", disabled: getProducibleUnassociatedCount(project.parts) === 0 },
];

if (project && project.pcbs && project.pcbs.length > 0) {
for(let i = 0; i < project.pcbs.length; i++) {
options.push({ key: i + 1, text: project.pcbs[i].name, description: project.pcbs[i].description, value: project.pcbs[i].pcbId, icon: !canProducePcb(project.pcbs[i]) && "warning circle", disabled: !canProducePcb(project.pcbs[i])});
options.push({ key: i + 1, text: project.pcbs[i].name, description: project.pcbs[i].description, value: project.pcbs[i].pcbId, icon: !canProducePcb(project, project.pcbs[i]) && "warning circle", disabled: !canProducePcb(project, project.pcbs[i])});
}
}
return options;
Expand Down Expand Up @@ -108,14 +108,14 @@ export function ProducePcbModal(props) {
// ensure we don't pass any pcb's to produce that don't have enough parts
const validPcbsToProcess = [];
for(let i = 0; i < pcbsToProcess.length; i++){
if (canProducePcb(pcbsToProcess[i])){
if (canProducePcb(project, pcbsToProcess[i])){
validPcbsToProcess.push(pcbsToProcess[i]);
}
}

// only process unassociated if parts are available
let processUnassociated = false;
if ((form.pcbs.includes(0) || form.pcbs.includes(-1)) && canProducePcb())
if ((form.pcbs.includes(0) || form.pcbs.includes(-1)) && canProducePcb(project))
processUnassociated = true;

props.onSubmit(e, { ...form,
Expand Down Expand Up @@ -200,23 +200,23 @@ export function ProducePcbModal(props) {
</Table.Header>
<Table.Body>
{getPcbsToDisplay(project).map((p, key) => (
<Table.Row key={key} className={!canProducePcb(p) ? "disabled" : ""}>
<Table.Row key={key} className={!canProducePcb(project, p) ? "disabled" : ""}>
<Table.Cell>{p.name}</Table.Cell>
<Table.Cell>
{p.pcbId && <Form.Field>
<Popup
wide
content={t('comp.producePcbModal.popup.serialNumber', "The next PCB will have it's serial number started at this value.")}
trigger={
<Input disabled={!canProducePcb(p)} style={{display: 'inline-block', width: '200px'}} placeholder="SN00000000" name="serialNumber" value={p.serialNumber || ''} id={p.pcbId} onChange={handleSerialNumberChange} />
<Input disabled={!canProducePcb(project, p)} style={{display: 'inline-block', width: '200px'}} placeholder="SN00000000" name="serialNumber" value={p.serialNumber || ''} id={p.pcbId} onChange={handleSerialNumberChange} />
}
/>
</Form.Field>}
</Table.Cell>
<Table.Cell textAlign="center">{p.pcbId > 0 ? getProduciblePcbCount(project.parts, p).count : getProducibleUnassociatedCount(project.parts)}</Table.Cell>
<Table.Cell textAlign="center">{p.pcbId > 0 ? _.filter(project.parts, x => x.pcbId === p.pcbId).length : _.filter(project.parts, x => x.pcbId === null).length}</Table.Cell>
<Table.Cell textAlign="center">{getTotalPartsOutOfStock(p.pcbId && p.pcbId > 0 ? p : null)}</Table.Cell>
<Table.Cell>{!canProducePcb(p) && <span><Icon name="warning circle" color="red" /> {t('message.notEnoughParts', "Not enough parts")}</span>}</Table.Cell>
<Table.Cell>{!canProducePcb(project, p) && (p.pcbId > 0 ? _.filter(project.parts, x => x.pcbId === p.pcbId).length : _.filter(project.parts, x => x.pcbId === null).length > 0) && <span><Icon name="warning circle" color="red" /> {t('message.notEnoughParts', "Not enough parts")}</span>}</Table.Cell>
</Table.Row>
))}
</Table.Body>
Expand Down
16 changes: 10 additions & 6 deletions Binner/Binner.Web/ClientApp/src/pages/Bom.js
Original file line number Diff line number Diff line change
Expand Up @@ -895,12 +895,16 @@ export function Bom(props) {
) : (
<Table.Row>
<Table.Cell colSpan={12} textAlign="center" style={{ padding: "30px" }}>
{t("message.noPartsAdded", "No parts added.")}
<br />
<br />
<Link to="" onClick={handleOpenAddPart}>
{t("button.addFirstPart", "Add your first part!")}
</Link>
{filterInStock ? t("message.noOutOfStockParts", "No out of stock parts.") :
<>
{t("message.noPartsAdded", "No parts added.")}
<br />
<br />
<Link to="" onClick={handleOpenAddPart}>
{t("button.addFirstPart", "Add your first part!")}
</Link>
</>
}
</Table.Cell>
</Table.Row>
)}
Expand Down
16 changes: 10 additions & 6 deletions Binner/Library/Binner.Common/StorageProviders/MigrationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,15 +450,19 @@ private bool ImportBinnerDb(Binner.Model.Common.IBinnerDb binnerDb, BinnerContex
IsAdmin = true
});

foreach (var e in db.PartTypes)
var partTypes = db.PartTypes.GroupBy(x => x.PartTypeId);
foreach (var e in partTypes)
{
var firstInGroup = e.FirstOrDefault();
if (e.Count() > 1)
_logger.Warn($"Found a duplicate part type record '{firstInGroup.PartTypeId}'! Filtering out");
context.PartTypes.Add(new Data.Model.PartType
{
PartTypeId = e.PartTypeId,
ParentPartTypeId = e.ParentPartTypeId,
Name = e.Name,
DateCreatedUtc = e.DateCreatedUtc,
DateModifiedUtc = e.DateCreatedUtc,
PartTypeId = firstInGroup.PartTypeId,
ParentPartTypeId = firstInGroup.ParentPartTypeId,
Name = firstInGroup.Name,
DateCreatedUtc = firstInGroup.DateCreatedUtc,
DateModifiedUtc = firstInGroup.DateCreatedUtc,
UserId = userId
});
}
Expand Down

0 comments on commit ebaea33

Please sign in to comment.