mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-12 08:58:17 +03:00
F OpenNebula/one#6724: Fix form import app (#3376)
Co-authored-by: Tino Vázquez <cvazquez@opennebula.io>
This commit is contained in:
parent
262dd0e371
commit
a27bb5b09f
@ -13,20 +13,24 @@
|
|||||||
* See the License for the specific language governing permissions and *
|
* See the License for the specific language governing permissions and *
|
||||||
* limitations under the License. *
|
* limitations under the License. *
|
||||||
* ------------------------------------------------------------------------- */
|
* ------------------------------------------------------------------------- */
|
||||||
import { useMemo } from 'react'
|
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { useFormContext } from 'react-hook-form'
|
import { useMemo } from 'react'
|
||||||
|
|
||||||
import { DatastoresTable } from '@modules/components/Tables'
|
import { DATASTORE_TYPES, T } from '@ConstantsModule'
|
||||||
import { SCHEMA } from '@modules/components/Forms/MarketplaceApp/ExportForm/Steps/DatastoresTable/schema'
|
import { useListForm } from '@HooksModule'
|
||||||
import { Step, decodeBase64 } from '@UtilsModule'
|
import { Step, decodeBase64 } from '@UtilsModule'
|
||||||
import { T, DATASTORE_TYPES } from '@ConstantsModule'
|
import { SCHEMA } from '@modules/components/Forms/MarketplaceApp/ExportForm/Steps/DatastoresTable/schema'
|
||||||
|
import { DatastoresTable } from '@modules/components/Tables'
|
||||||
|
|
||||||
export const STEP_ID = 'datastore'
|
export const STEP_ID = 'datastore'
|
||||||
|
|
||||||
const Content = ({ data, app }) => {
|
const Content = ({ data, app, setFormData }) => {
|
||||||
const { NAME } = data?.[0] ?? {}
|
const { ID } = data?.[0] ?? {}
|
||||||
const { setValue } = useFormContext()
|
|
||||||
|
const { handleSelect, handleClear } = useListForm({
|
||||||
|
key: STEP_ID,
|
||||||
|
setList: setFormData,
|
||||||
|
})
|
||||||
|
|
||||||
const isKernelType = useMemo(() => {
|
const isKernelType = useMemo(() => {
|
||||||
const appTemplate = String(decodeBase64(app?.TEMPLATE?.APPTEMPLATE64, ''))
|
const appTemplate = String(decodeBase64(app?.TEMPLATE?.APPTEMPLATE64, ''))
|
||||||
@ -37,7 +41,7 @@ const Content = ({ data, app }) => {
|
|||||||
const handleSelectedRows = (rows) => {
|
const handleSelectedRows = (rows) => {
|
||||||
const { original = {} } = rows?.[0] ?? {}
|
const { original = {} } = rows?.[0] ?? {}
|
||||||
|
|
||||||
setValue(STEP_ID, original.ID !== undefined ? [original] : [])
|
original.ID !== undefined ? handleSelect(original) : handleClear()
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -46,9 +50,9 @@ const Content = ({ data, app }) => {
|
|||||||
disableGlobalSort
|
disableGlobalSort
|
||||||
displaySelectedRows
|
displaySelectedRows
|
||||||
pageSize={5}
|
pageSize={5}
|
||||||
getRowId={(row) => String(row.NAME)}
|
getRowId={(row) => String(row.ID)}
|
||||||
initialState={{
|
initialState={{
|
||||||
selectedRowIds: { [NAME]: true },
|
selectedRowIds: { [ID]: true },
|
||||||
filters: [{ id: 'TYPE', value: isKernelType ? 'FILE' : 'IMAGE' }],
|
filters: [{ id: 'TYPE', value: isKernelType ? 'FILE' : 'IMAGE' }],
|
||||||
}}
|
}}
|
||||||
onSelectedRowsChange={handleSelectedRows}
|
onSelectedRowsChange={handleSelectedRows}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user