Skip to content

Commit

Permalink
Refactor BasicEntityCheckBoxField component and add BasicEntityRating…
Browse files Browse the repository at this point in the history
…Field
  • Loading branch information
zackatbrightbeam committed Jul 26, 2024
1 parent 9049caf commit 3e6fead
Show file tree
Hide file tree
Showing 7 changed files with 546 additions and 362 deletions.
4 changes: 2 additions & 2 deletions dist/BasicEntityCheckBoxField.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
declare function BasicEntityCheckBoxField(props: any): import("react/jsx-runtime").JSX.Element;
export { BasicEntityCheckBoxField };
declare function BasicEntityCheckboxField(props: any): import("react/jsx-runtime").JSX.Element;
export { BasicEntityCheckboxField };
2 changes: 2 additions & 0 deletions dist/BasicEntityRatingField.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare function BasicEntityRatingField(props: any): import("react/jsx-runtime").JSX.Element;
export { BasicEntityRatingField };
355 changes: 205 additions & 150 deletions dist/voxgig-model-react.es.js

Large diffs are not rendered by default.

353 changes: 204 additions & 149 deletions dist/voxgig-model-react.umd.js

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/lib/BasicEntityCheckBoxField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ import { Default, Exact, Gubu, Skip } from 'gubu'
const CMPNAME = 'BasicEntitySliderField'

