Skip to content

Commit

Permalink
adj translator typing for react; boolean convert cleanup;
Browse files Browse the repository at this point in the history
  • Loading branch information
elbakerino committed Sep 29, 2023
1 parent 3e31609 commit a1c78f8
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 15 deletions.
1 change: 1 addition & 0 deletions packages/demo-web/package.json
Expand Up @@ -27,6 +27,7 @@
"@ui-schema/pro": "~0.0.12",
"@ui-schema/material-pickers": "~0.4.0-alpha.4",
"@tactic-ui/react": "~0.0.10",
"@tactic-ui/engine": "~0.0.5",
"bootstrap": "^4.4.1",
"clsx": "^1.1.0",
"immutable": "^4.0.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/demo-web/src/material-ui/material-ui.tsx
Expand Up @@ -28,7 +28,8 @@ import { WidgetProps } from '@ui-schema/react/Widgets'
import { ObjectRenderer } from '@ui-schema/react-json-schema/ObjectRenderer'
import { StoreKeys } from '@ui-schema/system/ValueStore'
import { DecoratorPropsNext, ReactDeco } from '@tactic-ui/react/Deco'
import { LeafsRenderMapping } from '@tactic-ui/react/LeafsEngine'
// todo: somehow here the re-export from `@tactic-ui/react/LeafsEngine` doesn't resolve in IntelliJ if engine isn't installed directly
import { LeafsRenderMapping } from '@tactic-ui/engine/Leaf'
import { ExtractStorePlugin } from '@ui-schema/react/ExtractStorePlugin'
import { MuiComponentsBinding, NextMuiWidgetsBinding } from '@ui-schema/ds-material/WidgetsBinding'
import { SchemaPluginsAdapter } from '@ui-schema/react/SchemaPluginsAdapter'
Expand Down
6 changes: 2 additions & 4 deletions packages/demo-web/src/t.tsx
Expand Up @@ -42,8 +42,7 @@ const dicEN = createMap({
titles: {
'simple-number': 'Simple Number',
},
// todo: fix typings
}) as unknown as TranslatorDictionary
}) as TranslatorDictionary<translation | React.ComponentType>

const dicDE = createMap({
error: de.errors,
Expand All @@ -67,8 +66,7 @@ const dicDE = createMap({
titles: {
'simple-number': 'Einfache Nummer',
},
// todo: fix typings
}) as unknown as TranslatorDictionary
}) as TranslatorDictionary<translation | React.ComponentType>

const tEN = makeTranslator<translation | React.ComponentType>(dicEN, 'en')
const tDE = makeTranslator<translation | React.ComponentType>(dicDE, 'de')
Expand Down
2 changes: 1 addition & 1 deletion packages/docs/src/component/Schema/DemoUIGenerator.js
Expand Up @@ -186,7 +186,7 @@ const DemoUIGenerator = (
onClick ?
<Button
variant={'contained'}
disabled={!!isInvalid(store?.getValidity())}
disabled={Boolean(isInvalid(store?.getValidity()))}
style={{marginTop: 12}}
onClick={() => isInvalid(store?.getValidity()) ? undefined : onClick(store)}
>Send</Button> : null}
Expand Down
4 changes: 2 additions & 2 deletions packages/docs/src/page/PageQuickStart.js
Expand Up @@ -410,7 +410,7 @@ export const Generator = () => {
{/* add your sending button, in the onClick check for validity and do the needed action */}
<button
disabled={!!isInvalid(store.getValidity())}
disabled={Boolean(isInvalid(store.getValidity()))}
onClick={() => {
if(!isInvalid(store.getValidity())) {
// when not invalid, post to an API
Expand Down Expand Up @@ -574,7 +574,7 @@ export const Generator = () => {
{/* add your sending button, in the onClick check for validity and do the needed action */}
<button
disabled={!!isInvalid(store.getValidity())}
disabled={Boolean(isInvalid(store.getValidity()))}
onClick={() => {
if(!isInvalid(store.getValidity())) {
// when not invalid, post to an API
Expand Down
Expand Up @@ -15,12 +15,10 @@ const BoolRenderer = ({showValidity, required, errors, value, storeKeys, onChang
classForm.push('was-validated');
}

let currentChecked = !!value;

return <div className={classForm.join(' ')}>
<input
type="checkbox" className={classFormControl.join(' ')} id={'uis-' + id}
checked={currentChecked}
checked={Boolean(value)}
required={required}
onChange={() =>
onChange({
Expand Down
1 change: 1 addition & 0 deletions packages/uis-react/package.json
Expand Up @@ -40,6 +40,7 @@
"@tactic-ui/react": "~0.0.10"
},
"devDependencies": {
"@tactic-ui/engine": "~0.0.5",
"@ui-schema/system": "~0.5.0-alpha.0",
"@ui-schema/json-schema": "~0.5.0-alpha.0",
"immutable": "^4.0.0",
Expand Down
1 change: 1 addition & 0 deletions packages/uis-react/src/WidgetEngine/WidgetEngine.tsx
@@ -1,6 +1,7 @@
import { ReactDeco, DecoratorProps, ReactBaseDecorator } from '@tactic-ui/react/Deco'
import React from 'react'
import { createLeafsContext, defineLeafsContext } from '@tactic-ui/react/LeafsContext'
// todo: somehow here the re-export from `@tactic-ui/react/LeafsEngine` doesn't resolve in IntelliJ if engine isn't installed directly
import { LeafsRenderMapping, ReactLeafsNodeSpec } from '@tactic-ui/react/LeafsEngine'
import { WidgetProps } from '@ui-schema/react/Widgets'
import { UISchemaMap } from '@ui-schema/json-schema/Definitions'
Expand Down
3 changes: 1 addition & 2 deletions packages/uis-system/src/Translator/Translator.ts
Expand Up @@ -11,5 +11,4 @@ export type Translator<T = translation> = (
schema?: ValueOrImmutableOrdered<UISchema['t']>
) => T

// @todo: somehow allow adding further specifics, e.g. `React.ComponentType` in `/react`
export type TranslatorDictionary = Map<string | number, Map<string | number, { [key: string | number]: any }> | string | number | Function/* | React.ComponentType*/>
export type TranslatorDictionary<T = translation> = Map<string | number, Map<string | number, { [key: string | number]: any }> | T>
2 changes: 1 addition & 1 deletion packages/uis-system/src/Translator/makeTranslator.ts
Expand Up @@ -11,7 +11,7 @@ import { translation, Translator, TranslatorDictionary } from '@ui-schema/system
*/
export const makeTranslator =
<T = translation>(
dictionary: TranslatorDictionary,
dictionary: TranslatorDictionary<T>,
locale: string = ''
): Translator<T> =>
(text, context = Map(), schema = undefined) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/uis-system/src/ValidatorErrors/ValidatorErrors.ts
Expand Up @@ -87,7 +87,7 @@ export class ValidatorErrors extends Record({

hasError(type?: string): boolean {
const typeErrors = this.getIn(type ? ['errors', type] : ['errors'])
return !!(
return Boolean(
(List.isList(typeErrors) && typeErrors.size) ||
(Map.isMap(typeErrors) && typeErrors.keySeq().size)
)
Expand Down

0 comments on commit a1c78f8

Please sign in to comment.