gristlabs_grist-core/app/client/models/entities/CellRec.ts
Jarosław Sadziński bfd7243fe2 (core) Comments
Summary:
First iteration for comments system for Grist.
- Comments are stored in a generic metatable `_grist_Cells`
- Each comment is connected to a particular cell (hence the generic name of the table)
- Access level works naturally for records stored in this table
-- User can add/read comments for cells he can see
-- User can't update/remove comments that he doesn't own, but he can delete them by removing cells (rows/columns)
-- Anonymous users can't see comments at all.
- Each comment can have replies (but replies can't have more replies)

Comments are hidden by default, they can be enabled by COMMENTS=true env variable.
Some things for follow-up
- Avatars, currently the user's profile image is not shown or retrieved from the server
- Virtual rendering for comments list in creator panel. Currently, there is a limit of 200 comments.

Test Plan: New and existing tests

Reviewers: georgegevoian, paulfitz

Reviewed By: georgegevoian

Subscribers: paulfitz

Differential Revision: https://phab.getgrist.com/D3509
2022-10-17 13:38:21 +02:00

44 lines
1.8 KiB
TypeScript

import {isCensored} from 'app/common/gristTypes';
import * as ko from 'knockout';
import {KoArray} from 'app/client/lib/koArray';
import {jsonObservable} from 'app/client/models/modelUtil';
import * as modelUtil from 'app/client/models/modelUtil';
import {ColumnRec, DocModel, IRowModel, recordSet, refRecord, TableRec} from 'app/client/models/DocModel';
export interface CellRec extends IRowModel<"_grist_Cells"> {
column: ko.Computed<ColumnRec>;
table: ko.Computed<TableRec>;
children: ko.Computed<KoArray<CellRec>>;
hidden: ko.Computed<boolean>;
parent: ko.Computed<CellRec>;
text: modelUtil.KoSaveableObservable<string|undefined>;
userName: modelUtil.KoSaveableObservable<string|undefined>;
timeCreated: modelUtil.KoSaveableObservable<number|undefined>;
timeUpdated: modelUtil.KoSaveableObservable<number|undefined>;
resolved: modelUtil.KoSaveableObservable<boolean|undefined>;
resolvedBy: modelUtil.KoSaveableObservable<string|undefined>;
}
export function createCellRec(this: CellRec, docModel: DocModel): void {
this.hidden = ko.pureComputed(() => isCensored(this.content()));
this.column = refRecord(docModel.columns, this.colRef);
this.table = refRecord(docModel.tables, this.tableRef);
this.parent = refRecord(docModel.cells, this.parentId);
this.children = recordSet(this, docModel.cells, 'parentId');
const properContent = modelUtil.savingComputed({
read: () => this.hidden() ? '{}' : this.content(),
write: (setter, val) => setter(this.content, val)
});
const optionJson = jsonObservable(properContent);
// Comments:
this.text = optionJson.prop('text');
this.userName = optionJson.prop('userName');
this.timeCreated = optionJson.prop('timeCreated');
this.timeUpdated = optionJson.prop('timeUpdated');
this.resolved = optionJson.prop('resolved');
this.resolvedBy = optionJson.prop('resolvedBy');
}