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

Add Fake PIM and global.d.ts #9

Merged
merged 3 commits into from
Dec 3, 2024
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,695 changes: 2,446 additions & 249 deletions basic_sdk_samples/global.d.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion basic_sdk_samples/shortView.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const productUuid = globalThis.PIM.context.product.uuid;

document.body.innerHTML = '';

const product = await globalThis.PIM.api.products_uuid.get({uuid: productUuid})
const product = await globalThis.PIM.api.product_uuid.get({uuid: productUuid})
let table = `
<table>
<thead>
Expand Down
3 changes: 2 additions & 1 deletion dsm_sdk_script/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
<script type="module" src="src/fakePIM.js"></script>
<script type="module" src="src/main.tsx"></script>
</body>
</html>
40 changes: 31 additions & 9 deletions dsm_sdk_script/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,36 @@
import {Link, Placeholder, UsersIllustration} from "akeneo-design-system";
import {Link, Placeholder, SectionTitle, UsersIllustration} from "akeneo-design-system";
import {useGetProduct} from "./useGetProduct.ts";
import {useGetCategory} from "./useGetCategory.ts";

function App() {
return <Placeholder
size={'large'}
illustration={<UsersIllustration />}
title="Welcome to the SDM SDK starter kit!"
>
Please update the src/App.tsx file to match your needs!<br/>
<Link href="https://dsm.akeneo.com/" target="_blank">Link to the official Akeneo DSM</Link>
</Placeholder>
const PIMContext = globalThis.PIM.context;
const PIMUser = globalThis.PIM.user
const currentProduct = useGetProduct('product' in PIMContext ? PIMContext.product.uuid : undefined);
const currentCategory = useGetCategory('category' in PIMContext ? PIMContext.category.code : undefined);

return <>
<Placeholder
size={'large'}
illustration={<UsersIllustration/>}
title="Welcome to the SDM SDK starter kit!"
>
Please update the src/App.tsx file to match your needs!<br/>
<Link href="https://dsm.akeneo.com/" target="_blank">Link to the official Akeneo DSM</Link><br/>
</Placeholder>
<SectionTitle>
<SectionTitle.Title>PIM Context</SectionTitle.Title>
</SectionTitle>
<pre>{JSON.stringify(PIMContext)}</pre>
<SectionTitle>
<SectionTitle.Title>PIM User</SectionTitle.Title>
</SectionTitle>
<pre>{JSON.stringify(PIMUser)}</pre>
<SectionTitle>
<SectionTitle.Title>Current object properties</SectionTitle.Title>
</SectionTitle>
{currentProduct && <pre>{JSON.stringify(currentProduct, null, 4)}</pre>}
{currentCategory && <pre>{JSON.stringify(currentCategory, null, 4)}</pre>}
</>
}

export default App
45 changes: 45 additions & 0 deletions dsm_sdk_script/src/fakePIM.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
globalThis.PIM = {
user: {
username: 'admin',
first_name: 'John',
last_name: 'Doe',
},
context: {
product: {
uuid: '77aac2d4-cbec-4394-8ac7-ee1ccbfb079b',
identifier: 'my_product'
}
},
api: {
product_uuid: {
get: () => new Promise((e) => e({
uuid: '77aac2d4-cbec-4394-8ac7-ee1ccbfb079b',
enabled: true,
family: 'loudspeakers',
categories: ['loudspeakers'],
groups: [],
values: {
sku: [
{
locale: null,
scope: null,
data: 'my_product',
attribute_type: 'pim_catalog_identifier'
}
],
name: [{
locale: null,
scope: null,
data: 'My awesome product',
attribute_type: 'pim_catalog_text'
}],
},
associations: {},
quantifiedAssociations: {},
created: '2024-11-28T13:00:18+00:00',
updated: '2024-11-28T13:00:18+00:00',
metadata: {}
})),
}
}
}
Loading