const { Open } = Gubu
const BasicEntityCheckBoxFieldSpecShape = Gubu(Open({
const BasicEntityCheckboxFieldSpecShape = Gubu(Open({
field: Open({
id: String,
name: String,
kind: Skip(String),
label: Default('', String),
ux: Open({
kind: Exact('CheckBox'),
kind: Exact('Checkbox'),
edit: Default(true),
props: Open({}),
})
}),
}), {name: CMPNAME})

function BasicEntityCheckBoxField(props: any) {
function BasicEntityCheckboxField(props: any) {
const { spec } = props;

const basicEntityCheckBoxField: Spec = BasicEntityCheckBoxFieldSpecShape(spec)
const { control, field, getValues } = basicEntityCheckBoxField
const basicEntityCheckboxField: Spec = BasicEntityCheckboxFieldSpecShape(spec)
const { control, field, getValues } = basicEntityCheckboxField
const val = getValues(field.name)

return (
Expand Down Expand Up @@ -63,4 +63,4 @@ function BasicEntityCheckBoxField(props: any) {
);
}

export { BasicEntityCheckBoxField };
export { BasicEntityCheckboxField };
115 changes: 60 additions & 55 deletions src/lib/BasicEntityField.tsx
Original file line number Diff line number Diff line change
@@ -1,64 +1,76 @@
import React, { useEffect, forwardRef } from 'react'

import {
TextField,
} from '@mui/material'


import type { Spec } from './basic-types'

import { Default, Exact, Gubu, Skip } from 'gubu'
import { BasicEntityCheckBoxField } from './BasicEntityCheckBoxField'
import { BasicEntityAutocompleteField } from './BasicEntityAutocompleteField'
import { BasicEntitySliderField } from './BasicEntitySliderField'
import { BasicEntityRadioGroupField } from './BasicEntityRadioGroupField'
import { BasicEntityTextBoxField } from './BasicEntityTextBoxField'
import { BasicEntityTextField } from './BasicEntityTextField'
import { BasicEntityDateField } from './BasicEntityDateField'
import { BasicEntityTimeField } from './BasicEntityTimeField'
import { BasicEntityDateTimeField } from './BasicEntityDateTimeField'

const CMPNAME = 'BasicEntityField'

const { Open } = Gubu
const BasicEntityFieldSpecShape = Gubu(Open({
field: Open({
id: String,
name: String,
kind: Skip(String),
label: Default('', String),
ux: Open({
kind: Exact('Text', 'TextBox', 'Date', 'DateTime', 'Time', 'CheckBox', 'Autocomplete', 'Slider', 'RadioGroup'),
edit: Default(true),
rows: Default(3),
props: Open({}),
})
import React, { useEffect, forwardRef } from "react";

import { TextField } from "@mui/material";

import type { Spec } from "./basic-types";

import { Default, Exact, Gubu, Skip } from "gubu";
import { BasicEntityCheckboxField } from "./BasicEntityCheckboxField";

Check failure on line 8 in src/lib/BasicEntityField.tsx

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, lts/*)

Cannot find module './BasicEntityCheckboxField' or its corresponding type declarations.

Check failure on line 8 in src/lib/BasicEntityField.tsx

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 19.x)

Cannot find module './BasicEntityCheckboxField' or its corresponding type declarations.

Check failure on line 8 in src/lib/BasicEntityField.tsx

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 18.x)

Cannot find module './BasicEntityCheckboxField' or its corresponding type declarations.

Check failure on line 8 in src/lib/BasicEntityField.tsx

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, 16.x)

Cannot find module './BasicEntityCheckboxField' or its corresponding type declarations.

Check failure on line 8 in src/lib/BasicEntityField.tsx

View workflow job for this annotation

GitHub Actions / build (windows-latest, lts/*)

Already included file name 'D:/a/model-react/model-react/src/lib/BasicEntityCheckboxField.tsx' differs from file name 'D:/a/model-react/model-react/src/lib/BasicEntityCheckBoxField.tsx' only in casing.

Check failure on line 8 in src/lib/BasicEntityField.tsx

View workflow job for this annotation

GitHub Actions / build (windows-latest, 19.x)

Already included file name 'D:/a/model-react/model-react/src/lib/BasicEntityCheckboxField.tsx' differs from file name 'D:/a/model-react/model-react/src/lib/BasicEntityCheckBoxField.tsx' only in casing.

Check failure on line 8 in src/lib/BasicEntityField.tsx

View workflow job for this annotation

GitHub Actions / build (windows-latest, 18.x)

Already included file name 'D:/a/model-react/model-react/src/lib/BasicEntityCheckboxField.tsx' differs from file name 'D:/a/model-react/model-react/src/lib/BasicEntityCheckBoxField.tsx' only in casing.

Check failure on line 8 in src/lib/BasicEntityField.tsx

View workflow job for this annotation

GitHub Actions / build (windows-latest, 16.x)

Already included file name 'D:/a/model-react/model-react/src/lib/BasicEntityCheckboxField.tsx' differs from file name 'D:/a/model-react/model-react/src/lib/BasicEntityCheckBoxField.tsx' only in casing.

Check failure on line 8 in src/lib/BasicEntityField.tsx

View workflow job for this annotation

GitHub Actions / build (macos-latest, lts/*)

Already included file name '/Users/runner/work/model-react/model-react/src/lib/BasicEntityCheckboxField.tsx' differs from file name '/Users/runner/work/model-react/model-react/src/lib/BasicEntityCheckBoxField.tsx' only in casing.

Check failure on line 8 in src/lib/BasicEntityField.tsx

View workflow job for this annotation

GitHub Actions / build (macos-latest, 19.x)

Already included file name '/Users/runner/work/model-react/model-react/src/lib/BasicEntityCheckboxField.tsx' differs from file name '/Users/runner/work/model-react/model-react/src/lib/BasicEntityCheckBoxField.tsx' only in casing.

Check failure on line 8 in src/lib/BasicEntityField.tsx

View workflow job for this annotation

GitHub Actions / build (macos-latest, 18.x)

Already included file name '/Users/runner/work/model-react/model-react/src/lib/BasicEntityCheckboxField.tsx' differs from file name '/Users/runner/work/model-react/model-react/src/lib/BasicEntityCheckBoxField.tsx' only in casing.

Check failure on line 8 in src/lib/BasicEntityField.tsx

View workflow job for this annotation

GitHub Actions / build (macos-latest, 16.x)

Already included file name '/Users/runner/work/model-react/model-react/src/lib/BasicEntityCheckboxField.tsx' differs from file name '/Users/runner/work/model-react/model-react/src/lib/BasicEntityCheckBoxField.tsx' only in casing.
import { BasicEntityAutocompleteField } from "./BasicEntityAutocompleteField";
import { BasicEntitySliderField } from "./BasicEntitySliderField";
import { BasicEntityRadioGroupField } from "./BasicEntityRadioGroupField";
import { BasicEntityTextBoxField } from "./BasicEntityTextBoxField";
import { BasicEntityTextField } from "./BasicEntityTextField";
import { BasicEntityDateField } from "./BasicEntityDateField";
import { BasicEntityTimeField } from "./BasicEntityTimeField";
import { BasicEntityDateTimeField } from "./BasicEntityDateTimeField";
import { BasicEntityRatingField } from "./BasicEntityRatingField";

const CMPNAME = "BasicEntityField";

const { Open } = Gubu;
const BasicEntityFieldSpecShape = Gubu(
Open({
field: Open({
id: String,
name: String,
kind: Skip(String),
label: Default("", String),
ux: Open({
kind: Exact(
"Text",
"TextBox",
"Date",
"DateTime",
"Time",
"Checkbox",
"Autocomplete",
"Slider",
"RadioGroup",
"Rating"
),
edit: Default(true),
rows: Default(3),
props: Open({}),
}),
}),
}),
}), {name: CMPNAME})
{ name: CMPNAME }
);

const fieldMap: any = {
Text: BasicEntityTextField,
TextBox: BasicEntityTextBoxField,
Date: BasicEntityDateField,
DateTime: BasicEntityDateTimeField,
Time: BasicEntityTimeField,
CheckBox: BasicEntityCheckBoxField,
Checkbox: BasicEntityCheckboxField,
Autocomplete: BasicEntityAutocompleteField,
Slider: BasicEntitySliderField,
RadioGroup: BasicEntityRadioGroupField
}

RadioGroup: BasicEntityRadioGroupField,
Rating: BasicEntityRatingField,
};

function BasicEntityField (props: any) {
const { ctx, spec } = props
function BasicEntityField(props: any) {
const { ctx, spec } = props;

const basicEntityFieldSpec: Spec = BasicEntityFieldSpecShape(spec)
const field: any = basicEntityFieldSpec.field
const Field: any = fieldMap[field.ux.kind]
const basicEntityFieldSpec: Spec = BasicEntityFieldSpecShape(spec);
const field: any = basicEntityFieldSpec.field;
const Field: any = fieldMap[field.ux.kind];

// console.log('BEF ERR', spec)
return <Field ctx={ctx} spec={spec} />

return <Field ctx={ctx} spec={spec} />;
}

/*
Expand Down Expand Up @@ -105,9 +117,6 @@ function BasicEntityDateTimeField (props: any) {
}
*/




/* Notes
https://www.react-hook-form.com/
Expand All @@ -119,8 +128,4 @@ https://mui.com/material-ui/react-grid/
*/



export {
BasicEntityField
}
export { BasicEntityField };
67 changes: 67 additions & 0 deletions src/lib/BasicEntityRatingField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React, { useEffect, forwardRef } from "react";

import {
FormControlLabel,
Checkbox,
Box,
Rating,
FormLabel,
} from "@mui/material";
import { Controller } from "react-hook-form";

import type { Spec } from "./basic-types";

import { Default, Exact, Gubu, Skip } from "gubu";
const CMPNAME = "BasicEntitySliderField";

const { Open } = Gubu;
const BasicEntityRatingFieldSpecShape = Gubu(
Open({
field: Open({
id: String,
name: String,
kind: Skip(String),
label: Default("", String),
ux: Open({
kind: Exact("Rating"),
edit: Default(true),
precision: 1,
props: Open({}),
}),
}),
}),
{ name: CMPNAME }
);

function BasicEntityRatingField(props: any) {
const { spec } = props;

const basicEntityRatingField: Spec = BasicEntityRatingFieldSpecShape(spec);
const { control, field, getValues } = basicEntityRatingField;
const val = getValues(field.name);

// console.log("BasicEntityRatingField", "val", val);

return (
<div key={`${field.id}-div`}>
<FormLabel component="legend">{field.label}</FormLabel>
<Controller
key={`${field.id}-controller`}
name={field.name}
control={control}
defaultValue={!!val || 0}
render={({ field: { onChange, value } }) => (
<Rating
name={field.name}
value={value}
precision={field.ux.precision}
onChange={(_, newValue) => onChange(newValue)}
{...field.ux.props}
/>
)}
/>
</div>
);
}

export { BasicEntityRatingField };

0 comments on commit 3e6fead

Please sign in to comment.