Skip to content

Commit

Permalink
Fix [General] "Something went wrong" displayed on attempt to click "C…
Browse files Browse the repository at this point in the history
…reate feature set" from Project home (#1657)
  • Loading branch information
mariana-furyk authored Mar 12, 2023
1 parent 3ccdb80 commit ff313ed
Show file tree
Hide file tree
Showing 15 changed files with 300 additions and 231 deletions.
2 changes: 1 addition & 1 deletion src/actions/featureStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ const featureStoreActions = {
return response.data?.feature_sets
})
.catch(err => {
dispatch(featureStoreActions.fetchFeatureSetsFailure(err))
dispatch(featureStoreActions.fetchFeatureSetsFailure(err.message))
})
},
fetchFeatureSetsBegin: () => ({
Expand Down
4 changes: 3 additions & 1 deletion src/actions/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ const functionsActions = {

return data.funcs
})
.catch(err => dispatch(functionsActions.fetchFunctionsFailure(err)))
.catch(err => {
dispatch(functionsActions.fetchFunctionsFailure(err.message))
})
},
fetchFunctionsBegin: () => ({
type: FETCH_FUNCTIONS_BEGIN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ such restriction.
import React, { useEffect, useMemo, useState } from 'react'
import { connect, useSelector } from 'react-redux'
import PropTypes from 'prop-types'
import { cloneDeep } from 'lodash'
import { cloneDeep, isEmpty } from 'lodash'

import FeatureSetsPanelTargetStoreView from './FeatureSetsPanelTargetStoreView'

Expand All @@ -37,7 +37,9 @@ import {
partitionRadioButtonsInitialState,
selectedPartitionKindInitialState,
selectedTargetKindInitialState,
targetsPathEditDataInitialState
targetsPathEditDataInitialState,
handlePathChange,
ONLINE
} from './featureSetsPanelTargetStore.util'

const FeatureSetsPanelTargetStore = ({
Expand Down Expand Up @@ -167,6 +169,32 @@ const FeatureSetsPanelTargetStore = ({
targetsPathEditData.parquet.isModified
])

useEffect(() => {
if (isEmpty(frontendSpec.feature_store_data_prefixes)) {
setTargetsPathEditData(state => ({
...state,
[PARQUET]: {
...state[PARQUET],
isEditMode: true
},
[ONLINE]: {
...state[ONLINE],
isEditMode: true
}
}))
setDisableButtons(state => ({
...state,
isOfflineTargetPathEditModeClosed: false,
isOnlineTargetPathEditModeClosed: false
}))
setValidation(state => ({
...state,
isOfflineTargetPathValid: false,
isOnlineTargetPathValid: false
}))
}
}, [frontendSpec.feature_store_data_prefixes, setDisableButtons, setValidation])

const handleAdvancedLinkClick = kind => {
setShowAdvanced(prev => ({
...prev,
Expand Down Expand Up @@ -195,87 +223,35 @@ const FeatureSetsPanelTargetStore = ({
}

const handleOfflineKindPathChange = () => {
if (targetsPathEditData.parquet.isEditMode && validation.isOfflineTargetPathValid) {
setTargetsPathEditData(state => ({
...state,
parquet: {
isEditMode: false,
isModified: targetsPathEditData.parquet.isModified
? state.parquet.isModified
: offlineTarget.path !== data.parquet.path
}
}))
setDisableButtons(state => ({
...state,
isOfflineTargetPathEditModeClosed: true
}))

if (offlineTarget.path !== data.parquet.path) {
setNewFeatureSetTarget(
featureStore.newFeatureSet.spec.targets.map(targetKind => {
if (targetKind.name === PARQUET) {
return { ...targetKind, path: data.parquet.path }
}

return targetKind
})
)
}
} else {
setTargetsPathEditData(state => ({
...state,
parquet: {
...state.parquet,
isEditMode: true
}
}))
setDisableButtons(state => ({
...state,
isOfflineTargetPathEditModeClosed: false
}))
}
handlePathChange(
PARQUET,
PARQUET,
validation.isOfflineTargetPathValid,
targetsPathEditData,
data,
offlineTarget,
featureStore.newFeatureSet.spec.targets,
'isOfflineTargetPathEditModeClosed',
setTargetsPathEditData,
setDisableButtons,
setNewFeatureSetTarget
)
}

const handleOnlineKindPathChange = () => {
if (targetsPathEditData.online.isEditMode && validation.isOnlineTargetPathValid) {
setTargetsPathEditData(state => ({
...state,
online: {
isEditMode: false,
isModified: targetsPathEditData.online.isModified
? state.online.isModified
: onlineTarget.path !== data.online.path
}
}))
setDisableButtons(state => ({
...state,
isOnlineTargetPathEditModeClosed: true
}))

if (onlineTarget.path !== data.online.path) {
setNewFeatureSetTarget(
featureStore.newFeatureSet.spec.targets.map(targetKind => {
if (targetKind.name === NOSQL) {
return { ...targetKind, path: data.online.path }
}

return targetKind
})
)
}
} else {
setTargetsPathEditData(state => ({
...state,
online: {
...state.online,
isEditMode: true
}
}))
setDisableButtons(state => ({
...state,
isOnlineTargetPathEditModeClosed: false
}))
}
handlePathChange(
ONLINE,
NOSQL,
validation.isOnlineTargetPathValid,
targetsPathEditData,
data,
onlineTarget,
featureStore.newFeatureSet.spec.targets,
'isOnlineTargetPathEditModeClosed',
setTargetsPathEditData,
setDisableButtons,
setNewFeatureSetTarget
)
}

const handleExternalOfflineKindPathOnBlur = event => {
Expand All @@ -296,31 +272,33 @@ const FeatureSetsPanelTargetStore = ({
}
}

const handleDiscardPathChange = kind => {
setData(state => ({
...state,
[kind]: {
...state[kind],
path: kind === PARQUET ? offlineTarget.path : onlineTarget.path
}
}))
setTargetsPathEditData(state => ({
...state,
[kind]: {
...state[kind],
isEditMode: false
}
}))
setDisableButtons(state => ({
...state,
[kind === PARQUET
? 'isOfflineTargetPathEditModeClosed'
: 'isOnlineTargetPathEditModeClosed']: true
}))
setValidation(state => ({
...state,
[kind === PARQUET ? 'isOfflineTargetPathValid' : 'isOnlineTargetPathValid']: true
}))
const handleDiscardPathChange = (kind, value) => {
if (targetsPathEditData[kind].isModified) {
setData(state => ({
...state,
[kind]: {
...state[kind],
path: kind === PARQUET ? offlineTarget.path : onlineTarget.path
}
}))
setTargetsPathEditData(state => ({
...state,
[kind]: {
...state[kind],
isEditMode: false
}
}))
setDisableButtons(state => ({
...state,
[kind === PARQUET
? 'isOfflineTargetPathEditModeClosed'
: 'isOnlineTargetPathEditModeClosed']: true
}))
setValidation(state => ({
...state,
[kind === PARQUET ? 'isOfflineTargetPathValid' : 'isOnlineTargetPathValid']: true
}))
}
}

const handleExternalOfflineKindTypeChange = kind => {
Expand Down Expand Up @@ -685,6 +663,7 @@ const FeatureSetsPanelTargetStore = ({
handleSelectTargetKind={handleSelectTargetKind}
handleTimePartitioningGranularityChange={handleTimePartitioningGranularityChange}
partitionRadioButtonsState={partitionRadioButtonsState}
frontendSpecIsNotEmpty={!isEmpty(frontendSpec.feature_store_data_prefixes)}
selectedPartitionKind={selectedPartitionKind}
selectedTargetKind={selectedTargetKind}
setData={setData}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import './featureSetsPanelTargetStore.scss'

const FeatureSetsPanelTargetStoreView = ({
data,
frontendSpecIsNotEmpty,
handleAdvancedLinkClick,
handleDiscardPathChange,
handleExternalOfflineKindPathOnBlur,
Expand Down Expand Up @@ -96,7 +97,7 @@ const FeatureSetsPanelTargetStoreView = ({
<Input
density="normal"
floatingLabel
focused
focused={frontendSpecIsNotEmpty}
invalid={!validation.isOnlineTargetPathValid}
label="Path"
onChange={path =>
Expand Down Expand Up @@ -127,7 +128,7 @@ const FeatureSetsPanelTargetStoreView = ({
/>
</RoundedIcon>
<RoundedIcon
onClick={() => handleDiscardPathChange(ONLINE)}
onClick={() => handleDiscardPathChange(ONLINE, data.online.path)}
tooltipText="Discard changes"
>
<Close />
Expand Down Expand Up @@ -176,7 +177,7 @@ const FeatureSetsPanelTargetStoreView = ({
<Input
density="normal"
floatingLabel
focused
focused={frontendSpecIsNotEmpty}
invalid={!validation.isOfflineTargetPathValid}
label="Path"
onChange={path =>
Expand Down Expand Up @@ -204,7 +205,7 @@ const FeatureSetsPanelTargetStoreView = ({
<Checkmark className="target-store__apply-btn" />
</RoundedIcon>
<RoundedIcon
onClick={() => handleDiscardPathChange(PARQUET)}
onClick={() => handleDiscardPathChange(PARQUET, data.parquet.path)}
tooltipText="Discard changes"
>
<Close />
Expand Down Expand Up @@ -393,6 +394,7 @@ const FeatureSetsPanelTargetStoreView = ({

FeatureSetsPanelTargetStoreView.propTypes = {
data: PropTypes.shape({}).isRequired,
frontendSpecIsNotEmpty: PropTypes.bool.isRequired,
handleAdvancedLinkClick: PropTypes.func.isRequired,
handleDiscardPathChange: PropTypes.func.isRequired,
handleExternalOfflineKindPathOnBlur: PropTypes.func.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,75 @@ export const targetsPathEditDataInitialState = {
* @param {string} [suffix] - Optional. The suffix to add to the end of the path.
* @returns {string} The generated path.
*/
export const generatePath = (prefixes, project, kind, name = '{name}', suffix = '') => {
const path = prefixes[kind] || prefixes.default

return `${path.replace(
/{project}|{name}|{kind}/gi,
matchToReplace =>
({ '{project}': project, '{name}': name || '{name}', '{kind}': kind }[matchToReplace])
)}/sets/${name || '{name}'}${suffix ? '.' + suffix : ''}`
export const generatePath = (prefixes, project, name, suffix, kind) => {
if (prefixes) {
const path = prefixes[kind] || prefixes.default

return `${path.replace(
/{project}|{name}|{kind}/gi,
matchToReplace =>
({ '{project}': project, '{name}': name || '{name}', '{kind}': kind }[matchToReplace])
)}/sets/${name || '{name}'}${suffix ? '.' + suffix : ''}`
}

return ''
}

export const handlePathChange = (
targetType,
targetKindName,
isValid,
targetsPathEditData,
data,
target,
targets,
targetEditModeIsClosed,
setTargetsPathEditData,
setDisableButtons,
setNewFeatureSetTarget
) => {
const currentTargetPathEditData = targetsPathEditData[targetType]

if (currentTargetPathEditData.isEditMode && isValid) {
const isTargetPathModified = target.path !== data[targetType].path

setTargetsPathEditData(state => ({
...state,
[targetType]: {
isEditMode: false,
isModified: currentTargetPathEditData.isModified
? state[targetType].isModified
: isTargetPathModified
}
}))

setDisableButtons(state => ({
...state,
[targetEditModeIsClosed]: true
}))

if (isTargetPathModified) {
const updatedTargets = targets.map(targetKind => {
if (targetKind.name === targetKindName) {
return { ...targetKind, path: data[targetType].path }
}
return targetKind
})

setNewFeatureSetTarget(updatedTargets)
}
} else {
setTargetsPathEditData(state => ({
...state,
[targetType]: {
...currentTargetPathEditData,
isEditMode: true
}
}))

setDisableButtons(state => ({
...state,
[targetEditModeIsClosed]: false
}))
}
}
2 changes: 1 addition & 1 deletion src/components/FunctionsPanel/FunctionsPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const FunctionsPanel = ({
const data = {
function: { ...functionsStore.newFunction },
with_mlrun: functionsStore.newFunction.spec.build.commands.includes(
appStore.frontendSpec.function_deployment_mlrun_command
appStore.frontendSpec?.function_deployment_mlrun_command
)
}

Expand Down
Loading

0 comments on commit ff313ed

Please sign in to comment.