-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#375 initialization values are prepared from address field config; im…
…provements in validation rules preparation
- Loading branch information
1 parent
10b90fb
commit a397e63
Showing
10 changed files
with
280 additions
and
281 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
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
14 changes: 4 additions & 10 deletions
14
src/reactapp/src/components/billingAddress/utility/index.js
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
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,53 @@ | ||
import { | ||
ConfigMultiline, | ||
ConfigTextInput, | ||
ConfigSelectInput, | ||
} from '../components/common/Form'; | ||
import { _emptyFunc } from '../utils'; | ||
import { FieldType } from '../utils/field'; | ||
import RegionRenderer from '../components/address/components/RegionRenderer'; | ||
import CountryRenderer from '../components/address/components/CountryRenderer'; | ||
|
||
class FieldRenderer { | ||
rendererList = []; | ||
|
||
constructor() { | ||
this.#registerDefaultRenderers(); | ||
} | ||
|
||
register(renderer, sortOrder = 100, conditionCallback = _emptyFunc()) { | ||
const newRenderer = { | ||
renderer, | ||
sortOrder, | ||
canRenderField: conditionCallback, | ||
}; | ||
this.rendererList = [...this.rendererList, newRenderer].sort( | ||
(renderer1, renderer2) => renderer1.sortOrder - renderer2.sortOrder | ||
); | ||
} | ||
|
||
getRendererForField(field) { | ||
// eslint-disable-next-line no-restricted-syntax | ||
for (const renderer of this.rendererList) { | ||
if (renderer.canRenderField(field)) { | ||
return renderer.renderer; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
#registerDefaultRenderers() { | ||
this.register(CountryRenderer, 10, (field) => field.code === 'country_id'); | ||
this.register(RegionRenderer, 20, (field) => field.code === 'region'); | ||
this.register(ConfigTextInput, 30, (field) => FieldType.isText(field.type)); | ||
this.register(ConfigSelectInput, 10, (field) => | ||
FieldType.isSelect(field.type) | ||
); | ||
this.register(ConfigMultiline, 10, (field) => | ||
FieldType.isMultiline(field.type) | ||
); | ||
} | ||
} | ||
|
||
export const addressFieldRenderer = new FieldRenderer(); |
Oops, something went wrong.