Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web): template store integrate with api's #3475

Merged
merged 5 commits into from
May 24, 2023

Conversation

LetItRock
Copy link
Contributor

What change does this PR introduce?

In this PR I've integrated the FE Template Store with the blueprint APIs:

  • fetch grouped blueprints
  • create template from the blueprint
  • removed mock data

Why was this change needed?

Template Store PRD.

Other information (Screenshots)

Screen.Recording.2023-05-23.at.10.30.15.mov

@LetItRock LetItRock self-assigned this May 23, 2023
@linear
Copy link

linear bot commented May 23, 2023

NV-2361 🏪 [Template store] Integrate the FE with blueprints APIs

What?

We've created the mock data for the blueprints on the FE so far. In this ticket we would like to integrate the FE functionality with the Blueprints API.

Why? (Context)

We want to use real API, not mocked data.

Definition of Done

The FE fetches and creates the templates from the blueprints API.

Comment on lines -3 to -6
export class GroupedBlueprint {
name: string;
blueprints: INotificationTemplate[];
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved this interface to shared package, because I do reuse it on the FE

Comment on lines +19 to +31
export const useCreateTemplateFromBlueprint = (
options: UseMutationOptions<INotificationTemplate, any, { blueprint: INotificationTemplate }> = {}
) => {
const { mutate, ...rest } = useMutation<INotificationTemplate, any, { blueprint: INotificationTemplate }>(
({ blueprint }) => createTemplate(mapBlueprintToTemplate(blueprint)),
{ ...options }
);

return {
createTemplateFromBlueprint: mutate,
...rest,
};
};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create template from the blueprint hook, there is an important mapping at the top from INotificationTemplate to ICreateNotificationTemplateDto which is expected by the BE endpoint

}

const STEPS: IFormStep[] = [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed mock data

Comment on lines +31 to +42
const mapGroup = (group: IGroupedBlueprint): IBlueprintsGrouped => ({
name: group.name,
blueprints: group.blueprints.map((template) => {
const { name, iconName } = getTemplateDetails(template.name);

return {
...template,
name,
iconName,
};
}),
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function just walks through the blueprints and extracts the name and icon from the template name, and then adds these properties to the IBlueprintTemplate object

@@ -139,24 +141,25 @@ export const TemplatesListNoData = ({
: blueprints?.map((template, index) => (
<Popover
key={template.name}
opened={template.id === templateId}
opened={template._id === templateId && !!template.description}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when there is no description do not show the popover

target={
<Card
data-can-be-hidden={index === 2}
data-test-id="second-workflow-tile"
disabled={readonly}
disabled={readonly || isCreating}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the user has clicked on the popular template card and we are creating the template then the card should be disabled

Comment on lines +35 to +36
const { blueprintsGroupedAndPopular: { general, popular } = {}, isLoading: areBlueprintsLoading } =
useFetchBlueprints();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetch blueprints

Comment on lines 37 to 44
const { createTemplateFromBlueprint, isLoading: isCreatingTemplateFromBlueprint } = useCreateTemplateFromBlueprint({
onSuccess: (template) => {
navigate(`${parseUrl(ROUTES.TEMPLATES_EDIT_TEMPLATEID, { templateId: template._id ?? '' })}`);
},
onError: () => {
errorMessage('Something went wrong while creating template from blueprint, please try again later.');
},
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create the blueprint hook, on the success we will redirect to the editor

const templatePayload = mapBlueprintToTemplateCreatePayload();

return createTemplate(templatePayload);
const { createTemplateFromBlueprint, isLoading: isCreating } = useCreateTemplateFromBlueprint({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reuse the useCreateTemplateFromBlueprint hook

@@ -63,22 +66,24 @@ export const CreateWorkflowDropdown = ({
: blueprints?.map((template, index) => (
<Popover
key={template.name}
opened={template.id === templateId}
opened={template._id === templateId && !!template.description}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when there is no description in the template do not show the popover for the popular templates dropdown items

Copy link
Contributor

@djabarovgeorge djabarovgeorge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good left small question there

useFetchBlueprints();
const { createTemplateFromBlueprint, isLoading: isCreatingTemplateFromBlueprint } = useCreateTemplateFromBlueprint({
onSuccess: (template) => {
navigate(`${parseUrl(ROUTES.TEMPLATES_EDIT_TEMPLATEID, { templateId: template._id ?? '' })}`);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen here if template._id is not valid?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If template._id is not valid it means that we have a problem on the API because we are not returning it :) or someone has used this hook with a "not saved" template.

const hasTemplates = templates && templates.length > 0;

const { TemplatesStoreModal, openModal } = useTemplatesStoreModal({ groupedBlueprints });
const { TemplatesStoreModal, openModal } = useTemplatesStoreModal({ general });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never realized that we are not presenting the popular in the Template Store, raised a question HERE

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, the popular templates are a subset of the general.

Base automatically changed from NV-2365/template-store-aggregate-popular-blueprints to next May 24, 2023 09:41
@LetItRock LetItRock added this pull request to the merge queue May 24, 2023
Merged via the queue into next with commit cdbe506 May 24, 2023
33 checks passed
@LetItRock LetItRock deleted the nv-2361-template-store-integrate-with-api branch May 24, 2023 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants