Skip to content

Commit

Permalink
refactor: add time zone and remove unused code (#651)
Browse files Browse the repository at this point in the history
* refactor: add time zone and remove unused code

* fix: make test pass by using date lib luxon
  • Loading branch information
henrikbossart authored Oct 24, 2023
1 parent 07b9429 commit ab03f38
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{
"name": "date",
"type": "PLUGINS:dm-core-plugins/form/fields/StringField",
"format": "datetime-local"
"format": "datetime"
}
]
}
Expand Down
10 changes: 6 additions & 4 deletions packages/dm-core-plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@equinor/eds-tokens": "^0.9.0",
"axios": "^1.4.0",
"highlight.js": "^11.8.0",
"luxon": "^3.4.3",
"mermaid": "^10.0.0",
"react-hook-form": "^7.31.2",
"react-toastify": "^9.1.3",
Expand All @@ -21,19 +22,20 @@
"@testing-library/user-event": "14.4.3",
"@types/jest": "^29.5.0",
"@types/js-yaml": "^4.0.5",
"@types/luxon": "^3.3.3",
"@types/react-dom": "^18.2.7",
"@types/react-router-dom": "^5.3.3",
"@types/styled-components": "^5.1.26",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3",
"eslint-plugin-react": "^7.33.2",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"react-router-dom": ">=5.1.2",
"shx": " 0.3.4",
"ts-jest": "^29.1.0",
"ts-loader": "^9.3.1",
"typescript": "^5.1.6",
"eslint-plugin-react": "^7.33.2",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3"
"typescript": "^5.1.6"
},
"peerDependencies": {
"@types/react": "^18.2.8",
Expand Down
11 changes: 0 additions & 11 deletions packages/dm-core-plugins/src/form/fields/AttributeField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,6 @@ export const AttributeField = (props: TAttributeFieldProps) => {
readOnly={readOnly}
/>
)
// case "datetime":
// return (
// <DatePicker
// namePath={namePath}
// displayLabel={displayLabel}
// defaultValue={attribute.default}
// optional={attribute.optional ?? false}
// uiAttribute={uiAttribute}
// readOnly={readOnly}
// />
// )
default:
return <>UnknownField</>
}
Expand Down
22 changes: 18 additions & 4 deletions packages/dm-core-plugins/src/form/widgets/TextWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,44 @@ import { Icon, TextField } from '@equinor/eds-core-react'

import { error_filled } from '@equinor/eds-icons'
import { TWidget } from '../types'
import { DateTime } from 'luxon'

Icon.add({ error_filled })

const TextWidget = (props: TWidget) => {
const { label, onChange } = props

const onChangeHandler = (event: React.ChangeEvent<HTMLInputElement>) => {
const { value } = event.target
const formattedValue = value === '' ? null : value
let formattedValue
if (props.config?.format === 'datetime') {
formattedValue = new Date(value).toISOString()
} else {
formattedValue = value === '' ? null : value
}
onChange?.(formattedValue)
}

const fieldType = (format?: string): string => {
if (format && format === 'datetime') return 'datetime-local'
else if (format) return format
return 'string'
}
return (
<TextField
id={props.id}
readOnly={props.readOnly}
defaultValue={props.value}
defaultValue={
fieldType(props.config?.format) === 'datetime-local'
? DateTime.fromISO(props.value).toFormat("yyyy-MM-dd'T'T")
: props.value
}
onClick={props.onClick}
inputRef={props.inputRef}
variant={props.variant}
helperText={props.helperText}
onChange={onChangeHandler}
label={label}
type={props.config?.format ?? 'string'}
type={fieldType(props.config?.format)}
data-testid="form-textfield"
/>
)
Expand Down
14 changes: 8 additions & 6 deletions packages/dm-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,27 @@
"@equinor/eds-icons": "^0.19.3",
"@equinor/eds-tokens": "^0.9.0",
"axios": "^1.4.0",
"luxon": "^3.4.3",
"react-icons": "4.10.1",
"react-toastify": "^9.1.3",
"react-oauth2-code-pkce": "^1.10.1"
"react-oauth2-code-pkce": "^1.10.1",
"react-toastify": "^9.1.3"
},
"devDependencies": {
"@testing-library/react": "^14.0.0",
"@types/jest": "^29.5.3",
"@types/luxon": "^3.3.3",
"@types/react-dom": "^18.2.7",
"@types/react-router-dom": "^5.3.3",
"@types/styled-components": "^5.1.26",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3",
"eslint-plugin-react": "^7.33.2",
"jest": "^29.6.2",
"jest-environment-jsdom": "^29.6.2",
"shx": " 0.3.4",
"ts-jest": "^29.1.1",
"ts-loader": "^9.3.1",
"typescript": "^5.1.6",
"eslint-plugin-react": "^7.33.2",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3"
"typescript": "^5.1.6"
},
"files": [
"dist",
Expand Down

0 comments on commit ab03f38

Please sign in to comment.