Skip to content

Commit

Permalink
Merge pull request #207 from frappe/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
surajshetty3416 authored Aug 27, 2024
2 parents 27c90d8 + a252085 commit 5b94fe5
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 29 deletions.
32 changes: 29 additions & 3 deletions .github/workflows/ci.yml → .github/workflows/server-tests.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

name: CI
name: Server Tests

on:
push:
branches:
- master
- develop
pull_request:

jobs:
Expand Down Expand Up @@ -83,7 +84,7 @@ jobs:
working-directory: /home/runner/frappe-bench
run: |
bench get-app builder $GITHUB_WORKSPACE
bench setup requirements
bench setup requirements --dev
bench new-site --db-root-password root --admin-password admin test_site
bench --site test_site install-app builder
bench build
Expand All @@ -94,6 +95,31 @@ jobs:
working-directory: /home/runner/frappe-bench
run: |
bench --site test_site set-config allow_tests true
bench --site test_site run-tests --app builder
bench --site test_site run-tests --app builder --coverage
env:
TYPE: server

- name: Upload coverage data
uses: actions/upload-artifact@v3
with:
name: coverage-${{ matrix.container }}
path: /home/runner/frappe-bench/sites/coverage.xml

coverage:
name: Coverage Wrap Up
needs: tests
runs-on: ubuntu-latest
steps:
- name: Clone
uses: actions/checkout@v3

- name: Download artifacts
uses: actions/download-artifact@v3

- name: Upload coverage data
uses: codecov/codecov-action@v3
with:
name: Server
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
verbose: true
21 changes: 16 additions & 5 deletions builder/builder/doctype/builder_page/builder_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,26 @@ def before_insert(self):
)

def on_update(self):
if self.has_value_changed("dynamic_route") or self.has_value_changed("route"):
get_web_pages_with_dynamic_routes.clear_cache()
find_page_with_path.clear_cache()
if (
self.has_value_changed("dynamic_route")
or self.has_value_changed("route")
or self.has_value_changed("published")
):
self.clear_route_cache()

if self.has_value_changed("published") and not self.published:
find_page_with_path.clear_cache()
clear_cache(self.route)
# if this is homepage then clear homepage from builder settings
if frappe.get_cached_value("Builder Settings", None, "home_page") == self.route:
frappe.db.set_value("Builder Settings", None, "home_page", None)

if frappe.conf.developer_mode and self.is_template:
save_as_template(self)

def clear_route_cache(self):
get_web_pages_with_dynamic_routes.clear_cache()
find_page_with_path.clear_cache()
clear_cache(self.route)

