Skip to content

Commit

Permalink
Use cfg default_wrap value for grid logs (#25731)
Browse files Browse the repository at this point in the history
* Use cfg default_wrap value for grid logs

* Use meta tag to pass default_wrap data to the grid
  • Loading branch information
pierrejeambrun committed Aug 17, 2022
1 parent 69663b2 commit 48d2876
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
33 changes: 33 additions & 0 deletions airflow/www/static/js/dag/details/taskInstance/Logs/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import type { UseQueryResult } from 'react-query';

import * as utils from 'src/utils';
import * as useTaskLogModule from 'src/api/useTaskLog';

import Logs from './index';
Expand Down Expand Up @@ -88,6 +89,38 @@ describe('Test Logs Component.', () => {
});
});

test.each([
{ defaultWrap: 'True', shouldBeChecked: true },
{ defaultWrap: 'False', shouldBeChecked: false },
{ defaultWrap: '', shouldBeChecked: false },
])('Test wrap checkbox initial value $defaultWrap', ({ defaultWrap, shouldBeChecked }) => {
jest.spyOn(utils, 'getMetaValue').mockImplementation(
(meta) => {
if (meta === 'default_wrap') return defaultWrap;
return '';
},
);

const tryNumber = 2;
const { getByTestId } = render(
<Logs
dagId="dummyDagId"
dagRunId="dummyDagRunId"
taskId="dummyTaskId"
executionDate="2020:01:01T01:00+00:00"
mapIndex={1}
tryNumber={tryNumber}
/>,
);

const wrapCheckbox = getByTestId('wrap-checkbox');
if (shouldBeChecked) {
expect(wrapCheckbox).toHaveAttribute('data-checked');
} else {
expect(wrapCheckbox.getAttribute('data-checked')).toBeNull();
}
});

test('Test Logs Content Mapped Task', () => {
const tryNumber = 2;
const { getByText } = render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ const Logs = ({
const [internalIndexes, externalIndexes] = getLinkIndexes(tryNumber);
const [selectedAttempt, setSelectedAttempt] = useState(1);
const [shouldRequestFullContent, setShouldRequestFullContent] = useState(false);
const [wrap, setWrap] = useState(false);
const [wrap, setWrap] = useState(getMetaValue('default_wrap') === 'True');
const [logLevelFilters, setLogLevelFilters] = useState<Array<LogLevelOption>>([]);
const [fileSourceFilters, setFileSourceFilters] = useState<Array<FileSourceOption>>([]);
const { timezone } = useTimezone();
Expand Down Expand Up @@ -216,8 +216,10 @@ const Logs = ({
</Flex>
<Flex alignItems="center">
<Checkbox
isChecked={wrap}
onChange={() => setWrap((previousState) => !previousState)}
px={4}
data-testid="wrap-checkbox"
>
<Text as="strong">Wrap</Text>
</Checkbox>
Expand Down
1 change: 1 addition & 0 deletions airflow/www/templates/airflow/grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<meta name="num_runs" content="{{ num_runs }}">
<meta name="root" content="{{ root if root else '' }}">
<meta name="base_date" content="{{ request.args.get('base_date') if request.args.get('base_date') else '' }}">
<meta name="default_wrap" content="{{ default_wrap }}">
{% endblock %}

{% block content %}
Expand Down
1 change: 1 addition & 0 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2745,6 +2745,7 @@ def grid(self, dag_id, session=None):
dag_model=dag_model,
auto_refresh_interval=conf.getint('webserver', 'auto_refresh_interval'),
default_dag_run_display_number=default_dag_run_display_number,
default_wrap=conf.getboolean('webserver', 'default_wrap'),
filters_drop_down_values=htmlsafe_json_dumps(
{
"taskStates": [state.value for state in TaskInstanceState],
Expand Down

0 comments on commit 48d2876

Please sign in to comment.