-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3363 from uktrade/feat/managed-data-tile
Feat/managed data tile
- Loading branch information
Showing
14 changed files
with
324 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from rest_framework.routers import DefaultRouter | ||
|
||
from dataworkspace.apps.api_v2.managed_data.views import ManagedDataViewSet | ||
|
||
router = DefaultRouter() | ||
router.register(r"managed_data", ManagedDataViewSet) | ||
urlpatterns = router.urls |
38 changes: 38 additions & 0 deletions
38
dataworkspace/dataworkspace/apps/api_v2/managed_data/views.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from django.db.models import Q | ||
from django.urls import reverse | ||
from rest_framework import viewsets | ||
from rest_framework.decorators import action | ||
from rest_framework.pagination import PageNumberPagination | ||
from rest_framework.authentication import SessionAuthentication | ||
from rest_framework.permissions import IsAuthenticated | ||
from rest_framework.response import Response | ||
|
||
from dataworkspace.apps.api_v1.mixins import TimestampFilterMixin | ||
from dataworkspace.apps.datasets.models import DataSet | ||
|
||
|
||
class TimestampPageNumberPagination(PageNumberPagination): | ||
page_size_query_param = "page_size" | ||
max_page_size = 100 | ||
|
||
|
||
class ManagedDataViewSet(TimestampFilterMixin, viewsets.ModelViewSet): | ||
queryset = DataSet.objects.live() | ||
pagination_class = TimestampPageNumberPagination | ||
authentication_classes = [SessionAuthentication] | ||
permission_classes = [IsAuthenticated] | ||
|
||
def get_queryset(self): | ||
user_id = self.request.user.id | ||
return ( | ||
super() | ||
.get_queryset() | ||
.filter(Q(information_asset_manager=user_id) | Q(information_asset_owner=user_id)) | ||
) | ||
|
||
@action(detail=False, methods=["get"], url_path="stats") | ||
def stats(self, request, *args, **kwargs): | ||
kwargs = "?q=&sort=relevance&my_datasets=owned" | ||
managed_data_url = f"{reverse('datasets:find_datasets')}{kwargs}" | ||
count = self.get_queryset().count() | ||
return Response({"count": count, "managed_data_url": managed_data_url}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...ataworkspace/static/js/react/features/home-page/components/ManageData/ManageData.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { render } from '@testing-library/react'; | ||
|
||
import { ManagedDataResponse } from '../../../../types'; | ||
import ManagedData from '.'; | ||
|
||
describe('RecentCollections', () => { | ||
const managed_data_stats_multiple_datasets: ManagedDataResponse = { | ||
count: 5, | ||
managed_data_url: '/datasets?q=' | ||
}; | ||
|
||
const managed_data_stats_single_dataset: ManagedDataResponse = { | ||
count: 1, | ||
managed_data_url: '/datasets?q=' | ||
}; | ||
|
||
const managed_data_stats_no_dataset: ManagedDataResponse = { | ||
count: 0, | ||
managed_data_url: '/datasets?q=' | ||
}; | ||
|
||
describe('With results', () => { | ||
it('should render a title', () => { | ||
const { getByRole } = render( | ||
<ManagedData | ||
managed_data_stats={managed_data_stats_multiple_datasets} | ||
/> | ||
); | ||
expect( | ||
getByRole('heading', { | ||
level: 2, | ||
// eslint-disable-next-line quotes | ||
name: "You're the owner or manager of 5 datasets" | ||
}) | ||
); | ||
}); | ||
it('should render a title in the singular', () => { | ||
const { getByRole } = render( | ||
<ManagedData managed_data_stats={managed_data_stats_single_dataset} /> | ||
); | ||
expect( | ||
getByRole('heading', { | ||
level: 2, | ||
// eslint-disable-next-line quotes | ||
name: "You're the owner or manager of 1 dataset" | ||
}) | ||
); | ||
}); | ||
it('should not render at all', () => { | ||
const { queryByRole } = render( | ||
<ManagedData managed_data_stats={managed_data_stats_no_dataset} /> | ||
); | ||
expect( | ||
queryByRole('heading', { | ||
level: 2, | ||
// eslint-disable-next-line quotes | ||
name: "You're the owner or manager of 0 dataset" | ||
}) | ||
).not.toBeInTheDocument(); | ||
}); | ||
it('should render a link to the manage data page', () => { | ||
const { getByRole } = render( | ||
<ManagedData managed_data_stats={managed_data_stats_single_dataset} /> | ||
); | ||
expect( | ||
getByRole('link', { name: 'View and manage your data' }) | ||
).toHaveAttribute('href', '/datasets?q='); | ||
}); | ||
it('should render a link to helpcentre guidance', () => { | ||
const { getByRole } = render( | ||
<ManagedData managed_data_stats={managed_data_stats_single_dataset} /> | ||
); | ||
expect( | ||
getByRole('link', { | ||
// eslint-disable-next-line quotes | ||
name: "Learn how to maintain and manage data you're responsible for on Data Workspace" | ||
}) | ||
).toHaveAttribute( | ||
'href', | ||
'https://data-services-help.trade.gov.uk/data-workspace/how-to/data-owner-basics/managing-data-key-tasks-and-responsibilities' | ||
); | ||
}); | ||
it('should not render a link to helpcentre guidance', () => { | ||
const { queryByRole } = render( | ||
<ManagedData managed_data_stats={managed_data_stats_no_dataset} /> | ||
); | ||
expect( | ||
queryByRole('link', { | ||
// eslint-disable-next-line quotes | ||
name: "Learn how to maintain and manage data you're responsible for on Data Workspace" | ||
}) | ||
).not.toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.