Skip to content

Commit

Permalink
refactor: Remove prototype overwrite in favor of updating rdf-cube-vi…
Browse files Browse the repository at this point in the history
…ew-query
  • Loading branch information
bprusinowski committed Jun 1, 2023
1 parent 25d186e commit 76cd590
Show file tree
Hide file tree
Showing 4 changed files with 921 additions and 71 deletions.
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"postgres-migrations": "^5.2.0",
"prisma": "^4.5.0",
"qs": "^6.10.1",
"rdf-cube-view-query": "^1.11.1",
"rdf-cube-view-query": "^1.12.0",
"rdf-ext": "^1.3.2",
"react-beautiful-dnd": "^13.0.0",
"react-error-boundary": "^3.1.3",
Expand Down
27 changes: 5 additions & 22 deletions app/rdf/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
CubeDimension,
Filter,
LookupSource,
View as RDFView,
View,
} from "rdf-cube-view-query";
import rdf from "rdf-ext";
import { Literal, NamedNode } from "rdf-js";
Expand Down Expand Up @@ -45,23 +45,6 @@ import { loadResourceLiterals } from "./query-literals";
import { loadUnversionedResources } from "./query-sameas";
import { loadUnits } from "./query-unit-labels";

// FIXME: Remove once sorting is removed (https://github.com/zazuko/rdf-cube-view-query/pull/96)
const View = RDFView;
View.prototype.setDefaultColumns = function () {
const orderingColumns = this.dimensions.map((dimension) => ({
// @ts-ignore
iri: dimension.cubeDimensions[0].path.value,
term: dimension.ptr.term,
}));

const projectionPtr = this.ptr.out(ns.view.projection);
projectionPtr.addList(
ns.view.columns,
// @ts-ignore
orderingColumns.map((dimension) => dimension.term)
);
};

const DIMENSION_VALUE_UNDEFINED = ns.cube.Undefined.value;

/** Adds a suffix to an iri to mark its label */
Expand Down Expand Up @@ -513,7 +496,7 @@ export const getCubeObservations = async ({
observations: Observation[];
observationsRaw: Record<string, Literal | NamedNode>[];
}> => {
const cubeView = View.fromCube(cube);
const cubeView = View.fromCube(cube, false);

const allResolvedDimensions = await getCubeDimensions({
cube,
Expand Down Expand Up @@ -635,7 +618,7 @@ const buildFilters = ({
locale,
}: {
cube: Cube;
view: RDFView;
view: View;
filters: Filters;
locale: string;
}): Filter[] => {
Expand Down Expand Up @@ -735,7 +718,7 @@ async function fetchViewObservations({
disableDistinct,
}: {
limit: number | undefined;
observationsView: RDFView;
observationsView: View;
disableDistinct: boolean;
}) {
/**
Expand Down Expand Up @@ -820,7 +803,7 @@ function buildDimensions({
observationFilters,
raw,
}: {
cubeView: RDFView;
cubeView: View;
dimensions: Maybe<string[]>;
cubeDimensions: ResolvedDimension[];
cube: Cube;
Expand Down
2 changes: 1 addition & 1 deletion app/typings/rdf.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ declare module "rdf-cube-view-query" {
filters?: Filter[];
}
);
static fromCube(cube: Cube): View;
static fromCube(cube: Cube, sortColumns?: boolean): View;
out: AnyPointer;
dimensions: Dimension[];
dimension(options: { cubeDimension: NamedNode | string }): Dimension | null;
Expand Down
Loading

0 comments on commit 76cd590

Please sign in to comment.