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/handlebars template #8

Merged
merged 26 commits into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
9452df1
feat: adding handlebars dependency
eliasfeijo Mar 7, 2023
60d6c8d
feat: Menu EditTemplate with Handlebars
eliasfeijo Mar 8, 2023
30a1242
feat: TemplateHelper renderItemsXML items and children wrapper tags
eliasfeijo Mar 8, 2023
5af6961
feat: using default codemirror languages instead of ejs extensions
eliasfeijo Mar 8, 2023
4a859c3
fix: don't render empty items
eliasfeijo Mar 8, 2023
b92913b
refactor: replacing ejs strings and links with handlebars'
eliasfeijo Mar 8, 2023
8c5f664
refactor: prettyJSON -> json helper and optional spaces parameter
eliasfeijo Mar 8, 2023
6536d53
feat: logic helpers
eliasfeijo Mar 8, 2023
a06a50c
feat: length helper
eliasfeijo Mar 8, 2023
06902cc
feat: menu xml auto-closing tag
eliasfeijo Mar 8, 2023
4b7d3e5
refactor: TemplateHelpers logicOperators and getLength
eliasfeijo Mar 8, 2023
e0306a7
feat: TemplateHelpers renderItemsJSON
eliasfeijo Mar 8, 2023
16d2a05
feat: menu top level context
eliasfeijo Mar 8, 2023
9c1844c
feat: TemplateHelpers jsonFormatter
eliasfeijo Mar 8, 2023
0655b17
fix: top level context menu
eliasfeijo Mar 8, 2023
a02749c
fix: renderItemsJSON empty array
eliasfeijo Mar 8, 2023
c02cf19
feat: Menu Items EditTemplate
eliasfeijo Mar 9, 2023
13ee5d1
feat: removing id from menu initial template
eliasfeijo Mar 10, 2023
b43af96
feat: MenuService RENDER_MENU_TEMPLATE
eliasfeijo Mar 10, 2023
e3098a3
feat: Menu EditTemplate renderMenuTemplate query
eliasfeijo Mar 10, 2023
4b2d487
feat: Menu Items EditTemplate renderMenuItemTemplate query
eliasfeijo Mar 10, 2023
9142864
feat: defaultTemplate from api
eliasfeijo Mar 10, 2023
fb72eac
fix: Menu Item update
eliasfeijo Mar 10, 2023
0f43e41
fix: Diff crash
eliasfeijo Mar 10, 2023
7e4bc6c
refactor: menuRevisionDiff util
eliasfeijo Mar 10, 2023
caf71de
feat: Menu Revisions Publish no template error message
eliasfeijo Mar 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"codemirror-lang-ejs": "^0.1.5",
"ejs": "^3.1.8",
"graphql": "^16.6.0",
"handlebars": "^4.7.7",
"history": "^5.0.0",
"i18next": "^22.4.6",
"i18next-browser-languagedetector": "^7.0.1",
Expand Down
5 changes: 5 additions & 0 deletions src/api/services/MenuItemService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ export default class MenuItemService {
parentId
template
templateFormat
defaultTemplate {
json
xml
plain
}
enabled
startPublication
endPublication
Expand Down
25 changes: 25 additions & 0 deletions src/api/services/MenuService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ meta {
}
template
templateFormat
defaultTemplate {
json
xml
plain
}
items {
id
label
Expand All @@ -46,6 +51,11 @@ items {
menuId
templateFormat
template
defaultTemplate {
json
xml
plain
}
enabled
startPublication
endPublication
Expand Down Expand Up @@ -132,4 +142,19 @@ export default class MenuService {
}
}
`;

static RENDER_MENU_TEMPLATE: DocumentNode = gql`
query RenderMenuTemplate($input: RenderMenuTemplateInput!) {
renderMenuTemplate(renderMenuTemplateInput: $input)
}
`;

static RENDER_MENU_ITEM_TEMPLATE: DocumentNode = gql`
query RenderMenuItemTemplate(
$item: RenderMenuItemTemplateInput!
$menu: RenderMenuTemplateInput!
) {
renderMenuItemTemplate(renderMenuItemTemplateInput: $item, renderMenuTemplateInput: $menu)
}
`;
}
1 change: 1 addition & 0 deletions src/components/CodeViewer/CodeViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface Props {
}

const CodeViewer = ({ code, language, lineNumbers = true }: Props) => {
language = language === 'plain' ? 'json' : language;
useEffect(() => {
Prism.highlightAll();
}, [code]);
Expand Down
13 changes: 12 additions & 1 deletion src/components/Menu/Items/OperationScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,18 @@ export const OperationScreen = ({
const formatNodes = (nodes: INode[]) =>
nodes
.map(node => {
const { id, children, original, parentId, ...rest } = node;
const {
id,
children,
original,
parentId,
createdAt,
updatedAt,
version,
menuId,
defaultTemplate,
...rest
} = node;
const meta = Object.keys(rest.meta).reduce((acc, key) => {
const meta = rest.meta[key];
if (meta == null || meta === '') {
Expand Down
5 changes: 3 additions & 2 deletions src/components/Menu/Revisions/Diff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export const MenuRevisionsDiff = ({ id, diff, snapshot, renderTemplateChanges }:
field === 'parentId' ||
field === 'menuId' ||
field === 'menu' ||
field === 'defaultTemplate' ||
field === 'createdAt' ||
field === 'updatedAt' ||
field === 'deletedAt' ||
Expand Down Expand Up @@ -284,8 +285,8 @@ export const MenuRevisionsDiff = ({ id, diff, snapshot, renderTemplateChanges }:
);
return Object.keys(items)
.sort((a, b) => {
const aOrder = items[a].order;
const bOrder = items[b].order;
const aOrder = items[a]?.order;
const bOrder = items[b]?.order;
if (!aOrder || !bOrder) return Number(a) - Number(b);
if (aOrder < bOrder) return -1;
if (aOrder > bOrder) return 1;
Expand Down
5 changes: 3 additions & 2 deletions src/i18n/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@
"title": "Edit Template",
"templateFormat": {
"title": "Template Format",
"description": "The template format defines how it will be rendered before sending it to your application. You can use the variables below to define the template using the <2>EJS</2> (Embedded JavaScript) syntax.",
"description": "The template format defines how it will be rendered before sending it to your application. You can use the variables below to define the template using the <2>Handlebars</2> syntax.",
"formats": {
"json": "JSON",
"xml": "XML",
Expand Down Expand Up @@ -354,7 +354,8 @@
"notification": {
"success": "The menu version was published successfully"
},
"noChanges": "No changes were made to the menu."
"noChanges": "No changes were made to the menu.",
"noTemplate": "The menu version does not have a template."
}
}
}
5 changes: 3 additions & 2 deletions src/i18n/locales/pt-BR/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@
"title": "Editar Template",
"templateFormat": {
"title": "Formato do Template",
"description": "O formato do template define como ele será renderizado antes de enviar para a sua aplicação. Você pode usar as variáveis abaixo para definir o template usando a sintaxe do <2>EJS</2> (Embedded JavaScript).",
"description": "O formato do template define como ele será renderizado antes de enviar para a sua aplicação. Você pode usar as variáveis abaixo para definir o template usando a sintaxe do <2>Handlebars</2>.",
"formats": {
"json": "JSON",
"xml": "XML",
Expand Down Expand Up @@ -353,7 +353,8 @@
"notification": {
"success": "Versão do menu publicada com sucesso"
},
"noChanges": "Nenhuma alteração foi feita no menu."
"noChanges": "Nenhuma alteração foi feita no menu.",
"noTemplate": "A versão do menu não possui um template definido."
}
}
}
Loading