-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support from structured datasets (#801)
* feat: add support from structured datasets Signed-off-by: Carina Ursu <[email protected]> * chore: don't enfore format Signed-off-by: Carina Ursu <[email protected]> * chore: fix tests Signed-off-by: Carina Ursu <[email protected]> --------- Signed-off-by: Carina Ursu <[email protected]>
- Loading branch information
1 parent
3eb0fa7
commit 16abb34
Showing
18 changed files
with
177 additions
and
9 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
84 changes: 84 additions & 0 deletions
84
.../console/src/components/Launch/LaunchForm/LaunchFormComponents/StructuredDatasetInput.tsx
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,84 @@ | ||
import React, { FC, useEffect, useMemo, useState } from 'react'; | ||
import { TextField } from '@material-ui/core'; | ||
import { makeStyles, Theme } from '@material-ui/core/styles'; | ||
import t from '../strings'; | ||
import { DatasetValue, InputProps } from '../types'; | ||
import { getLaunchInputId } from '../utils'; | ||
import { StyledCard } from './StyledCard'; | ||
import { getHelperForInput } from '../inputHelpers/getHelperForInput'; | ||
|
||
const useStyles = makeStyles((theme: Theme) => ({ | ||
formatInput: { | ||
flex: '1 1 auto', | ||
}, | ||
inputContainer: { | ||
marginTop: theme.spacing(1), | ||
paddingLeft: theme.spacing(1), | ||
}, | ||
metadataContainer: { | ||
display: 'flex', | ||
marginTop: theme.spacing(1), | ||
width: '100%', | ||
}, | ||
})); | ||
|
||
/** A micro form for entering the values related to a Structured Dataset Literal */ | ||
export const StructuredDatasetInput: FC<InputProps> = props => { | ||
const styles = useStyles(); | ||
const { | ||
error, | ||
name, | ||
onChange, | ||
value: propValue, | ||
typeDefinition, | ||
label, | ||
} = props; | ||
|
||
const helper = useMemo( | ||
() => getHelperForInput(typeDefinition.type), | ||
[typeDefinition], | ||
); | ||
|
||
const [datasetValue, setDatasetValue] = useState<DatasetValue>( | ||
propValue || | ||
(helper.typeDefinitionToDefaultValue(typeDefinition) as DatasetValue), | ||
); | ||
|
||
const handleChange = (input: Partial<DatasetValue>) => { | ||
const value = { ...datasetValue, ...input } as DatasetValue; | ||
setDatasetValue(value); | ||
}; | ||
|
||
useEffect(() => { | ||
onChange(datasetValue); | ||
}, [datasetValue]); | ||
|
||
const inputId = getLaunchInputId(`${name}-dsd`); | ||
|
||
return ( | ||
<StyledCard error={error} label={label}> | ||
<div className={styles.inputContainer}> | ||
<TextField | ||
id={`${inputId}-uri`} | ||
helperText={t('sdsUriHelperText')} | ||
fullWidth={true} | ||
label="uri" | ||
onChange={e => handleChange({ uri: e.target.value })} | ||
value={datasetValue?.uri} | ||
variant="outlined" | ||
/> | ||
<div className={styles.metadataContainer}> | ||
<TextField | ||
className={styles.formatInput} | ||
id={`${inputId}-format`} | ||
helperText={t('sdsFormatHelperText')} | ||
label="format" | ||
onChange={e => handleChange({ format: e.target.value })} | ||
value={datasetValue?.format} | ||
variant="outlined" | ||
/> | ||
</div> | ||
</div> | ||
</StyledCard> | ||
); | ||
}; |
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
2 changes: 1 addition & 1 deletion
2
packages/console/src/components/Launch/LaunchForm/UnsupportedRequiredInputsError.tsx
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
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
60 changes: 60 additions & 0 deletions
60
packages/console/src/components/Launch/LaunchForm/inputHelpers/structuredDataSet.ts
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,60 @@ | ||
import { Core } from '@flyteorg/flyteidl-types'; | ||
import { isObject } from 'lodash'; | ||
import { DatasetValue, InputTypeDefinition } from '../types'; | ||
import { ConverterInput, InputHelper, InputValidatorParams } from './types'; | ||
|
||
function fromLiteral( | ||
literal: Core.ILiteral, | ||
typeDefinition: InputTypeDefinition, | ||
): DatasetValue { | ||
const { structuredDataset } = literal?.scalar || {}; | ||
|
||
const { metadata, uri } = structuredDataset || {}; | ||
const { format } = metadata?.structuredDatasetType || {}; | ||
return { | ||
uri: uri!, | ||
format: format!, | ||
}; | ||
} | ||
|
||
function toLiteral({ value, typeDefinition }: ConverterInput): Core.ILiteral { | ||
const dsValue = value as DatasetValue; | ||
return { | ||
scalar: { | ||
structuredDataset: { | ||
metadata: { | ||
structuredDatasetType: { | ||
format: dsValue.format, | ||
}, | ||
}, | ||
uri: dsValue.uri, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
function validate({ value, required }: InputValidatorParams) { | ||
if (!isObject(value)) { | ||
throw new Error('Invalid structured datased value'); | ||
} | ||
const dsValue = value as DatasetValue; | ||
if (required && (!dsValue?.uri || typeof dsValue?.uri !== 'string')) { | ||
throw new Error('Dataset uri is required'); | ||
} | ||
|
||
if (!!dsValue.format && typeof dsValue.format !== 'string') { | ||
throw new Error('Dataset format must be a string'); | ||
} | ||
} | ||
|
||
export const structuredDataSetHelper: InputHelper = { | ||
fromLiteral, | ||
toLiteral, | ||
validate, | ||
typeDefinitionToDefaultValue: typeDefinition => { | ||
return { | ||
format: undefined, | ||
uri: undefined, | ||
} as DatasetValue; | ||
}, | ||
}; |
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
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