这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,10 @@
display: initial !important;

.tableIcon, .functionIcon {
//display: inline;
margin-right: 5px;
font-size: 12px;
}

.functionIcon {
width: 12px;

img {
width: 100%;
}
}
}
}
Expand All @@ -174,7 +168,7 @@
}
}

.activeTable {
.activeLink {
a {
// border-left: 4px solid #FFC627;
color: #FD9540!important;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ const WarningSymbol = ({
return (
<div className={styles.display_inline}>
<OverlayTrigger placement={tooltipPlacement} overlay={tooltip}>
<WarningIcon customStyle={customStyle} />
<span>
<WarningIcon customStyle={customStyle} />
</span>
</OverlayTrigger>
</div>
);
Expand Down
65 changes: 63 additions & 2 deletions console/src/components/Common/utils/jsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,22 @@ export const isEqual = (value1, value2) => {

if (typeof value1 === typeof value2) {
if (isArray(value1)) {
// TODO
} else if (isObject(value2)) {
_isEqual = JSON.stringify(value1) === JSON.stringify(value2);
} else if (isObject(value2)) {
const value1Keys = Object.keys(value1);
const value2Keys = Object.keys(value2);

if (value1Keys.length === value2Keys.length) {
_isEqual = true;

for (let i = 0; i < value1Keys.length; i++) {
const key = value1Keys[i];
if (!isEqual(value1[key], value2[key])) {
_isEqual = false;
break;
}
}
}
} else {
_isEqual = value1 === value2;
}
Expand All @@ -48,6 +61,54 @@ export const isEqual = (value1, value2) => {
return _isEqual;
};

export function isJsonString(str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}

return true;
}

export function getAllJsonPaths(json, leafKeys = [], prefix = '') {
const _paths = [];

const addPrefix = subPath => {
return prefix + (prefix && subPath ? '.' : '') + subPath;
};

const handleSubJson = (subJson, newPrefix) => {
const subPaths = getAllJsonPaths(subJson, leafKeys, newPrefix);

subPaths.forEach(subPath => {
_paths.push(subPath);
});

if (!subPaths.length) {
_paths.push(newPrefix);
}
};

if (isArray(json)) {
json.forEach((subJson, i) => {
handleSubJson(subJson, addPrefix(i.toString()));
});
} else if (isObject(json)) {
Object.keys(json).forEach(key => {
if (leafKeys.includes(key)) {
_paths.push({ [addPrefix(key)]: json[key] });
} else {
handleSubJson(json[key], addPrefix(key));
}
});
} else {
_paths.push(addPrefix(json));
}

return _paths;
}

// use browser confirm and prompt to get user confirmation for actions
export const getConfirmation = (
message = '',
Expand Down
138 changes: 123 additions & 15 deletions console/src/components/Common/utils/pgUtils.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import React from 'react';
import { isEqual } from './jsUtils';
import { isEqual, isString } from './jsUtils';

/*** Table/View utils ***/

// TODO: figure out better pattern for overloading fns

export const getTableName = table => {
return table.table_name;
};
Expand All @@ -13,6 +11,7 @@ export const getTableSchema = table => {
return table.table_schema;
};

// TODO: figure out better pattern for overloading fns
// tableName and tableNameWithSchema are either/or arguments
export const generateTableDef = (
tableName,
Expand All @@ -34,15 +33,12 @@ export const getTableDef = table => {
return generateTableDef(getTableName(table), getTableSchema(table));
};

// table and tableDef are either/or arguments
export const getTableNameWithSchema = (
table,
wrapDoubleQuotes = true,
tableDef = null
) => {
let _fullTableName;
export const getQualifiedTableDef = tableDef => {
return isString(tableDef) ? generateTableDef(tableDef) : tableDef;
};

tableDef = tableDef || getTableDef(table);
export const getTableNameWithSchema = (tableDef, wrapDoubleQuotes = false) => {
let _fullTableName;

if (wrapDoubleQuotes) {
_fullTableName =
Expand All @@ -69,14 +65,40 @@ export const findTable = (allTables, tableDef) => {
return allTables.find(t => isEqual(getTableDef(t), tableDef));
};

export const getSchemaTables = (allTables, tableSchema) => {
return allTables.filter(t => getTableSchema(t) === tableSchema);
};

export const getTrackedTables = tables => {
return tables.filter(t => t.is_table_tracked);
};

/*** Table/View column utils ***/

export const getTableColumns = table => {
return table.columns;
};

export const getColumnName = column => {
return column.column_name;
};

export const getTableColumnNames = table => {
return getTableColumns(table).map(c => getColumnName(c));
};

export const getTableColumn = (table, columnName) => {
return getTableColumns(table).find(
column => getColumnName(column) === columnName
);
};

export const getColumnType = column => {
let _columnType = column.data_type;

if (_columnType === 'USER-DEFINED') {
_columnType = column.udt_name;
}

return _columnType;
};

export const isColumnAutoIncrement = column => {
const columnDefault = column.column_default;

Expand All @@ -88,7 +110,79 @@ export const isColumnAutoIncrement = column => {
);
};

/*** Table/View relationship utils ***/

export const getTableRelationships = table => {
return table.relationships;
};

export const getRelationshipName = relationship => {
return relationship.rel_name;
};

export const getRelationshipDef = relationship => {
return relationship.rel_def;
};

export const getRelationshipType = relationship => {
return relationship.rel_type;
};

export const getTableRelationshipNames = table => {
return getTableRelationships(table).map(r => getRelationshipName(r));
};

export function getTableRelationship(table, relationshipName) {
return getTableRelationships(table).find(
relationship => getRelationshipName(relationship) === relationshipName
);
}

export function getRelationshipRefTable(table, relationship) {
let _refTable = null;

const relationshipDef = getRelationshipDef(relationship);
const relationshipType = getRelationshipType(relationship);

// if manual relationship
if (relationshipDef.manual_configuration) {
_refTable = relationshipDef.manual_configuration.remote_table;
}

// if foreign-key based relationship
if (relationshipDef.foreign_key_constraint_on) {
// if array relationship
if (relationshipType === 'array') {
_refTable = relationshipDef.foreign_key_constraint_on.table;
}

// if object relationship
if (relationshipType === 'object') {
const fkCol = relationshipDef.foreign_key_constraint_on;

for (let i = 0; i < table.foreign_key_constraints.length; i++) {
const fkConstraint = table.foreign_key_constraints[i];
const fkConstraintCol = Object.keys(fkConstraint.column_mapping)[0];
if (fkCol === fkConstraintCol) {
_refTable = generateTableDef(
fkConstraint.ref_table,
fkConstraint.ref_table_table_schema
);
break;
}
}
}
}

if (typeof _refTable === 'string') {
_refTable = generateTableDef(_refTable);
}

return _refTable;
}

/*** Table/View permissions utils ***/

export const getTablePermissions = (table, role = null, action = null) => {
let tablePermissions = table.permissions;

Expand All @@ -112,3 +206,17 @@ export const getFunctionSchema = pgFunction => {
export const getFunctionName = pgFunction => {
return pgFunction.function_name;
};

/*** Schema utils ***/

export const getSchemaName = schema => {
return schema.schema_name;
};

export const getSchemaTables = (allTables, tableSchema) => {
return allTables.filter(t => getTableSchema(t) === tableSchema);
};

export const getSchemaTableNames = (allTables, tableSchema) => {
return getSchemaTables(allTables, tableSchema).map(t => getTableName(t));
};
9 changes: 1 addition & 8 deletions console/src/components/Services/Data/DataPageContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { NotFoundError } from '../../Error/PageNotFound';
const sectionPrefix = '/data';

const DataPageContainer = ({
schema,
currentSchema,
schemaList,
children,
Expand Down Expand Up @@ -81,12 +80,7 @@ const DataPageContainer = ({
</div>
</div>
</Link>
<DataSubSidebar
location={location}
schema={schema}
currentSchema={currentSchema}
dispatch={dispatch}
/>
<DataSubSidebar location={location} />
</li>
<li
role="presentation"
Expand Down Expand Up @@ -117,7 +111,6 @@ const DataPageContainer = ({

const mapStateToProps = state => {
return {
schema: state.tables.allSchemas,
schemaList: state.tables.schemaList,
currentSchema: state.tables.currentSchema,
};
Expand Down
1 change: 0 additions & 1 deletion console/src/components/Services/Data/DataState.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const defaultPermissionsState = {
limitEnabled: true,
bulkSelect: [],
applySamePermissions: [],
tableSchemas: [],
};

const defaultPresetsState = {
Expand Down
Loading