Skip to content

Commit 7564040

Browse files
check for file:/// or https:// data file url in Open Data File prompt (#99)
prior to executing view table command for the given data file url
1 parent a71d73c commit 7564040

File tree

3 files changed

+126
-3
lines changed

3 files changed

+126
-3
lines changed

data/usa-airports.tsv.schema.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"fields": [
3+
{
4+
"name": "iata",
5+
"type": "string",
6+
"format": "default"
7+
},
8+
{
9+
"name": "name",
10+
"type": "string",
11+
"format": "default"
12+
},
13+
{
14+
"name": "city",
15+
"type": "string",
16+
"format": "default"
17+
},
18+
{
19+
"name": "state",
20+
"type": "string",
21+
"format": "default"
22+
},
23+
{
24+
"name": "country",
25+
"type": "string",
26+
"format": "default"
27+
},
28+
{
29+
"name": "latitude",
30+
"type": "number",
31+
"format": "default"
32+
},
33+
{
34+
"name": "longitude",
35+
"type": "number",
36+
"format": "default"
37+
}
38+
],
39+
"missingValues": [
40+
""
41+
]
42+
}

data/usa-airports.tsv.table.json

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"columns": [
3+
{
4+
"width": 52,
5+
"minWidth": 40,
6+
"download": false,
7+
"formatter": "rowSelection",
8+
"titleFormatter": "rowSelection",
9+
"resizable": true,
10+
"headerSort": false
11+
},
12+
{
13+
"field": "iata",
14+
"title": "iata",
15+
"width": 79,
16+
"minWidth": 40,
17+
"resizable": true,
18+
"sorter": "string",
19+
"headerSort": true
20+
},
21+
{
22+
"field": "name",
23+
"title": "name",
24+
"width": 155,
25+
"minWidth": 40,
26+
"resizable": true,
27+
"sorter": "string",
28+
"headerSort": true
29+
},
30+
{
31+
"field": "city",
32+
"title": "city",
33+
"width": 143,
34+
"minWidth": 40,
35+
"resizable": true,
36+
"sorter": "string",
37+
"headerSort": true
38+
},
39+
{
40+
"field": "state",
41+
"title": "state",
42+
"width": 87,
43+
"minWidth": 40,
44+
"resizable": true,
45+
"sorter": "string",
46+
"headerSort": true
47+
},
48+
{
49+
"field": "country",
50+
"title": "country",
51+
"width": 104,
52+
"minWidth": 40,
53+
"resizable": true,
54+
"sorter": "string",
55+
"headerSort": true
56+
},
57+
{
58+
"field": "latitude",
59+
"title": "latitude",
60+
"width": 104,
61+
"minWidth": 40,
62+
"resizable": true,
63+
"sorter": "number",
64+
"headerSort": true
65+
},
66+
{
67+
"field": "longitude",
68+
"title": "longitude",
69+
"width": 177,
70+
"minWidth": 40,
71+
"resizable": true,
72+
"sorter": "number",
73+
"headerSort": true
74+
}
75+
]
76+
}

src/commands/openDataFile.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,20 @@ export async function registerOpenDataFileCommand(context: ExtensionContext) {
1818
window.showInputBox({
1919
ignoreFocusOut: true,
2020
placeHolder: 'file:/// or https://',
21-
prompt: 'Enter Data File Url'
22-
}).then((dataFileUrl: string | undefined) => {
21+
prompt: 'Enter Data File Url for Table View'
22+
}).then((dataFileUrl: string | undefined) => {
2323
if (dataFileUrl && dataFileUrl !== undefined && dataFileUrl.length > 0) {
2424
// create data file Uri
2525
const dataFileUri: Uri = Uri.parse(dataFileUrl);
2626

2727
// check supported data files
2828
const fileExtension: string = path.extname(dataFileUrl);
29-
if ((<any>Object).values(FileTypes).includes(fileExtension)) {
29+
if (!dataFileUrl?.startsWith('file:///') && !dataFileUrl?.startsWith('https://')) {
30+
window.showErrorMessage(
31+
`Tabular Data Viewer requires a valid \`file:///\` or \`https://\` data file Url \
32+
to display Table View. Invalid data document Url: \`${dataFileUrl}\`.`);
33+
}
34+
else if ((<any>Object).values(FileTypes).includes(fileExtension)) {
3035
// open table view for the data file
3136
commands.executeCommand(ViewCommands.viewTable, dataFileUri);
3237
}

0 commit comments

Comments
 (0)