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

Add isHidden prop for optional hiding of stories #1090

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
60 changes: 34 additions & 26 deletions app/scripts/components/common/catalog/prepare-datasets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,29 @@ interface FilterOptionsType {
filterLayers?: boolean | null;
}

export function prepareDatasets(data: DatasetData[], options: FilterOptionsType): DatasetData[];
export function prepareDatasets(data: StoryData[], options: FilterOptionsType): StoryData[];
export function prepareDatasets (
export function prepareDatasets(
data: DatasetData[],
options: FilterOptionsType
): DatasetData[];
export function prepareDatasets(
data: StoryData[],
options: FilterOptionsType
): StoryData[];
export function prepareDatasets(
data: DatasetData[] | StoryData[],
options: FilterOptionsType
) {
const { sortField, sortDir, search, taxonomies, filterLayers } = options;
let filtered = [...data];

filtered = filtered.filter((d) => !d.isHidden);

// Does the free text search appear in specific fields?
if (search && search.length >= 3) {
const searchLower = search.toLowerCase();
// Function to check if searchLower is included in any of the string fields
const includesSearchLower = (str) => str.toLowerCase().includes(searchLower);
const includesSearchLower = (str) =>
str.toLowerCase().includes(searchLower);
// Function to determine if a layer matches the search criteria
const layerMatchesSearch = (layer) =>
includesSearchLower(layer.stacCol) ||
Expand All @@ -37,28 +46,27 @@ export function prepareDatasets (
includesSearchLower(layer.parentDataset.id) ||
includesSearchLower(layer.description);

filtered = filtered
.filter((d) => {
// Pre-calculate lowercased versions to use in comparisons
const idLower = d.id.toLowerCase();
const nameLower = d.name.toLowerCase();
const descriptionLower = d.description.toLowerCase();
const topicsTaxonomy = d.taxonomy.find((t) => t.name === TAXONOMY_TOPICS);
// Check if any of the conditions for including the item are met
return (
idLower.includes(searchLower) ||
nameLower.includes(searchLower) ||
descriptionLower.includes(searchLower) ||
(isDatasetData(d) && d.layers.some(layerMatchesSearch)) ||
topicsTaxonomy?.values.some((t) => includesSearchLower(t.name))
);
});
filtered = filtered.filter((d) => {
// Pre-calculate lowercased versions to use in comparisons
const idLower = d.id.toLowerCase();
const nameLower = d.name.toLowerCase();
const descriptionLower = d.description.toLowerCase();
const topicsTaxonomy = d.taxonomy.find((t) => t.name === TAXONOMY_TOPICS);
// Check if any of the conditions for including the item are met
return (
idLower.includes(searchLower) ||
nameLower.includes(searchLower) ||
descriptionLower.includes(searchLower) ||
(isDatasetData(d) && d.layers.some(layerMatchesSearch)) ||
topicsTaxonomy?.values.some((t) => includesSearchLower(t.name))
);
});

if (filterLayers)
filtered = filtered.map((d) => ({
...d,
layers: (isDatasetData(d) && d.layers.filter(layerMatchesSearch)),
})) as DatasetData[];
if (filterLayers)
filtered = filtered.map((d) => ({
...d,
layers: isDatasetData(d) && d.layers.filter(layerMatchesSearch)
})) as DatasetData[];
}

taxonomies &&
Expand Down Expand Up @@ -86,4 +94,4 @@ export function prepareDatasets (
}

return filtered;
}
}
29 changes: 13 additions & 16 deletions app/scripts/types/veda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { MDXModule } from 'mdx/types';
// ///////////////////////////////////////////////////////////////////////////
// Datasets //
// ///////////////////////////////////////////////////////////////////////////
export type DatasetLayerType = 'raster' | 'vector' | 'zarr'| 'cmr';
export type DatasetLayerType = 'raster' | 'vector' | 'zarr' | 'cmr';

//
// Dataset Layers
Expand All @@ -26,7 +26,7 @@ interface DatasetLayerCommonCompareProps {
mapLabel?: string | DatasetDatumFn<DatasetDatumReturnType>;
}

interface DatasetLayerCommonProps extends DatasetLayerCommonCompareProps{
interface DatasetLayerCommonProps extends DatasetLayerCommonCompareProps {
zoomExtent?: number[];
bounds?: number[];
sourceParams?: Record<string, any>;
Expand All @@ -35,17 +35,15 @@ interface DatasetLayerCommonProps extends DatasetLayerCommonCompareProps{
export type DatasetDatumFn<T> = (bag: DatasetDatumFnResolverBag) => T;
export type DatasetDatumReturnType = Primitives | Date;

export interface DatasetLayerCompareSTAC
extends DatasetLayerCommonProps {
export interface DatasetLayerCompareSTAC extends DatasetLayerCommonProps {
stacCol: string;
type: DatasetLayerType;
name: string;
description: string;
legend?: LayerLegendCategorical | LayerLegendGradient;
}

export interface DatasetLayerCompareInternal
extends DatasetLayerCommonProps {
export interface DatasetLayerCompareInternal extends DatasetLayerCommonProps {
datasetId: string;
layerId: string;
}
Expand All @@ -56,10 +54,10 @@ export enum TimeDensity {
DAY = 'day'
}
export interface LayerInfo {
source: string;
spatialExtent: string;
temporalResolution: string;
unit: string;
source: string;
spatialExtent: string;
temporalResolution: string;
unit: string;
}
export interface DatasetLayer extends DatasetLayerCommonProps {
id: string;
Expand All @@ -83,22 +81,20 @@ export interface DatasetLayer extends DatasetLayerCommonProps {
assetUrlReplacements?: {
from: string;
to: string;
},
};
time_density?: TimeDensity;
info?: LayerInfo;
}
// A normalized compare layer is the result after the compare definition is
// resolved from DatasetLayerCompareSTAC or DatasetLayerCompareInternal. The
// difference with a "base" dataset layer is not having a name and
// description.
export interface DatasetLayerCompareBase
extends DatasetLayerCommonProps {
export interface DatasetLayerCompareBase extends DatasetLayerCommonProps {
id: string;
stacCol: string;
type: DatasetLayerType;
}
export interface DatasetLayerCompareNormalized
extends DatasetLayerCommonProps {
export interface DatasetLayerCompareNormalized extends DatasetLayerCommonProps {
id: string;
name: string;
description: string;
Expand Down Expand Up @@ -130,7 +126,6 @@ interface LayerLegendUnit {
label: string;
}


export interface LayerLegendGradient {
type: 'gradient';
unit?: LayerLegendUnit;
Expand Down Expand Up @@ -189,6 +184,7 @@ export interface DatasetData {
layers: DatasetLayer[];
related?: RelatedContentData[];
disableExplore?: boolean;
isHidden?: boolean;
}

// ///////////////////////////////////////////////////////////////////////////
Expand All @@ -208,6 +204,7 @@ export interface StoryData {
taxonomy: Taxonomy[];
related?: RelatedContentData[];
asLink?: LinkContentData;
isHidden?: boolean;
}

// ///////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions mock/stories/life-of-water.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ related:
id: no2
- type: story
id: external-link-test
isHidden: true
---

<Block>
Expand Down
52 changes: 25 additions & 27 deletions parcel-resolver-veda/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ declare module 'veda' {
// ///////////////////////////////////////////////////////////////////////////
// Datasets //
// ///////////////////////////////////////////////////////////////////////////
type DatasetLayerType = 'raster' | 'vector' | 'zarr'| 'cmr';
type DatasetLayerType = 'raster' | 'vector' | 'zarr' | 'cmr';

//
// Dataset Layers
Expand All @@ -28,26 +28,24 @@ declare module 'veda' {
mapLabel?: string | DatasetDatumFn<DatasetDatumReturnType>;
}

interface DatasetLayerCommonProps extends DatasetLayerCommonCompareProps{
interface DatasetLayerCommonProps extends DatasetLayerCommonCompareProps {
zoomExtent?: number[];
bounds?: number[];
sourceParams?: Record<string, any>;
}

export type DatasetDatumFn<T> = (bag: DatasetDatumFnResolverBag) => T;
export type DatasetDatumReturnType = Primitives | Date;

export interface DatasetLayerCompareSTAC
extends DatasetLayerCommonProps {

export interface DatasetLayerCompareSTAC extends DatasetLayerCommonProps {
stacCol: string;
type: DatasetLayerType;
name: string;
description: string;
legend?: LayerLegendCategorical | LayerLegendGradient;
}

export interface DatasetLayerCompareInternal
extends DatasetLayerCommonProps {
export interface DatasetLayerCompareInternal extends DatasetLayerCommonProps {
datasetId: string;
layerId: string;
}
Expand All @@ -57,12 +55,12 @@ declare module 'veda' {
MONTH = 'month',
DAY = 'day'
}
export interface LayerInfo {
source: string;
spatialExtent: string;
temporalResolution: string;
unit: string;
}
export interface LayerInfo {
source: string;
spatialExtent: string;
temporalResolution: string;
unit: string;
}
export interface DatasetLayer extends DatasetLayerCommonProps {
id: string;
stacCol: string;
Expand All @@ -85,16 +83,15 @@ export interface LayerInfo {
assetUrlReplacements?: {
from: string;
to: string;
},
};
time_density?: TimeDensity;
info?: LayerInfo;
}
// A normalized compare layer is the result after the compare definition is
// resolved from DatasetLayerCompareSTAC or DatasetLayerCompareInternal. The
// difference with a "base" dataset layer is not having a name and
// description.
export interface DatasetLayerCompareBase
extends DatasetLayerCommonProps {
export interface DatasetLayerCompareBase extends DatasetLayerCommonProps {
id: string;
stacCol: string;
type: DatasetLayerType;
Expand Down Expand Up @@ -190,6 +187,7 @@ export interface LayerInfo {
layers: DatasetLayer[];
related?: RelatedContentData[];
disableExplore?: boolean;
isHidden?: boolean;
}

// ///////////////////////////////////////////////////////////////////////////
Expand All @@ -209,6 +207,7 @@ export interface LayerInfo {
taxonomy: Taxonomy[];
related?: RelatedContentData[];
asLink?: LinkContentData;
isHidden?: boolean;
}

// ///////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -251,24 +250,23 @@ export interface LayerInfo {
id: string;
name: string;
}
/**
* Not exporting this type
* Since we are moving forward to ditching VEDA faux module
*/
/**
* Not exporting this type
* Since we are moving forward to ditching VEDA faux module
*/

enum BannerType {
info = 'info',
warning ='warning'
warning = 'warning'
}

const infoTypeFlag = BannerType.info;
interface BannerData {
expires: Date,
url: string,
text: string,
type?: BannerType
expires: Date;
url: string;
text: string;
type?: BannerType;
}


/**
* Named exports: datasets.
Expand Down
Loading