Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit object references #175

Merged
merged 7 commits into from
Sep 30, 2017
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
9 changes: 5 additions & 4 deletions src/ui/realm-browser/Cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { StringCellContainer } from './types/StringCellContainer';

export const Cell = ({
onUpdateValue,
onListCellClick,
onCellClick,
property,
style,
value,
Expand All @@ -18,7 +18,7 @@ export const Cell = ({
onContextMenu,
}: {
onUpdateValue: (value: string) => void;
onListCellClick: (property: Realm.ObjectSchemaProperty, value: any) => void;
onCellClick: (property: Realm.ObjectSchemaProperty, value: any) => void;
property: Realm.ObjectSchemaProperty;
style: React.CSSProperties;
value: any;
Expand All @@ -40,6 +40,7 @@ export const Cell = ({
value={value}
onUpdateValue={onUpdateValue}
onContextMenu={onContextMenu}
onClick={onCellClick}
/>
);
break;
Expand All @@ -50,7 +51,7 @@ export const Cell = ({
onContextMenu={onContextMenu}
property={property}
value={value}
onClick={onListCellClick}
onClick={onCellClick}
/>
);
break;
Expand All @@ -60,7 +61,7 @@ export const Cell = ({
onContextMenu={onContextMenu}
property={property}
value={value}
onClick={onListCellClick}
onClick={onCellClick}
/>
);
break;
Expand Down
33 changes: 20 additions & 13 deletions src/ui/realm-browser/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const Content = ({
gridContentRef,
gridHeaderRef,
onCellChange,
onListCellClick,
onCellClick,
onColumnWidthChanged,
schema,
rowToHighlight,
Expand All @@ -29,21 +29,27 @@ export const Content = ({
columnWidths: number[];
gridContentRef: (grid: Grid) => void;
gridHeaderRef: (grid: Grid) => void;
onCellChange: (object: any, propertyName: string, value: string) => void;
onListCellClick: (
onCellChange?: (object: any, propertyName: string, value: string) => void;
onCellClick?: (
object: any,
property: Realm.ObjectSchemaProperty,
value: any,
rowIndex: number,
columnIndex: number,
) => void;
onColumnWidthChanged: (index: number, width: number) => void;
schema: Realm.ObjectSchema | null;
rowToHighlight: number | null;
rowToHighlight?: number;
data: Realm.Results<any> | any;
query: string | null;
onQueryChange: (e: React.SyntheticEvent<any>) => void;
sort: string | null;
onSortClick: (property: string) => void;
onContextMenu: (e: React.SyntheticEvent<any>, object: any) => void;
onContextMenu?: (
e: React.SyntheticEvent<any>,
object: any,
property: Realm.ObjectSchemaProperty,
) => void;
}) => {
if (schema) {
// Generate the columns from the schemas properties
Expand All @@ -64,24 +70,25 @@ export const Content = ({
style: React.CSSProperties;
}) => {
const object = data[rowIndex];

return (
<Cell
key={key}
width={columnWidths[columnIndex]}
style={style}
onListCellClick={(
onCellClick={(
property: Realm.ObjectSchemaProperty, // tslint:disable-line:no-shadowed-variable
value: any,
) => {
onListCellClick(object, property, value);
}}
) =>
onCellClick &&
onCellClick(object, property, value, rowIndex, columnIndex)}
value={object[propertyName]}
property={property}
onUpdateValue={value => {
onCellChange(object, propertyName, value);
}}
onUpdateValue={value =>
onCellChange && onCellChange(object, propertyName, value)}
isHighlight={rowToHighlight === rowIndex}
onContextMenu={e => onContextMenu(e, object)}
onContextMenu={e =>
onContextMenu && onContextMenu(e, object, property)}
/>
);
};
Expand Down
26 changes: 20 additions & 6 deletions src/ui/realm-browser/ContentContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,23 @@ import { Content } from './Content';
const MINIMUM_COLUMN_WIDTH = 20;

export interface IContentContainerProps {
onCellChange: (object: any, propertyName: string, value: string) => void;
onListCellClick: (
onCellChange?: (object: any, propertyName: string, value: string) => void;
onCellClick?: (
object: any,
property: Realm.ObjectSchemaProperty,
value: any,
rowIndex: number,
columnIndex: number,
) => void;
schema: Realm.ObjectSchema | null;
rowToHighlight: number | null;
rowToHighlight?: number;
columnToHighlight?: number;
data: Realm.Results<any> | any;
onContextMenu: (e: React.SyntheticEvent<any>, object: any) => void;
onContextMenu?: (
e: React.SyntheticEvent<any>,
object: any,
property: Realm.ObjectSchemaProperty,
) => void;
}

export class ContentContainer extends React.Component<
Expand Down Expand Up @@ -84,6 +91,12 @@ export class ContentContainer extends React.Component<
);
}

public componentWillMount() {
if (this.props.schema) {
this.setDefaultColumnWidths(this.props.schema);
}
}

public componentWillReceiveProps(props: IContentContainerProps) {
if (props.schema && this.props.schema !== props.schema) {
this.setDefaultColumnWidths(props.schema);
Expand All @@ -95,10 +108,11 @@ export class ContentContainer extends React.Component<
if (
this.gridContent &&
this.props.rowToHighlight &&
this.props.rowToHighlight !== prevProps.rowToHighlight
(this.props.rowToHighlight !== prevProps.rowToHighlight ||
this.props.columnToHighlight !== prevProps.columnToHighlight)
) {
this.gridContent.scrollToCell({
columnIndex: 0,
columnIndex: this.props.columnToHighlight || 0,
rowIndex: this.props.rowToHighlight,
});
}
Expand Down
12 changes: 12 additions & 0 deletions src/ui/realm-browser/RealmBrowser.scss
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,14 @@ $realm-browser-header-icon-space: 24px;
flex-direction: column;
}

&__SelectObject {
display: flex;
flex-direction: column;
flex: 1 1 0;
min-height: 300px;
padding: 0;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some spaces and sorted the lines - are you running the SASS linter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn’t worry too much about this. We were going to propose yesterday to use prettier + stylelinter so we don’t have to fix this stuff manually, but the new features seemed more important.
Also, we could add css-modules in order to avoid long class names (e.g RealmBrowser__Content__Cell could be just cell or Cell).

I can fix them right now if that's a priority 😛

&__Tabs {
min-height: 42px;
}
Expand Down Expand Up @@ -248,6 +256,10 @@ $realm-browser-header-icon-space: 24px;
&--disabled {
color: $color-elephant;
}

&--unselectable {
user-select: none;
}
}

&__Link {
Expand Down
45 changes: 36 additions & 9 deletions src/ui/realm-browser/RealmBrowser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,60 @@ import { ContextMenu } from '../reusable/context-menu';
import { ContentContainer } from './ContentContainer';
import './RealmBrowser.scss';
import { IList } from './RealmBrowserContainer';
import { SelectObject } from './SelectObject';
import { Sidebar } from './Sidebar';

export const RealmBrowser = ({
getSchemaLength,
getSelectedSchema,
onCellChange,
onSchemaSelected,
onListCellClick,
onCellClick,
schemas,
rowToHighlight,
columnToHighlight,
getSelectedData,
selectedSchemaName,
list,
onContextMenu,
contextMenu,
onContextMenuClose,
confirmModal,
selectObject,
closeSelectObject,
updateObjectReference,
}: {
getSchemaLength: (name: string) => number;
getSelectedData: () => any;
getSelectedSchema: () => Realm.ObjectSchema | null;
onCellChange: (object: any, propertyName: string, value: string) => void;
onSchemaSelected: (name: string, objectToScroll: any) => void;
onListCellClick: (
onCellClick: (
object: any,
property: Realm.ObjectSchemaProperty,
value: any,
rowIndex: number,
columnIndex: number,
) => void;
schemas: Realm.ObjectSchema[];
rowToHighlight: number | null;
selectedSchemaName?: string | null;
list: IList | null;
onContextMenu: (e: React.SyntheticEvent<any>, object: any) => void;
rowToHighlight?: number;
columnToHighlight?: number;
selectedSchemaName?: string;
list?: IList;
onContextMenu: (
e: React.SyntheticEvent<any>,
object: any,
property: Realm.ObjectSchemaProperty,
) => void;
contextMenu: any;
onContextMenuClose: () => void;
confirmModal: {
confirmModal?: {
yes: () => void;
no: () => void;
} | null;
};
selectObject?: any;
closeSelectObject: () => void;
updateObjectReference: (object: any) => void;
}) => {
const values = getSelectedData();
return (
Expand All @@ -60,7 +75,8 @@ export const RealmBrowser = ({
<ContentContainer
schema={getSelectedSchema()}
onCellChange={onCellChange}
onListCellClick={onListCellClick}
onCellClick={onCellClick}
columnToHighlight={columnToHighlight}
rowToHighlight={rowToHighlight}
data={values}
onContextMenu={onContextMenu}
Expand All @@ -78,6 +94,17 @@ export const RealmBrowser = ({
no={confirmModal.no}
/>
)}
{selectObject && (
<SelectObject
status={true}
schema={selectObject.schema}
data={selectObject.data}
optional={selectObject.optional}
schemaName={selectObject.schemaName}
updateReference={updateObjectReference}
close={closeSelectObject}
/>
)}
</div>
);
};
Loading