-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2379 from Shopify/generic-picker
Add picker API
- Loading branch information
Showing
34 changed files
with
664 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@shopify/ui-extensions-react': minor | ||
'@shopify/data-extensions': minor | ||
'@shopify/ui-extensions': minor | ||
--- | ||
|
||
Add Picker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@shopify/ui-extensions': patch | ||
--- | ||
|
||
Sync picker and resourcePicker docs with app-bridge |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+58.4 KB
packages/ui-extensions/docs/surfaces/admin/screenshots/resource-picker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions
20
packages/ui-extensions/docs/surfaces/admin/staticPages/examples/resource-picker-product.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { | ||
reactExtension, | ||
useApi, | ||
Button, | ||
} from '@shopify/ui-extensions-react/admin'; | ||
|
||
const TARGET = 'admin.product-details.block.render'; | ||
|
||
export default reactExtension(TARGET, () => <App />); | ||
|
||
function App() { | ||
const {resourcePicker} = useApi(TARGET); | ||
|
||
const selectProduct = async () => { | ||
const selected = await resourcePicker({type: 'product'}); | ||
console.log(selected); | ||
}; | ||
|
||
return <Button onClick={selectProduct}>Select product</Button>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
packages/ui-extensions/src/surfaces/admin/api/picker/examples/direct-api.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const r = await fetch('shopify:admin/api/graphql.json', { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
query: ` | ||
query GetOrders($first: Int!) { | ||
orders(first: $first) { | ||
edges { | ||
node { | ||
id | ||
name | ||
customer { | ||
displayName | ||
} | ||
originalTotalPriceSet { | ||
shopMoney { | ||
amount | ||
} | ||
} | ||
displayFulfillmentStatus | ||
displayFinancialStatus | ||
unpaid | ||
} | ||
} | ||
} | ||
} | ||
`, | ||
variables: {first: 10}, | ||
}), | ||
}); | ||
const {data} = await r.json(); | ||
const orderData = data.orders.edges; | ||
|
||
const selected = await picker({ | ||
heading: 'Select orders', | ||
multiple: true, | ||
headers: [ | ||
{title: 'Order'}, | ||
{title: 'Customer'}, | ||
{title: 'Total', type: 'number'}, | ||
], | ||
items: orderData.map((order) => { | ||
const { | ||
id, | ||
name, | ||
customer, | ||
originalTotalPriceSet: {shopMoney}, | ||
displayFulfillmentStatus, | ||
displayFinancialStatus, | ||
} = order.node; | ||
|
||
return { | ||
id, | ||
heading: name, | ||
data: [customer.displayName, `$${shopMoney.amount}`], | ||
badges: [ | ||
{ | ||
content: displayFulfillmentStatus, | ||
tone: displayFulfillmentStatus === 'FULFILLED' ? '' : 'attention', | ||
progress: | ||
displayFulfillmentStatus === 'FULFILLED' | ||
? 'complete' | ||
: 'incomplete', | ||
}, | ||
{ | ||
content: displayFinancialStatus, | ||
tone: displayFinancialStatus === 'PENDING' ? 'warning' : '', | ||
progress: | ||
displayFinancialStatus === 'PENDING' ? 'incomplete' : 'complete', | ||
}, | ||
], | ||
}; | ||
}), | ||
}); |
16 changes: 16 additions & 0 deletions
16
packages/ui-extensions/src/surfaces/admin/api/picker/examples/disabled.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const pickerInstance = await picker({ | ||
heading: 'Disabled items', | ||
items: [ | ||
{ | ||
id: '1', | ||
heading: 'Item 1', | ||
disabled: true, | ||
}, | ||
{ | ||
id: '2', | ||
heading: 'Item 2', | ||
}, | ||
], | ||
}); | ||
|
||
const selected = await pickerInstance.selected; |
16 changes: 16 additions & 0 deletions
16
packages/ui-extensions/src/surfaces/admin/api/picker/examples/minimal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const pickerInstance = await picker({ | ||
heading: 'Select an item', | ||
headers: [{title: 'Main heading'}], | ||
items: [ | ||
{ | ||
id: '1', | ||
heading: 'Item 1', | ||
}, | ||
{ | ||
id: '2', | ||
heading: 'Item 2', | ||
}, | ||
], | ||
}); | ||
|
||
const selected = await pickerInstance.selected; |
21 changes: 21 additions & 0 deletions
21
packages/ui-extensions/src/surfaces/admin/api/picker/examples/multiple-limit.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const pickerInstance = await picker({ | ||
heading: 'Select items (up to 2)', | ||
multiple: 2, | ||
headers: [{title: 'Main heading'}], | ||
items: [ | ||
{ | ||
id: '1', | ||
heading: 'Item 1', | ||
}, | ||
{ | ||
id: '2', | ||
heading: 'Item 2', | ||
}, | ||
{ | ||
id: '3', | ||
heading: 'Item 3', | ||
}, | ||
], | ||
}); | ||
|
||
const selected = await pickerInstance.selected; |
21 changes: 21 additions & 0 deletions
21
packages/ui-extensions/src/surfaces/admin/api/picker/examples/multiple-true.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const pickerInstance = await picker({ | ||
heading: 'Select items', | ||
multiple: true, | ||
headers: [{title: 'Main heading'}], | ||
items: [ | ||
{ | ||
id: '1', | ||
heading: 'Item 1', | ||
}, | ||
{ | ||
id: '2', | ||
heading: 'Item 2', | ||
}, | ||
{ | ||
id: '3', | ||
heading: 'Item 3', | ||
}, | ||
], | ||
}); | ||
|
||
const selected = await pickerInstance.selected; |
16 changes: 16 additions & 0 deletions
16
packages/ui-extensions/src/surfaces/admin/api/picker/examples/preselected.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const pickerInstance = await picker({ | ||
heading: 'Preselected items', | ||
items: [ | ||
{ | ||
id: '1', | ||
heading: 'Item 1', | ||
selected: true, | ||
}, | ||
{ | ||
id: '2', | ||
heading: 'Item 2', | ||
}, | ||
], | ||
}); | ||
|
||
const selected = await pickerInstance.selected; |
37 changes: 37 additions & 0 deletions
37
packages/ui-extensions/src/surfaces/admin/api/picker/examples/template-picker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const {picker} = useApi(TARGET); | ||
|
||
const pickerInstance = await picker({ | ||
heading: 'Select a template', | ||
multiple: false, | ||
headers: [ | ||
{title: 'Templates'}, | ||
{title: 'Created by'}, | ||
{title: 'Times used', type: 'number'}, | ||
], | ||
items: [ | ||
{ | ||
id: '1', | ||
heading: 'Full width, 1 column', | ||
data: ['Karine Ruby', '0'], | ||
badges: [{content: 'Draft', tone: 'info'}, {content: 'Marketing'}], | ||
}, | ||
{ | ||
id: '2', | ||
heading: 'Large graphic, 3 column', | ||
data: ['Russell Winfield', '5'], | ||
badges: [ | ||
{content: 'Published', tone: 'success'}, | ||
{content: 'New feature'}, | ||
], | ||
selected: true, | ||
}, | ||
{ | ||
id: '3', | ||
heading: 'Promo header, 2 column', | ||
data: ['Russel Winfield', '10'], | ||
badges: [{content: 'Published', tone: 'success'}], | ||
}, | ||
], | ||
}); | ||
|
||
const selected = await pickerInstance.selected; |
Oops, something went wrong.