-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/add new data structure component (#19)
* feat: ✨ add new data structure component * feat: ✨ add explore button Co-authored-by: maudetes <[email protected]>
- Loading branch information
1 parent
b35cfed
commit 0fdb324
Showing
13 changed files
with
363 additions
and
122 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,42 @@ | ||
import { apify, configure, getData } from "@etalab/explore.data.gouv.fr/lib/csvapi"; | ||
|
||
/** | ||
* @typedef {object} CsvapiResponseWithEndpoint | ||
* @property {string} endpoint - the endpoint for further requests | ||
* @property {Promise<import("@etalab/explore.data.gouv.fr/lib/csvapi").CsvapiResponse>} data - data from the first call | ||
*/ | ||
|
||
/** | ||
* @type {Map<string, Promise<CsvapiResponseWithEndpoint>>} | ||
*/ | ||
const csvapiRequests = new Map(); | ||
|
||
/** | ||
* Call Csvapi functions apify and getData with provided configuration. | ||
* Configuration is called twice : one time before each call to Csvapi. | ||
* | ||
* @param {string} url - a url to a resource hosted on udata | ||
* @param {import("@etalab/explore.data.gouv.fr/lib/csvapi").CsvapiRequestConfiguration} config - Csvapi configuration | ||
* @returns {Promise<CsvapiResponseWithEndpoint>} | ||
*/ | ||
export default function requestCsvapi(url, config) { | ||
let existingRequest; | ||
if(existingRequest = csvapiRequests.get(url)) { | ||
return existingRequest; | ||
} | ||
configure(config); | ||
const request = apify(url).then(res => { | ||
if (res.ok) { | ||
config.dataEndpoint = res.endpoint; | ||
configure(config); | ||
return { | ||
endpoint: res.endpoint, | ||
data: getData("apify"), | ||
}; | ||
} else { | ||
throw new Error("Got 200 but result isn't ok"); | ||
} | ||
}); | ||
csvapiRequests.set(url, request); | ||
return request; | ||
} |
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,71 @@ | ||
<template> | ||
<div class="bg-alt-green-tilleul-verveine fr-p-3v fr-mb-2w" v-if="hasError"> | ||
<p class="fr-grid-row fr-m-0"> | ||
<span class="fr-icon-warning-line" aria-hidden="true"></span> | ||
{{ $t("The data structure of this file failed to load.") }} | ||
</p> | ||
</div> | ||
<Loader v-if="loading" /> | ||
<div v-if="!hasError && !loading" class="fr-grid-row fr-grid-row--gutters"> | ||
<div class="bg-alt-green-tilleul-verveine fr-p-3v fr-mb-2w" v-if="isExcel"> | ||
<p class="fr-grid-row fr-m-0"> | ||
<span class="fr-icon-warning-line" aria-hidden="true"></span> | ||
{{ $t("This is an Excel file, analysis on this type of files are limited.") }} | ||
</p> | ||
</div> | ||
<div class="bg-alt-green-tilleul-verveine fr-p-3v fr-mb-2w" v-else-if="!hasColumnInfos"> | ||
<p class="fr-grid-row fr-m-0"> | ||
<span class="fr-icon-warning-line" aria-hidden="true"></span> | ||
{{ $t("No data structure found for this file.") }} | ||
</p> | ||
</div> | ||
<div v-if="hasColumnInfos" class="fr-col-12 fr-col-sm-6 fr-col-md-4 fr-col-lg-3" v-for="column in columns"> | ||
<h5 class="fr-text--sm fr-text--bold fr-mt-0 fr-mb-1v">{{column}}</h5> | ||
<code class="code"> | ||
{{ columnsInfos[column].format }} | ||
</code> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { computed, defineComponent } from 'vue'; | ||
import Loader from "./loader.vue"; | ||
import useCsvapi from './useCsvapi'; | ||
export default defineComponent({ | ||
components: {Loader}, | ||
props: { | ||
resource: { | ||
/** @type {import("vue").PropType<import("./index").Resource>} */ | ||
type: Object, | ||
required: true | ||
} | ||
}, | ||
setup(props) { | ||
const { | ||
apifyAndGetData, | ||
columns, | ||
columnsInfos, | ||
generalInfos, | ||
hasError, | ||
isExcel, | ||
loading, | ||
} = useCsvapi(props.resource); | ||
const hasColumnInfos = computed(() => Object.keys(columnsInfos.value).length > 0); | ||
apifyAndGetData(); | ||
return { | ||
columns, | ||
columnsInfos, | ||
generalInfos, | ||
hasColumnInfos, | ||
hasError, | ||
isExcel, | ||
loading, | ||
}; | ||
} | ||
}); | ||
</script> |
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 |
---|---|---|
@@ -1,7 +1,13 @@ | ||
import 'vite/modulepreload-polyfill'; | ||
import { registerComponent, registerTranslation } from "@etalab/udata-front-plugins-helper"; | ||
import DataStructure from "./data-structure.vue"; | ||
import Explore from "./explore.vue"; | ||
import messages from '@intlify/unplugin-vue-i18n/messages'; | ||
|
||
/** | ||
* @typedef {{title: string, preview_url:string, url: string}} Resource | ||
*/ | ||
|
||
registerComponent("explore", Explore, "udata-tabular-preview", "explore"); | ||
registerComponent("data-structure", DataStructure, "udata-tabular-preview", "data-structure"); | ||
registerTranslation(messages, "udata-tabular-preview"); |
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
Oops, something went wrong.