Skip to content

Commit

Permalink
Merge pull request #1342 from Shelf-nu/fix-issue-with-saving-boolean-…
Browse files Browse the repository at this point in the history
…custom-field-value

fix: bug causing AssetCustomFieldValue to be removed for BOOLEAN fields that are set to false
  • Loading branch information
DonKoko authored Oct 7, 2024
2 parents d408bce + dd990e5 commit b21dbab
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/routes/_layout+/assets.$assetId.overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ export async function loader({ context, request, params }: LoaderFunctionArgs) {

asset.bookings = [currentBooking];
}

/** We only need customField with same category of asset or without any category */
let customFields = asset.categoryId
? asset.customFields.filter(
Expand Down Expand Up @@ -227,6 +226,7 @@ export default function AssetOverview() {
asset && asset.customFields?.length > 0
? asset.customFields.filter((f) => f.value)
: [];

const location = asset && asset.location;
usePosition();
const fetcher = useFetcher();
Expand Down
2 changes: 1 addition & 1 deletion app/routes/_layout+/assets.$assetId_.edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export async function action({ context, request, params }: ActionFunctionArgs) {
return redirect(`/assets/new`);
}

return redirect(`/assets/${id}`);
return json(data({ success: true }));
} catch (cause) {
const reason = makeShelfError(cause, { userId, id });
return json(error(reason), { status: reason.status });
Expand Down
8 changes: 6 additions & 2 deletions app/utils/custom-fields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ export const buildCustomFieldValue = (
): ShelfAssetCustomFieldValueType["value"] | undefined => {
try {
const { raw } = value;

if (!raw) {
/** We handle boolean different because it returns false */
if (def.type !== "BOOLEAN" && !raw) {
return undefined;
}

Expand Down Expand Up @@ -188,6 +188,10 @@ export const getCustomFieldDisplayValue = (
return parseMarkdownToReact(value.raw as string);
}

if (Object.hasOwnProperty.call(value, "valueBoolean")) {
return value.valueBoolean ? "Yes" : "No";
}

if (value.valueDate && value.raw) {
return hints
? formatDateBasedOnLocaleOnly(value.valueDate as string, hints.locale)
Expand Down

0 comments on commit b21dbab

Please sign in to comment.