Skip to content

Commit

Permalink
refactor: error handling in editing panel
Browse files Browse the repository at this point in the history
  • Loading branch information
d-rita committed Dec 6, 2024
1 parent c62f536 commit 59877d9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 27 deletions.
40 changes: 15 additions & 25 deletions src/components/panel/EditPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,6 @@ const keyValuesQuery = ({ store }: { store: string }) => ({
},
})

// const useKeyValuesQuery = ({ store, key, namespace }) => {
// if (key && namespace) {
// return useDataQuery(keyValuesQuery({ store }), {
// variables: {
// key,
// namespace,
// },
// })
// } else {
// return {
// data: null,
// loading: false,
// error: null,
// refetch: () => Promise.resolve(),
// }
// }
// }

const PanelEdit = () => {
const { key, namespace, store } = useParams()
const { showSuccess, showError } = useCustomAlert()
Expand Down Expand Up @@ -81,6 +63,20 @@ const PanelEdit = () => {
setValue(value)
}

const handleUpdate = async () => {
try {
await updateKey({
key,
namespace,
value,
})
} catch (error) {
const message = i18n.t('There was an error updating the key')
showError(message)
}

}

useEffect(() => {
setValue(JSON.stringify(data?.results, null, 4))
}, [data])
Expand Down Expand Up @@ -110,13 +106,7 @@ const PanelEdit = () => {
<Button
aria-label="Save"
name="save"
onClick={async () => {
await updateKey({
key,
namespace,
value,
})
}}
onClick={handleUpdate}
title="Save"
primary
loading={loading}
Expand Down
2 changes: 0 additions & 2 deletions src/components/panel/NamespacesPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ const NamespacesPanel = () => {
navigate(`/${value}`)
}

console.log('store', store)
useEffect(() => {
const storeOptions = ['dataStore', 'userDataStore']
// console.log("store", store)
if (!storeOptions.includes(store)) {
navigate('/dataStore')
} else {
Expand Down

0 comments on commit 59877d9

Please sign in to comment.