Skip to content

Commit 3f607f5

Browse files
DynamoDB: Pagination in Query Panel (#5438)
* Pagination in query panel * Query pagination changes * Query pagination final changes * Added items per page icon * Added external link to dynamodb node * Updated refreshed on to human readable format * Added title on the vscode cell to view data on hover * Edit item changes * Fixing UI bugs * Fixing tooltip issue * Changes to to make Run button theme friendly. * Fixed page number link * fix for context menu truncated issue * Changes related to no items to display * Edit item changes --------- Co-authored-by: Lokesh Dogga <[email protected]>
1 parent 4f0aaff commit 3f607f5

File tree

14 files changed

+463
-70
lines changed

14 files changed

+463
-70
lines changed

package-lock.json

Lines changed: 30 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"dependencies": {
7171
"@aws-toolkits/telemetry": "^1.0.229",
7272
"@vscode/webview-ui-toolkit": "^1.4.0",
73+
"date-fns": "^3.6.0",
7374
"vscode-nls": "^5.2.0",
7475
"vscode-nls-dev": "^4.0.4"
7576
}

packages/core/package.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@
7575
"maximum": 250,
7676
"markdownDescription": "%AWS.configuration.description.iot.maxItemsPerPage%"
7777
},
78+
"aws.dynamodb.maxItemsPerPage": {
79+
"type": "number",
80+
"default": 100,
81+
"minimum": 10,
82+
"maximum": 250,
83+
"markdownDescription": "%AWS.configuration.description.dynamodb.maxItemsPerPage%"
84+
},
7885
"aws.s3.maxItemsPerPage": {
7986
"type": "number",
8087
"default": 300,
@@ -1224,6 +1231,10 @@
12241231
{
12251232
"command": "aws.dynamoDb.deleteTable",
12261233
"when": "false"
1234+
},
1235+
{
1236+
"command": "aws.dynamoDb.openTableInConsole",
1237+
"when": "false"
12271238
}
12281239
],
12291240
"editor/title": [
@@ -2039,6 +2050,11 @@
20392050
"command": "aws.dynamoDb.deleteTable",
20402051
"group": "0@1",
20412052
"when": "view == aws.explorer && viewItem == awsDynamoDbTableNode"
2053+
},
2054+
{
2055+
"command": "aws.dynamoDb.openTableInConsole",
2056+
"group": "inline@1",
2057+
"when": "view == aws.explorer && viewItem == awsDynamoDbTableNode"
20422058
}
20432059
],
20442060
"aws.toolkit.auth": [
@@ -3637,6 +3653,18 @@
36373653
"category": "%AWS.title.cn%"
36383654
}
36393655
}
3656+
},
3657+
{
3658+
"command": "aws.dynamoDb.openTableInConsole",
3659+
"title": "%AWS.command.dynamoDb.openTableInConsole%",
3660+
"category": "%AWS.title%",
3661+
"enablement": "!aws.isWebExtHost",
3662+
"icon": "$(link-external)",
3663+
"cloud9": {
3664+
"cn": {
3665+
"category": "%AWS.title.cn%"
3666+
}
3667+
}
36403668
}
36413669
],
36423670
"jsonValidation": [

packages/core/package.nls.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"AWS.configuration.description.lambda.recentlyUploaded": "Recently selected Lambda upload targets.",
1010
"AWS.configuration.description.ecs.openTerminalCommand": "The command to run when starting a new interactive terminal session.",
1111
"AWS.configuration.description.iot.maxItemsPerPage": "Controls how many IoT Things, Certificates, or Policies are listed before showing a node to `Load More...`.",
12+
"AWS.configuration.description.dynamodb.maxItemsPerPage": "Controls how many items to show per page in DynamoDB table view.",
1213
"AWS.configuration.description.s3.maxItemsPerPage": "Controls how many S3 items are listed before showing a node to `Load More...`.\nThis corresponds to the `MaxKeys` requested in a single call to S3. [Learn More](https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html#AmazonS3-ListObjectsV2-response-MaxKeys)",
1314
"AWS.configuration.description.samcli.lambdaTimeout": "Maximum time (in milliseconds) to wait for SAM output while starting a Local Lambda session",
1415
"AWS.configuration.description.samcli.location": "Location of SAM CLI. SAM CLI is used to create, build, package, and deploy Serverless Applications. [Learn More](https://aws.amazon.com/serverless/sam/)",
@@ -266,7 +267,8 @@
266267
"AWS.amazonq.codewhisperer.title": "Amazon Q",
267268
"AWS.amazonq.toggleCodeSuggestion": "Toggle Auto-Suggestions",
268269
"AWS.amazonq.toggleCodeScan": "Toggle Auto-Scans",
269-
"AWS.command.dynamoDb.searchTables": "Search Tables",
270+
"AWS.command.dynamoDb.searchTables": "Search DynamoDB Tables",
270271
"AWS.command.dynamoDb.viewTable": "View Table",
271-
"AWS.command.dynamoDb.deleteTable": "Delete Table"
272+
"AWS.command.dynamoDb.deleteTable": "Delete Table",
273+
"AWS.command.dynamoDb.openTableInConsole": "Open table in browser"
272274
}