def on_trash(self):
if self.is_template and frappe.conf.developer_mode:
page_template_folder = os.path.join(
Expand Down Expand Up @@ -141,6 +147,11 @@ def publish(self, **kwargs):

return self.route

@frappe.whitelist()
def unpublish(self, **kwargs):
self.published = 0
self.save()

def get_context(self, context):
# delete default favicon
del context.favicon
Expand Down
59 changes: 57 additions & 2 deletions builder/builder/doctype/builder_page/test_builder_page.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,64 @@
# Copyright (c) 2023, asdf and Contributors
# See license.txt

# import frappe
import frappe
from frappe.desk.form.load import getdoc
from frappe.tests.utils import FrappeTestCase
from frappe.website.serve import get_response_content


class TestBuilderPage(FrappeTestCase):
pass
@classmethod
def setUpClass(cls):
cls.page = frappe.get_doc(
{
"doctype": "Builder Page",
"name": "test-page",
"page_title": "Test Page",
"published": 1,
"route": "/test-page",
"blocks": [{"element": "body", "children": [{"element": "h1", "innerHTML": "Hello World!"}]}],
}
).insert(ignore_if_duplicate=True)
cls.page_with_dynamic_route = frappe.get_doc(
{
"doctype": "Builder Page",
"page_title": "Test Page Dynamic Route",
"published": 1,
"route": "/test-page-dynamic-route/<name>",
"dynamic_route": 1,
"blocks": [
{"element": "body", "children": [{"element": "h1", "innerHTML": "Dynamic Content!"}]}
],
}
).insert(ignore_if_duplicate=True)

def test_can_render(self):
content = get_response_content("/test-page")
self.assertTrue("Hello World!" in content)

def test_onload(self):
getdoc("Builder Page", self.page.name)
self.assertEqual(frappe.response.docs[0].get("__onload").get("builder_path"), "builder")

def test_dynamic_route(self):
from frappe.utils import get_html_for_route

content = get_html_for_route("/test-page-dynamic-route/123")
self.assertTrue("Dynamic Content!" in content)

def test_publish_unpublish(self):
self.page.unpublish()
from frappe.utils import get_html_for_route

content = get_html_for_route("/test-page")
self.assertTrue("The page you are looking for has gone missing" in content)

self.page.publish()
content = get_response_content("/test-page")
self.assertTrue("Hello World!" in content)

@classmethod
def tearDownClass(cls):
cls.page.delete()
cls.page_with_dynamic_route.delete()
4 changes: 2 additions & 2 deletions builder/www/_builder.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import frappe

no_cache = 1
from frappe.utils.telemetry import capture

from builder.hooks import builder_path

no_cache = 1


def get_context(context):
csrf_token = frappe.sessions.get_csrf_token()
Expand Down
26 changes: 13 additions & 13 deletions frontend/src/components/BuilderCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -648,27 +648,27 @@ const toggleBlockSelection = (_block: Block) => {
}
};
const selectBlockRange = (_block: Block) => {
const selectBlockRange = (newSelectedBlock: Block) => {
const lastSelectedBlockId = selectedBlockIds.value[selectedBlockIds.value.length - 1];
const lastSelectedBlock = findBlock(lastSelectedBlockId);
if (!lastSelectedBlock) {
_block.selectBlock();
const lastSelectedBlockParent = lastSelectedBlock?.parentBlock;
if (!lastSelectedBlock || !lastSelectedBlockParent) {
newSelectedBlock.selectBlock();
return;
}
const lastSelectedBlockIndex = lastSelectedBlock.parentBlock?.children.indexOf(lastSelectedBlock);
const _blockIndex = _block.parentBlock?.children.indexOf(_block);
if (lastSelectedBlockIndex === undefined || _blockIndex === undefined) {
const newSelectedBlockIndex = newSelectedBlock.parentBlock?.children.indexOf(newSelectedBlock);
const newSelectedBlockParent = newSelectedBlock.parentBlock;
if (lastSelectedBlockIndex === undefined || newSelectedBlockIndex === undefined) {
return;
}
const start = Math.min(lastSelectedBlockIndex, _blockIndex);
const end = Math.max(lastSelectedBlockIndex, _blockIndex);
const parentBlock = lastSelectedBlock.parentBlock;
if (!parentBlock) {
return;
const start = Math.min(lastSelectedBlockIndex, newSelectedBlockIndex);
const end = Math.max(lastSelectedBlockIndex, newSelectedBlockIndex);
if (lastSelectedBlockParent === newSelectedBlockParent) {
const blocks = lastSelectedBlockParent.children.slice(start, end + 1);
selectedBlockIds.value = selectedBlockIds.value.concat(...blocks.map((b) => b.blockId));
selectedBlockIds.value = Array.from(new Set(selectedBlockIds.value));
}
const blocks = parentBlock.children.slice(start, end + 1);
selectedBlockIds.value = selectedBlockIds.value.concat(...blocks.map((b) => b.blockId));
selectedBlockIds.value = Array.from(new Set(selectedBlockIds.value));
};
const clearSelection = () => {
Expand Down
7 changes: 4 additions & 3 deletions frontend/src/components/PageScript.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
height="65vh"
@save="savePageDataScript"
:showSaveButton="true"
description='Can be used to fetch dynamic data from server and pass it to the page.
<br />
eg. data.events = frappe.get_list("Event")'
description='Use Data Script to provide dynamic data to your web page.<br>
<b>Example:</b> data.events = frappe.get_list("Event")<br><br>
For more details on how to write data script, refer to <b><a class="underline" href="https://docs.frappe.io/builder/data-script" target="_blank">this documentation</a></b>.
'
:show-line-numbers="true"></CodeEditor>
</div>
</template>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/TextBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
}"
v-if="editor"
class="z-50 rounded-md border border-gray-300 bg-white p-1 text-lg">
class="z-50 rounded-md border border-gray-300 bg-white p-1 text-lg shadow-2xl">
<div v-if="settingLink" class="flex">
<Input
v-model="textLink"
Expand Down

0 comments on commit 5b94fe5

Please sign in to comment.