Skip to content

Commit

Permalink
Add style and allow empty model (for notebook panel for example)
Browse files Browse the repository at this point in the history
  • Loading branch information
brichet committed Oct 22, 2024
1 parent 8c5959b commit 71edae1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
17 changes: 11 additions & 6 deletions packages/collaboration/src/users-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { User } from '@jupyterlab/services';
import { ReactWidget } from '@jupyterlab/ui-components';
import * as React from 'react';

const USERS_ITEM_CLASS = 'jp-toolbar-users-item';

/**
* The namespace for the UsersItem component.
*/
Expand All @@ -19,7 +21,7 @@ export namespace UsersItem {
/**
* The model of the document.
*/
model: DocumentRegistry.IModel;
model: DocumentRegistry.IModel | null;

/**
* A function to display the user icons, optional.
Expand Down Expand Up @@ -92,7 +94,7 @@ export class UsersItem extends React.Component<
}

componentDidMount(): void {
this._model.sharedModel.awareness.on('change', this._awarenessChange);
this._model?.sharedModel.awareness.on('change', this._awarenessChange);
this._awarenessChange();
}

Expand All @@ -119,9 +121,12 @@ export class UsersItem extends React.Component<
render(): React.ReactNode {
const IconRenderer = this._iconRenderer ?? DefaultUserIcon;
return (
<div className="jp-user-toolbar-items">
<div className={USERS_ITEM_CLASS}>
{this.filterDuplicated(this.state.usersList).map(user => {
if (user.userId !== this._model.sharedModel.awareness.clientID) {
if (
this._model &&
user.userId !== this._model.sharedModel.awareness.clientID
) {
return IconRenderer({ user });
}
})}
Expand All @@ -133,7 +138,7 @@ export class UsersItem extends React.Component<
* Triggered when a change occurs in the document awareness, to build again the users list.
*/
private _awarenessChange = () => {
const clients = this._model.sharedModel.awareness.getStates() as Map<
const clients = this._model?.sharedModel.awareness.getStates() as Map<
number,
User.IIdentity
>;
Expand All @@ -149,7 +154,7 @@ export class UsersItem extends React.Component<
this.setState(old => ({ ...old, usersList: users }));
};

private _model: DocumentRegistry.IModel;
private _model: DocumentRegistry.IModel | null;
private _iconRenderer:
| ((props: UsersItem.IIconRendererProps) => JSX.Element)
| null;
Expand Down
1 change: 1 addition & 0 deletions packages/collaboration/style/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

@import url('./menu.css');
@import url('./sidepanel.css');
@import url('./users-item.css');

.jp-shared-link-body {
user-select: none;
Expand Down
19 changes: 19 additions & 0 deletions packages/collaboration/style/users-item.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* -----------------------------------------------------------------------------
| Copyright (c) Jupyter Development Team.
| Distributed under the terms of the Modified BSD License.
|---------------------------------------------------------------------------- */

.jp-toolbar-users-item {
flex-grow: 1;
display: flex;
flex-direction: row-reverse;
}

.jp-toolbar-users-item .jp-MenuBar-anonymousIcon,
.jp-toolbar-users-item .jp-MenuBar-imageIcon {
position: unset !important;
margin-right: 2px;
height: 22px;
width: 22px;
box-sizing: border-box;
}

0 comments on commit 71edae1

Please sign in to comment.