diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 00000000..580c14e7 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,20 @@ +module.exports = { + parser: '@typescript-eslint/parser', + extends: [ + 'eslint:recommended', + 'plugin:@typescript-eslint/recommended', + 'next', + 'prettier', + ], + rules: { + 'no-unused-vars': 'off', + '@typescript-eslint/no-unused-vars': ['warn'], + '@typescript-eslint/no-explicit-any': ['off'], + 'react/display-name': 'off', + '@next/next/no-html-link-for-pages': 'off', + 'prefer-const': 'off', + '@typescript-eslint/no-var-requires': 'off', + '@next/next/no-img-element': 'off', + }, + ignorePatterns: ['**/generated/**/*.ts', 'node_modules/', 'dist/'], +} diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 00000000..10c89b4e --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,10 @@ +{ + "ignorePatterns": ["**/generated/**/*.ts"], + "extends": ["eslint:recommended", "next"], + "rules": { + "no-unused-vars": "off", + // "@typescript-eslint/no-unused-vars": ["warn"], + "react/display-name": "off", + "@next/next/no-html-link-for-pages": "off" + } +} diff --git a/.github/workflows/pre-merge.yml b/.github/workflows/pre-merge.yml new file mode 100644 index 00000000..aaedafe0 --- /dev/null +++ b/.github/workflows/pre-merge.yml @@ -0,0 +1,40 @@ +name: Build Status + +on: + push: + branches: ['dev'] + pull_request: + branches: ['dev'] +env: + KEYCLOAK_CLIENT_ID: ${{secrets.KEYCLOAK_CLIENT_ID}} + KEYCLOAK_CLIENT_SECRET: ${{secrets.KEYCLOAK_CLIENT_SECRET}} + AUTH_ISSUER: ${{secrets.AUTH_ISSUER}} + NEXTAUTH_URL: ${{secrets.NEXTAUTH_URL}} + NEXTAUTH_SECRET: ${{secrets.NEXTAUTH_SECRET}} + END_SESSION_URL: ${{secrets.END_SESSION_URL}} + REFRESH_TOKEN_URL: ${{secrets.REFRESH_TOKEN_URL}} + NEXT_PUBLIC_BACKEND_URL: ${{secrets.NEXT_PUBLIC_BACKEND_URL}} + BACKEND_GRAPHQL_URL: ${{secrets.BACKEND_GRAPHQL_URL}} + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [20.x] + + env: + BACKEND_GRAPHQL_URL: ${{secrets.BACKEND_GRAPHQL_URL}} + + steps: + - uses: actions/checkout@v4 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + + - run: npm ci --force + - run: npm run generate + - run: npm run build --if-present diff --git a/.github/workflows/push-to-ec2.yml b/.github/workflows/push-to-ec2.yml new file mode 100644 index 00000000..a90442e0 --- /dev/null +++ b/.github/workflows/push-to-ec2.yml @@ -0,0 +1,38 @@ +name: Push-to-EC2 + +on: push + +jobs: + deploy: + name: Push to EC2 Instance + runs-on: ubuntu-latest + + steps: + - name: Checkout the code + uses: actions/checkout@v1 + + - name: Deploy to my EC2 instance + uses: easingthemes/ssh-deploy@v2.1.5 + env: + SSH_PRIVATE_KEY: ${{ secrets.EC2_SSH_KEY }} + SOURCE: "./" + SCRIPT_BEFORE: ls + REMOTE_HOST: "datakeep.civicdays.in" + REMOTE_USER: "ubuntu" + TARGET: "/home/ubuntu/DataExchange/DataExFrontend/" + + - name: run the application remotely + uses: appleboy/ssh-action@v1.0.3 + with: + host: "datakeep.civicdays.in" + username: "ubuntu" + key: ${{ secrets.EC2_SSH_KEY }} + port: 22 + script: | + cd /home/ubuntu/DataExchange/DataExFrontend/ + kill $(ps aux | grep 'npm run start' | awk '{print $2}') + kill $(ps aux | grep 'next-server' | awk '{print $2}') + npm run build + npm run generate + npm run start + diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..4d463706 --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# next.js +/.next/ +/out/ + +# production +/build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# local env files +.env*.local* + +# vercel +.vercel + +# typescript +*.tsbuildinfo +next-env.d.ts + +# intellij files +.idea + +# generated graphql files +/gql/generated/gql.ts +/gql/generated/graphql.ts \ No newline at end of file diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100755 index 00000000..21c6ca44 --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1,4 @@ +#!/bin/bash +. "$(dirname "$0")/_/husky.sh" + +npx commitlint --edit diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..57928de9 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,4 @@ +dist +node_modules +.next +build \ No newline at end of file diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 00000000..6aaec2f6 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,28 @@ +module.exports = { + endOfLine: 'lf', + semi: true, + trailingComma: 'es5', + printWidth: 80, + tabWidth: 2, + useTabs: false, + singleQuote: true, + importOrder: [ + '^(react/(.*)$)|^(react$)', + '^(next/(.*)$)|^(next$)', + '', + '', + '^types$', + '^@local/(.*)$', + '^@/config/(.*)$', + '^@/lib/(.*)$', + '^@/components/(.*)$', + '^@/styles/(.*)$', + '^[./]', + ], + importOrderParserPlugins: ['typescript', 'jsx', 'decorators-legacy'], + plugins: [ + '@ianvs/prettier-plugin-sort-imports', + 'prettier-plugin-tailwindcss', + ], + tailwindFunctions: ['clsx', 'cn'], +}; diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..58a83b9e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,29 @@ + + +## [0.1.3](https://github.com/CivicDataLab/DataExFrontend/compare/0.1.2...0.1.3) (2024-04-15) + + +### Features + +* add mutation integration to the action bar in layout ([612c158](https://github.com/CivicDataLab/DataExFrontend/commit/612c15809a7213947b1e34abce31c7f6c237b5f7)) + + +### Bug Fixes + +* fix the redirection link on click of the button in homepage ([b81b219](https://github.com/CivicDataLab/DataExFrontend/commit/b81b219240f83479cd9cc89d5866adb6a4ff576c)) +* replace hard coded url with environment variable ([7a55c94](https://github.com/CivicDataLab/DataExFrontend/commit/7a55c9491819284bfc0a6c7e7e625043e4e143f9)) +* routing in edit dataset layout ([991b042](https://github.com/CivicDataLab/DataExFrontend/commit/991b042f107b3149f1894404652a35cf0d06db96)) + +## [0.1.2](https://github.com/CivicDataLab/DataExFrontend/compare/0.1.1...0.1.2) (2024-04-05) + + +### Bug Fixes + +* add commit lint config file ([fc00fd5](https://github.com/CivicDataLab/DataExFrontend/commit/fc00fd51fa2ad135de3b79303aa6c1981ae34a0d)) + +## 0.1.1 (2024-04-05) + + +### Bug Fixes + +* add commit lint config file ([fc00fd5](https://github.com/CivicDataLab/DataExFrontend/commit/fc00fd51fa2ad135de3b79303aa6c1981ae34a0d)) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 00000000..969d4c88 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,45 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies within all project spaces, and it also applies when an individual is representing the project or its community in public spaces. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project maintainer team [private contact address](mailto:tech@civicdatalab.in). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant](https://www.contributor-covenant.org), version 1.4, available at + +For answers to common questions about this code of conduct, see \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..79437ad9 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,36 @@ +## Contributing + +Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great. + + + +Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the project's open source license. + +Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. + +## Submitting a pull request + +0. Fork and clone the repository +1. Configure and install the dependencies (if applicable) +2. Make sure the tests pass on your machine (if applicable) +3. Create a new branch: `git checkout -b my-branch-name` +4. Make your change, add tests, and make sure the tests still pass +5. Push to your fork and submit a pull request +6. Pat your self on the back and wait for your pull request to be reviewed and merged. + +## Merging a pull request + +Here are a few things you can do that will increase the likelihood of your pull request being accepted: + +- Ask for feedback early. You don't need to wait until you're done to get feedback. +- Follow standards for style and code quality +- Write tests. +- Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests. +- Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) that follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) convention. + +## Resources + +- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/) +- [Using Pull Requests](https://help.github.com/articles/about-pull-requests/) +- [GitHub Help](https://help.github.com) \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..a3e4aa4e --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 CivicDataLab + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 00000000..cb7b38ba --- /dev/null +++ b/README.md @@ -0,0 +1,67 @@ +# Data Exchange Frontend + +A platform to speed up the development of Open Data Exchange. + +## Getting Started + +To get started, you can clone the repository and run it locally using the following steps: + +1. Clone the repository: + +```bash +git clone https://github.com/CivicDataLab/data-exchange.git +``` + +2. Install dependencies + +```bash +cd data-exchange + +npm i +``` + +3. Create '.env.local' file in the project folder with the following: + +``` +KEYCLOAK_CLIENT_ID +KEYCLOAK_CLIENT_SECRET +AUTH_ISSUER +NEXTAUTH_URL +NEXTAUTH_SECRET +END_SESSION_URL +REFRESH_TOKEN_URL +NEXT_PUBLIC_BACKEND_URL +BACKEND_GRAPHQL_URL +NEXT_PUBLIC_BACKEND_GRAPHQL_URL +NEXT_PUBLIC_BACKEND_URL +``` + +4. Start the development server: + +```bash +npm run dev +``` + +## Documentation + +Data Exchange uses Next.js new `app` directory. For more information on how to use Next.js, refer to the [Next.js documentation](https://beta.nextjs.org/docs/getting-started). + +## Community + +We use Github Discussions to discuss ideas, proposals and questions about the project. You can [head over there](https://github.com/CivicDataLab/data-exchange/discussions) to interact with the community. + +Our [Code of Conduct](CODE_OF_CONDUCT.md) applies to all community channels. + +## Contributing + +Contributions to the project are welcome! To contribute, simply fork the repository, make your changes, and submit a pull request. + +For more information on contributing to the project, refer to the [CONTRIBUTING.md](CONTRIBUTING.md) file. + +## License + +This project is licensed under the MIT license. For more information, refer to the [LICENSE](LICENSE) file. + +## Security + +If you believe you have found a security vulnerability in Data Exchange, we encourage you to responsibly disclose this and not open a public issue. We will investigate all legitimate reports. Email `tech@civicdatalab.in` to disclose any security vulnerabilities. diff --git a/app/[locale]/(user)/categories/[categorySlug]/page.tsx b/app/[locale]/(user)/categories/[categorySlug]/page.tsx new file mode 100644 index 00000000..f0644e48 --- /dev/null +++ b/app/[locale]/(user)/categories/[categorySlug]/page.tsx @@ -0,0 +1,396 @@ +'use client'; + +import GraphqlPagination from '@/app/[locale]/dashboard/components/GraphqlPagination/graphqlPagination'; +import { fetchDatasets } from '@/fetch'; +import { graphql } from '@/gql'; +import { useQuery } from '@tanstack/react-query'; +import Image from 'next/image'; +import { useRouter } from 'next/navigation'; +import { Pill, SearchInput, Select, Text } from 'opub-ui'; +import { useEffect, useReducer, useState } from 'react'; + +import BreadCrumbs from '@/components/BreadCrumbs'; +import { ErrorPage } from '@/components/error'; +import { Loading } from '@/components/loading'; +import { GraphQL } from '@/lib/api'; +import Card from '../../datasets/components/Card'; +import Filter from '../../datasets/components/FIlter/Filter'; + +const categoryQueryDoc: any = graphql(` + query CategoryDetails($filters: CategoryFilter) { + categories(filters: $filters) { + id + name + description + datasetCount + } + } +`); + +interface Bucket { + key: string; + doc_count: number; +} + +interface Aggregation { + buckets: Bucket[]; +} + +interface Aggregations { + [key: string]: Aggregation; +} + +interface FilterOptions { + [key: string]: string[]; +} + +interface QueryParams { + pageSize: number; + currentPage: number; + filters: FilterOptions; + query?: string; +} + +type Action = + | { type: 'SET_PAGE_SIZE'; payload: number } + | { type: 'SET_CURRENT_PAGE'; payload: number } + | { type: 'SET_FILTERS'; payload: { category: string; values: string[] } } + | { type: 'REMOVE_FILTER'; payload: { category: string; value: string } } + | { type: 'SET_QUERY'; payload: string } + | { type: 'INITIALIZE'; payload: QueryParams }; + +const initialState: QueryParams = { + pageSize: 5, + currentPage: 1, + filters: {}, + query: '', +}; + +const queryReducer = (state: QueryParams, action: Action): QueryParams => { + switch (action.type) { + case 'SET_PAGE_SIZE': { + return { ...state, pageSize: action.payload, currentPage: 1 }; + } + case 'SET_CURRENT_PAGE': { + return { ...state, currentPage: action.payload }; + } + case 'SET_FILTERS': { + return { + ...state, + filters: { + ...state.filters, + [action.payload.category]: action.payload.values, + }, + currentPage: 1, + }; + } + case 'REMOVE_FILTER': { + const newFilters = { ...state.filters }; + newFilters[action.payload.category] = newFilters[ + action.payload.category + ].filter((v) => v !== action.payload.value); + return { ...state, filters: newFilters, currentPage: 1 }; + } + case 'SET_QUERY': { + return { ...state, query: action.payload }; + } + case 'INITIALIZE': { + return { ...state, ...action.payload }; + } + default: + return state; + } +}; + +const useUrlParams = ( + queryParams: QueryParams, + setQueryParams: React.Dispatch, + setVariables: (vars: string) => void +) => { + const router = useRouter(); + + useEffect(() => { + const urlParams = new URLSearchParams(window.location.search); + const sizeParam = urlParams.get('size'); + const pageParam = urlParams.get('page'); + const filters: FilterOptions = {}; + + urlParams.forEach((value, key) => { + if (!['size', 'page', 'query'].includes(key)) { + filters[key] = value.split(','); + } + }); + + const initialParams: QueryParams = { + pageSize: sizeParam ? Number(sizeParam) : 5, + currentPage: pageParam ? Number(pageParam) : 1, + filters, + query: urlParams.get('query') || '', + }; + + setQueryParams({ type: 'INITIALIZE', payload: initialParams }); + }, [setQueryParams]); + + useEffect(() => { + const filtersString = Object.entries(queryParams.filters) + .filter(([_, values]) => values.length > 0) + .map(([key, values]) => `${key}=${values.join(',')}`) + .join('&'); + + const searchParam = queryParams.query + ? `&query=${encodeURIComponent(queryParams.query)}` + : ''; + const variablesString = `?${filtersString}&size=${queryParams.pageSize}&page=${queryParams.currentPage}${searchParam}`; + setVariables(variablesString); + + const currentUrl = new URL(window.location.href); + currentUrl.searchParams.set('size', queryParams.pageSize.toString()); + currentUrl.searchParams.set('page', queryParams.currentPage.toString()); + + Object.entries(queryParams.filters).forEach(([key, values]) => { + if (values.length > 0) { + currentUrl.searchParams.set(key, values.join(',')); + } else { + currentUrl.searchParams.delete(key); + } + }); + + if (queryParams.query) { + currentUrl.searchParams.set('query', queryParams.query); + } else { + currentUrl.searchParams.delete('query'); + } + + router.push(currentUrl.toString()); + }, [queryParams, setVariables, router]); +}; + +const CategoryDetailsPage = ({ params }: { params: { categorySlug: any } }) => { + const getCategoryDetails: { + data: any; + isLoading: boolean; + isError: boolean; + } = useQuery([`get_category_details_${params.categorySlug}`], () => + GraphQL(categoryQueryDoc, { filters: { slug: params.categorySlug } }) + ); + + const [facets, setFacets] = useState<{ + results: any[]; + total: number; + aggregations: Aggregations; + } | null>(null); + const [variables, setVariables] = useState(''); + const [open, setOpen] = useState(false); + const count = facets?.total ?? 0; + const datasetDetails = facets?.results ?? []; + const [queryParams, setQueryParams] = useReducer(queryReducer, initialState); + + useEffect(() => { + if (variables) { + fetchDatasets(variables) + .then((res) => { + setFacets(res); + }) + .catch((err) => { + console.error(err); + }); + } + }, [variables]); + + useUrlParams(queryParams, setQueryParams, setVariables); + + const handlePageChange = (newPage: number) => { + setQueryParams({ type: 'SET_CURRENT_PAGE', payload: newPage }); + }; + + const handlePageSizeChange = (newSize: number) => { + setQueryParams({ type: 'SET_PAGE_SIZE', payload: newSize }); + }; + + const handleFilterChange = (category: string, values: string[]) => { + setQueryParams({ type: 'SET_FILTERS', payload: { category, values } }); + }; + + const handleRemoveFilter = (category: string, value: string) => { + setQueryParams({ type: 'REMOVE_FILTER', payload: { category, value } }); + }; + + const handleSearch = (searchTerm: string) => { + setQueryParams({ type: 'SET_QUERY', payload: searchTerm }); + }; + + const aggregations: Aggregations = facets?.aggregations || {}; + + const filterOptions = Object.entries(aggregations).reduce( + (acc: Record, [key, value]) => { + acc[key.replace('.raw', '')] = value.buckets.map((bucket: Bucket) => ({ + label: bucket.key, + value: bucket.key, + })); + return acc; + }, + {} + ); + + return ( +
+ + + {getCategoryDetails.isError ? ( + + ) : getCategoryDetails.isLoading ? ( + + ) : ( +
+
+
+ {`${params.categorySlug} +
+
+ + {getCategoryDetails.data?.categories[0].name || + params.categorySlug} + + + {getCategoryDetails.data?.categories[0].datasetCount} Datasets + + + {getCategoryDetails.data?.categories[0].description || + 'No description available.'} + +
+
+ +
+
+
+ Showing 10 of 30 Datasets +
+
+ console.log(value)} + onClear={(value: any) => console.log(value)} + /> +
+
+
+ + Sort by: + + +
+
+
+
+ +
+
+ +
+
+
+ {Object.entries(queryParams.filters).map(([category, values]) => + values.map((value) => ( + handleRemoveFilter(category, value)} + > + {value} + + )) + )} +
+ +
+ {facets && datasetDetails?.length > 0 && ( + + {datasetDetails.map((item: any, index: any) => ( + + ))} + + )} +
+
+
+
+ )} +
+ ); +}; + +export default CategoryDetailsPage; diff --git a/app/[locale]/(user)/categories/page.tsx b/app/[locale]/(user)/categories/page.tsx new file mode 100644 index 00000000..cebb9a29 --- /dev/null +++ b/app/[locale]/(user)/categories/page.tsx @@ -0,0 +1,87 @@ +'use client'; + +import { graphql } from '@/gql'; +import { useQuery } from '@tanstack/react-query'; +import Image from 'next/image'; +import Link from 'next/link'; +import { Text } from 'opub-ui'; + +import BreadCrumbs from '@/components/BreadCrumbs'; +import { ErrorPage } from '@/components/error'; +import { Loading } from '@/components/loading'; +import { GraphQL } from '@/lib/api'; + +const categoriesListQueryDoc: any = graphql(` + query CategoriesList { + categories { + id + name + description + slug + datasetCount + } + } +`); + +const CategoriesListingPage = () => { + const getCategoriesList: { + data: any; + isLoading: boolean; + error: any; + isError: boolean; + } = useQuery([`categories_list_page`], () => + GraphQL(categoriesListQueryDoc, []) + ); + + return ( +
+ + <> + {getCategoriesList.isLoading ? ( + + ) : getCategoriesList.data?.categories.length > 0 ? ( + <> +
+ + Categories + +
+ {getCategoriesList.data?.categories.map((category: any) => ( + +
+
+ {'Category +
+
+ + {category.name} + + {category.datasetCount} Dataset(s) +
+
+ + ))} +
+
+ + ) : getCategoriesList.isError ? ( + + ) : ( + <> + )} + +
+ ); +}; + +export default CategoriesListingPage; diff --git a/app/[locale]/(user)/chart/Content.tsx b/app/[locale]/(user)/chart/Content.tsx new file mode 100644 index 00000000..949da8ce --- /dev/null +++ b/app/[locale]/(user)/chart/Content.tsx @@ -0,0 +1,227 @@ +'use client'; + +import React from 'react'; +import { EChartsOption } from 'echarts-for-react'; +import { ShareDialog, useScreenshot } from 'opub-ui'; +import { BarChart } from 'opub-ui/viz'; +import { useMediaQuery } from 'usehooks-ts'; + +import { eCharts } from '@/lib/eCharts'; +import { navigateEnd } from '@/lib/navigation'; +import MapChart from '@/components/MapChart'; + +type Props = { + options: EChartsOption; +}; +export function Content({ + bar, + line, + stacked, + mapOptions, +}: { + bar: Props; + line: Props; + stacked: Props; + mapOptions: any; +}) { + const mapDataFn = (value: number) => { + return value >= 330 + ? '#a50f15' + : value >= 325 + ? '#de2d26' + : value >= 320 + ? '#fb6a4a' + : value >= 315 + ? '#fc9272' + : value >= 310 + ? '#fcbba1' + : '#fee5d9'; + }; + + return ( +
+ + + + +
+ ); +} + +const Chart = ({ + options, + props, +}: Props & { + props: { + title: string; + }; +}) => { + const [svgURL, setSvgURL] = React.useState(''); + + const isDesktop = useMediaQuery('(min-width: 768px)'); + + const { createSvg, svgToPngURL, downloadFile } = useScreenshot(); + + const generateImage = async () => { + const dataUrlBar = eCharts({ options: options }); + + const svg = await createSvg( +