packages/core/src/dynamoDb/activation.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import * as vscode from 'vscode'
67
import { ExtContext } from '../shared/extensions'
78
import { copyDynamoDbArn } from './utils/dynamodb'
89
import { viewDynamoDbTable } from './vue/tableView'
10+
import { dynamoDbConsoleUrl } from './utils/dynamodb'
911
import { Commands } from '../shared/vscode/commands2'
1012
import { DynamoDbTableNode } from './explorer/dynamoDbTableNode'
1113
import { deleteDynamoDbTable } from './commands/deleteDynamoDbTable'
@@ -34,6 +36,11 @@ export async function activate(context: ExtContext): Promise<void> {
3436

3537
Commands.register('aws.dynamoDb.deleteTable', async (node: DynamoDbTableNode) => {
3638
await deleteDynamoDbTable(node)
39+
}),
40+
41+
Commands.register('aws.dynamoDb.openTableInConsole', async (node: DynamoDbTableNode) => {
42+
const url = dynamoDbConsoleUrl(node)
43+
return vscode.env.openExternal(url)
3744
})
3845
)
3946
}

packages/core/src/dynamoDb/explorer/dynamoDbInstanceNode.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { DynamoDbTableNode } from './dynamoDbTableNode'
88
import { makeChildrenNodes } from '../../shared/treeview/utils'
99
import { DynamoDbClient } from '../../shared/clients/dynamoDbClient'
1010
import { AWSTreeNodeBase } from '../../shared/treeview/nodes/awsTreeNodeBase'
11+
import { PlaceholderNode } from '../../shared/treeview/nodes/placeholderNode'
1112
import { toMap, toArrayAsync, updateInPlace } from '../../shared/utilities/collectionUtils'
1213

1314
export class DynamoDbInstanceNode extends AWSTreeNodeBase {
@@ -29,6 +30,7 @@ export class DynamoDbInstanceNode extends AWSTreeNodeBase {
2930
await this.updateChildren()
3031
return [...this.dynamoDbTableNodes.values()]
3132
},
33+
getNoChildrenPlaceholderNode: async () => new PlaceholderNode(this, this.placeHolderMessage),
3234
})
3335
}
3436

packages/core/src/dynamoDb/utils/dynamodb.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import * as vscode from 'vscode'
67
import { DynamoDB } from 'aws-sdk'
8+
import { Settings } from '../../shared'
79
import { copyToClipboard } from '../../shared/utilities/messages'
810
import { DynamoDbTableNode } from '../explorer/dynamoDbTableNode'
911
import { DynamoDbClient } from '../../shared/clients/dynamoDbClient'
@@ -33,6 +35,7 @@ export async function getTableContent(
3335
regionCode: string,
3436
client = new DynamoDbClient(regionCode)
3537
) {
38+
tableRequest.Limit = await getMaxItemsPerPage()
3639
const response = await client.scanTable(tableRequest)
3740
const { columnNames, tableHeader } = getTableColumnsNames(response)
3841
const tableItems = getTableItems(columnNames, response)
@@ -45,7 +48,7 @@ export async function getTableContent(
4548
return tableData
4649
}
4750

48-
function getTableColumnsNames(items: DynamoDB.Types.ScanOutput): {
51+
export function getTableColumnsNames(items: DynamoDB.Types.ScanOutput): {
4952
columnNames: Set<string>
5053
tableHeader: RowData[]
5154
} {
@@ -66,7 +69,7 @@ function getTableColumnsNames(items: DynamoDB.Types.ScanOutput): {
6669
}
6770
}
6871

69-
function getTableItems(tableColumnsNames: Set<string>, items: DynamoDB.Types.ScanOutput) {
72+
export function getTableItems(tableColumnsNames: Set<string>, items: DynamoDB.Types.ScanOutput) {
7073
const tableItems = []
7174
for (const item of items.Items ?? []) {
7275
const curItem: RowData = {}
@@ -99,9 +102,12 @@ export async function queryTableContent(
99102
queryRequest: { partitionKey: string; sortKey: string },
100103
regionCode: string,
101104
tableName: string,
105+
lastEvaluatedKey?: Key,
102106
client = new DynamoDbClient(regionCode)
103107
) {
104108
const queryRequestObject = await prepareQueryRequestObject(tableName, regionCode, client, queryRequest)
109+
queryRequestObject.Limit = await getMaxItemsPerPage()
110+
queryRequestObject.ExclusiveStartKey = lastEvaluatedKey
105111
const queryResponse = await client.queryTable(queryRequestObject)
106112
const { columnNames, tableHeader } = getTableColumnsNames(queryResponse)
107113
const tableItems = getTableItems(columnNames, queryResponse)
@@ -203,7 +209,7 @@ export async function getTableKeySchema(
203209
return tableSchema
204210
}
205211

206-
function getAttributeValue(attribute: AttributeValue): { key: string; value: any } | undefined {
212+
export function getAttributeValue(attribute: AttributeValue): { key: string; value: any } | undefined {
207213
const keys = Object.keys(attribute) as (keyof AttributeValue)[]
208214
for (const key of keys) {
209215
const value = attribute[key]
@@ -242,3 +248,13 @@ export async function deleteItem(
242248
}
243249
return await client.deleteItem(deleteRequest)
244250
}
251+
252+
async function getMaxItemsPerPage(): Promise<number> {
253+
return Settings.instance.getSection('aws').get<number>('dynamodb.maxItemsPerPage', 100)
254+
}
255+
256+
export function dynamoDbConsoleUrl(node: DynamoDbTableNode): vscode.Uri {
257+
const service = 'dynamodb'
258+
const resourcePath = `tables:selected=${node.dynamoDbtable}`
259+
return vscode.Uri.parse(`https://console.aws.amazon.com/${service}/home?region=${node.regionCode}#/${resourcePath}`)
260+
}

0 commit comments

Comments
 (0)