diff --git a/package.json b/package.json index 10cb12a..42a506d 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "charts" ], "license": "MIT", - "version": "0.0.37", + "version": "0.0.38", "type": "module", "main": "./dist/galaxy-charts.umd.cjs", "module": "./dist/galaxy-charts.js", diff --git a/src/store/columnsStore.ts b/src/store/columnsStore.ts index 6fc7f5b..b8c769a 100644 --- a/src/store/columnsStore.ts +++ b/src/store/columnsStore.ts @@ -11,6 +11,10 @@ interface Track { } export function useColumnsStore() { + function checkColumns(tracks: Track[], keys: string[]) { + return tracks.every((track) => keys.every((key) => typeof track[key] === "string" && track[key].trim() !== "")); + } + function getColumns(tracks: Track[], keys: string[]): string[] { const columnsList: string[] = []; for (const track of tracks) { @@ -25,31 +29,35 @@ export function useColumnsStore() { } async function fetchColumns(datasetId: string, tracks: Track[], keys: string[]): Promise[]> { - columns.value[datasetId] = columns.value[datasetId] || {}; - const columnsAvailable = Object.keys(columns.value[datasetId]); - const columnsList = getColumns(tracks, keys).filter((x) => !columnsAvailable.includes(x)); - if (columnsList.length > 0) { - const columnsData = await datasetsGetColumns(datasetId, columnsList); - if (columnsData) { - for (const [index, column] of columnsList.entries()) { - columns.value[datasetId][column] = columnsData[index]; + if (checkColumns(tracks, keys)) { + columns.value[datasetId] = columns.value[datasetId] || {}; + const columnsAvailable = Object.keys(columns.value[datasetId]); + const columnsList = getColumns(tracks, keys).filter((x) => !columnsAvailable.includes(x)); + if (columnsList.length > 0) { + const columnsData = await datasetsGetColumns(datasetId, columnsList); + if (columnsData) { + for (const [index, column] of columnsList.entries()) { + columns.value[datasetId][column] = columnsData[index]; + } } } - } - const results: Record[] = []; - tracks.forEach((track) => { - const trackEntry: Record = {}; - keys.forEach((key) => { - const column = track[key]; - if (column && !SPECIAL_KEYS.includes(column)) { - trackEntry[key] = columns.value[datasetId][column]; - } + const results: Record[] = []; + tracks.forEach((track) => { + const trackEntry: Record = {}; + keys.forEach((key) => { + const column = track[key]; + if (column && !SPECIAL_KEYS.includes(column)) { + trackEntry[key] = columns.value[datasetId][column]; + } + }); + results.push(trackEntry); }); - results.push(trackEntry); - }); - return results; + return results; + } else { + return []; + } } return {