This is an automated email from the ASF dual-hosted git repository.
bbovenzi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 5c384e12de Remove legacy dag code (#33058)
5c384e12de is described below
commit 5c384e12dea898b0bf8dee44df115e33942686a6
Author: Brent Bovenzi <[email protected]>
AuthorDate: Thu Aug 3 18:46:49 2023 +0800
Remove legacy dag code (#33058)
* Remove legacy dag code and redirect to grid view
* update docs image
---
airflow/www/static/js/dag.js | 9 +++++
.../static/js/dag/details/dagCode/CodeBlock.tsx | 5 ++-
airflow/www/static/js/dag_code.js | 35 ----------------
airflow/www/templates/airflow/dag.html | 2 +-
airflow/www/templates/airflow/dag_code.html | 45 ---------------------
airflow/www/views.py | 33 +++------------
airflow/www/webpack.config.js | 1 -
docs/apache-airflow/img/code.png | Bin 169890 -> 506092 bytes
8 files changed, 20 insertions(+), 110 deletions(-)
diff --git a/airflow/www/static/js/dag.js b/airflow/www/static/js/dag.js
index c3d0cd7475..39a26f28e6 100644
--- a/airflow/www/static/js/dag.js
+++ b/airflow/www/static/js/dag.js
@@ -49,18 +49,27 @@ const onTabChange = () => {
const gridNav = document.getElementById("grid-nav");
const graphNav = document.getElementById("graph-nav");
const ganttNav = document.getElementById("gantt-nav");
+ const codeNav = document.getElementById("code-nav");
if (isGrid) {
if (tab === "graph") {
gridNav.classList.remove("active");
ganttNav.classList.remove("active");
+ codeNav.classList.remove("active");
graphNav.classList.add("active");
} else if (tab === "gantt") {
gridNav.classList.remove("active");
graphNav.classList.remove("active");
+ codeNav.classList.remove("active");
ganttNav.classList.add("active");
+ } else if (tab === "code") {
+ gridNav.classList.remove("active");
+ graphNav.classList.remove("active");
+ ganttNav.classList.remove("active");
+ codeNav.classList.add("active");
} else {
graphNav.classList.remove("active");
ganttNav.classList.remove("active");
+ codeNav.classList.remove("active");
gridNav.classList.add("active");
}
}
diff --git a/airflow/www/static/js/dag/details/dagCode/CodeBlock.tsx
b/airflow/www/static/js/dag/details/dagCode/CodeBlock.tsx
index 0d78db7500..baa673bbe1 100644
--- a/airflow/www/static/js/dag/details/dagCode/CodeBlock.tsx
+++ b/airflow/www/static/js/dag/details/dagCode/CodeBlock.tsx
@@ -22,6 +22,7 @@ import { oneLight } from
"react-syntax-highlighter/dist/esm/styles/prism";
import python from "react-syntax-highlighter/dist/esm/languages/prism/python";
import React, { useState } from "react";
import { Box, Button } from "@chakra-ui/react";
+import { getMetaValue } from "src/utils";
SyntaxHighlighter.registerLanguage("python", python);
@@ -29,7 +30,9 @@ interface Props {
code: string;
}
export default function CodeBlock({ code }: Props) {
- const [codeWrap, setCodeWrap] = useState(false);
+ const [codeWrap, setCodeWrap] = useState(
+ getMetaValue("default_wrap") === "True"
+ );
const toggleCodeWrap = () => setCodeWrap(!codeWrap);
return (
diff --git a/airflow/www/static/js/dag_code.js
b/airflow/www/static/js/dag_code.js
deleted file mode 100644
index 73e1dc4413..0000000000
--- a/airflow/www/static/js/dag_code.js
+++ /dev/null
@@ -1,35 +0,0 @@
-/*!
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-/* global window, $ */
-
-import { getMetaValue } from "./utils";
-
-function toggleWrap() {
- $(".code pre").toggleClass("wrap");
-}
-
-const isWrapped = getMetaValue("wrapped");
-
-// pygments generates the HTML so set wrap toggle via js
-if (isWrapped === "True") {
- toggleWrap();
-}
-
-window.toggleWrap = toggleWrap;
diff --git a/airflow/www/templates/airflow/dag.html
b/airflow/www/templates/airflow/dag.html
index 1fa2153509..4fc11ea138 100644
--- a/airflow/www/templates/airflow/dag.html
+++ b/airflow/www/templates/airflow/dag.html
@@ -210,7 +210,7 @@
<li><a href="{{ url_for('Airflow.dag_details', dag_id=dag.dag_id)
}}">
<span class="material-icons" aria-hidden="true">details</span>
Details</a></li>
- <li><a href="{{ url_for('Airflow.code', dag_id=dag.dag_id,
root=root) }}">
+ <li id="code-nav"><a href="{{ url_for('Airflow.code',
dag_id=dag.dag_id, root=root) }}">
<span class="material-icons" aria-hidden="true">code</span>
Code</a></li>
<li><a href="{{ url_for('Airflow.audit_log', dag_id=dag.dag_id,
root=root) }}">
diff --git a/airflow/www/templates/airflow/dag_code.html
b/airflow/www/templates/airflow/dag_code.html
deleted file mode 100644
index bce4eb19b0..0000000000
--- a/airflow/www/templates/airflow/dag_code.html
+++ /dev/null
@@ -1,45 +0,0 @@
-{#
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
-#}
-
-{% extends "airflow/dag.html" %}
-
-{% block page_title %}{{ dag.dag_id }} - Code - {{ appbuilder.app_name }}{%
endblock %}
-
-{% block head_meta %}
- {{ super() }}
- <meta name="wrapped" content="{{ wrapped }}">
-{% endblock %}
-
-{% block content %}
- {{ super() }}
- {% if dag_model is defined and dag_model.last_parsed_time is defined %}
- <h4 class="parsed-at" style="padding-left: 50px;">
- Parsed at: <time datetime="{{ dag_model.last_parsed_time }}">{{
dag_model.last_parsed_time }}</time>
- </h4>
- {% endif %}
- <div class="code-wrap">
- <a onclick="toggleWrap()" class="btn btn-default code-wrap-toggle">Toggle
Wrap</a>
- {{ html_code }}
- </div>
-{% endblock %}
-
-{% block tail_js %}
- {{ super() }}
- <script src="{{ url_for_asset('dagCode.js') }}"></script>
-{% endblock %}
diff --git a/airflow/www/views.py b/airflow/www/views.py
index 4227d13eb5..f69634f7cf 100644
--- a/airflow/www/views.py
+++ b/airflow/www/views.py
@@ -67,8 +67,6 @@ from jinja2.utils import htmlsafe_json_dumps, pformat #
type: ignore
from markupsafe import Markup, escape
from pendulum.datetime import DateTime
from pendulum.parsing.exceptions import ParserError
-from pygments import highlight, lexers
-from pygments.formatters import HtmlFormatter
from sqlalchemy import Date, and_, case, desc, func, inspect, or_, select,
union_all
from sqlalchemy.exc import IntegrityError
from sqlalchemy.orm import Session, joinedload
@@ -100,7 +98,6 @@ from airflow.jobs.triggerer_job_runner import
TriggererJobRunner
from airflow.models import Connection, DagModel, DagTag, Log, SlaMiss,
TaskFail, Trigger, XCom, errors
from airflow.models.abstractoperator import AbstractOperator
from airflow.models.dag import DAG, get_dataset_triggered_next_run_info
-from airflow.models.dagcode import DagCode
from airflow.models.dagrun import RUN_ID_REGEX, DagRun, DagRunType
from airflow.models.dataset import DagScheduleDatasetReference,
DatasetDagRunQueue, DatasetEvent, DatasetModel
from airflow.models.mappedoperator import MappedOperator
@@ -1320,31 +1317,13 @@ class Airflow(AirflowBaseView):
@provide_session
def code(self, dag_id, session: Session = NEW_SESSION):
"""Dag Code."""
- dag = get_airflow_app().dag_bag.get_dag(dag_id, session=session)
- dag_model = DagModel.get_dagmodel(dag_id, session=session)
- if not dag or not dag_model:
- flash(f'DAG "{dag_id}" seems to be missing.', "error")
- return redirect(url_for("Airflow.index"))
-
- wwwutils.check_import_errors(dag_model.fileloc, session)
- wwwutils.check_dag_warnings(dag_model.dag_id, session)
-
- try:
- code = DagCode.get_code_by_fileloc(dag_model.fileloc)
- html_code = Markup(highlight(code, lexers.PythonLexer(),
HtmlFormatter(linenos=True)))
- except Exception as e:
- error = f"Exception encountered during dag code retrieval/code
highlighting:\n\n{e}\n"
- html_code = Markup("<p>Failed to load DAG file
Code.</p><p>Details: {}</p>").format(escape(error))
+ kwargs = {
+ **sanitize_args(request.args),
+ "dag_id": dag_id,
+ "tab": "code",
+ }
- return self.render_template(
- "airflow/dag_code.html",
- html_code=html_code,
- dag=dag,
- dag_model=dag_model,
- title=dag_id,
- root=request.args.get("root"),
- wrapped=conf.getboolean("webserver", "default_wrap"),
- )
+ return redirect(url_for("Airflow.grid", **kwargs))
@expose("/dag_details")
@auth.has_access(
diff --git a/airflow/www/webpack.config.js b/airflow/www/webpack.config.js
index 2483faea32..fc5c6a6497 100644
--- a/airflow/www/webpack.config.js
+++ b/airflow/www/webpack.config.js
@@ -61,7 +61,6 @@ const config = {
connectionForm: `${JS_DIR}/connection_form.js`,
chart: [`${CSS_DIR}/chart.css`],
dag: `${JS_DIR}/dag.js`,
- dagCode: `${JS_DIR}/dag_code.js`,
dagDependencies: `${JS_DIR}/dag_dependencies.js`,
dags: [`${CSS_DIR}/dags.css`, `${JS_DIR}/dags.js`],
flash: `${CSS_DIR}/flash.css`,
diff --git a/docs/apache-airflow/img/code.png b/docs/apache-airflow/img/code.png
index c65095a901..8c7513f4ce 100644
Binary files a/docs/apache-airflow/img/code.png and
b/docs/apache-airflow/img/code.png differ