-
Notifications
You must be signed in to change notification settings - Fork 615
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ModelFeatureFlag and improve plugin support
- Loading branch information
1 parent
89dfb5c
commit e712229
Showing
15 changed files
with
344 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
frontend/packages/console-plugin-sdk/src/codegen/__tests__/index.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import { | ||
Package, | ||
PluginPackage, | ||
isValidPluginPackage, | ||
resolveActivePlugins, | ||
getActivePluginsModule, | ||
} from '..'; | ||
|
||
const templatePackage: Package = { name: 'test', version: '1.2.3', readme: '', _id: '@' }; | ||
|
||
describe('codegen', () => { | ||
|
||
describe('isValidPluginPackage', () => { | ||
it('returns false if package.consolePlugin is missing', () => { | ||
expect(isValidPluginPackage({ | ||
...templatePackage, | ||
})).toBe(false); | ||
}); | ||
|
||
it('returns false if package.consolePlugin.entry is missing', () => { | ||
expect(isValidPluginPackage({ | ||
...templatePackage, | ||
consolePlugin: {}, | ||
})).toBe(false); | ||
}); | ||
|
||
it('returns false if package.consolePlugin.entry is an empty string', () => { | ||
expect(isValidPluginPackage({ | ||
...templatePackage, | ||
consolePlugin: { entry: '' }, | ||
})).toBe(false); | ||
}); | ||
|
||
it('returns true if package.consolePlugin.entry is not an empty string', () => { | ||
expect(isValidPluginPackage({ | ||
...templatePackage, | ||
consolePlugin: { entry: 'plugin.ts' }, | ||
})).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('resolveActivePlugins', () => { | ||
it('filters out packages which are not listed in appPackage.dependencies', () => { | ||
const appPackage: Package = { | ||
...templatePackage, | ||
name: 'app', | ||
dependencies: { | ||
'foo': '0.1.2', | ||
'bar': '1.2.3', | ||
}, | ||
}; | ||
|
||
const pluginPackages: PluginPackage[] = [ | ||
{ | ||
...templatePackage, | ||
name: 'bar', | ||
version: '1.2.3', | ||
consolePlugin: { entry: 'plugin.ts' }, | ||
}, | ||
{ | ||
...templatePackage, | ||
name: 'qux', | ||
version: '2.3.4', | ||
consolePlugin: { entry: 'plugin.ts' }, | ||
}, | ||
]; | ||
|
||
expect(resolveActivePlugins(appPackage, pluginPackages)).toEqual([ | ||
{ ...pluginPackages[0] }, | ||
]); | ||
}); | ||
}); | ||
|
||
describe('getActivePluginsModule', () => { | ||
it('returns the source of a module that exports the list of active plugins', () => { | ||
const pluginPackages: PluginPackage[] = [ | ||
{ | ||
...templatePackage, | ||
name: 'bar', | ||
version: '1.2.3', | ||
consolePlugin: { entry: 'src/plugin.ts' }, | ||
}, | ||
{ | ||
...templatePackage, | ||
name: 'qux-plugin', | ||
version: '2.3.4', | ||
consolePlugin: { entry: 'index.ts' }, | ||
}, | ||
]; | ||
|
||
const expectedModule = ` | ||
const activePlugins = []; | ||
import plugin_0 from 'bar/src/plugin.ts'; | ||
activePlugins.push(plugin_0); | ||
import plugin_1 from 'qux-plugin/index.ts'; | ||
activePlugins.push(plugin_1); | ||
export default activePlugins; | ||
`.replace(/^\s+/gm, ''); | ||
|
||
expect(getActivePluginsModule(pluginPackages)).toBe(expectedModule); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
frontend/packages/console-plugin-sdk/src/typings/features.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Extension } from '.'; | ||
import { K8sKind } from '@console/internal/module/k8s'; | ||
|
||
namespace ExtensionProperties { | ||
export interface ModelFeatureFlag { | ||
model: K8sKind; | ||
flag: string; | ||
} | ||
} | ||
|
||
export interface ModelFeatureFlag extends Extension<ExtensionProperties.ModelFeatureFlag> { | ||
type: 'FeatureFlag/Model'; | ||
} | ||
|
||
// TODO(vojtech): add ActionFeatureFlag | ||
export type FeatureFlag = ModelFeatureFlag; | ||
|
||
export function isModelFeatureFlag(e: Extension<any>): e is ModelFeatureFlag { | ||
return e.type === 'FeatureFlag/Model'; | ||
} | ||
|
||
export function isFeatureFlag(e: Extension<any>): e is FeatureFlag { | ||
return isModelFeatureFlag(e); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.