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

fix(asset-import): fix issue with boolean field while importing #1557

Merged
merged 3 commits into from
Jan 6, 2025
Merged
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
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
Loading