From b8e2213e6dc1f3c60d15caecb00435f7eb5a8c73 Mon Sep 17 00:00:00 2001 From: Jonathan Weyermann Date: Tue, 25 Jul 2023 09:34:10 -0600 Subject: [PATCH] CS-2198 - Generate should now reflect updates every time Additional bugs fixed * Refreshing a template should now work correctly, instead of showing a blank template * Editing a template no longer causes the preview pane to be refreshed unnnecessarily --- apps/pdf-service/src/pdf/job/generate.ts | 5 ++- .../previewEditor/PreviewTemplate.tsx | 3 +- .../previewEditor/TemplateEditor.tsx | 4 ++- .../src/app/store/pdf/reducers.ts | 3 +- .../src/configuration/configurationService.ts | 31 ++++++++++++++----- 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/apps/pdf-service/src/pdf/job/generate.ts b/apps/pdf-service/src/pdf/job/generate.ts index a0425345c0..051cc970b4 100644 --- a/apps/pdf-service/src/pdf/job/generate.ts +++ b/apps/pdf-service/src/pdf/job/generate.ts @@ -39,12 +39,15 @@ export function createGenerateJob({ const tenantId = AdspId.parse(tenantIdValue); + const disableCaching = true; + try { const token = await tokenProvider.getAccessToken(); const [configuration] = await configurationService.getConfiguration>( serviceId, token, - tenantId + tenantId, + disableCaching ); const pdfTemplate = configuration[templateId]; diff --git a/apps/tenant-management-webapp/src/app/pages/admin/services/pdf/templates/previewEditor/PreviewTemplate.tsx b/apps/tenant-management-webapp/src/app/pages/admin/services/pdf/templates/previewEditor/PreviewTemplate.tsx index 3ccc20376c..db768dd81f 100644 --- a/apps/tenant-management-webapp/src/app/pages/admin/services/pdf/templates/previewEditor/PreviewTemplate.tsx +++ b/apps/tenant-management-webapp/src/app/pages/admin/services/pdf/templates/previewEditor/PreviewTemplate.tsx @@ -51,7 +51,6 @@ export const PreviewTemplate = ({ channelTitle }: PreviewTemplateProps) => { ); const pdfGenerationError = jobList?.[0]?.payload?.error; const hasError = pdfGenerationError && pdfGenerationError.length > 0; - const tempPdfTemplate = useSelector((state: RootState) => state?.pdf?.tempTemplate); useEffect(() => { dispatch(updatePdfResponse({ fileList: fileList })); @@ -148,7 +147,7 @@ export const PreviewTemplate = ({ channelTitle }: PreviewTemplateProps) => { {title} }, []); //eslint-disable-next-line - useEffect(() => {}, [pdfTemplate]); + useEffect(() => { + setTmpTemplate(JSON.parse(JSON.stringify(pdfTemplate || ''))); + }, [pdfTemplate]); const reloadFile = useSelector((state: RootState) => state.pdf?.reloadFile); diff --git a/apps/tenant-management-webapp/src/app/store/pdf/reducers.ts b/apps/tenant-management-webapp/src/app/store/pdf/reducers.ts index 7cfc74c88f..f6d54bfa17 100644 --- a/apps/tenant-management-webapp/src/app/store/pdf/reducers.ts +++ b/apps/tenant-management-webapp/src/app/store/pdf/reducers.ts @@ -39,8 +39,9 @@ export default function (state: PdfState = defaultState, action: PdfActionTypes) pdfTemplates: action.payload, }; case UPDATE_TEMP_TEMPLATE: + //Intentionally don't want to cause an immediate refresh on update, as it refreshed the preview pane on text input state.tempTemplate = action.payload; - return { ...state }; + return state; case UPDATE_PDF_TEMPLATE_SUCCESS_ACTION: return { ...state, diff --git a/libs/adsp-service-sdk/src/configuration/configurationService.ts b/libs/adsp-service-sdk/src/configuration/configurationService.ts index 319f797df4..bdf9767c04 100644 --- a/libs/adsp-service-sdk/src/configuration/configurationService.ts +++ b/libs/adsp-service-sdk/src/configuration/configurationService.ts @@ -24,7 +24,7 @@ export interface ConfigurationService { * @returns {Promise} * @memberof ConfigurationService */ - getConfiguration(serviceId: AdspId, token: string, tenantId?: AdspId): Promise; + getConfiguration(serviceId: AdspId, token: string, tenantId?: AdspId, unCached?: boolean): Promise; } export class ConfigurationServiceImpl implements ConfigurationService { @@ -120,19 +120,34 @@ export class ConfigurationServiceImpl implements ConfigurationService { } }; - getConfiguration = async (serviceId: AdspId, token: string, tenantId?: AdspId): Promise => { + getConfiguration = async ( + serviceId: AdspId, + token: string, + tenantId?: AdspId, + unCached?: boolean + ): Promise => { let configuration = null; if (tenantId) { assertAdspId(tenantId, 'Provided ID is not for a tenant', 'resource'); - configuration = - this.#configuration.get(`${tenantId}-${serviceId}`) || - (await this.#retrieveConfiguration(serviceId, token, tenantId)) || - null; + if (unCached) { + configuration = (await this.#retrieveConfiguration(serviceId, token, tenantId)) || null; + } else { + configuration = + this.#configuration.get(`${tenantId}-${serviceId}`) || + (await this.#retrieveConfiguration(serviceId, token, tenantId)) || + null; + } } - const options = - this.#configuration.get(`${serviceId}`) || (await this.#retrieveConfiguration(serviceId, token)) || null; + let options = null; + + if (unCached) { + options = (await this.#retrieveConfiguration(serviceId, token)) || null; + } else { + options = + this.#configuration.get(`${serviceId}`) || (await this.#retrieveConfiguration(serviceId, token)) || null; + } return this.#combine(configuration, options, tenantId) as R; };