Skip to content

Commit

Permalink
Merge pull request #1852 from GovAlta/CS-2198
Browse files Browse the repository at this point in the history
CS-2198 - Generate should now reflect updates every time
  • Loading branch information
jonathanweyermann authored Jul 25, 2023
2 parents 381444c + b8e2213 commit b7a49a9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
5 changes: 4 additions & 1 deletion apps/pdf-service/src/pdf/job/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<string, PdfTemplateEntity>>(
serviceId,
token,
tenantId
tenantId,
disableCaching
);

const pdfTemplate = configuration[templateId];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
Expand Down Expand Up @@ -148,7 +147,7 @@ export const PreviewTemplate = ({ channelTitle }: PreviewTemplateProps) => {
<PDFTitle>{title}</PDFTitle>

<GoAButton
disabled={indicator.show || tempPdfTemplate === null}
disabled={indicator.show || pdfTemplate === null}
type="secondary"
testId="generate-template"
size="compact"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ export const TemplateEditor = ({ errors }: TemplateEditorProps): JSX.Element =>
}, []);

//eslint-disable-next-line
useEffect(() => {}, [pdfTemplate]);
useEffect(() => {
setTmpTemplate(JSON.parse(JSON.stringify(pdfTemplate || '')));
}, [pdfTemplate]);

const reloadFile = useSelector((state: RootState) => state.pdf?.reloadFile);

Expand Down
3 changes: 2 additions & 1 deletion apps/tenant-management-webapp/src/app/store/pdf/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
31 changes: 23 additions & 8 deletions libs/adsp-service-sdk/src/configuration/configurationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface ConfigurationService {
* @returns {Promise<R>}
* @memberof ConfigurationService
*/
getConfiguration<C, R = [C, C]>(serviceId: AdspId, token: string, tenantId?: AdspId): Promise<R>;
getConfiguration<C, R = [C, C]>(serviceId: AdspId, token: string, tenantId?: AdspId, unCached?: boolean): Promise<R>;
}

export class ConfigurationServiceImpl implements ConfigurationService {
Expand Down Expand Up @@ -120,19 +120,34 @@ export class ConfigurationServiceImpl implements ConfigurationService {
}
};

getConfiguration = async <C, R = [C, C]>(serviceId: AdspId, token: string, tenantId?: AdspId): Promise<R> => {
getConfiguration = async <C, R = [C, C]>(
serviceId: AdspId,
token: string,
tenantId?: AdspId,
unCached?: boolean
): Promise<R> => {
let configuration = null;
if (tenantId) {
assertAdspId(tenantId, 'Provided ID is not for a tenant', 'resource');

configuration =
this.#configuration.get<C>(`${tenantId}-${serviceId}`) ||
(await this.#retrieveConfiguration<C>(serviceId, token, tenantId)) ||
null;
if (unCached) {
configuration = (await this.#retrieveConfiguration<C>(serviceId, token, tenantId)) || null;
} else {
configuration =
this.#configuration.get<C>(`${tenantId}-${serviceId}`) ||
(await this.#retrieveConfiguration<C>(serviceId, token, tenantId)) ||
null;
}
}

const options =
this.#configuration.get<C>(`${serviceId}`) || (await this.#retrieveConfiguration<C>(serviceId, token)) || null;
let options = null;

if (unCached) {
options = (await this.#retrieveConfiguration<C>(serviceId, token)) || null;
} else {
options =
this.#configuration.get<C>(`${serviceId}`) || (await this.#retrieveConfiguration<C>(serviceId, token)) || null;
}

return this.#combine(configuration, options, tenantId) as R;
};
Expand Down

0 comments on commit b7a49a9

Please sign in to comment.