Skip to content

Commit adc4758

Browse files
committed
Migrate date to commentable DateRecord
Now that the new data model and commenting logic is in-place, migrate old instances of the app to have commentable date fields. It Works ======== UI -- - Before (no comments supported on date field): ![image](https://user-images.githubusercontent.com/2456381/55261668-d22f5e80-5228-11e9-8fb9-f767ebf7f9b1.png) - After: ![image](https://user-images.githubusercontent.com/2456381/55261693-dce9f380-5228-11e9-83b1-89806f8645f9.png) Migrations ---------- - Migration from pre-commentable-date version (version 1): ![image](https://user-images.githubusercontent.com/2456381/55257807-44e70c80-521e-11e9-91fd-2e07a99e7520.png) - Migration from rigid data model (version 0): ![image](https://user-images.githubusercontent.com/2456381/55260305-449e3f80-5225-11e9-9b2e-84edb36fa1ac.png)
1 parent bc908f7 commit adc4758

4 files changed

Lines changed: 19 additions & 34 deletions

File tree

app/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"manifest_version": 4,
44
"name": "Toastmasters Agenda",
55
"disable_app_level_comments": false,
6-
"version_name": "2.0.3",
7-
"version_number": 18,
6+
"version_name": "2.1.0",
7+
"version_number": 19,
88
"sizing_mode": "fill_container",
99
"initial_height": 300,
1010
"initial_width": 300,

src/components/roles.js

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ import styles from 'css/roles.less';
77
export default function Roles() {
88
const rootRecord = quip.apps.getRootRecord();
99
const date = rootRecord.get('date');
10-
const {ref, dateValue, commentsBubble} = getDateData(date);
1110

1211
return (
1312
<table className={styles.roles}>
14-
<tr ref={ref}>
13+
<tr ref={node => date.setDom(node)}>
1514
<td>Meeting Date</td>
16-
<td>{commentsBubble}</td>
15+
<td>
16+
<CommentsBubble record={date} />
17+
</td>
1718
<td>
1819
<PlainRichTextBox
19-
record={dateValue}
20+
record={date.get('value')}
2021
interceptClicks={false}
2122
/>
2223
</td>
@@ -42,17 +43,3 @@ export default function Roles() {
4243
</table>
4344
);
4445
}
45-
46-
// TODO(#26): Drop conditional logic after data migration to `DateRecord` is
47-
// complete.
48-
const getDateData = dateRecord => dateRecord.setDom
49-
? {
50-
ref: node => dateRecord.setDom(node),
51-
dateValue: dateRecord.get('value'),
52-
commentsBubble: <CommentsBubble record={dateRecord} />,
53-
}
54-
: {
55-
ref: () => {},
56-
dateValue: dateRecord,
57-
commentsBubble: null,
58-
};

src/model/migrations.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {getRichTextRecordContent} from 'utils/utils';
33

44
const MIGRATION_FUNCTIONS = [
55
migrateFromVersion0,
6+
migrateFromVersion1,
67
];
78

89
/**
@@ -128,6 +129,16 @@ function migrateFromVersion0() {
128129
}
129130
}
130131

132+
/*
133+
* Migrate date record to commentable version.
134+
*/
135+
function migrateFromVersion1() {
136+
const rootRecord = quip.apps.getRootRecord();
137+
const dateValue = rootRecord.clear('date', true);
138+
const newDateRecord = rootRecord.get('date');
139+
newDateRecord.set('value', dateValue);
140+
}
141+
131142
function getAppLogText() {
132143
const rootRecord = quip.apps.getRootRecord();
133144

src/root.jsx

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class RootRecord extends quip.apps.RootRecord {
1313
roles: {},
1414
});
1515

16-
static DATA_VERSION = 1;
16+
static DATA_VERSION = 2;
1717
}
1818

1919
quip.apps.registerClass(RootRecord, 'root');
@@ -34,19 +34,6 @@ quip.apps.initialize({
3434
runMigrations();
3535
}
3636

37-
/*
38-
* Date migration logic. Uncomment after app supports both versions
39-
* of date record.
40-
*
41-
* if (!(rootRecord.get('date') instanceof DateRecord)) {
42-
* // Migrate date record to commentable version.
43-
* const dateValue = rootRecord.clear('date', true);
44-
* const dateRecord = rootRecord.get('date');
45-
* dateRecord.clear('value');
46-
* dateRecord.set('value', dateValue);
47-
* }
48-
*/
49-
5037
ReactDOM.render(<Roles />, root);
5138
},
5239
});

0 commit comments

Comments
 (0)