-
Notifications
You must be signed in to change notification settings - Fork 9
feat(charts): show charts cards in admin #1210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nicolaskempf57
wants to merge
15
commits into
main
Choose a base branch
from
feat/show-charts-cards-in-admin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b4b88f5
feat(components): add ChartCard component
10a328c
feat(design): add Chart card section to cards design page
8a608eb
test(visualizations): add e2e tests for ChartCard on design page
2069e9f
add dedicated chart page
6e56871
feat: chart wip
nicolaskempf57 f1bdd50
feat: small changes
nicolaskempf57 9357b27
Merge branch 'main' into feat/show-charts-cards-in-admin
nicolaskempf57 986a4a1
fix: revert pnpm workspace changes
nicolaskempf57 24916fd
feat: handle private chart
nicolaskempf57 866c4d1
fix: dedupe menu icon
nicolaskempf57 824310b
feat: improve separation between v-model and initialChart
nicolaskempf57 ca2260b
feat: add deleted chart badge
nicolaskempf57 e46831b
feat: remove unwanted server: false
nicolaskempf57 2c54c4c
feat: PR review improvments
nicolaskempf57 9f23c52
Merge branch 'main' into feat/show-charts-cards-in-admin
nicolaskempf57 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,81 @@ | ||
| <template> | ||
| <div> | ||
| <AdminBreadcrumb> | ||
| <BreadcrumbItem>{{ t('Graphiques') }}</BreadcrumbItem> | ||
| </AdminBreadcrumb> | ||
|
|
||
| <h1 class="font-extrabold text-2xl text-gray-title mb-5"> | ||
| {{ t('Graphiques') }} | ||
| </h1> | ||
|
|
||
| <div | ||
| v-if="pageData" | ||
| class="flex flex-wrap gap-x-4 gap-y-2 items-center" | ||
| > | ||
| <div class="w-full flex-none md:flex-1"> | ||
| <h2 class="text-sm font-bold uppercase m-0"> | ||
| {{ t('{n} graphiques | {n} graphique | {n} graphiques', pageData.total) }} | ||
| </h2> | ||
| </div> | ||
| </div> | ||
|
|
||
| <LoadingBlock | ||
| v-slot="{ data: chartsPage }" | ||
| :status | ||
| :data="pageData" | ||
| > | ||
| <div v-if="chartsPage && chartsPage.total > 0"> | ||
| <div class="not-prose grid gap-4"> | ||
| <ChartCard | ||
| v-for="chart in chartsPage.data" | ||
| :key="chart.id" | ||
| :chart | ||
| :chart-url="`/admin/beta/charts/${chart.id}`" | ||
| /> | ||
| </div> | ||
| <Pagination | ||
| :page="page" | ||
| :page-size="pageSize" | ||
| :total-results="chartsPage.total" | ||
| @change="(changedPage: number) => page = changedPage" | ||
| /> | ||
| </div> | ||
|
nicolaskempf57 marked this conversation as resolved.
|
||
| </LoadingBlock> | ||
|
|
||
| <div | ||
| v-if="status != 'pending' && pageData && !pageData.total" | ||
| class="flex flex-col items-center" | ||
| > | ||
| <img | ||
| src="/illustrations/chart.svg" | ||
| class="h-20" | ||
| alt="" | ||
| > | ||
| <p class="fr-text--bold fr-my-3v"> | ||
| {{ t(`Il n'y a pas encore de graphique sur le site`) }} | ||
| </p> | ||
| </div> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { ChartCard, LoadingBlock, Pagination, type Chart } from '@datagouv/components-next' | ||
| import { ref } from 'vue' | ||
| import AdminBreadcrumb from '../Breadcrumbs/AdminBreadcrumb.vue' | ||
| import BreadcrumbItem from '../Breadcrumbs/BreadcrumbItem.vue' | ||
| import type { PaginatedArray } from '~/types/types' | ||
|
|
||
| const { t } = useTranslation() | ||
|
|
||
| const page = ref(1) | ||
| const pageSize = ref(20) | ||
|
|
||
| const params = computed(() => { | ||
| return { | ||
| page_size: pageSize.value, | ||
| page: page.value, | ||
| } | ||
| }) | ||
|
|
||
| const { data: pageData, status } = await useAPI<PaginatedArray<Chart>>('/api/1/visualizations/', { lazy: true, server: false, query: params }) | ||
| </script> | ||
This file contains hidden or 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 hidden or 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,86 @@ | ||
| <template> | ||
| <ObjectCard media-size="xl"> | ||
|
nicolaskempf57 marked this conversation as resolved.
|
||
| <template #media> | ||
| <img | ||
| v-if="chart.image" | ||
| :src="chart.image" | ||
| class="w-full h-full object-cover" | ||
| :alt="chart.title" | ||
| > | ||
| <Placeholder | ||
| v-else | ||
| type="Chart" | ||
| class="w-full h-full" | ||
| /> | ||
| </template> | ||
|
|
||
| <ObjectCardHeader | ||
| :icon="chartIcon" | ||
| :url="chartUrl || chart.page" | ||
| > | ||
| {{ chart.title }} | ||
| </ObjectCardHeader> | ||
|
|
||
| <div | ||
| v-if="chart.organization || chart.owner" | ||
| class="text-sm flex flex-wrap gap-y-1 items-center truncate" | ||
| > | ||
| <ObjectCardOwner | ||
| :organization="chart.organization" | ||
| :owner="chart.owner" | ||
| :organization-url="organizationUrl" | ||
| /> | ||
| <RiSubtractLine | ||
| aria-hidden="true" | ||
| class="size-4 flex-none fill-gray-medium" | ||
| /> | ||
| <p class="text-sm whitespace-nowrap mb-0 text-gray-medium"> | ||
| {{ t('Mis à jour {date}', { date: formatRelativeIfRecentDate(chart.last_modified, { dateStyle: 'medium' }) }) }} | ||
| </p> | ||
|
Comment on lines
+52
to
+54
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can now use FormattedDate from #1198 |
||
| </div> | ||
|
|
||
| <div class="mx-0 -mb-1 flex flex-wrap items-center text-sm text-gray-medium mt-1"> | ||
| <p | ||
| class="text-sm mb-0 flex items-center gap-0.5" | ||
| :aria-label="t('{n} vues | {n} vue | {n} vues', chart.metrics.views)" | ||
| > | ||
| <RiEyeLine | ||
| aria-hidden="true" | ||
| class="size-3.5" | ||
| />{{ summarize(chart.metrics.views) }} | ||
| </p> | ||
| </div> | ||
|
|
||
| <ObjectCardShortDescription :text="chart.description" /> | ||
|
|
||
| <slot /> | ||
| </ObjectCard> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { computed } from 'vue' | ||
| import { RiBarChartBoxLine, RiEyeLine, RiLineChartLine, RiSubtractLine } from '@remixicon/vue' | ||
| import type { RouteLocationRaw } from 'vue-router' | ||
| import type { Chart } from '../types/visualizations' | ||
| import { useFormatDate } from '../functions/dates' | ||
| import { summarize } from '../functions/helpers' | ||
| import { useTranslation } from '../composables/useTranslation' | ||
| import Placeholder from './Placeholder.vue' | ||
| import ObjectCard from './ObjectCard.vue' | ||
| import ObjectCardHeader from './ObjectCardHeader.vue' | ||
| import ObjectCardOwner from './ObjectCardOwner.vue' | ||
| import ObjectCardShortDescription from './ObjectCardShortDescription.vue' | ||
|
|
||
| const props = defineProps<{ | ||
| chart: Chart | ||
| chartUrl?: RouteLocationRaw | ||
| organizationUrl?: RouteLocationRaw | ||
| }>() | ||
|
|
||
| const { t } = useTranslation() | ||
| const { formatRelativeIfRecentDate } = useFormatDate() | ||
|
|
||
| const chartIcon = computed(() => { | ||
| return props.chart.series[0]?.type === 'line' ? RiLineChartLine : RiBarChartBoxLine | ||
| }) | ||
| </script> | ||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.