From 883e69ae13a99a7e03efd40792bebcc600092802 Mon Sep 17 00:00:00 2001 From: Gautam Bajaj Date: Thu, 12 Sep 2024 23:19:02 +0530 Subject: [PATCH 1/6] reloading profile search data on profile update --- ecc/components/profile-container/profile-container.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ecc/components/profile-container/profile-container.js b/ecc/components/profile-container/profile-container.js index b0513587..a11f40d6 100644 --- a/ecc/components/profile-container/profile-container.js +++ b/ecc/components/profile-container/profile-container.js @@ -1,5 +1,6 @@ /* eslint-disable import/prefer-default-export */ /* eslint-disable class-methods-use-this */ +import { getSpeakers } from '../../scripts/esp-controller.js'; import { LIBS } from '../../scripts/scripts.js'; import { isEmptyObject } from '../../scripts/utils.js'; import { style } from './profile-container.css.js'; @@ -32,8 +33,14 @@ export class ProfileContainer extends LitElement { this.requestUpdate(); } + reloadSearchData = async () => { + const spResp = await getSpeakers(this.seriesId); + if (spResp) this.searchdata = spResp.speakers; + }; + updateProfile(index, profile) { this.profiles[index] = profile; + this.reloadSearchData(); this.requestUpdate(); } From 7522344907af65d310c2279983aa185ccb7fcaa3 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Thu, 12 Sep 2024 16:02:23 -0500 Subject: [PATCH 2/6] speaker operates still with empty array --- .../form-handler/controllers/profile-component-controller.js | 1 - 1 file changed, 1 deletion(-) diff --git a/ecc/blocks/form-handler/controllers/profile-component-controller.js b/ecc/blocks/form-handler/controllers/profile-component-controller.js index ee0eae9b..bfdfa4bc 100644 --- a/ecc/blocks/form-handler/controllers/profile-component-controller.js +++ b/ecc/blocks/form-handler/controllers/profile-component-controller.js @@ -14,7 +14,6 @@ export async function onSubmit(component, props) { const profileContainer = component.querySelector('profile-container'); if (profileContainer) { const speakers = profileContainer.getProfiles(); - if (speakers.length === 0) return; if (speakers.filter((speaker) => !speaker.speakerType).length > 0) { throw new Error('Please select a speaker type for the speakers'); From 898608417d8d17b35e4e9e4950d7475ce4c6692f Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Thu, 12 Sep 2024 16:36:50 -0500 Subject: [PATCH 3/6] multiple profile component fixes --- .../product-promotion-component-controller.js | 10 ++++---- .../profile-component-controller.js | 24 ++++++++++++++----- ecc/blocks/form-handler/form-handler.js | 2 +- ecc/components/profile/profile.js | 2 +- 4 files changed, 25 insertions(+), 13 deletions(-) diff --git a/ecc/blocks/form-handler/controllers/product-promotion-component-controller.js b/ecc/blocks/form-handler/controllers/product-promotion-component-controller.js index 1bec3156..65b5046d 100644 --- a/ecc/blocks/form-handler/controllers/product-promotion-component-controller.js +++ b/ecc/blocks/form-handler/controllers/product-promotion-component-controller.js @@ -12,7 +12,7 @@ export function onSubmit(component, props) { if (selectedProducts) { const topicsVal = props.payload.fullTopicsValue?.map((x) => JSON.parse(x)); const relatedProducts = selectedProducts - .filter((p) => topicsVal.find((t) => p.tagID.includes(t.tagID))) + .filter((p) => topicsVal.find((t) => p.tagID?.includes(t.tagID))) .map((p) => ({ name: p.title, showProductBlade: !!p.showProductBlade, @@ -65,19 +65,19 @@ async function updateProductSelector(component, props) { 'Substance 3D Collection', ]; const caasTags = await getCaasTags(); - const topicsVal = props.payload.fullTopicsValue?.map((x) => JSON.parse(x)); - if (!caasTags || !topicsVal) return; + const topics = props.payload.fullTopicsValue?.map((x) => JSON.parse(x)); + if (!caasTags || !topics) return; const productGroups = component.querySelectorAll('product-selector-group'); let products = Object.values(caasTags.namespaces.caas.tags['product-categories'].tags).map((x) => [...Object.values(x.tags).map((y) => y)]).flat(); products = products.filter( - (p) => topicsVal.find((t) => p.tagID.includes(t.tagID)) && supportedProducts.includes(p.title), + (p) => topics.find((t) => p.tagID?.includes(t.tagID)) && supportedProducts?.includes(p.title), ); productGroups.forEach((pg) => { pg.setAttribute('data-products', JSON.stringify(products)); - pg.setAttribute('data-selected-topics', JSON.stringify(topicsVal)); + pg.setAttribute('data-selected-topics', JSON.stringify(topics)); pg.requestUpdate(); const selectedProducts = pg.getSelectedProducts(); diff --git a/ecc/blocks/form-handler/controllers/profile-component-controller.js b/ecc/blocks/form-handler/controllers/profile-component-controller.js index bfdfa4bc..ccc9925e 100644 --- a/ecc/blocks/form-handler/controllers/profile-component-controller.js +++ b/ecc/blocks/form-handler/controllers/profile-component-controller.js @@ -13,14 +13,29 @@ export async function onSubmit(component, props) { const profileContainer = component.querySelector('profile-container'); if (profileContainer) { + const { eventId } = getFilteredCachedResponse(); const speakers = profileContainer.getProfiles(); + if (speakers.length === 0) { + if (props.eventDataResp.speakers) { + const savedSpeakers = props.eventDataResp.speakers; + await savedSpeakers.reduce(async (promise, speaker) => { + await promise; + const { speakerId } = speaker; + const resp = await removeSpeakerFromEvent(speakerId, eventId); + if (resp.error) return; + props.eventDataResp = { ...props.eventDataResp, ...resp }; + }, Promise.resolve()); + } + + return; + } + + console.log('speakers', speakers); if (speakers.filter((speaker) => !speaker.speakerType).length > 0) { throw new Error('Please select a speaker type for the speakers'); } - const { eventId } = getFilteredCachedResponse(); - await speakers.reduce(async (promise, speaker) => { await promise; @@ -79,10 +94,7 @@ export async function onSubmit(component, props) { if (!stillNeeded) { const resp = await removeSpeakerFromEvent(speakerId, eventId); - if (resp.error) { - return; - } - + if (resp.error) return; props.eventDataResp = { ...props.eventDataResp, ...resp }; } }, Promise.resolve()); diff --git a/ecc/blocks/form-handler/form-handler.js b/ecc/blocks/form-handler/form-handler.js index cee726eb..972d3632 100644 --- a/ecc/blocks/form-handler/form-handler.js +++ b/ecc/blocks/form-handler/form-handler.js @@ -410,7 +410,7 @@ async function saveEvent(props, options = { toPublish: false }) { try { await gatherValues(props); } catch (e) { - return { message: e.message }; + return { error: { message: e.message } }; } let resp; diff --git a/ecc/components/profile/profile.js b/ecc/components/profile/profile.js index ffdbe133..cb814a9d 100644 --- a/ecc/components/profile/profile.js +++ b/ecc/components/profile/profile.js @@ -41,7 +41,7 @@ export class Profile extends LitElement { this.attachShadow({ mode: 'open' }); this.fieldlabels = this.fieldlabels ?? DEFAULT_FIELD_LABELS; - this.profile = this.profile ?? { socialMedia: [{ link: '' }] }; + this.profile = this.profile ?? { socialMedia: [{ link: '' }], isPlaceholder: true }; this.profileCopy = {}; } From 474f9b7acb21da6431f47c62b5147de4d9b6b8b9 Mon Sep 17 00:00:00 2001 From: Gautam Bajaj Date: Fri, 13 Sep 2024 10:09:46 +0530 Subject: [PATCH 4/6] minor fix --- ecc/components/profile/profile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ecc/components/profile/profile.js b/ecc/components/profile/profile.js index ffdbe133..cb814a9d 100644 --- a/ecc/components/profile/profile.js +++ b/ecc/components/profile/profile.js @@ -41,7 +41,7 @@ export class Profile extends LitElement { this.attachShadow({ mode: 'open' }); this.fieldlabels = this.fieldlabels ?? DEFAULT_FIELD_LABELS; - this.profile = this.profile ?? { socialMedia: [{ link: '' }] }; + this.profile = this.profile ?? { socialMedia: [{ link: '' }], isPlaceholder: true }; this.profileCopy = {}; } From 80cbe31f007e4a5f4f219d05bd640d41901dab50 Mon Sep 17 00:00:00 2001 From: Gautam Bajaj Date: Fri, 13 Sep 2024 10:25:17 +0530 Subject: [PATCH 5/6] adding default value for isPlaceholder --- ecc/blocks/profile-component/profile-component.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ecc/blocks/profile-component/profile-component.js b/ecc/blocks/profile-component/profile-component.js index 613d1e31..db41d1a5 100644 --- a/ecc/blocks/profile-component/profile-component.js +++ b/ecc/blocks/profile-component/profile-component.js @@ -36,7 +36,7 @@ async function decorateProfile(element) { const profileContainer = createTag('profile-container', { class: 'profile-component' }); profileContainer.fieldlabels = fieldlabels; - profileContainer.profiles = [{ socialMedia: [{ link: '' }] }]; + profileContainer.profiles = [{ socialMedia: [{ link: '' }], isPlaceholder: true }]; element.append(profileContainer); } From afd686103ff2771c3cdd90754091196c70f76ab5 Mon Sep 17 00:00:00 2001 From: Qiyun Dai Date: Fri, 13 Sep 2024 09:07:08 -0500 Subject: [PATCH 6/6] linting --- .../form-handler/controllers/profile-component-controller.js | 1 - ecc/components/profile-container/profile-container.js | 1 - 2 files changed, 2 deletions(-) diff --git a/ecc/blocks/form-handler/controllers/profile-component-controller.js b/ecc/blocks/form-handler/controllers/profile-component-controller.js index ccc9925e..999eb50b 100644 --- a/ecc/blocks/form-handler/controllers/profile-component-controller.js +++ b/ecc/blocks/form-handler/controllers/profile-component-controller.js @@ -31,7 +31,6 @@ export async function onSubmit(component, props) { return; } - console.log('speakers', speakers); if (speakers.filter((speaker) => !speaker.speakerType).length > 0) { throw new Error('Please select a speaker type for the speakers'); } diff --git a/ecc/components/profile-container/profile-container.js b/ecc/components/profile-container/profile-container.js index a11f40d6..eba817cb 100644 --- a/ecc/components/profile-container/profile-container.js +++ b/ecc/components/profile-container/profile-container.js @@ -63,7 +63,6 @@ export class ProfileContainer extends LitElement { } enableRepeater() { - // eslint-disable-next-line max-len return this.profiles.every((profile) => !profile.isPlaceholder && profile.type); }