Skip to content

Commit

Permalink
Merge pull request #1418 from Shelf-nu/1341-feature-request-support-m…
Browse files Browse the repository at this point in the history
…arking-assets-as-non-bookable-via-csv-import

improvement: handle 'availableToBook' on asset import
  • Loading branch information
DonKoko authored Nov 12, 2024
2 parents f35f89e + 7476ba0 commit 535bac9
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 32 deletions.
22 changes: 12 additions & 10 deletions app/components/assets/import-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,18 @@ export const ImportContent = () => (
free to get in touch with support and we can provide those for you.
</div>

<h4 className="mt-2">Extra considerations</h4>
<ul className="list-inside list-disc">
<li>
The first row of the sheet will be ignored. Use it to describe the
columns as in the example sheet.
</li>
<li>
If any of the data in the file is invalid, the whole import will fail
</li>
</ul>
<div>
<h4 className="mt-2">Extra considerations</h4>
<ul className="list-inside list-disc pl-4">
<li>
The first row of the sheet will be ignored. Use it to describe the
columns as in the example sheet.
</li>
<li>
If any of the data in the file is invalid, the whole import will fail
</li>
</ul>
</div>
<FileForm intent={"content"} />
</>
);
Expand Down
4 changes: 4 additions & 0 deletions app/modules/asset/service.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ export async function createAsset({
customFieldsValues,
organizationId,
valuation,
availableToBook = true,
}: Pick<
Asset,
"description" | "title" | "categoryId" | "userId" | "valuation"
Expand All @@ -829,6 +830,7 @@ export async function createAsset({
custodian?: TeamMember["id"];
customFieldsValues?: ShelfAssetCustomFieldValueType[];
organizationId: Organization["id"];
availableToBook?: Asset["availableToBook"];
}) {
try {
/** User connection data */
Expand Down Expand Up @@ -880,6 +882,7 @@ export async function createAsset({
qrCodes,
valuation,
organization,
availableToBook,
};

/** If a categoryId is passed, link the category to the asset. */
Expand Down Expand Up @@ -1940,6 +1943,7 @@ export async function createAssetsFromContentImport({
: undefined,
valuation: asset.valuation ? +asset.valuation : null,
customFieldsValues,
availableToBook: asset?.bookable !== "no",
});
}
} catch (cause) {
Expand Down
1 change: 1 addition & 0 deletions app/modules/asset/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export interface CreateAssetFromContentImportPayload
tags: string[];
location?: string;
custodian?: string;
bookable?: "yes" | "no";
}
export interface CreateAssetFromBackupImportPayload
extends Record<string, any> {
Expand Down
28 changes: 9 additions & 19 deletions app/routes/_layout+/assets.import.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const action = async ({ context, request }: ActionFunctionArgs) => {
const { intent } = parseData(
await request.clone().formData(),
z.object({
intent: z.enum(["backup", "content"]),
intent: z.enum(["content"]),
})
);

Expand All @@ -59,27 +59,17 @@ export const action = async ({ context, request }: ActionFunctionArgs) => {
message: "CSV file is empty",
additionalData: { intent },
label: "Assets",
shouldBeCaptured: false,
});
}

switch (intent) {
case "backup": {
throw new ShelfError({
cause: null,
message: "This feature is not available for you",
label: "Assets",
});
}
case "content": {
const contentData = extractCSVDataFromContentImport(csvData);
await createAssetsFromContentImport({
data: contentData,
userId,
organizationId,
});
return json(data(null));
}
}
const contentData = extractCSVDataFromContentImport(csvData);
await createAssetsFromContentImport({
data: contentData,
userId,
organizationId,
});
return json(data(null));
} catch (cause) {
const reason = makeShelfError(cause, { userId });
return json(error(reason), { status: reason.status });
Expand Down
6 changes: 3 additions & 3 deletions public/static/shelf.nu-example-asset-import-from-content.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
qrId,title,description,kit,category,tags,location,valuation,custodian,"cf: Serial number,type:text","cf:brand, type:option","cf:purchase date, type:date"
abcde12345,AMD Ryzen,"CPU from my new home PC",Home PC,CPU,"High priority, small",Sofia office,100,John,WQE239123d,amd,02/22/2024
12345abcde"Macbook Pro.","New laptop",Working gear,Laptop,"High priority, mid-size",Dutch office,2500,Thea,43543we23d,apple,03/12/2022
qrId,title,description,kit,category,tags,location,valuation,custodian,bookable,"cf: Serial number,type:text","cf:brand, type:option","cf:purchase date, type:date"
abcde12345,AMD Ryzen,"CPU from my new home PC",Home PC,CPU,"High priority, small",Sofia office,100,John,yes,WQE239123d,amd,02/22/2024
12345abcde,"Macbook Pro.","New laptop",Working gear,Laptop,"High priority, mid-size",Dutch office,2500,Thea,no,43543we23d,apple,03/12/2022

0 comments on commit 535bac9

Please sign in to comment.