console: fix browsing data for tables with json column and no primary key

GitOrigin-RevId: eb1696d3bf00c2e5805ffbf5847d382de655fab5
This commit is contained in:
Ikechukwu Eze 2021-03-23 18:08:49 +01:00 committed by hasura-bot
parent d236391af8
commit 341c8d8309
6 changed files with 33 additions and 9 deletions

View File

@ -37,7 +37,7 @@ export const addsNewPostgresDatabaseWithUrl = () => {
cy.getBySel('idle-timeout').type('180'); cy.getBySel('idle-timeout').type('180');
cy.getBySel('retries').type('1'); cy.getBySel('retries').type('1');
cy.getBySel('save-database').click(); cy.getBySel('save-database').click();
cy.get('.notification-success') cy.get('.notification-success', { timeout: 10000 })
.should('be.visible') .should('be.visible')
.and('contain', 'Database added successfully!'); .and('contain', 'Database added successfully!');
cy.url().should('eq', `${baseUrl}/data/manage`); cy.url().should('eq', `${baseUrl}/data/manage`);
@ -57,7 +57,7 @@ export const addsNewPgDBWithConParams = () => {
} }
cy.getBySel('database-name').type(config.dbName); cy.getBySel('database-name').type(config.dbName);
cy.getBySel('save-database').click(); cy.getBySel('save-database').click();
cy.get('.notification-success') cy.get('.notification-success', { timeout: 10000 })
.should('be.visible') .should('be.visible')
.and('contain', 'Database added successfully!'); .and('contain', 'Database added successfully!');
cy.url().should('eq', `${baseUrl}/data/manage`); cy.url().should('eq', `${baseUrl}/data/manage`);
@ -71,7 +71,7 @@ export const addsNewPgDBWithEnvVar = () => {
cy.getBySel('database-type').select('postgres'); cy.getBySel('database-type').select('postgres');
cy.getBySel('database-url-env').type('HASURA_GRAPHQL_DATABASE_URL'); cy.getBySel('database-url-env').type('HASURA_GRAPHQL_DATABASE_URL');
cy.getBySel('save-database').click(); cy.getBySel('save-database').click();
cy.get('.notification-success') cy.get('.notification-success', { timeout: 10000 })
.should('be.visible') .should('be.visible')
.and('contain', 'Database added successfully!'); .and('contain', 'Database added successfully!');
cy.url().should('eq', `${baseUrl}/data/manage`); cy.url().should('eq', `${baseUrl}/data/manage`);

View File

@ -227,11 +227,17 @@ const ViewRows = props => {
const pkClause = {}; const pkClause = {};
if (!isView && hasPrimaryKey) { if (!isView && hasPrimaryKey) {
tableSchema.primary_key.columns.map(key => { tableSchema.primary_key.columns.forEach(key => {
pkClause[key] = row[key];
});
} else if (tableSchema.unique_constraints?.length) {
tableSchema.unique_constraints[0].columns.forEach(key => {
pkClause[key] = row[key]; pkClause[key] = row[key];
}); });
} else { } else {
tableSchema.columns.map(key => { tableSchema.columns
.filter(c => !dataSource.isJsonColumn(c))
.forEach(key => {
pkClause[key.column_name] = row[key.column_name]; pkClause[key.column_name] = row[key.column_name];
}); });
} }

View File

@ -8,6 +8,7 @@ import {
TableColumn, TableColumn,
FrequentlyUsedColumn, FrequentlyUsedColumn,
PermissionColumnCategories, PermissionColumnCategories,
BaseTableColumn,
} from './types'; } from './types';
import { PGFunction, FunctionState } from './services/postgresql/types'; import { PGFunction, FunctionState } from './services/postgresql/types';
import { Operations } from './common'; import { Operations } from './common';
@ -89,6 +90,7 @@ export interface DataSourcesAPI {
fetchColumnTypesQuery: string; fetchColumnTypesQuery: string;
fetchColumnDefaultFunctions(schema: string): string; fetchColumnDefaultFunctions(schema: string): string;
isSQLFunction(str: string): boolean; isSQLFunction(str: string): boolean;
isJsonColumn(column: BaseTableColumn): boolean;
getEstimateCountQuery: (schemaName: string, tableName: string) => string; getEstimateCountQuery: (schemaName: string, tableName: string) => string;
isColTypeString(colType: string): boolean; isColTypeString(colType: string): boolean;
cascadeSqlQuery(sql: string): string; cascadeSqlQuery(sql: string): string;

View File

@ -1,6 +1,6 @@
import React from 'react'; import React from 'react';
import { DataSourcesAPI } from '../..'; import { DataSourcesAPI } from '../..';
import { TableColumn, Table } from '../../types'; import { TableColumn, Table, BaseTableColumn } from '../../types';
import { getTableRowRequest } from './utils'; import { getTableRowRequest } from './utils';
const permissionColumnDataTypes = { const permissionColumnDataTypes = {
@ -87,6 +87,10 @@ export const displayTableName = (table: Table) => {
return isTable(table) ? <span>{tableName}</span> : <i>{tableName}</i>; return isTable(table) ? <span>{tableName}</span> : <i>{tableName}</i>;
}; };
export const isJsonColumn = (column: BaseTableColumn): boolean => {
return column.data_type_name === 'json' || column.data_type_name === 'jsonb';
};
const processTableRowData = ( const processTableRowData = (
data: any, data: any,
config?: { originalTable: string; currentSchema: string } config?: { originalTable: string; currentSchema: string }
@ -103,6 +107,7 @@ const processTableRowData = (
export const mssql: DataSourcesAPI = { export const mssql: DataSourcesAPI = {
isTable, isTable,
isJsonColumn,
displayTableName, displayTableName,
operators, operators,
getTableRowRequest, getTableRowRequest,

View File

@ -135,6 +135,7 @@ export const mysql: DataSourcesAPI = {
getFunctionSchema: () => { getFunctionSchema: () => {
return ''; return '';
}, },
isJsonColumn: () => false,
getFunctionDefinitionSql: () => { getFunctionDefinitionSql: () => {
return ''; return '';
}, },

View File

@ -1,5 +1,10 @@
import React from 'react'; import React from 'react';
import { Table, TableColumn, ComputedField } from '../../types'; import {
Table,
TableColumn,
ComputedField,
BaseTableColumn,
} from '../../types';
import { QUERY_TYPES, Operations } from '../../common'; import { QUERY_TYPES, Operations } from '../../common';
import { PGFunction } from './types'; import { PGFunction } from './types';
import { DataSourcesAPI, ColumnsInfoResult } from '../..'; import { DataSourcesAPI, ColumnsInfoResult } from '../..';
@ -176,6 +181,10 @@ export const getSchemaFunctions = (
); );
}; };
export const isJsonColumn = (column: BaseTableColumn): boolean => {
return column.data_type === 'json' || column.data_type === 'jsonb';
};
export const findFunction = ( export const findFunction = (
allFunctions: PGFunction[], allFunctions: PGFunction[],
functionName: string, functionName: string,
@ -504,6 +513,7 @@ const permissionColumnDataTypes = {
export const postgres: DataSourcesAPI = { export const postgres: DataSourcesAPI = {
isTable, isTable,
isJsonColumn,
displayTableName, displayTableName,
getFunctionSchema, getFunctionSchema,
getFunctionDefinition, getFunctionDefinition,