Skip to content

Commit

Permalink
Merge pull request #28509 from code-dot-org/column-dropdown
Browse files Browse the repository at this point in the history
Populate column dropdown for getList
  • Loading branch information
ajpal committed May 13, 2019
2 parents 4dd53ad + 9ba45f2 commit 85a9624
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
3 changes: 2 additions & 1 deletion apps/src/applab/dropletConfig.js
Expand Up @@ -15,6 +15,7 @@ import {
setPropertyDropdown,
setPropertyValueSelector
} from './setPropertyDropdown';
import {getListColumnDropdown} from './getListDropdown';
import {getStore} from '../redux';
import * as applabConstants from './constants';

Expand Down Expand Up @@ -527,7 +528,7 @@ export var blocks = [
params: ['tableName', 'columnName'],
dropdown: {
0: () => getAssetDropdown('dataset'),
1: ['true', 'false'] // () => populateColumns()
1: getListColumnDropdown()
},
nativeIsAsync: true,
type: 'value'
Expand Down
23 changes: 23 additions & 0 deletions apps/src/applab/getListDropdown.js
@@ -0,0 +1,23 @@
import datasetLibrary from '../code-studio/datasetLibrary.json';
import {getFirstParam} from '../dropletUtils';

export function getListColumnDropdown() {
return function(aceEditor) {
const tableName = getFirstParam('getList', this.parent, aceEditor);
const columns = getColumnsForTable(tableName);
const opts = [];
columns.forEach(columnName =>
opts.push({display: `"${columnName}"`, text: `"${columnName}"`})
);
return opts;
};
}

function getColumnsForTable(tableName) {
for (let dataset of datasetLibrary.datasets) {
if (`"${dataset.name}"` === tableName) {
return dataset.columns.split(',');
}
}
return [];
}
15 changes: 10 additions & 5 deletions apps/src/code-studio/datasetLibrary.json
Expand Up @@ -3,27 +3,32 @@
{
"name": "dogs",
"description": "Different breeds of dogs, including images and rankings on different qualities like size and friendliness",
"url": "/api/v1/dataset-library/dogBreeds.csv"
"url": "/api/v1/dataset-library/dogBreeds.csv",
"columns": "name,size,dogFriendly,imgURL"
},
{
"name": "words",
"description": "The 1000 most commonly used English words and their parts of speech",
"url": "/api/v1/dataset-library/words.csv"
"url": "/api/v1/dataset-library/words.csv",
"columns": "word,partOfSpeech"
},
{
"name": "countries",
"description": "Information about different countries, images of their flags, and MP3 of their anthem",
"url": "/api/v1/dataset-library/countries.csv"
"url": "/api/v1/dataset-library/countries.csv",
"columns": "Country,flagImgURL,Capital,anthemMP3"
},
{
"name": "spotify",
"description": "The top 20 songs in many regions of the world, including 30 second MP3 links to most songs",
"url": "/api/v1/dataset-library/spotify.csv"
"url": "/api/v1/dataset-library/spotify.csv",
"columns": "Track Name,Artist,Streams,songURL,Album Image,previewMP3,Position,Region,Country Code"
},
{
"name": "weather",
"description": "Daily weather forecasts for the next five days for a selection of US cities.",
"url": "/api/v1/dataset-library/weather.csv"
"url": "/api/v1/dataset-library/weather.csv",
"columns": "city,date,lowTemp,highTemp,condition,icon"
}
]
}

0 comments on commit 85a9624

Please sign in to comment.