Skip to content

Commit

Permalink
Revert "Add profile id"
Browse files Browse the repository at this point in the history
This reverts commit b33bc94.
  • Loading branch information
khaitruong922 committed Nov 2, 2024
1 parent b33bc94 commit 4d984d0
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 36 deletions.
11 changes: 0 additions & 11 deletions ext/js/data/options-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,6 @@ export class OptionsUtil {
this._updateVersion50,
this._updateVersion51,
this._updateVersion52,
this._updateVersion53,
];
/* eslint-enable @typescript-eslint/unbound-method */
if (typeof targetVersion === 'number' && targetVersion < result.length) {
Expand Down Expand Up @@ -1499,16 +1498,6 @@ export class OptionsUtil {
}
}

/**
* - Added profile id
* @type {import('options-util').UpdateFunction}
*/
async _updateVersion53(options) {
for (let i = 0; i < options.profiles.length; i++) {
options.profiles[i].id = `profile-${i}`;
}
}

/**
* @param {string} url
* @returns {Promise<chrome.tabs.Tab>}
Expand Down
7 changes: 3 additions & 4 deletions ext/js/pages/settings/dictionary-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1143,14 +1143,13 @@ export class DictionaryController {
const {profiles} = options;

/** @type {import('settings-controller.js').ProfilesDictionarySettings} */
const profilesDictionarySettings = {};
const profilesDictionarySettings = [];

for (let i = 0, ii = profiles.length; i < ii; ++i) {
const profile = profiles[i];
const dictionaries = profile.options.dictionaries;
const dictionaries = profiles[i].options.dictionaries;
for (let j = 0, jj = dictionaries.length; j < jj; ++j) {
if (dictionaries[j].name === dictionaryTitle) {
profilesDictionarySettings[profile.id] = {...dictionaries[j], index: j};
profilesDictionarySettings.push({...dictionaries[j], index: j});
break;
}
}
Expand Down
6 changes: 3 additions & 3 deletions ext/js/pages/settings/dictionary-import-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,15 +668,15 @@ export class DictionaryImportController {
const targets = [];
const profileCount = optionsFull.profiles.length;
for (let i = 0; i < profileCount; ++i) {
const {options, id: profileId} = optionsFull.profiles[i];
const {options} = optionsFull.profiles[i];
const enabled = profileIndex === i;
const defaultSettings = DictionaryController.createDefaultDictionarySettings(title, enabled, styles);
const path1 = `profiles[${i}].options.dictionaries`;

if (profilesDictionarySettings === null || typeof profilesDictionarySettings[profileId] === 'undefined') {
if (profilesDictionarySettings === null || typeof profilesDictionarySettings[i] === 'undefined') {
targets.push({action: 'push', path: path1, items: [defaultSettings]});
} else {
const {index, ...currentSettings} = profilesDictionarySettings[profileId];
const {index, ...currentSettings} = profilesDictionarySettings[i];
targets.push({
action: 'splice',
path: path1,
Expand Down
15 changes: 1 addition & 14 deletions ext/js/pages/settings/profile-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

import {EventListenerCollection} from '../../core/event-listener-collection.js';
import {clone, generateId} from '../../core/utilities.js';
import {clone} from '../../core/utilities.js';
import {querySelectorNotNull} from '../../dom/query-selector.js';
import {ProfileConditionsUI} from './profile-conditions-ui.js';

Expand Down Expand Up @@ -184,7 +184,6 @@ export class ProfileController {
// Create new profile
const newProfile = clone(profile);
newProfile.name = this._createCopyName(profile.name, this._profiles, 100);
newProfile.id = this._createId(this._profiles);

// Update state
const index = this._profiles.length;
Expand Down Expand Up @@ -595,18 +594,6 @@ export class ProfileController {
}
}
}
/**
* @param {import('settings').Profile[]} profiles
* @returns {string}
*/
_createId(profiles) {
const ids = new Set(profiles.map((profile) => profile.id));
let id = '';
while (id === '' || ids.has(id)) {
id = generateId(16);
}
return id;
}

/**
* @template [T=unknown]
Expand Down
3 changes: 1 addition & 2 deletions test/options-util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,6 @@ function createOptionsUpdatedTestData1() {
return {
profiles: [
{
id: 'profile-0',
name: 'Default',
options: createProfileOptionsUpdatedTestData1(),
conditionGroups: [
Expand Down Expand Up @@ -645,7 +644,7 @@ function createOptionsUpdatedTestData1() {
},
],
profileCurrent: 0,
version: 53,
version: 52,
global: {
database: {
prefixWildcardsSupported: false,
Expand Down
2 changes: 1 addition & 1 deletion types/ext/settings-controller.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type PageExitPrevention = {

type ProfileDictionarySettings = Settings.DictionaryOptions & {index: number};

export type ProfilesDictionarySettings = {[profileId: string]: ProfileDictionarySettings} | null;
export type ProfilesDictionarySettings = ProfileDictionarySettings[] | null;

export type Events = {
optionsChanged: {
Expand Down
1 change: 0 additions & 1 deletion types/ext/settings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export type GlobalDatabaseOptions = {
};

export type Profile = {
id: string;
name: string;
conditionGroups: ProfileConditionGroup[];
options: ProfileOptions;
Expand Down

0 comments on commit 4d984d0

Please sign in to comment.