Skip to content

Commit

Permalink
Merge pull request #2815 from uktrade/feat/snippets-copy-and-styling
Browse files Browse the repository at this point in the history
Remove the "View data structure" section from code snippets
  • Loading branch information
ian-leggett authored Oct 20, 2023
2 parents 61187da + 31bbd3c commit 8d1634e
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ <h2 class="govuk-heading-l">{{ object.name }}</h2>
</div>
<div class="govuk-grid-column-full">
{% if columns or code_snippets and has_access %}
{% if columns %}
{% include "partials/column_list.html" with columns=columns dataset=dataset source=datacut_link %}
{% endif %}
{% if code_snippets and has_access %}
<details class="govuk-details govuk-!-margin-bottom-2" data-module="govuk-details">
<summary class="govuk-details__summary">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ <h2 class="govuk-heading-l">{{ object.name }}</h2>
</div>
<div class="govuk-grid-column-full">
{% if columns or code_snippets and has_access %}
{% if columns %}
{% include "partials/column_list.html" with columns=columns dataset=dataset source=datacut_link %}
{% endif %}
{% if code_snippets and has_access %}
<details class="govuk-details govuk-!-margin-bottom-2" data-module="govuk-details">
<summary class="govuk-details__summary">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,36 +78,11 @@ <h2 class="govuk-heading-l">{{ model.name }} </h2>
</div>
<div class="govuk-grid-column-full">
{% if code_snippets or columns %}
{% if columns %}
<details class="govuk-details govuk"
data-module="govuk-details">
<summary class="govuk-details__summary">
<span class="govuk-details__summary-text">
View data structure <span class="govuk-visually-hidden">for "{{ model.name }}"</span>
</span>
</summary>
<div class="govuk-details__text">
<ul class="govuk-list govuk-list--bullet">
{% for column, data_type in columns|slice:":12" %}
<li>
<strong>{{ column }}</strong> ({{ data_type }})
</li>
{% endfor %}
{% if columns|length > 12 %}
<a class="govuk-link"
href="{% url 'datasets:reference_dataset_column_details' dataset_uuid=model.uuid %}">
View all columns <span class="govuk-visually-hidden">for "{{ model.name }}"</span>
</a>
{% endif %}
</ul>
</div>
</details>
{% endif %}
{% if model.external_database %}
<details class="govuk-details govuk" data-module="govuk-details">
<details class="govuk-details govuk govuk-!-margin-bottom-2" data-module="govuk-details">
<summary class="govuk-details__summary">
<span class="govuk-details__summary-text">
Use this data <span class="govuk-visually-hidden">for "{{ model.name }}"</span>
Use this data for analysis
</span>
</summary>
<div class="govuk-details__text">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,6 @@ <h2 class="govuk-heading-l govuk-!-margin-top-8">Data</h2>
{% if columns or code_snippets and has_access %}
<tr class="govuk-table__row">
<td colspan="6" class="govuk-table__cell">
{% if columns %}
{% include "partials/column_list.html" with columns=columns dataset=dataset source=datacut_link %}
{% endif %}
{% if code_snippets and has_access %}
<details class="govuk-details govuk-!-margin-bottom-2" data-module="govuk-details">
<summary class="govuk-details__summary">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,6 @@ <h2 class="govuk-heading-l">Data</h2>
{% if code_snippets or columns %}
<tr class="govuk-table__row">
<td colspan="{% flag DATASET_CHANGELOG_PAGE_FLAG %}5{% else %}4{% endflag %}" class="govuk-table__cell">
{% if columns %}
<div class="govuk-!-margin-bottom-6">
{% include "partials/column_list.html" with columns=columns dataset=dataset source=source_table %}
</div>
{% endif %}

