Skip to content

Commit

Permalink
Completely remove Embedde Object Classes from the sidebar menu (befor…
Browse files Browse the repository at this point in the history
…e they had same behaviour as "sytem classes"). (#1327)
  • Loading branch information
steffenagger authored Sep 24, 2020
1 parent bf02515 commit 0d3f031
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/ui/RealmBrowser/LeftSidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Focus } from '../focus';
import { LeftSidebar } from './LeftSidebar';

function isSystemClassName(cls?: Realm.ObjectSchema) {
return cls && (cls.name.indexOf('__') === 0 || cls.embedded === true);
return cls && cls.name.indexOf('__') === 0;
}

interface ILeftSidebarContainerProps {
Expand Down Expand Up @@ -70,9 +70,9 @@ class LeftSidebarContainer extends React.Component<
}

public render() {
const classes = this.filterClasses(this.props.classes);
const classes = this.getFilterClasses();
const hiddenClassCount = Math.max(
this.props.classes.length - classes.length,
this.getAllowedClasses().length - classes.length,
0,
);
return (
Expand All @@ -92,20 +92,24 @@ class LeftSidebarContainer extends React.Component<
);
}

private filterClasses(classes: Realm.ObjectSchema[]) {
if (this.state.hideSystemClasses) {
return classes.filter(c => !isSystemClassName(c));
} else {
return classes;
}
private getAllowedClasses() {
return this.props.classes.filter(c => !c.embedded);
}

private getFilterClasses() {
return this.state.hideSystemClasses
? this.getAllowedClasses().filter(c => !isSystemClassName(c))
: this.getAllowedClasses();
}

private onShowSystemClassesChange = (showSystemClasses: boolean) => {
this.setState({ hideSystemClasses: !showSystemClasses }, () => {
const shouldSelectAnotherClass = this.isFocussedOnSystemClass();
if (showSystemClasses === false && shouldSelectAnotherClass) {
// Focus on another class
const firstClass = this.props.classes.find(c => !isSystemClassName(c));
const firstClass = this.getAllowedClasses().find(
c => !isSystemClassName(c),
);
if (firstClass) {
this.props.onClassFocussed(firstClass.name);
}
Expand Down

0 comments on commit 0d3f031

Please sign in to comment.