Luccas Mateus 20ac80a5e8
Example of how to create a data portal in 5 minutes (#769)
* [example][m] - start of a simple-example

* Empty-Commit

* [simple-example][sm] - change from repos.json to datasets.json

* [example][m] - changed styling and added octokit

* [build][sm] - fix build
2023-04-18 13:51:48 -03:00

56 lines
1.2 KiB
TypeScript

// FrictionlessView is a factory because we have to
// set the views and resources lists before using it
import { convertSimpleToVegaLite } from "../../lib/viewSpecConversion";
import VegaLite from "./VegaLite";
export default function FrictionlessViewFactory({
views = [],
resources = [],
}): ({
viewId,
fullWidth,
}: {
viewId: number;
fullWidth?: boolean;
}) => JSX.Element {
return ({ viewId, fullWidth = false }) => {
if (!(viewId in views)) {
console.error(`View ${viewId} not found`);
return <></>;
}
const view = views[viewId];
let resource;
if (resources.length > 1) {
resource = resources.find((r) => r.name === view.resourceName);
} else {
resource = resources[0];
}
if (!resource) {
console.error(`Resource not found for view id ${viewId}`);
return <></>;
}
let vegaSpec;
switch (view.specType) {
case "simple":
vegaSpec = convertSimpleToVegaLite(view, resource);
break;
// ... other conversions
}
vegaSpec.data = { url: resource.path };
return (
<VegaLite
fullWidth={fullWidth}
spec={vegaSpec}
actions={{ editor: false }}
downloadFileName={resource.name}
/>
);
};
}