这是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
2 changes: 1 addition & 1 deletion console/src/components/Common/utils/jsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const isArray = value => {
};

export const isObject = value => {
return typeof value === 'object';
return typeof value === 'object' && value !== null;
};

export const isString = value => {
Expand Down
7 changes: 1 addition & 6 deletions console/src/components/Services/Data/RawSQL/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const getSQLValue = value => {
return sqlValue.replace(/['"]+/g, '');
};

const parseCreateSQL = sql => {
export const parseCreateSQL = sql => {
const _objects = [];

const regExp = createSQLRegex;
Expand Down Expand Up @@ -49,8 +49,3 @@ const parseCreateSQL = sql => {

return _objects;
};

export {
createSQLRegex,
parseCreateSQL
};
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ class PermissionBuilder extends React.Component {
};

const _dispatchFunc = data => {
const { dispatch, filter, dispatchFuncSetFilter, tableDef } = this.props;
const { filter, dispatchFuncSetFilter, tableDef } = this.props;

const newFilter = getFilter(
tableDef.schema,
Expand All @@ -393,8 +393,8 @@ class PermissionBuilder extends React.Component {
data.value
);

// dispatch(dispatchFuncSetFilter(JSON.stringify(newFilter, null, 4)));
dispatch(dispatchFuncSetFilter(JSON.stringify(newFilter)));
// dispatchFuncSetFilter(JSON.stringify(newFilter, null, 4));
dispatchFuncSetFilter(JSON.stringify(newFilter));
};

/********************************/
Expand Down Expand Up @@ -521,7 +521,7 @@ class PermissionBuilder extends React.Component {
val.substr(-1) !== '.'
) {
_val = Number(val);
} else if (PGTypes.json.includes(valueType) && isJsonString(val)) {
} else if (PGTypes.jsonb.includes(valueType) && isJsonString(val)) {
_val = JSON.parse(val);
}
}
Expand All @@ -546,7 +546,7 @@ class PermissionBuilder extends React.Component {

if (PGTypes.boolean.includes(valueType)) {
input = renderBoolSelect(dispatchInput, value);
} else if (PGTypes.json.includes(valueType)) {
} else if (PGTypes.jsonb.includes(valueType)) {
input = inputBox();
suggestion = jsonSuggestion();
} else if (valueType === 'column') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export const PGTypes = {
],
geometry: ['geometry'],
geography: ['geography'],
json: ['json', 'jsonb'],
json: ['json'],
jsonb: ['jsonb'],
numeric: [
'smallint',
'integer',
Expand All @@ -40,7 +41,7 @@ const operatorTypePGTypesMap = {
'user_defined',
],
pattern_match: ['character'],
json: ['json'],
jsonb: ['jsonb'],
geometric: ['geometry'],
geometric_geographic: ['geometry', 'geography'],
is_null: Object.keys(PGTypes), // all types
Expand Down Expand Up @@ -154,25 +155,25 @@ const columnOperatorsInfo = {
inputStructure: 'object',
},
_contains: {
type: 'json',
type: 'jsonb',
inputStructure: 'object',
},
_contained_in: {
type: 'json',
type: 'jsonb',
inputStructure: 'object',
},
_has_key: {
type: 'json',
type: 'jsonb',
inputStructure: 'object',
inputType: 'character',
},
_has_keys_any: {
type: 'json',
type: 'jsonb',
inputStructure: 'array',
inputType: 'character',
},
_has_keys_all: {
type: 'json',
type: 'jsonb',
inputStructure: 'array',
inputType: 'character',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import Button from '../../../Common/Button/Button';
import { defaultPresetsState } from '../DataState';

import { NotFoundError } from '../../../Error/PageNotFound';
import { getConfirmation } from '../../../Common/utils/jsUtils';
import { getConfirmation, isJsonString } from '../../../Common/utils/jsUtils';
import {
findTable,
generateTableDef,
Expand All @@ -64,6 +64,7 @@ import {
getTableColumns,
getGroupedTableComputedFields,
} from '../../../Common/utils/pgUtils';
import { showErrorNotification } from '../../Common/Notification';

class Permissions extends Component {
constructor() {
Expand All @@ -78,6 +79,8 @@ class Permissions extends Component {
columnTypeMap: {},
},
},
filterString: '',
prevPermissionsState: {},
};
}

Expand All @@ -89,6 +92,24 @@ class Permissions extends Component {
dispatch(fetchFunctionInit());
}

static getDerivedStateFromProps(nextProps, prevState) {
const prevPermissionsState = prevState.prevPermissionsState;
const nextPermissionsState = nextProps.permissionsState;

const newState = {
prevPermissionsState: nextPermissionsState,
};

if (
prevPermissionsState.role !== nextPermissionsState.role ||
prevPermissionsState.query !== nextPermissionsState.query
) {
newState.filterString = '';
}

return newState;
}

componentDidUpdate(prevProps) {
const currPermissionsState = this.props.permissionsState;
const prevPermissionsState = prevProps.permissionsState;
Expand Down Expand Up @@ -134,6 +155,8 @@ class Permissions extends Component {
trackableFunctions,
} = this.props;

const localFilterString = this.state.filterString;

const currentTableSchema = findTable(
allSchemas,
generateTableDef(tableName, currentSchema)
Expand Down Expand Up @@ -603,6 +626,14 @@ class Permissions extends Component {
dispatch(permAllowAll());
};

const dispatchFuncSetFilter = filter => {
this.setState({ filterString: filter });

if (isJsonString(filter)) {
dispatch(permSetFilter(JSON.parse(filter)));
}
};

const dispatchSetFilterSameAs = filter => () => {
dispatch(permSetFilterSameAs(JSON.parse(filter)));
};
Expand Down Expand Up @@ -644,11 +675,11 @@ class Permissions extends Component {
const selectedValue = (
<AceEditor
mode="json"
value={filterString}
readOnly
value={localFilterString || filterString}
onChange={dispatchFuncSetFilter}
theme="github"
height="5em"
maxLines={5}
maxLines={15}
width="100%"
showPrintMargin={false}
key={-3}
Expand Down Expand Up @@ -741,9 +772,6 @@ class Permissions extends Component {
};

const addCustomCheckOption = () => {
const dispatchFuncSetFilter = filter =>
permSetFilter(JSON.parse(filter));

const loadSchemasFunc = schemaNames => {
dispatch(updateSchemaInfo({ schemas: schemaNames }));
};
Expand Down Expand Up @@ -792,7 +820,6 @@ class Permissions extends Component {
allTableSchemas={allSchemas}
schemaList={schemaList}
filter={filterString}
dispatch={dispatch}
key={-4}
/>
);
Expand Down Expand Up @@ -1700,6 +1727,16 @@ class Permissions extends Component {
}

const dispatchSavePermissions = () => {
if (localFilterString && !isJsonString(localFilterString)) {
dispatch(
showErrorNotification(
'Saving permissions failed',
'Row permission is not a valid JSON'
)
);
return;
}

dispatch(permChangePermissions(permChangeTypes.save));
};

Expand Down