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

Chore: add accessor to formatters #267

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
15f15a3
feat: add clickable and hoverable rows to table
etienneburdet Nov 12, 2024
ea871be
fix: change implem to extra column to avoid formatting issues
etienneburdet Nov 13, 2024
649f62d
chore: export formatters and fix typing
etienneburdet Nov 20, 2024
ef9de89
fix: import alias and export old types
etienneburdet Nov 25, 2024
6573913
chore(release): publish new versions
etienneburdet Nov 27, 2024
a010680
chore: add accessor functiond and make warnings optionals
etienneburdet Nov 28, 2024
22ea94d
Revert "chore: add accessor functiond and make warnings optionals"
etienneburdet Nov 28, 2024
0069b57
fix: rename rows, lint, simplify callbacks
etienneburdet Nov 28, 2024
b648eb3
fix: make colors more easily customizable
etienneburdet Nov 29, 2024
f8128d6
chore: add accessor functiond and make warnings optionals
etienneburdet Nov 28, 2024
bb3988f
fix: lift accessor function to table
etienneburdet Dec 5, 2024
0c5019b
fix: reverse warning type check
etienneburdet Dec 6, 2024
ff2b4d1
chore: rename base props
etienneburdet Dec 9, 2024
27096ce
fix: upgrade nx for CI
etienneburdet Dec 9, 2024
c3334ba
fix: restore lockfile after rebase
etienneburdet Dec 9, 2024
a727acb
fix: fix stories with new accessor value
etienneburdet Dec 10, 2024
ae60e36
chore: Add generic record type to columns
etienneburdet Dec 17, 2024
663c230
chore: remove double return mapping
etienneburdet Jan 8, 2025
90d3102
fix: refactor debug warnings and remove span in format
etienneburdet Jan 10, 2025
f7e2032
Merge branch 'main' into chore/add-accessors
etienneburdet Jan 10, 2025
aa24ba2
fix: use store for debug warnings instead of column property
etienneburdet Jan 13, 2025
5c70cfd
chore: move debugWarnings checks inside the function
etienneburdet Jan 16, 2025
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
274 changes: 205 additions & 69 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"devDependencies": {
"lerna": "^8.1.2",
"nx": "^19.2.3"
"nx": "^20.2.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, better to avoid upgrades (especially a major version) in a feature PR 😄 But if you tested alright and Kevin and I didn't get any issue during review either, I guess we're good

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's for github actions, it crashes because nx doesn't find its arm64 or linux package… It's not the first time and I really don't know how to fix that. Maybe we should have a fixed version instead of carret 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I once had a similar issue locally, and then not anymore a few days later, so that's a good probability 😬

},
"dependencies": {
"-": "^0.0.1"
Expand Down
16 changes: 5 additions & 11 deletions packages/visualizations-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import {
BooleanFormat as _BooleanFormat,
DateFormat as _DateFormat,
GeoFormat as _GeoFormat,
LongTextFormat as _LongTextFormat,
ShortTextFormat as _ShortTextFormat,
TextFormat as _TextFormat,
URLFormat as _URLFormat,
NumberFormat as _NumberFormat,
} from '@opendatasoft/visualizations';
Expand All @@ -30,8 +29,7 @@ import type {
BooleanFormatProps,
DateFormatProps,
GeoFormatProps,
LongTextFormatProps,
ShortTextFormatProps,
TextFormatProps,
URLFormatProps,
NumberFormatProps,
} from '@opendatasoft/visualizations';
Expand Down Expand Up @@ -70,13 +68,9 @@ export const GeoFormat = reactifySvelte<GeoFormatProps>(
_GeoFormat,
'ods-visualizations-format-geo'
);
export const ShortTextFormat = reactifySvelte<ShortTextFormatProps>(
_ShortTextFormat,
'ods-visualizations-format-shorttext'
);
export const LongTextFormat = reactifySvelte<LongTextFormatProps>(
_LongTextFormat,
'ods-visualizations-format-longtext'
export const TextFormat = reactifySvelte<TextFormatProps>(
_TextFormat,
'ods-visualizations-format-text'
);
export const NumberFormat = reactifySvelte<NumberFormatProps>(
_NumberFormat,
Expand Down
38 changes: 24 additions & 14 deletions packages/visualizations-react/stories/Table/Table.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import './custom-style.css';
import { Table } from '../../src';

import value from './data';
import options from './options';
import options, { DatasetRecord } from './options';

const meta: ComponentMeta<typeof Table> = {
title: 'Table/Table',
Expand Down Expand Up @@ -41,22 +41,32 @@ const ScrollTemplate: ComponentStory<typeof Table> = args => (

const RowHoverTemplate: ComponentStory<typeof Table> = args => {
const { options: argOptions, data: argData } = args;
const [hoveredRecord, setHovered] = useState<Record<string, unknown> | undefined | null>(null);
const [lastClicked, setLastClicked] = useState<Record<string, unknown> | undefined | null>(null);

const onMouseEnter = (record?: Record<string, unknown>) => {setHovered(record);};
const onMouseLeave = () => {setHovered(null);};
const onClick = (record?: Record<string, unknown>) => {setLastClicked(record);};
const [hoveredRecord, setHovered] = useState<DatasetRecord | undefined | null>(null);
const [lastClicked, setLastClicked] = useState<DatasetRecord | undefined | null>(null);

const onMouseEnter = (record: DatasetRecord) => {
setHovered(record);
};
const onMouseLeave = () => {
setHovered(null);
};
const onClick = (record: DatasetRecord) => {
setLastClicked(record);
};

return (
<>
<h3>Hovered</h3>
<pre>{JSON.stringify(hoveredRecord)}</pre>
<h3>Clicked</h3>
<pre>{JSON.stringify(lastClicked)}</pre>
<div style={{ maxWidth: '800px' }} className='design-system'>
<Table data={argData} options={{...argOptions, rowProps: { onClick, onMouseEnter, onMouseLeave}}}/>
</div>;
<h3>Hovered</h3>
<pre>{JSON.stringify(hoveredRecord)}</pre>
<h3>Clicked</h3>
<pre>{JSON.stringify(lastClicked)}</pre>
<div style={{ maxWidth: '800px' }} className="design-system">
<Table
data={argData}
options={{ ...argOptions, rowProps: { onClick, onMouseEnter, onMouseLeave } }}
/>
</div>
;
</>
);
};
Expand Down
48 changes: 32 additions & 16 deletions packages/visualizations-react/stories/Table/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ export default [
wordCount: 1200,
readingTime: 5.5,
url: 'htt:broken-url',
geopoint: [2.357573,48.837904],
geoshape: 'centre-val-de-loire',
geopoint: [2.357573, 48.837904],
region: 'Centre Val de Loire',
geoshape:
'https://france-geojson.gregoiredavid.fr/repo/regions/centre-val-de-loire/region-centre-val-de-loire.geojson',
},
{
title: 'pellentesque nec blog post',
Expand All @@ -21,8 +23,10 @@ export default [
wordCount: 800,
readingTime: 3.8,
url: 'https://example.com/pellentesque-nec',
geopoint: [2.357573,48.837904],
geoshape: 'bretagne',
geopoint: [2.357573, 48.837904],
region: 'Bretagne',
geoshape:
'https://france-geojson.gregoiredavid.fr/repo/regions/bretagne/region-bretagne.geojson',
},
{
title: 'fusce sit amet blog post',
Expand All @@ -34,8 +38,10 @@ export default [
wordCount: 1500,
readingTime: 7.2,
url: 'https://example.com/fusce-sit-amet',
geopoint: [2.357573,48.837904],
geoshape: 'nouvelle-aquitaine',
geopoint: [2.357573, 48.837904],
region: 'Nouvelle Aquitaine',
geoshape:
'https://france-geojson.gregoiredavid.fr/repo/regions/nouvelle-aquitaine/region-nouvelle-aquitaine.geojson',
},
{
title: 'vestibulum nec blog post',
Expand All @@ -46,8 +52,10 @@ export default [
wordCount: 1000,
readingTime: 4.5,
url: 'https://example.com/vestibulum-nec',
geopoint: [2.357573,48.837904],
geoshape: 'occitanie',
geopoint: [2.357573, 48.837904],
region: 'Occitanie',
geoshape:
'https://france-geojson.gregoiredavid.fr/repo/regions/occitanie/region-occitanie.geojson',
},
{
title: 'Cras At Blog Post',
Expand All @@ -59,8 +67,10 @@ export default [
wordCount: 1300,
readingTime: 6.0,
url: 'https://example.com/cras-at',
geopoint: [2.357573,48.837904],
geoshape: 'provence-alpes-cote-d-azur',
geopoint: [2.357573, 48.837904],
region: 'PACA',
geoshape:
'https://france-geojson.gregoiredavid.fr/repo/regions/provence-alpes-cote-d-azur/region-provence-alpes-cote-d-azur.geojson',
},
{
title: 'Quisque A Blog Post',
Expand All @@ -72,8 +82,10 @@ export default [
wordCount: 900,
readingTime: 4.0,
url: 'https://example.com/quisque-a',
geopoint: [2.357573,48.837904],
geoshape: 'auvergne-rhone-alpes',
geopoint: [2.357573, 48.837904],
region: 'Auvergnes Rhône-Alpes',
geoshape:
'https://france-geojson.gregoiredavid.fr/repo/regions/auvergne-rhone-alpes/region-auvergne-rhone-alpes.geojson',
},
{
title: 'Ut Vitae Blog Post',
Expand All @@ -85,8 +97,10 @@ export default [
wordCount: 1100,
readingTime: 5.0,
url: 'https://example.com/ut-vitae',
geopoint: [2.357573,48.837904],
geoshape: 'bourgogne-franche-comte',
geopoint: [2.357573, 48.837904],
region: 'Bourgogne Franche-Comté',
geoshape:
'https://france-geojson.gregoiredavid.fr/repo/regions/bourgogne-franche-comte/region-bourgogne-franche-comte.geojson',
},
{
title: 'Integer Id Blog Post',
Expand All @@ -98,8 +112,10 @@ export default [
wordCount: 950,
readingTime: 4.2,
url: 'https://example.com/integer-id',
geopoint: [2.357573,48.837904],
geoshape: 'grand-est',
geopoint: [2.357573, 48.837904],
region: 'Grand Est',
geoshape:
'https://france-geojson.gregoiredavid.fr/repo/regions/grand-est/region-grand-est.geojson',
},
{
title: 'Undefined row',
Expand Down
127 changes: 77 additions & 50 deletions packages/visualizations-react/stories/Table/options.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
import type { Column, TableOptions } from '@opendatasoft/visualizations';

export const columns: Column[] = [
export type DatasetRecord = {
title: string;
price: number;
content: string;
datePublished: string;
isFeatured: boolean;
wordCount: number;
readingTime: number;
url: string;
geopoint: [number, number];
region: string;
geoshape: string;
};

export const columns: Column<DatasetRecord>[] = [
{
title: 'Title',
key: 'title',
dataFormat: 'short-text',
options: {
display: (title: string) => `${title.toUpperCase()}`,
valueToLabel: (v: string) => v.toUpperCase(),
},
},
{
Expand All @@ -30,7 +44,7 @@ export const columns: Column[] = [
key: 'datePublished',
dataFormat: 'date',
options: {
display: (date: string) => `${date} 🗓️`,
valueToLabel: (v: string) => `${v} 🗓️`,
intl: {
dateStyle: 'full',
},
Expand All @@ -41,15 +55,15 @@ export const columns: Column[] = [
key: 'isFeatured',
dataFormat: 'boolean',
options: {
display: (bool: boolean) => (bool ? 'αληθές' : 'ψευδές'),
valueToLabel: (v: boolean) => (v ? 'αληθές' : 'ψευδές'),
},
},
{
title: 'Word count',
key: 'wordCount',
dataFormat: 'number',
options: {
display: (v: string) => `${v} words`,
valueToLabel: (v: number) => `${v} words`,
KevinFabre-ods marked this conversation as resolved.
Show resolved Hide resolved
},
},
{
Expand All @@ -68,72 +82,85 @@ export const columns: Column[] = [
key: 'url',
dataFormat: 'url',
options: {
display: (value: string) => value.startsWith('https://') ? 'link' : 'broken link',
valueToLabel: (v: string) => (v.startsWith('https://') ? 'link' : 'broken link'),
},
},
{
title: 'Geo point',
key: 'geopoint',
dataFormat: 'geo',
options: {
accessor: r => {
const coordinates = r.geopoint;

return {
sources: {
'table-stories': {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: [
{
id: 1,
type: 'Feature',
geometry: {
type: 'Point',
coordinates,
},
},
],
},
},
},
layers: [
{
id: 'table-stories-layer',
source: 'table-stories',
type: 'circle',
color: 'black',
borderColor: 'white',
},
],
};
},
options: r => ({
mapOptions: {
style: 'https://demotiles.maplibre.org/style.json',
interactive: false,
},
display: (v: unknown) => `longitude: ${(v as number[])[0]}, latitude: ${(v as number[])[1]}`,
sources: (coordinates: unknown) => ({
'table-stories' : {
type: 'geojson',
data: {
type: 'FeatureCollection',
features: [
{
id: 1,
type: 'Feature',
geometry: {
type: 'Point',
coordinates,
},
},
],
}
},
}),
layers: () => ([{
id:'table-stories-layer',
source: 'table-stories',
type: 'circle',
color: 'black',
borderColor: 'white',
}])
},
valueToLabel: () =>
r?.geopoint && `longitude: ${r.geopoint[0]}, latitude: ${r.geopoint[1]}`,
}),
},
{
title: 'Geo shapes',
key: 'geoshape',
dataFormat: 'geo',
options: {
accessor: r => ({
sources: {
'table-stories': {
type: 'geojson',
data: r.geoshape,
},
},
layers: [
{
id: 'table-stories-layer',
source: 'table-stories',
type: 'fill',
color: 'black',
borderColor: 'white',
},
],
}),
options: r => ({
mapOptions: {
style: 'https://demotiles.maplibre.org/style.json',
interactive: false,
bbox: [-6.855469, 41.343825, 11.645508, 51.37178],
zoom: 3,
},
display: (v : unknown) => v as string,
sources: (v: unknown) => ({
'table-stories' : {
type: 'geojson',
data: `https://france-geojson.gregoiredavid.fr/repo/regions/${v}/region-${v}.geojson`
},
}),
layers: () => ([{
id:'table-stories-layer',
source: 'table-stories',
type: "fill",
color: 'black',
borderColor: 'white',
}])
},
valueToLabel: () => r.region,
}),
},
];

Expand Down
Loading
Loading