{% if has_access %}
<details class="govuk-details govuk-!-margin-bottom-6" data-module="govuk-details">
<summary class="govuk-details__summary">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,36 +241,11 @@ <h2 class="govuk-heading-l">Data</h2>
</tbody>
</table>
{% if code_snippets or columns %}
{% if columns %}
<details class="govuk-details govuk"
data-module="govuk-details">
<summary class="govuk-details__summary">
<span class="govuk-details__summary-text">
View data structure <span class="govuk-visually-hidden">for "{{ model.name }}"</span>
</span>
</summary>
<div class="govuk-details__text">
<ul class="govuk-list govuk-list--bullet">
{% for column, data_type in columns|slice:":12" %}
<li>
<strong>{{ column }}</strong> ({{ data_type }})
</li>
{% endfor %}
{% if columns|length > 12 %}
<a class="govuk-link"
href="{% url 'datasets:reference_dataset_column_details' dataset_uuid=model.uuid %}">
View all columns <span class="govuk-visually-hidden">for "{{ model.name }}"</span>
</a>
{% endif %}
</ul>
</div>
</details>
{% endif %}
{% if model.external_database %}
<details class="govuk-details govuk" data-module="govuk-details">
<summary class="govuk-details__summary">
<span class="govuk-details__summary-text">
Use this data <span class="govuk-visually-hidden">for "{{ model.name }}"</span>
Use this data for analysis
</span>
</summary>
<div class="govuk-details__text">
Expand Down
28 changes: 0 additions & 28 deletions dataworkspace/dataworkspace/templates/partials/column_list.html

This file was deleted.

79 changes: 0 additions & 79 deletions dataworkspace/dataworkspace/tests/datasets/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1773,52 +1773,6 @@ def test_reference_dataset_shows_code_snippets(self, mock_sync):
in response.content.decode(response.charset)
)

@pytest.mark.parametrize(
"request_client,published",
[("client", True), ("staff_client", True), ("staff_client", False)],
indirect=["request_client"],
)
@pytest.mark.django_db
def test_reference_dataset_shows_column_details(self, request_client, published):
group = factories.DataGroupingFactory.create()
external_db = factories.DatabaseFactory.create(memorable_name="my_database")
rds = factories.ReferenceDatasetFactory.create(
published=published,
group=group,
external_database=external_db,
)
field1 = factories.ReferenceDatasetFieldFactory.create(
reference_dataset=rds,
name="code",
column_name="code",
data_type=2,
is_identifier=True,
)
field2 = factories.ReferenceDatasetFieldFactory.create(
reference_dataset=rds, name="name", column_name="name", data_type=1
)
rds.save_record(
None,
{
"reference_dataset": rds,
field1.column_name: 1,
field2.column_name: "Test record",
},
)
rds.save_record(
None,
{
"reference_dataset": rds,
field1.column_name: 2,
field2.column_name: "Ánd again",
},
)
response = request_client.get(rds.get_absolute_url())

assert response.status_code == 200
assert "<strong>code</strong> (integer)" in response.content.decode(response.charset)
assert "<strong>name</strong> (text)" in response.content.decode(response.charset)

@pytest.mark.parametrize(
"request_client,published",
[("client", True), ("staff_client", True), ("staff_client", False)],
Expand Down Expand Up @@ -2002,39 +1956,6 @@ def test_datacut_dataset_shows_code_snippets_to_tool_user(metadata_db):
assert """SELECT * FROM foo""" in response.content.decode(response.charset)


@pytest.mark.parametrize(
"dataset_type, source_factory,source_type",
(
(DataSetType.MASTER, factories.SourceTableFactory, "table"),
(DataSetType.DATACUT, factories.CustomDatasetQueryFactory, "datacut"),
),
)
@mock.patch("dataworkspace.apps.datasets.views.datasets_db.get_columns")
@pytest.mark.django_db
def test_dataset_shows_first_12_columns_of_source_table_with_link_to_the_rest(
get_columns_mock, dataset_type, source_factory, source_type, metadata_db
):
ds = factories.DataSetFactory.create(type=dataset_type, published=True)
user = get_user_model().objects.create(email="test@example.com", is_superuser=False)
factories.DataSetUserPermissionFactory.create(user=user, dataset=ds)
st = source_factory.create(
dataset=ds,
database=factories.DatabaseFactory(memorable_name="my_database"),
)
get_columns_mock.return_value = [(f"column_{i}", "integer") for i in range(20)]

client = Client(**get_http_sso_data(user))
response = client.get(ds.get_absolute_url())
response_body = response.content.decode(response.charset)
doc = html.fromstring(response_body)

assert response.status_code == 200
for i in range(12):
assert f"<strong>column_{i}</strong> (integer)" in response_body

assert len(doc.xpath(f"//a[@href = '/datasets/{ds.id}/{source_type}/{st.id}/columns']")) == 1


@pytest.mark.django_db(transaction=True)
def test_launch_master_dataset_in_data_explorer(metadata_db):
ds = factories.DataSetFactory.create(type=DataSetType.MASTER, published=True)
Expand Down

0 comments on commit 8d1634e

Please sign in to comment.