Skip to content

Commit 17693fa

Browse files
Ivan KitanovIvan Kitanov
authored andcommitted
chore(combo): Simplyfing migration to only provide comment
1 parent fd5e65e commit 17693fa

File tree

4 files changed

+21
-200
lines changed

4 files changed

+21
-200
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All notable changes for each version of this project will be documented in this file.
44

5-
## 20.0.5
5+
## 20.0.6
66
### General
77
- `IgxSimpleCombo`
88
- Added `disableFiltering` to the `IgxSimpleCombo`, which enables/disables the filtering in the list. The default is `false`.

projects/igniteui-angular/migrations/migration-collection.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@
239239
},
240240
"migration-48": {
241241
"version": "20.0.6",
242-
"description": "Updates Ignite UI for Angular from v20.0.2 to v20.0.5",
242+
"description": "Updates Ignite UI for Angular from v20.0.2 to v20.0.6",
243243
"factory": "./update-20_0_6"
244244
}
245245
}

projects/igniteui-angular/migrations/update-20_0_6/index.spec.ts

Lines changed: 13 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -76,134 +76,31 @@ describe('Migration 20.0.6 - Replace filteringOptions.filterable', () => {
7676

7777
// TS file tests
7878

79-
it('should remove line when filteringOptions.filterable is set to true', async () => {
80-
const input = `this.igxSimpleCombo.filteringOptions.filterable = true;`;
81-
appTree.create(makeScript('tsRemoveTrue'), input);
82-
83-
const tree = await runner.runSchematic(migrationName, {}, appTree);
84-
const output = tree.readContent(makeScript('tsRemoveTrue'));
85-
86-
expect(output).not.toContain('filteringOptions.filterable');
87-
});
88-
89-
it('should replace filteringOptions.filterable = false with disableFiltering = true', async () => {
90-
const input = `this.igxSimpleCombo.filteringOptions.filterable = false;`;
91-
appTree.create(makeScript('tsReplaceFalse'), input);
92-
93-
const tree = await runner.runSchematic(migrationName, {}, appTree);
94-
const output = tree.readContent(makeScript('tsReplaceFalse'));
95-
96-
expect(output).toContain('this.igxSimpleCombo.disableFiltering = true;');
97-
});
98-
99-
it('should handle the use of negative flag correctly', async () => {
100-
const input = `this.igxSimpleCombo.filteringOptions.filterable = !this.disableFilteringFlag;`;
101-
appTree.create(makeScript('tsNegativeFlag'), input);
102-
103-
const tree = await runner.runSchematic(migrationName, {}, appTree);
104-
const output = tree.readContent(makeScript('tsNegativeFlag'));
105-
106-
expect(output).toContain('this.igxSimpleCombo.disableFiltering = this.disableFilteringFlag;');
107-
});
108-
109-
it('should handle the use of possitive flag correctly', async () => {
110-
const input = `this.igxSimpleCombo.filteringOptions.filterable = this.disableFilteringFlag;`;
111-
appTree.create(makeScript('tsNegativeFlag'), input);
112-
113-
const tree = await runner.runSchematic(migrationName, {}, appTree);
114-
const output = tree.readContent(makeScript('tsNegativeFlag'));
115-
116-
expect(output).toContain('this.igxSimpleCombo.disableFiltering = !this.disableFilteringFlag;');
117-
});
118-
119-
it('should split filteringOptions object and move filterable out', async () => {
120-
const input = `this.igxSimpleCombo.filteringOptions = { filterable: false, caseSensitive: true };`;
121-
appTree.create(makeScript('tsSplitObj'), input);
122-
123-
const tree = await runner.runSchematic(migrationName, {}, appTree);
124-
const output = tree.readContent(makeScript('tsSplitObj'));
125-
126-
expect(output).toContain('this.igxSimpleCombo.disableFiltering = true;');
127-
expect(output).toContain('this.igxSimpleCombo.filteringOptions = { caseSensitive: true };');
128-
expect(output).not.toContain('filterable');
129-
});
130-
131-
it('should not add disableFiltering again if already present when filterable is set to false', async () => {
132-
const input = `
133-
this.igxCombo.filteringOptions.filterable = false;
134-
this.igxCombo.disableFiltering = true;
135-
`;
136-
appTree.create(makeScript('tsDirectFalseExistingDisable'), input);
137-
138-
const tree = await runner.runSchematic(migrationName, {}, appTree);
139-
const output = tree.readContent(makeScript('tsDirectFalseExistingDisable'));
140-
141-
const occurrences = (output.match(/\.disableFiltering/g) || []).length;
142-
143-
expect(occurrences).toBe(1);
144-
expect(output).not.toContain('filterable');
145-
});
146-
147-
it('should not add disableFiltering again if already present when using negative flag assignment', async () => {
148-
const input = `
149-
this.igxSimpleCombo.filteringOptions.filterable = !this.flag;
150-
this.igxSimpleCombo.disableFiltering = this.flag;
151-
`;
152-
appTree.create(makeScript('tsNegativeFlagExistingDisable'), input);
153-
154-
const tree = await runner.runSchematic(migrationName, {}, appTree);
155-
const output = tree.readContent(makeScript('tsNegativeFlagExistingDisable'));
156-
157-
const occurrences = (output.match(/\.disableFiltering/g) || []).length;
158-
159-
expect(occurrences).toBe(1);
160-
expect(output).not.toContain('filterable');
161-
});
162-
163-
it('should not add disableFiltering again if already present when using positive flag assignment', async () => {
164-
const input = `
165-
this.igxSimpleCombo.filteringOptions.filterable = this.flag;
166-
this.igxSimpleCombo.disableFiltering = !this.flag;
167-
`;
168-
appTree.create(makeScript('tsPositiveFlagExistingDisable'), input);
169-
170-
const tree = await runner.runSchematic(migrationName, {}, appTree);
171-
const output = tree.readContent(makeScript('tsPositiveFlagExistingDisable'));
172-
173-
const occurrences = (output.match(/\.disableFiltering/g) || []).length;
174-
175-
expect(occurrences).toBe(1);
176-
expect(output).not.toContain('filterable');
177-
});
79+
it('should insert warning comment before `.filteringOptions.filterable = ...` assignment', async () => {
80+
const input = `this.igxCombo.filteringOptions.filterable = false;`;
81+
const expectedComment = "// Manual migration needed: please use 'disableFiltering' instead of filteringOptions.filterable." +
82+
"Since it has been deprecated.'";
17883

179-
it('should split filteringOptions object and remove filterable if disableFiltering is already present', async () => {
180-
const input = `
181-
this.igxCombo.filteringOptions = { filterable: false, caseSensitive: true };
182-
this.igxCombo.disableFiltering = true;
183-
`;
184-
appTree.create(makeScript('tsSplitObjAndDisabledFiltering'), input);
84+
appTree.create(makeScript('tsWarnOnDirectAssignment'), input);
18585

18686
const tree = await runner.runSchematic(migrationName, {}, appTree);
187-
const output = tree.readContent(makeScript('tsSplitObjAndDisabledFiltering'));
188-
189-
const occurrences = (output.match(/\.disableFiltering/g) || []).length;
87+
const output = tree.readContent(makeScript('tsWarnOnDirectAssignment'));
19088

191-
expect(occurrences).toBe(1);
192-
expect(output).toContain('this.igxCombo.filteringOptions = { caseSensitive: true };');
193-
expect(output).not.toContain('filterable');
89+
expect(output).toContain(expectedComment);
90+
expect(output).toContain('this.igxCombo.filteringOptions.filterable = false;');
19491
});
19592

196-
it('should insert warning comment when filteringOptions is assigned from a variable', async () => {
197-
const input = `this.igxSimpleCombo.filteringOptions = filterOpts;`;
93+
it('should insert warning comment before `.filteringOptions = { ... }` assignment', async () => {
94+
const input = `this.igxCombo.filteringOptions = { filterable: false, caseSensitive: true };`;
19895
const expectedComment = "// Manual migration needed: please use 'disableFiltering' instead of filteringOptions.filterable." +
19996
"Since it has been deprecated.'";
20097

201-
appTree.create(makeScript('tsVariableAssign'), input);
98+
appTree.create(makeScript('tsWarnOnObjectAssignment'), input);
20299

203100
const tree = await runner.runSchematic(migrationName, {}, appTree);
204-
const output = tree.readContent(makeScript('tsVariableAssign'));
101+
const output = tree.readContent(makeScript('tsWarnOnObjectAssignment'));
205102

206-
expect(output).toContain(input);
207103
expect(output).toContain(expectedComment);
104+
expect(output).toContain('this.igxCombo.filteringOptions = { filterable: false, caseSensitive: true };');
208105
});
209106
});

projects/igniteui-angular/migrations/update-20_0_6/index.ts

Lines changed: 6 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -102,92 +102,16 @@ export default (): Rule => async (host: Tree, context: SchematicContext) => {
102102
for (const path of update.tsFiles) {
103103
const content = host.read(path).toString();
104104
const lines = content.split('\n');
105-
const hasDisableFiltering = lines.some(l => /\.disableFiltering\s*=/.test(l));
106105
const newLines: string[] = [];
107106

108107
let modified = false;
109108

110-
for (let i = 0; i < lines.length; i++) {
111-
let line = lines[i];
112-
113-
const directTrue = /\.filteringOptions\.filterable\s*=\s*true\s*;/.test(line);
114-
const directFalse = /\.filteringOptions\.filterable\s*=\s*false\s*;/.test(line);
115-
const negativeFlagBinding = /\.filteringOptions\.filterable\s*=\s*!\s*(.+);/.exec(line);
116-
const positiveFlagBinding = /\.filteringOptions\.filterable\s*=\s*(this\.\w+);/.exec(line);
117-
const inlineObjectAssign = /\.filteringOptions\s*=\s*{[^}]*}/.test(line);
118-
const filterableInObject = /filterable\s*:\s*([^,}]+)/.exec(line);
119-
const objectAssignment = /\.filteringOptions\s*=\s*[^;{]+;/.test(line);
120-
121-
if (directTrue) {
122-
// Remove the line entirely
123-
modified = true;
124-
continue;
125-
}
126-
127-
if (directFalse) {
128-
if (hasDisableFiltering) {
129-
modified = true;
130-
continue;
131-
}
132-
133-
line = line.replace(/\.filteringOptions\.filterable\s*=\s*false\s*;/, '.disableFiltering = true;');
134-
modified = true;
135-
} else if (negativeFlagBinding) {
136-
if (hasDisableFiltering) {
137-
modified = true;
138-
continue;
139-
}
140-
141-
const variable = negativeFlagBinding[1].trim();
142-
line = line.replace(/\.filteringOptions\.filterable\s*=\s*!\s*.+;/, `.disableFiltering = ${variable};`);
143-
modified = true;
144-
} else if (positiveFlagBinding) {
145-
if (hasDisableFiltering) {
146-
modified = true;
147-
continue;
148-
}
149-
150-
const variable = positiveFlagBinding[1].trim();
151-
line = line.replace(/\.filteringOptions\.filterable\s*=\s*(this\.\w+);/, `.disableFiltering = !${variable};`);
152-
modified = true;
153-
}else if (inlineObjectAssign && filterableInObject) {
154-
if(hasDisableFiltering){
155-
// clear object literal without adding disableFiltering
156-
const cleanedLine = line
157-
.replace(/filterable\s*:\s*[^,}]+,?\s*/g, '')
158-
.replace(/,\s*}/, ' }')
159-
.replace(/{\s*}/, '{}');
160-
161-
newLines.push(cleanedLine);
162-
modified = true;
163-
continue;
164-
}
165-
166-
const filterVal = filterableInObject[1].trim();
167-
168-
let disableFilteringValue: string;
169-
if (filterVal === 'true') {
170-
disableFilteringValue = 'false';
171-
} else if (filterVal === 'false') {
172-
disableFilteringValue = 'true';
173-
} else if (filterVal.startsWith('!')) {
174-
disableFilteringValue = filterVal.slice(1).trim();
175-
} else {
176-
disableFilteringValue = `!${filterVal}`;
177-
}
178-
179-
const cleanedLine = line
180-
.replace(/filterable\s*:\s*[^,}]+,?\s*/g, '')
181-
.replace(/,\s*}/, ' }')
182-
.replace(/{\s*}/, '{}');
183-
184-
// Output both lines
185-
newLines.push(line.replace(/\.filteringOptions\s*=.*/, `.disableFiltering = ${disableFilteringValue};`));
186-
newLines.push(cleanedLine);
187-
modified = true;
188-
continue;
189-
} else if (objectAssignment) {
190-
newLines.push('// '+ warnMsg);
109+
for (const line of lines) {
110+
if (
111+
/\.filteringOptions\.filterable\s*=/.test(line) ||
112+
/\.filteringOptions\s*=/.test(line)
113+
) {
114+
newLines.push('// ' + warnMsg);
191115
modified = true;
192116
}
193117
newLines.push(line);

0 commit comments

Comments
 (0)