Skip to content

Commit

Permalink
Merge pull request #1557 from rockingrohit9639/fix/boolean-imports
Browse files Browse the repository at this point in the history
fix(asset-import): fix issue with boolean field while importing
  • Loading branch information
DonKoko authored Jan 6, 2025
2 parents c5c0459 + 4e2267e commit f3e1790
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/components/assets/custom-fields-inputs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default function AssetCustomFields({
name={`cf-${field.id}`}
disabled={disabled}
defaultChecked={
getCustomFieldVal(field.id) === "true" || field.required
getCustomFieldVal(field.id) === "Yes" || field.required
}
/>
<label className="font-medium text-gray-700 lg:hidden">
Expand Down
4 changes: 2 additions & 2 deletions app/utils/csv.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const parseCsv = (csvData: ArrayBuffer) => {
const csv = iconv.decode(Buffer.from(csvData), encoding || "utf-8");
const delimiter = guessDelimiters(csv, [",", ";"]);

return new Promise((resolve, reject) => {
return new Promise<CSVData>((resolve, reject) => {
const parser = parse({
encoding: "utf-8", // Set encoding to utf-8
delimiter, // Set delimiter
Expand Down Expand Up @@ -95,7 +95,7 @@ export const csvDataFromRequest = async ({ request }: { request: Request }) => {

const csvData = await csvFile.arrayBuffer();

return (await parseCsv(csvData)) as CSVData;
return await parseCsv(csvData);
} catch (cause) {
throw new ShelfError({
cause,
Expand Down
7 changes: 5 additions & 2 deletions app/utils/custom-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,11 @@ export const buildCustomFieldValue = (
}

switch (def.type) {
case "BOOLEAN":
return { raw, valueBoolean: Boolean(raw) };
case "BOOLEAN": {
const finalValue =
typeof raw === "string" ? raw === "yes" : Boolean(raw);
return { raw, valueBoolean: finalValue };
}
case "DATE": {
// Store raw date as entered by user
// But format valueDate as ISO string with UTC midnight to satisfy DB constraint
Expand Down

0 comments on commit f3e1790

Please sign in to comment.