-
Notifications
You must be signed in to change notification settings - Fork 24
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
chore: preparation to NPM publish #1511
base: develop
Are you sure you want to change the base?
Changes from all commits
9715d0a
8f47453
9bfa507
8f39241
b8e8787
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
{ | ||
"name": "@splunk/ucc_ui_lib", | ||
"version": "0.0.1", | ||
"name": "@splunk/add-on-ucc-framework", | ||
"description": "Splunk Add-on SDK formerly UCC is a build and code generation framework", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/splunk/addonfactory-ucc-generator.git", | ||
"directory": "ui" | ||
}, | ||
"version": "5.55.0", | ||
"license": "Apache-2.0", | ||
"private": true, | ||
"author": "Splunk Inc.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add this one? |
||
"homepage": "https://splunk.github.io/addonfactory-ucc-generator", | ||
"scripts": { | ||
"build": "cross-env NODE_ENV=production webpack --bail", | ||
"build:lib": "cross-env NODE_ENV=production tsc --project tsconfig.lib.json", | ||
"build:watch": "webpack --watch", | ||
"format": "prettier \"src/**/*.(js|jsx|ts|tsx|css)\" --write", | ||
"format:verify": "prettier \"src/**/*.(js|jsx|ts|tsx|css)\" --list-different", | ||
|
@@ -18,7 +26,8 @@ | |
"storybook": "storybook dev -p 6006", | ||
"build-storybook": "storybook build", | ||
"test-storybook": "test-storybook", | ||
"test-storybook:update-snapshots": "yarn run test-storybook -u" | ||
"test-storybook:update-snapshots": "yarn run test-storybook -u", | ||
"prepublishOnly": "yarn run build:lib" | ||
}, | ||
"dependencies": { | ||
"@splunk/dashboard-action-buttons": "^27.5.1", | ||
|
@@ -118,6 +127,10 @@ | |
"webpack-dev-server": "^5.2.0", | ||
"webpack-merge": "^6.0.1" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.14.0", | ||
"typescript": "^5.6.3" | ||
}, | ||
"resolutions": { | ||
"@npmcli/git": "^2.1.0", | ||
"@types/react": "^16.14.62", | ||
|
@@ -138,5 +151,9 @@ | |
"workerDirectory": [ | ||
"src/public" | ||
] | ||
} | ||
}, | ||
"types": "./dist/lib/publicApi.d.ts", | ||
"files": [ | ||
"dist/lib" | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,30 +4,12 @@ import { getUnifiedConfigs } from '../../util/util'; | |
import { getBuildDirPath } from '../../util/script'; | ||
import { AcceptableFormValueOrNullish } from '../../types/components/shareableTypes'; | ||
import { UtilBaseForm } from '../../types/components/BaseFormTypes'; | ||
import { GlobalConfig } from '../../types/globalConfig/globalConfig'; | ||
import { Mode } from '../../constants/modes'; | ||
import { invariant } from '../../util/invariant'; | ||
import { CustomControlConstructor } from './CustomControlBase'; | ||
import { ControlData } from './CustomControl.types'; | ||
|
||
interface IData { | ||
value: AcceptableFormValueOrNullish; | ||
mode: Mode; | ||
serviceName: string; | ||
} | ||
|
||
interface ICustomCompClass { | ||
new ( | ||
config: GlobalConfig, | ||
el: HTMLElement | undefined, | ||
data: IData, | ||
setValue: (field: string, newValue: AcceptableFormValueOrNullish) => void, | ||
util: UtilBaseForm | ||
): { | ||
render: () => void; | ||
validation?: (submittedField: string, submittedValue: string) => void; | ||
}; | ||
} | ||
|
||
interface ICustomCompProps { | ||
data: IData; | ||
interface Props { | ||
data: ControlData; | ||
field: string; | ||
handleChange: (field: string, newValue: AcceptableFormValueOrNullish) => void; | ||
controlOptions: { src: string; type: string }; | ||
|
@@ -38,37 +20,40 @@ interface ICustomCompProps { | |
utilCustomFunctions: UtilBaseForm; | ||
} | ||
|
||
interface ICustomCompState { | ||
interface State { | ||
loading: boolean; | ||
} | ||
|
||
class CustomControl extends React.Component<ICustomCompProps, ICustomCompState> { | ||
class CustomControl extends React.Component<Props, State> { | ||
static loadCustomControl = ( | ||
module: string, | ||
type: string, | ||
appName: string | ||
): Promise<ICustomCompClass> => | ||
): Promise<CustomControlConstructor> => | ||
new Promise((resolve) => { | ||
if (type === 'external') { | ||
import(/* webpackIgnore: true */ `${getBuildDirPath()}/custom/${module}.js`).then( | ||
(external) => { | ||
const Control = external.default; | ||
async (external) => { | ||
const Control = external.default as CustomControlConstructor; | ||
resolve(Control); | ||
} | ||
); | ||
} else { | ||
// @ts-expect-error typeof __non_webpack_require__ is not known during bundle | ||
__non_webpack_require__([`app/${appName}/js/build/custom/${module}`], (Control) => { | ||
resolve(Control); | ||
}); | ||
__non_webpack_require__( | ||
[`app/${appName}/js/build/custom/${module}`], | ||
(Control: CustomControlConstructor) => { | ||
resolve(Control); | ||
} | ||
); | ||
} | ||
}); | ||
|
||
shouldRender: boolean; | ||
|
||
el?: HTMLElement; | ||
|
||
constructor(props: ICustomCompProps) { | ||
constructor(props: Props) { | ||
super(props); | ||
this.state = { | ||
loading: true, | ||
|
@@ -85,14 +70,15 @@ class CustomControl extends React.Component<ICustomCompProps, ICustomCompState> | |
this.props.controlOptions.type, | ||
appName | ||
).then((Control) => { | ||
invariant(this.el !== undefined, 'Element should be defined'); | ||
const customControl = new Control( | ||
globalConfig, | ||
this.el, | ||
this.props.data, | ||
this.setValue, | ||
this.props.utilCustomFunctions | ||
); | ||
customControl?.render(); | ||
customControl.render(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to not change behaviour, should we validate if that one exists? |
||
|
||
if (typeof customControl.validation === 'function') { | ||
this.props.addCustomValidator(this.props.field, customControl.validation); | ||
|
@@ -101,7 +87,7 @@ class CustomControl extends React.Component<ICustomCompProps, ICustomCompState> | |
}); | ||
} | ||
|
||
shouldComponentUpdate(_nextProps: ICustomCompProps, nextState: ICustomCompState) { | ||
shouldComponentUpdate(_nextProps: Props, nextState: State) { | ||
if (!nextState.loading && this.shouldRender) { | ||
this.shouldRender = false; | ||
return true; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { AcceptableFormValueOrNullish } from '../../types/components/shareableTypes'; | ||
import { Mode } from '../../constants/modes'; | ||
|
||
export interface ControlData { | ||
value: AcceptableFormValueOrNullish; | ||
mode: Mode; | ||
serviceName: string; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { GlobalConfig } from '../../types/globalConfig/globalConfig'; | ||
import { UtilBaseForm } from '../../types/components/BaseFormTypes'; | ||
import { AcceptableFormValueOrNullish } from '../../types/components/shareableTypes'; | ||
import { ControlData } from './CustomControl.types'; | ||
|
||
type ValueSetter = (newValue: AcceptableFormValueOrNullish) => void; | ||
|
||
export type CustomControlInstance<T extends typeof CustomControlBase = typeof CustomControlBase> = | ||
InstanceType<T>; | ||
|
||
export type CustomControlConstructor< | ||
T extends typeof CustomControlBase = typeof CustomControlBase | ||
> = new (...args: ConstructorParameters<T>) => CustomControlInstance<T>; | ||
|
||
export abstract class CustomControlBase { | ||
protected globalConfig: GlobalConfig; | ||
|
||
protected el: HTMLElement; | ||
|
||
protected data: ControlData; | ||
|
||
protected setValue: ValueSetter; | ||
|
||
protected util: UtilBaseForm; | ||
|
||
constructor( | ||
globalConfig: GlobalConfig, | ||
el: HTMLElement, | ||
data: ControlData, | ||
setValue: ValueSetter, | ||
util: UtilBaseForm | ||
) { | ||
this.globalConfig = globalConfig; | ||
this.el = el; | ||
this.data = data; | ||
this.setValue = setValue; | ||
this.util = util; | ||
} | ||
|
||
abstract render(): void; | ||
|
||
validation?(field: string, value: ControlData['value']): string | undefined; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export type CustomTabInstance<T extends typeof CustomTabBase = typeof CustomTabBase> = | ||
InstanceType<T>; | ||
|
||
export type CustomTabConstructor<T extends typeof CustomTabBase = typeof CustomTabBase> = new ( | ||
...args: ConstructorParameters<T> | ||
) => CustomTabInstance<T>; | ||
|
||
export abstract class CustomTabBase { | ||
protected tab: object; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe lets add a type for this one? |
||
|
||
protected el: HTMLElement; | ||
|
||
constructor(tab: object, el: HTMLElement) { | ||
this.tab = tab; | ||
this.el = el; | ||
} | ||
|
||
abstract render(): void; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formerly?