diff --git a/src/components/StoredQueryTab/index.tsx b/src/components/StoredQueryTab/index.tsx new file mode 100644 index 00000000..269a2c7c --- /dev/null +++ b/src/components/StoredQueryTab/index.tsx @@ -0,0 +1,65 @@ +import React, { useEffect, useState } from 'react'; +import TransformedDate from '../TransformedDate'; + +interface StoredQuery { + title?: string; + description?: string; + uuid?: string; + identifier?: string; + modified?: string; +} + +interface StoredQueryApiResponse { + storedQuery?: StoredQuery; +} + +interface StoredQueryViewerProps { + id: string; +} + +const StoredQueryViewer: React.FC = ({ id }) => { + const [loading, setLoading] = useState(false); + const [data, setData] = useState(null); + const [error, setError] = useState(null); + + useEffect(() => { + if (!id) return; + setLoading(true); + fetch(`/api/1/stored-query/items/${id}`) + .then((response) => { + if (!response.ok) throw new Error('Network response was not ok'); + return response.json(); + }) + .then((json: StoredQueryApiResponse) => { + setData(json); + setLoading(false); + }) + .catch((err: Error) => { + setError(err.message); + setLoading(false); + }); + }, [id]); + + if (loading) return
Loading...
; + if (error) return
Error: {error}
; + if (!data) return
No data found.
; +const storedQueryUrl = `/stored-query/${data.storedQuery?.uuid}`; + return ( +
  • +
    +
    + + Updated + +

    {data.storedQuery?.title}

    +
    +
    +
    +

    {data.storedQuery?.description}

    +
    +
    +
  • + ); +}; + +export default StoredQueryViewer; diff --git a/src/templates/Dataset/index.tsx b/src/templates/Dataset/index.tsx index 0745102a..987ea91f 100644 --- a/src/templates/Dataset/index.tsx +++ b/src/templates/Dataset/index.tsx @@ -12,6 +12,7 @@ import SearchItemIcon from '../../assets/icons/searchItem'; import DatasetOverview from '../../components/DatasetOverviewTab'; import DatasetAPI from '../../components/DatasetAPITab'; import DataDictionary from '../../components/DatasetDataDictionaryTab'; +import StoredQuery from '../../components/StoredQueryTab'; import { DatasetDictionaryItemType, DatasetPageType, DatasetDictionaryType, DistributionType, ResourceType, ColumnType } from '../../types/dataset'; import TransformedDate from '../../components/TransformedDate'; import { getFormatType } from '../../utilities/format'; @@ -53,6 +54,7 @@ const Dataset = ({ dataDictionaryBanner = false, disableTableControls = false, hideDataDictionary = false, + hideStoredQuery = true, customDescription, updateAriaLive, showRowLimitNotice = false @@ -143,6 +145,7 @@ const Dataset = ({ const displayDataDictionaryTab = ((distribution.data && distribution.data.describedBy && distribution.data.describedByType === 'application/vnd.tableschema+json') || (datasetSitewideDictionary && datasetSitewideDictionary.length > 0)) as boolean; + return ( <> {dataset.error ? ( @@ -245,6 +248,7 @@ const Dataset = ({ )} + )} diff --git a/src/types/dataset.ts b/src/types/dataset.ts index 771a0306..59bad249 100644 --- a/src/types/dataset.ts +++ b/src/types/dataset.ts @@ -70,6 +70,7 @@ export type DatasetPageType = { dataDictionaryBanner: boolean, disableTableControls: boolean, hideDataDictionary: boolean, + hideStoredQuery: boolean, customDescription?: Function, updateAriaLive?: Function, showRowLimitNotice?: boolean, @@ -111,6 +112,12 @@ export type DatasetOverviewPropsType = { metadataMapping: any, //TODO } +export type DatasetStoredQuery = { + dataset: DatasetType, + resource: ResourceType, + distributions: DistributionType[], +} + export type DatasetDictionaryItemType = { format: string, name: string,