Skip to content
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

catching up #2

Merged
merged 57 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
4ddfc11
Created the style property for the map component
Gutts-n Dec 20, 2023
2ec1437
Merge pull request #1061 from datopian/feature/style-in-map-component
Gutts-n Dec 20, 2023
e687779
Version Packages
github-actions[bot] Dec 20, 2023
1394f02
Merge pull request #1062 from datopian/changeset-release/main
Gutts-n Dec 20, 2023
b13e3ad
Created auto zoom configuration for the map component
Gutts-n Dec 22, 2023
8560f16
Merge pull request #1063 from datopian/feature/auto-zoom-in-map-compo…
Gutts-n Dec 22, 2023
38bf06f
Version Packages
github-actions[bot] Dec 22, 2023
8a4ec39
Merge pull request #1064 from datopian/changeset-release/main
Gutts-n Dec 22, 2023
9e73410
Fix React warning about unique "key" prop
marcchehab Jan 4, 2024
a93b13f
Component start
Gutts-n Jan 18, 2024
e5b0a85
Created Iframe component
Gutts-n Jan 18, 2024
dd03a49
Created Iframe component
Gutts-n Jan 18, 2024
7049917
Merge pull request #1066 from datopian/feature/iframe-component
Gutts-n Jan 18, 2024
4985576
Version Packages
github-actions[bot] Jan 18, 2024
1a5bbd4
Merge pull request #1067 from datopian/changeset-release/main
Gutts-n Jan 18, 2024
92a549d
[core][m]: Add analytics component to the core packages
mohamedsalem401 Jan 18, 2024
96904ae
Merge pull request #1068 from datopian/analytics
mohamedsalem401 Jan 18, 2024
27c99ad
Added pagination and filter properties for the BucketViewer component
Gutts-n Jan 23, 2024
1343a7a
Merge pull request #1071 from datopian/feature/search-and-pagination-…
Gutts-n Jan 23, 2024
0a47610
Version Packages
github-actions[bot] Jan 23, 2024
2c45da6
Merge pull request #1072 from datopian/changeset-release/main
Gutts-n Jan 23, 2024
cf24042
Fixed bug on filter by startDate
Gutts-n Jan 23, 2024
09d5324
Merge pull request #1073 from datopian/feature/search-and-pagination-…
Gutts-n Jan 23, 2024
8d7059a
Version Packages
github-actions[bot] Jan 23, 2024
d18e3dd
Merge pull request #1074 from datopian/changeset-release/main
Gutts-n Jan 23, 2024
26dcffc
Fixed problem presenting the download component in the first load of …
Gutts-n Jan 24, 2024
a7e90b6
Merge pull request #1075 from datopian/fix/download-button-presented-…
Gutts-n Jan 24, 2024
35ca1d6
Version Packages
github-actions[bot] Jan 24, 2024
7c30842
Merge pull request #1076 from datopian/changeset-release/main
Gutts-n Jan 24, 2024
6d7acd2
Created property to present a component while is loading the download…
Gutts-n Jan 24, 2024
a58e2b8
Merge pull request #1077 from datopian/feature/download-loading-message
Gutts-n Jan 24, 2024
dd79da1
Version Packages
github-actions[bot] Jan 24, 2024
7d010cf
Merge pull request #1078 from datopian/changeset-release/main
Gutts-n Jan 24, 2024
540a089
Changed behavior of the download data bucket viewer component
Gutts-n Jan 25, 2024
058d236
Added changeset to the PR
Gutts-n Jan 25, 2024
2bffd13
Merge pull request #1079 from datopian/fix/changed-the-download-behavior
Gutts-n Jan 25, 2024
9ae2b31
Version Packages
github-actions[bot] Jan 25, 2024
af11f0c
Merge pull request #1080 from datopian/changeset-release/main
Gutts-n Jan 25, 2024
c26b763
Fixed error to remove anchor from document
Gutts-n Jan 25, 2024
2bbf313
Fixed error to remove anchor from document
Gutts-n Jan 25, 2024
464cda6
Merge pull request #1081 from datopian/fix/changed-the-download-behavior
Gutts-n Jan 25, 2024
b511c9f
Version Packages
github-actions[bot] Jan 25, 2024
09daa98
Merge pull request #1082 from datopian/changeset-release/main
Gutts-n Jan 25, 2024
86a2945
Created integration with datastore api for table component
Gutts-n Jan 29, 2024
c904e37
Merge pull request #1083 from datopian/feature/table-with-integration…
anuveyatsu Jan 31, 2024
0891dfd
Version Packages
github-actions[bot] Jan 31, 2024
f7f03fd
Merge pull request #1085 from datopian/changeset-release/main
Gutts-n Jan 31, 2024
00e61e1
[site/config][xs]: change discord server to datahub.
rufuspollock Feb 9, 2024
90178af
[examples/fivethirtyeight][s]: add link to demo site to README.
rufuspollock Feb 13, 2024
9e1a324
[examples/fivethirtyeight][xs]: link to blog post we wrote about it.
rufuspollock Feb 13, 2024
42c72e5
Delete tools/generators/.gitkeep
rufuspollock Feb 28, 2024
ed9ac2c
Delete tools/tsconfig.tools.json
rufuspollock Feb 28, 2024
1b58c31
Plotly components
luccasmmg Mar 22, 2024
a044f56
Changeset
luccasmmg Mar 22, 2024
3aac4da
Version Packages (#1087)
github-actions[bot] Mar 22, 2024
d898b5a
Merge pull request #1065 from marcchehab/patch-1
rufuspollock Mar 29, 2024
fb3598f
Delete .vscode/extensions.json
rufuspollock Apr 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions .vscode/extensions.json

This file was deleted.

6 changes: 6 additions & 0 deletions examples/fivethirtyeight/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# PortalJS Demo replicating the FiveThirtyEight data portal

## 👉 https://fivethirtyeight.portaljs.org 👈

Here's a blog post we wrote about it: https://www.datopian.com/blog/fivethirtyeight-replica

This is a replica of the awesome data.fivethirtyeight.com using PortalJS.

You might be asking why we did that, there are three main reasons:
Expand Down
3,518 changes: 3,322 additions & 196 deletions package-lock.json

Large diffs are not rendered by default.

66 changes: 66 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,71 @@
# @portaljs/components

## 0.6.0

### Minor Changes

- [`a044f56e`](https://github.com/datopian/portaljs/commit/a044f56e3cbe0519ddf9d24d78b0bb7eac917e1c) Thanks [@luccasmmg](https://github.com/luccasmmg)! - Added plotly components

## 0.5.10

### Patch Changes

- [#1083](https://github.com/datopian/portaljs/pull/1083) [`86a2945e`](https://github.com/datopian/portaljs/commit/86a2945ee68dfcea0299984ca9cc9070d68fe1c2) Thanks [@Gutts-n](https://github.com/Gutts-n)! - Created integration with datastore api for table component

## 0.5.9

### Patch Changes

- [#1081](https://github.com/datopian/portaljs/pull/1081) [`2bbf3134`](https://github.com/datopian/portaljs/commit/2bbf3134896df3ecc66560bdf95bece143614c7b) Thanks [@Gutts-n](https://github.com/Gutts-n)! - Fixed error to remove anchor from document

## 0.5.8

### Patch Changes

- [#1079](https://github.com/datopian/portaljs/pull/1079) [`058d2367`](https://github.com/datopian/portaljs/commit/058d23678a024890f8a6d909ded9fc8fc11cf145) Thanks [@Gutts-n](https://github.com/Gutts-n)! - Changed the download behaviour of the bucket viewer component and removed loading component while downloading

## 0.5.7

### Patch Changes

- [#1077](https://github.com/datopian/portaljs/pull/1077) [`6d7acd27`](https://github.com/datopian/portaljs/commit/6d7acd27ed9299cbcc14eab906f2f0eb414656b8) Thanks [@Gutts-n](https://github.com/Gutts-n)! - Created property to present a component while is loading the download of the file and fixed download bug on pagination

## 0.5.6

### Patch Changes

- [#1075](https://github.com/datopian/portaljs/pull/1075) [`26dcffc2`](https://github.com/datopian/portaljs/commit/26dcffc279057f80a579134e862085ba042c06c3) Thanks [@Gutts-n](https://github.com/Gutts-n)! - Fixed problem presenting the download component in the first load of the bucket viewer

## 0.5.5

### Patch Changes

- [#1073](https://github.com/datopian/portaljs/pull/1073) [`cf24042a`](https://github.com/datopian/portaljs/commit/cf24042a910567e98eeb75ade42ce0149bdb62d1) Thanks [@Gutts-n](https://github.com/Gutts-n)! - Fixed filter by startDate error

## 0.5.4

### Patch Changes

- [#1071](https://github.com/datopian/portaljs/pull/1071) [`27c99add`](https://github.com/datopian/portaljs/commit/27c99adde8fa36ad2c2e03f227f93aa62454eefa) Thanks [@Gutts-n](https://github.com/Gutts-n)! - Added pagination and filter properties for the BucketViewer component

## 0.5.3

### Patch Changes

- [#1066](https://github.com/datopian/portaljs/pull/1066) [`dd03a493`](https://github.com/datopian/portaljs/commit/dd03a493beca5459d1ef447b2df505609fc64e95) Thanks [@Gutts-n](https://github.com/Gutts-n)! - Created Iframe component

## 0.5.2

### Patch Changes

- [#1063](https://github.com/datopian/portaljs/pull/1063) [`b13e3ade`](https://github.com/datopian/portaljs/commit/b13e3ade3ccefe7dffe84f824bdedd3e512ce499) Thanks [@Gutts-n](https://github.com/Gutts-n)! - Created auto zoom configuration for the map component

## 0.5.1

### Patch Changes

- [#1061](https://github.com/datopian/portaljs/pull/1061) [`4ddfc112`](https://github.com/datopian/portaljs/commit/4ddfc1126a3f0b8137ea47a08a36c56b7373b8f6) Thanks [@Gutts-n](https://github.com/Gutts-n)! - Created the style property in the Map component

## 0.5.0

### Minor Changes
Expand Down
4 changes: 3 additions & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@portaljs/components",
"version": "0.5.0",
"version": "0.6.0",
"type": "module",
"description": "https://portaljs.org",
"keywords": [
Expand Down Expand Up @@ -40,11 +40,13 @@
"ol": "^7.4.0",
"papaparse": "^5.4.1",
"pdfjs-dist": "2.15.349",
"plotly.js": "^2.30.1",
"postcss-url": "^10.1.3",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.43.9",
"react-leaflet": "^4.2.1",
"react-plotly.js": "^2.6.0",
"react-query": "^3.39.3",
"react-vega": "^7.6.0",
"vega": "5.25.0",
Expand Down
215 changes: 178 additions & 37 deletions packages/components/src/components/BucketViewer.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
import { useEffect, useState } from 'react';
import { CSSProperties, ReactNode, useEffect, useState } from 'react';
import LoadingSpinner from './LoadingSpinner';

export interface BucketViewerFilterSearchedDataEvent {
startDate?: Date;
endDate?: Date;
}

export interface BucketViewerProps {
onLoadTotalNumberOfItems?: (total: number) => void;
domain: string;
downloadConfig?: {
hoverOfTheFileComponent?: ReactNode;
};
suffix?: string;
className?: string;
paginationConfig?: BucketViewerPaginationConfig;
filterState?: BucketViewerFilterSearchedDataEvent;
dataMapperFn: (rawData: Response) => Promise<BucketViewerData[]>;
}

export interface BucketViewerPaginationConfig {
containerClassName?: string;
containerStyles?: CSSProperties;
itemsPerPage: number;
}

export interface BucketViewerData {
fileName: string;
downloadFileUri: string;
dateProps?: {
date: Date;
dateFormatter: (date: Date) => string;
dateFormatter?: (date: Date) => string;
};
}

Expand All @@ -22,60 +39,184 @@ export function BucketViewer({
suffix,
dataMapperFn,
className,
filterState,
paginationConfig,
downloadConfig,
onLoadTotalNumberOfItems,
}: BucketViewerProps) {
suffix = suffix ?? '/';

const { hoverOfTheFileComponent } = downloadConfig ?? {};
const [isLoading, setIsLoading] = useState<boolean>(false);
const [showDownloadComponentOnLine, setShowDownloadComponentOnLine] =
useState(-1);
const [currentPage, setCurrentPage] = useState<number>(0);
const [lastPage, setLastPage] = useState<number>(0);
const [bucketFiles, setBucketFiles] = useState<BucketViewerData[]>([]);
suffix = suffix ?? '/';
const [paginatedData, setPaginatedData] = useState<BucketViewerData[]>([]);
const [filteredData, setFilteredData] = useState<BucketViewerData[]>([]);

useEffect(() => {
setIsLoading(true);
fetch(`${domain}${suffix}`)
.then((res) => dataMapperFn(res))
.then((data) => setBucketFiles(data))
.then((data) => {
setBucketFiles(data);
setFilteredData(data);
})
.finally(() => setIsLoading(false));
}, [domain, suffix]);

useEffect(() => {
if (paginationConfig) {
const startIndex = paginationConfig
? currentPage * paginationConfig.itemsPerPage
: 0;

const endIndex = paginationConfig
? startIndex + paginationConfig.itemsPerPage
: 0;

setLastPage(
Math.ceil(filteredData.length / paginationConfig.itemsPerPage) - 1
);
setPaginatedData(filteredData.slice(startIndex, endIndex));
}
}, [currentPage, filteredData]);

useEffect(() => {
if (onLoadTotalNumberOfItems) onLoadTotalNumberOfItems(filteredData.length);
}, [filteredData]);

useEffect(() => {
if (!filterState) return;

if (filterState.startDate && filterState.endDate) {
setFilteredData(
bucketFiles.filter(({ dateProps }) =>
dateProps
? dateProps.date.getTime() >= filterState.startDate.getTime() &&
dateProps.date.getTime() <= filterState.endDate.getTime()
: true
)
);
} else if (filterState.startDate) {
setFilteredData(
bucketFiles.filter(({ dateProps }) =>
dateProps
? dateProps.date.getTime() >= filterState.startDate.getTime()
: true
)
);
} else if (filterState.endDate) {
setFilteredData(
bucketFiles.filter(({ dateProps }) =>
dateProps
? dateProps.date.getTime() <= filterState.endDate.getTime()
: true
)
);
} else {
setFilteredData(bucketFiles);
}
}, [filterState]);

return isLoading ? (
<div className="w-full flex items-center justify-center h-[300px]">
<LoadingSpinner />
</div>
) : bucketFiles ? (
<>
{...bucketFiles?.map((data, i) => (
{...(paginationConfig && bucketFiles ? paginatedData : filteredData)?.map(
(data, i) => (
<ul
onClick={() => {
const a: HTMLAnchorElement = document.createElement('a');
a.href = data.downloadFileUri;
a.target = `_blank`;
a.download = data.fileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}}
key={i}
onMouseEnter={() => setShowDownloadComponentOnLine(i)}
onMouseLeave={() => setShowDownloadComponentOnLine(undefined)}
className={`${
className ??
'mb-2 border-b-[2px] border-b-[red] hover:cursor-pointer'
}`}
>
{hoverOfTheFileComponent && showDownloadComponentOnLine === i ? (
hoverOfTheFileComponent
) : (
<></>
)}
<div className="flex justify-between w-full items-center">
<div>
<li>{data.fileName}</li>
{data.dateProps && data.dateProps.dateFormatter ? (
<li>{data.dateProps.dateFormatter(data.dateProps.date)}</li>
) : (
<></>
)}
</div>
</div>
</ul>
)
)}
{paginationConfig ? (
<ul
onClick={() => {
const anchorId = `download_anchor_${i}`;
const a: HTMLAnchorElement =
(document.getElementById(anchorId) as HTMLAnchorElement | null) ??
document.createElement('a');
a.id = anchorId;
if (a.download) a.click();
else {
setIsLoading(true);
fetch(data.downloadFileUri)
.then((res) => res.blob())
.then((res) => {
a.href = URL.createObjectURL(res);
a.download = res.name ?? data.fileName;
document.body.appendChild(a);
a.click();
})
.finally(() => setIsLoading(false));
}
}}
key={i}
className={`${
className ??
'mb-2 border-b-[2px] border-b-[red] hover:cursor-pointer'
}`}
className={
paginationConfig.containerClassName
? paginationConfig.containerClassName
: 'flex justify-end gap-x-[0.5rem] w-full'
}
style={paginationConfig.containerStyles ?? {}}
>
<li>{data.fileName}</li>
{data.dateProps ? (
<li>{data.dateProps.dateFormatter(data.dateProps.date)}</li>
) : (
<></>
)}
<li>
<button
className="hover:cursor-pointer hover:disabled:cursor-not-allowed"
disabled={currentPage === 0}
onClick={() => setCurrentPage(0)}
>
First
</button>
</li>
<li>
<button
className="hover:cursor-pointer hover:disabled:cursor-not-allowed"
onClick={() => setCurrentPage(currentPage - 1)}
disabled={currentPage === 0}
>
Previous
</button>
</li>
<label>{currentPage + 1}</label>

<li>
<button
onClick={() => setCurrentPage(currentPage + 1)}
disabled={currentPage >= lastPage}
className="hover:cursor-pointer hover:disabled:cursor-not-allowed"
>
Next
</button>
</li>

<li>
<button
onClick={() => setCurrentPage(lastPage)}
disabled={currentPage >= lastPage}
className="hover:cursor-pointer hover:disabled:cursor-not-allowed"
>
Last
</button>
</li>
</ul>
))}
) : (
<></>
)}
</>
) : null;
}
14 changes: 14 additions & 0 deletions packages/components/src/components/Iframe.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { CSSProperties } from "react";

export interface IframeProps {
url: string;
style?: CSSProperties;
}

export function Iframe({
url, style
}: IframeProps) {
return (
<iframe src={url} style={style ?? { width: `100%`, height: `100%` }}></iframe>
);
}
Loading