Skip to content

Commit aeeb958

Browse files
Add ProtectedFields dialog and enhance Permissions dialogs (#1478)
* chip and multiselect dense variant * autocomplete component * popover refactor, ContextProxy -> portal * add intersection observer component * suggestions for autocomplete * do not show security dialog in edit modal * table will ignore keys when security modal opened * add autocomplete for ACL * add protected fields dialog component * permissioons dialog refactor * add new dialogs to databroowser toolbar * protected fields dialog example * removed comments * fix floating menus - show on top of toolbar * add whitespaces in toolbar menu * use menuitem * trailing newlines * update examples * adds scroll hint * handle case when no fields to protect Co-authored-by: Antonio Davi Macedo Coelho de Castro <[email protected]>
1 parent 69cab35 commit aeeb958

33 files changed

+3667
-744
lines changed

src/components/ACLEditor/ACLEditor.react.js

+49-9
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,58 @@ import PermissionsDialog from 'components/PermissionsDialog/PermissionsDialog.re
1010
import React from 'react';
1111

1212
function validateEntry(text) {
13-
let userQuery = Parse.Query.or(
14-
new Parse.Query(Parse.User).equalTo('username', text),
15-
new Parse.Query(Parse.User).equalTo('objectId', text)
16-
);
17-
let roleQuery = new Parse.Query(Parse.Role).equalTo('name', text);
18-
return Promise.all([userQuery.find({ useMasterKey: true }), roleQuery.find({ useMasterKey: true })]).then(([user, role]) => {
13+
14+
let userQuery;
15+
let roleQuery;
16+
17+
if (text === '*') {
18+
return Promise.resolve({ entry: '*', type: 'public' });
19+
}
20+
21+
if (text.startsWith('user:')) {
22+
// no need to query roles
23+
roleQuery = {
24+
find: () => Promise.resolve([])
25+
};
26+
27+
let user = text.substring(5);
28+
userQuery = new Parse.Query.or(
29+
new Parse.Query(Parse.User).equalTo('username', user),
30+
new Parse.Query(Parse.User).equalTo('objectId', user)
31+
);
32+
} else if (text.startsWith('role:')) {
33+
// no need to query users
34+
userQuery = {
35+
find: () => Promise.resolve([])
36+
};
37+
let role = text.substring(5);
38+
roleQuery = new Parse.Query.or(
39+
new Parse.Query(Parse.Role).equalTo('name', role),
40+
new Parse.Query(Parse.Role).equalTo('objectId', role)
41+
);
42+
} else {
43+
// query both
44+
userQuery = Parse.Query.or(
45+
new Parse.Query(Parse.User).equalTo('username', text),
46+
new Parse.Query(Parse.User).equalTo('objectId', text)
47+
);
48+
49+
roleQuery = Parse.Query.or(
50+
new Parse.Query(Parse.Role).equalTo('name', text),
51+
new Parse.Query(Parse.Role).equalTo('objectId', text)
52+
);
53+
}
54+
55+
return Promise.all([
56+
userQuery.find({ useMasterKey: true }),
57+
roleQuery.find({ useMasterKey: true })
58+
]).then(([user, role]) => {
1959
if (user.length > 0) {
20-
return { user: user[0] };
60+
return { entry: user[0], type: 'user' };
2161
} else if (role.length > 0) {
22-
return { role: role[0] };
62+
return { entry: role[0], type: 'role' };
2363
} else {
24-
throw new Error();
64+
return Promise.reject();
2565
}
2666
});
2767
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2016-present, Parse, LLC
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the license found in the LICENSE file in
6+
* the root directory of this source tree.
7+
*/
8+
import React from 'react';
9+
import Autocomplete from 'components/Autocomplete/Autocomplete.react';
10+
11+
export const component = Autocomplete;
12+
13+
class AutocompleteDemo extends React.Component {
14+
constructor() {
15+
super();
16+
17+
this.state = {
18+
suggestions: ['aaa', 'abc', 'xxx', 'xyz']
19+
};
20+
21+
this.onSubmit = input => console.log('onSubmit: ' + input);
22+
this.onUserInput = input => {
23+
console.log(`input: ${input}`);
24+
};
25+
this.buildLabel = input =>
26+
input.length > 0
27+
? `You've typed ${input.length} characters`
28+
: 'Start typing';
29+
this.buildSuggestions = input =>
30+
this.state.suggestions.filter(s => s.startsWith(input));
31+
}
32+
33+
render() {
34+
return (
35+
<Autocomplete
36+
inputStyle={{
37+
width: '400px',
38+
padding: '0 6px',
39+
margin: '10px 20px'
40+
}}
41+
suggestionsStyle={{
42+
margin: '-6px 0px 0px 20px',
43+
width: '400px'
44+
}}
45+
locked={true}
46+
onChange={this.onUserInput}
47+
onSubmit={this.onSubmit}
48+
placeholder={'Placeholder'}
49+
buildSuggestions={this.buildSuggestions}
50+
buildLabel={this.buildLabel}
51+
/>
52+
);
53+
}
54+
}
55+
56+
export const demos = [
57+
{
58+
render: () => (
59+
<div>
60+
<AutocompleteDemo />
61+
</div>
62+
)
63+
}
64+
];

0 commit comments

Comments
 (0)