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

profiles syncing #161523

Merged
merged 1 commit into from Sep 22, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -182,7 +182,7 @@ export class UserDataProfilesManifestSynchroniser extends AbstractSynchroniser i
await this.backupLocal(this.stringifyLocalProfiles(this.getLocalUserDataProfiles(), false));
const promises: Promise<any>[] = [];
for (const profile of local.added) {
promises.push(this.userDataProfilesService.createProfile(profile.id, profile.name));
promises.push(this.userDataProfilesService.createProfile(profile.id, profile.name, { shortName: profile.shortName }));
}
for (const profile of local.removed) {
promises.push(this.userDataProfilesService.removeProfile(profile));
Expand Down
Expand Up @@ -100,7 +100,7 @@ suite('UserDataProfilesManifestSync', () => {
assert.deepStrictEqual(testObject.conflicts.conflicts, []);

const profiles = getLocalProfiles(testClient);
assert.deepStrictEqual(profiles, [{ id: '1', name: 'name 1' }]);
assert.deepStrictEqual(profiles, [{ id: '1', name: 'name 1', shortName: undefined }]);
});

test('first time sync when profiles exists', async () => {
Expand All @@ -113,7 +113,7 @@ suite('UserDataProfilesManifestSync', () => {
assert.deepStrictEqual(testObject.conflicts.conflicts, []);

const profiles = getLocalProfiles(testClient);
assert.deepStrictEqual(profiles, [{ id: '1', name: 'name 1' }, { id: '2', name: 'name 2' }]);
assert.deepStrictEqual(profiles, [{ id: '1', name: 'name 1', shortName: undefined }, { id: '2', name: 'name 2', shortName: undefined }]);

const { content } = await testClient.read(testObject.resource);
assert.ok(content !== null);
Expand All @@ -132,7 +132,7 @@ suite('UserDataProfilesManifestSync', () => {
assert.deepStrictEqual(testObject.conflicts.conflicts, []);

const profiles = getLocalProfiles(testClient);
assert.deepStrictEqual(profiles, [{ id: '1', name: 'name 1' }]);
assert.deepStrictEqual(profiles, [{ id: '1', name: 'name 1', shortName: undefined }]);

const { content } = await testClient.read(testObject.resource);
assert.ok(content !== null);
Expand All @@ -141,23 +141,23 @@ suite('UserDataProfilesManifestSync', () => {
});

test('sync adding a profile', async () => {
await testClient.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 1');
await testClient.instantiationService.get(IUserDataProfilesService).createProfile('1', 'name 1', { shortName: 'short 1' });
await testObject.sync(await testClient.getResourceManifest());
await client2.sync();

await testClient.instantiationService.get(IUserDataProfilesService).createProfile('2', 'name 2');
await testObject.sync(await testClient.getResourceManifest());
assert.strictEqual(testObject.status, SyncStatus.Idle);
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
assert.deepStrictEqual(getLocalProfiles(testClient), [{ id: '1', name: 'name 1' }, { id: '2', name: 'name 2' }]);
assert.deepStrictEqual(getLocalProfiles(testClient), [{ id: '1', name: 'name 1', shortName: 'short 1' }, { id: '2', name: 'name 2', shortName: undefined }]);

await client2.sync();
assert.deepStrictEqual(getLocalProfiles(client2), [{ id: '1', name: 'name 1' }, { id: '2', name: 'name 2' }]);
assert.deepStrictEqual(getLocalProfiles(client2), [{ id: '1', name: 'name 1', shortName: 'short 1' }, { id: '2', name: 'name 2', shortName: undefined }]);

const { content } = await testClient.read(testObject.resource);
assert.ok(content !== null);
const actual = parseRemoteProfiles(content!);
assert.deepStrictEqual(actual, [{ id: '1', name: 'name 1', collection: '1' }, { id: '2', name: 'name 2', collection: '2' }]);
assert.deepStrictEqual(actual, [{ id: '1', name: 'name 1', collection: '1', shortName: 'short 1' }, { id: '2', name: 'name 2', collection: '2' }]);
});

test('sync updating a profile', async () => {
Expand All @@ -169,10 +169,10 @@ suite('UserDataProfilesManifestSync', () => {
await testObject.sync(await testClient.getResourceManifest());
assert.strictEqual(testObject.status, SyncStatus.Idle);
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
assert.deepStrictEqual(getLocalProfiles(testClient), [{ id: '1', name: 'name 2' }]);
assert.deepStrictEqual(getLocalProfiles(testClient), [{ id: '1', name: 'name 2', shortName: '2' }]);

await client2.sync();
assert.deepStrictEqual(getLocalProfiles(client2), [{ id: '1', name: 'name 2' }]);
assert.deepStrictEqual(getLocalProfiles(client2), [{ id: '1', name: 'name 2', shortName: '2' }]);

const { content } = await testClient.read(testObject.resource);
assert.ok(content !== null);
Expand All @@ -190,10 +190,10 @@ suite('UserDataProfilesManifestSync', () => {
await testObject.sync(await testClient.getResourceManifest());
assert.strictEqual(testObject.status, SyncStatus.Idle);
assert.deepStrictEqual(testObject.conflicts.conflicts, []);
assert.deepStrictEqual(getLocalProfiles(testClient), [{ id: '2', name: 'name 2' }]);
assert.deepStrictEqual(getLocalProfiles(testClient), [{ id: '2', name: 'name 2', shortName: undefined }]);

await client2.sync();
assert.deepStrictEqual(getLocalProfiles(client2), [{ id: '2', name: 'name 2' }]);
assert.deepStrictEqual(getLocalProfiles(client2), [{ id: '2', name: 'name 2', shortName: undefined }]);

const { content } = await testClient.read(testObject.resource);
assert.ok(content !== null);
Expand All @@ -206,10 +206,10 @@ suite('UserDataProfilesManifestSync', () => {
return JSON.parse(syncData.content);
}

function getLocalProfiles(client: UserDataSyncClient): { id: string; name: string }[] {
function getLocalProfiles(client: UserDataSyncClient): { id: string; name: string; shortName?: string }[] {
return client.instantiationService.get(IUserDataProfilesService).profiles
.slice(1).sort((a, b) => a.name.localeCompare(b.name))
.map(profile => ({ id: profile.id, name: profile.name }));
.map(profile => ({ id: profile.id, name: profile.name, shortName: profile.shortName }));
}


Expand Down
Expand Up @@ -587,7 +587,7 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
}

private getConfigureSyncQuickPickItems(): ConfigureSyncQuickPickItem[] {
return [{
const result = [{
id: SyncResource.Settings,
label: getSyncAreaLabel(SyncResource.Settings)
}, {
Expand All @@ -607,6 +607,13 @@ export class UserDataSyncWorkbenchContribution extends Disposable implements IWo
id: SyncResource.GlobalState,
label: getSyncAreaLabel(SyncResource.GlobalState),
}];
if (this.productService.enableSyncingProfiles) {
result.push({
id: SyncResource.Profiles,
label: getSyncAreaLabel(SyncResource.Profiles),
});
}
return result;
}

private updateConfiguration(items: ConfigureSyncQuickPickItem[], selectedItems: ReadonlyArray<ConfigureSyncQuickPickItem>): void {
Expand Down