Notes
Notes - notes.io |
if (!Array.isArray(aosContainerParts) || aosContainerParts.length === 0) {
runInAction(() => {
this.configureForm.steps[page][collection].variants = [[null, []]];
this.configureForm.steps[page][collection].prepopulate = '';
this.optionGroupTypes[page][collection] = [];
this.optionGroupTypeVariantAttributesKeys[page][collection] = {};
});
return;
}
try {
const parts = aosContainerParts.map(part => part?.value || part);
const response = await api.fetchPnpPrototype({
method: 'getOptionGroupTypeVariants',
collectionIds: parts
});
const { _expire, ...ogtData } = response.data || {};
const ogtSet = new Set();
const ogtvakMap = {};
for (const [ogtKey, variantValues] of Object.entries(ogtData)) {
ogtSet.add(ogtKey);
if (!ogtvakMap[ogtKey]) {
ogtvakMap[ogtKey] = new Set();
}
variantValues.forEach(val => ogtvakMap[ogtKey].add(val));
}
const ogtOptions = Array.from(ogtSet).map(key => ({ label: key, value: key }));
const ogtvakOptions = {};
for (const [key, valSet] of Object.entries(ogtvakMap)) {
ogtvakOptions[key] = Array.from(valSet).map(v => ({ label: v, value: v }));
}
runInAction(() => {
this.optionGroupTypes[page][collection] = ogtOptions;
this.optionGroupTypeVariantAttributesKeys[page][collection] = ogtvakOptions;
// Always reset variants when collection ID changes
this.configureForm.steps[page][collection].variants = [[null, []]];
if ('processor' in ogtvakOptions) {
this.configureForm.steps[page][collection].prepopulate = 'processor';
}
});
// Check for schema and apply if found
let schemaFound = false;
for (const part of parts) {
const hasSchema = await this.getInputSchema(part, ogtData);
if (hasSchema) {
schemaFound = true;
break;
}
}
// If no schema was found and we have option groups, initialize with default values
runInAction(() => {
if (!schemaFound && ogtOptions.length > 0) {
this.configureForm.steps[page][collection].variants = [[null, []]];
}
});
} catch (error) {
console.error(error);
this.appState.handleNotification({
error,
message: 'Unable to fetch optionGroupTypes. Please try again.',
levelType: 'danger'
});
runInAction(() => {
this.appState.err = true;
});
}
}
async getInputSchema(aosContainerPart, ogtVarAttrKeys) {
const { result } = (await api.fetchCollectionInputSchema({
method: 'getCollectionInputSchema',
collectionId: aosContainerPart
})).data;
if (!result) return false;
const variants = [];
result.forEach(res => {
const { primaryVariantGroup, subVariantGroup, groupPrimaryVariant } = res;
const isValidOGT = primaryVariantGroup?.optionGroupTypeKey in ogtVarAttrKeys;
if (isValidOGT) {
const child = subVariantGroup?.[0]?.optionGroupTypeKey;
const childVariants = subVariantGroup?.[0]?.variants || [];
const entry = [
primaryVariantGroup.optionGroupTypeKey,
(primaryVariantGroup.variants || []).map(item => ({ label: item, value: item })),
child && child in ogtVarAttrKeys
? {
isGroupDefaultVariants: groupPrimaryVariant,
variants: [[child, childVariants.map(v => ({ label: v, value: v }))]]
}
: undefined
];
variants.push(entry);
}
});
runInAction(() => {
// Always apply schema variants if they exist
if (variants.length) {
this.configureForm.steps[this.page][this.collection].variants = variants;
}
});
return variants.length > 0;
}
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team
