Introduce modal to show warning to users, and toast to show success.
This commit is contained in:
parent
a701933f48
commit
2f0a40e9bb
|
@ -53,6 +53,11 @@
|
||||||
await datasources.fetch()
|
await datasources.fetch()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const refreshDefinitions = async () => {
|
||||||
|
await tables.fetch()
|
||||||
|
await datasources.fetch()
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
|
@ -66,6 +71,7 @@
|
||||||
schemaOverrides={isUsersTable ? userSchemaOverrides : null}
|
schemaOverrides={isUsersTable ? userSchemaOverrides : null}
|
||||||
showAvatars={false}
|
showAvatars={false}
|
||||||
on:updatedatasource={handleGridTableUpdate}
|
on:updatedatasource={handleGridTableUpdate}
|
||||||
|
on:refreshdefinitions={refreshDefinitions}
|
||||||
>
|
>
|
||||||
<svelte:fragment slot="filter">
|
<svelte:fragment slot="filter">
|
||||||
{#if isUsersTable && $store.features.disableUserMetadata}
|
{#if isUsersTable && $store.features.disableUserMetadata}
|
||||||
|
|
|
@ -1,9 +1,17 @@
|
||||||
<script>
|
<script>
|
||||||
import { getContext, onMount, tick } from "svelte"
|
import { getContext, onMount, tick } from "svelte"
|
||||||
import { canBeDisplayColumn, canBeSortColumn } from "@budibase/shared-core"
|
import { canBeDisplayColumn, canBeSortColumn } from "@budibase/shared-core"
|
||||||
import { Icon, Popover, Menu, MenuItem, clickOutside } from "@budibase/bbui"
|
import {
|
||||||
|
Icon,
|
||||||
|
Popover,
|
||||||
|
Menu,
|
||||||
|
MenuItem,
|
||||||
|
clickOutside,
|
||||||
|
Modal,
|
||||||
|
} from "@budibase/bbui"
|
||||||
import GridCell from "./GridCell.svelte"
|
import GridCell from "./GridCell.svelte"
|
||||||
import { getColumnIcon } from "../lib/utils"
|
import { getColumnIcon } from "../lib/utils"
|
||||||
|
import MigrationModal from "../controls/MigrationModal.svelte"
|
||||||
|
|
||||||
export let column
|
export let column
|
||||||
export let idx
|
export let idx
|
||||||
|
@ -32,6 +40,7 @@
|
||||||
let editIsOpen = false
|
let editIsOpen = false
|
||||||
let timeout
|
let timeout
|
||||||
let popover
|
let popover
|
||||||
|
let migrationModal
|
||||||
|
|
||||||
$: sortedBy = column.name === $sort.column
|
$: sortedBy = column.name === $sort.column
|
||||||
$: canMoveLeft = orderable && idx > 0
|
$: canMoveLeft = orderable && idx > 0
|
||||||
|
@ -115,24 +124,6 @@
|
||||||
open = false
|
open = false
|
||||||
}
|
}
|
||||||
|
|
||||||
const migrateUserColumn = async () => {
|
|
||||||
let subtype = "users"
|
|
||||||
if (column.schema.relationshipType === "one-to-many") {
|
|
||||||
subtype = "user"
|
|
||||||
}
|
|
||||||
|
|
||||||
await API.migrateColumn({
|
|
||||||
tableId: $definition._id,
|
|
||||||
oldColumn: column.schema,
|
|
||||||
newColumn: {
|
|
||||||
name: `${column.schema.name} migrated`,
|
|
||||||
type: "bb_reference",
|
|
||||||
subtype,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
open = false
|
|
||||||
}
|
|
||||||
|
|
||||||
const duplicateColumn = async () => {
|
const duplicateColumn = async () => {
|
||||||
open = false
|
open = false
|
||||||
|
|
||||||
|
@ -160,9 +151,18 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const openMigrationModal = () => {
|
||||||
|
migrationModal.show()
|
||||||
|
open = false
|
||||||
|
}
|
||||||
|
|
||||||
onMount(() => subscribe("close-edit-column", cancelEdit))
|
onMount(() => subscribe("close-edit-column", cancelEdit))
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<Modal bind:this={migrationModal}>
|
||||||
|
<MigrationModal {column} />
|
||||||
|
</Modal>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="header-cell"
|
class="header-cell"
|
||||||
class:open
|
class:open
|
||||||
|
@ -281,8 +281,8 @@
|
||||||
>
|
>
|
||||||
Hide column
|
Hide column
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
{#if column.schema.type === "link" && column.schema.tableId === "ta_users"}
|
{#if $config.canEditColumns && column.schema.type === "link" && column.schema.tableId === "ta_users"}
|
||||||
<MenuItem icon="User" on:click={migrateUserColumn}>
|
<MenuItem icon="User" on:click={openMigrationModal}>
|
||||||
Migrate to user column
|
Migrate to user column
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
<script>
|
||||||
|
import { ModalContent, notifications } from "@budibase/bbui"
|
||||||
|
import { getContext } from "svelte"
|
||||||
|
|
||||||
|
const { API, dispatch, definition, rows } = getContext("grid")
|
||||||
|
|
||||||
|
export let column
|
||||||
|
|
||||||
|
const migrateUserColumn = async () => {
|
||||||
|
let subtype = "users"
|
||||||
|
if (column.schema.relationshipType === "one-to-many") {
|
||||||
|
subtype = "user"
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await API.migrateColumn({
|
||||||
|
tableId: $definition._id,
|
||||||
|
oldColumn: column.schema,
|
||||||
|
newColumn: {
|
||||||
|
name: `${column.schema.name} migrated`,
|
||||||
|
type: "bb_reference",
|
||||||
|
subtype,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
notifications.success("Column migrated")
|
||||||
|
} catch (e) {
|
||||||
|
notifications.error(`Failed to migrate: ${e.message}`)
|
||||||
|
}
|
||||||
|
await rows.actions.refreshData()
|
||||||
|
dispatch("refreshdefintions")
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<ModalContent
|
||||||
|
title="Migrate column"
|
||||||
|
confirmText="Continue"
|
||||||
|
cancelText="Cancel"
|
||||||
|
onConfirm={migrateUserColumn}
|
||||||
|
size="M"
|
||||||
|
>
|
||||||
|
TODO: copy here
|
||||||
|
</ModalContent>
|
Loading…
Reference in New Issue