Skip to content

Commit

Permalink
UI changes for DAG Reparsing feature
Browse files Browse the repository at this point in the history
releated: apache#39138
  • Loading branch information
utkarsharma2 committed May 15, 2024
1 parent 6bcec90 commit d3c6523
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions airflow/www/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,18 @@ $(document).ready(() => {
// Global Tooltip selector
$(".js-tooltip").tooltip();
});

$(".reparse_dag").click((event) => {
console.log(event);
event.preventDefault();
$.ajax({
url: event.currentTarget.attributes.href.value,
type: "PUT",
done(response) {
console.log(response);
},
fail(response) {
console.log(response);
},
});
});
6 changes: 6 additions & 0 deletions airflow/www/templates/airflow/dag.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,12 @@ <h4 class="js-dataset-triggered" style="user-select: none;-moz-user-select: auto
onclick="return confirmDeleteDag(this, '{{ dag.safe_dag_id }}')">
<span class="material-icons text-danger" aria-hidden="true">delete_outline</span>
</a>
<a href="{{ url_for('/api/v1.airflow_api_connexion_endpoints_dag_parsing_reparse_dag_file', file_token=dag.file_token) }}"
title="Reparse&nbsp;DAG"
aria-label="Reparse DAG"
class="btn btn-default btn-icon-only{{ ' disabled' if not dag.can_edit }} reparse_dag">
<span class="material-icons">cached</span>
</a>
</div>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions airflow/www/templates/airflow/dags.html
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ <h2>{{ page_title }}</h2>
class="btn btn-sm btn-default btn-icon-only{{ ' disabled' if not dag.can_delete }}">
<span class="material-icons text-danger" aria-hidden="true">delete_outline</span>
</a>
<a href="{{ url_for('/api/v1.airflow_api_connexion_endpoints_dag_parsing_reparse_dag_file', file_token=dag.file_token) }}" title="Reparse&nbsp;DAG" aria-label="Reparse DAG"
class="btn btn-sm btn-default btn-icon-only{{ ' disabled' if not dag.can_delete }} reparse_dag">
<span class="material-icons">cached</span>
</a>
{% endif %}
</div>
</td>
Expand Down
5 changes: 5 additions & 0 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
Response,
abort,
before_render_template,
current_app,
flash,
g,
has_request_context,
Expand All @@ -67,6 +68,7 @@
from flask_appbuilder.urltools import get_order_args, get_page_args, get_page_size_args
from flask_appbuilder.widgets import FormWidget
from flask_babel import lazy_gettext
from itsdangerous import URLSafeSerializer
from jinja2.utils import htmlsafe_json_dumps, pformat # type: ignore
from markupsafe import Markup, escape
from pendulum.datetime import DateTime
Expand Down Expand Up @@ -163,6 +165,7 @@
SENSITIVE_FIELD_PLACEHOLDER = "RATHER_LONG_SENSITIVE_FIELD_PLACEHOLDER"

logger = logging.getLogger(__name__)
url_serializer = URLSafeSerializer(current_app.config["SECRET_KEY"])


def sanitize_args(args: dict[str, Any]) -> dict[str, Any]:
Expand Down Expand Up @@ -937,6 +940,7 @@ def index(self):
dag.can_delete = get_auth_manager().is_authorized_dag(
method="DELETE", details=DagDetails(id=dag.dag_id), user=g.user
)
dag.file_token = url_serializer.dumps(dag.fileloc)

dagtags = session.execute(select(func.distinct(DagTag.name)).order_by(DagTag.name)).all()
tags = [
Expand Down Expand Up @@ -2846,6 +2850,7 @@ def grid(self, dag_id: str, session: Session = NEW_SESSION):
color_log_warning_keywords = conf.get("logging", "color_log_warning_keywords", fallback="")

dag = get_airflow_app().dag_bag.get_dag(dag_id, session=session)
dag.file_token = url_serializer.dumps(dag.fileloc)
dag_model = DagModel.get_dagmodel(dag_id, session=session)
if not dag:
flash(f'DAG "{dag_id}" seems to be missing from DagBag.', "error")
Expand Down

0 comments on commit d3c6523

Please sign in to comment.