move rows to it's separate store
This commit is contained in:
parent
9d3088c3f3
commit
3e58ad9031
|
@ -1,21 +1,13 @@
|
||||||
import { writable } from "svelte/store"
|
import { writable } from "svelte/store"
|
||||||
|
|
||||||
|
const INITIAL_BACKEND_UI_STATE = {
|
||||||
|
}
|
||||||
|
|
||||||
export const getBackendUiStore = () => {
|
export const getBackendUiStore = () => {
|
||||||
const store = writable({})
|
const store = writable({ ...INITIAL_BACKEND_UI_STATE })
|
||||||
|
|
||||||
store.actions = {
|
store.actions = {
|
||||||
rows: {
|
reset: () => store.set({ ...INITIAL_BACKEND_UI_STATE }),
|
||||||
save: () =>
|
|
||||||
store.update(state => {
|
|
||||||
state.selectedView = state.selectedView
|
|
||||||
return state
|
|
||||||
}),
|
|
||||||
delete: () =>
|
|
||||||
store.update(state => {
|
|
||||||
state.selectedView = state.selectedView
|
|
||||||
return state
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return store
|
return store
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
export { database } from "./database"
|
export { database } from "./database"
|
||||||
export { tables } from "./tables"
|
export { tables } from "./tables"
|
||||||
export { views } from "./views"
|
export { views } from "./views"
|
||||||
|
export { rows } from "./rows"
|
||||||
export { permissions } from "./permissions"
|
export { permissions } from "./permissions"
|
||||||
export { roles } from "./roles"
|
export { roles } from "./roles"
|
||||||
export { datasources } from "./datasources"
|
export { datasources } from "./datasources"
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { writable,get } from "svelte/store"
|
||||||
|
import { views } from './'
|
||||||
|
|
||||||
|
function createRowsStore() {
|
||||||
|
const { subscribe } = writable([])
|
||||||
|
|
||||||
|
return {
|
||||||
|
subscribe,
|
||||||
|
save: () => views.select(get(views).selected),
|
||||||
|
delete: () => views.select(get(views).selected),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const rows = createRowsStore()
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { tables } from "./"
|
||||||
import api from "../../api"
|
import api from "../../api"
|
||||||
|
|
||||||
function createViewsStore() {
|
function createViewsStore() {
|
||||||
const { subscribe, set, update } = writable({
|
const { subscribe, update } = writable({
|
||||||
list: [],
|
list: [],
|
||||||
selected: null
|
selected: null
|
||||||
})
|
})
|
||||||
|
@ -15,7 +15,6 @@ function createViewsStore() {
|
||||||
...state,
|
...state,
|
||||||
selected: view,
|
selected: view,
|
||||||
}))
|
}))
|
||||||
tables.select()
|
|
||||||
},
|
},
|
||||||
delete: async view => {
|
delete: async view => {
|
||||||
await api.delete(`/api/views/${view}`)
|
await api.delete(`/api/views/${view}`)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import { backendUiStore } from "builderStore"
|
import { tables, rows } from 'builderStore/store/backend/'
|
||||||
import { tables } from 'builderStore/store/backend/'
|
|
||||||
import { notifier } from "builderStore/store/notifications"
|
import { notifier } from "builderStore/store/notifications"
|
||||||
import RowFieldControl from "../RowFieldControl.svelte"
|
import RowFieldControl from "../RowFieldControl.svelte"
|
||||||
import * as api from "../api"
|
import * as api from "../api"
|
||||||
|
@ -35,7 +34,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
notifier.success("Row saved successfully.")
|
notifier.success("Row saved successfully.")
|
||||||
backendUiStore.actions.rows.save(rowResponse)
|
rows.save(rowResponse)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import { backendUiStore } from "builderStore"
|
import { tables, rows } from 'builderStore/store/backend/'
|
||||||
import { tables } from 'builderStore/store/backend/'
|
|
||||||
import { roles } from 'builderStore/store/backend/'
|
import { roles } from 'builderStore/store/backend/'
|
||||||
import { notifier } from "builderStore/store/notifications"
|
import { notifier } from "builderStore/store/notifications"
|
||||||
import RowFieldControl from "../RowFieldControl.svelte"
|
import RowFieldControl from "../RowFieldControl.svelte"
|
||||||
|
@ -68,7 +67,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
notifier.success("User saved successfully.")
|
notifier.success("User saved successfully.")
|
||||||
backendUiStore.actions.rows.save(rowResponse)
|
rows.save(rowResponse)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
import { backendUiStore } from "builderStore"
|
import { rows } from 'builderStore/store/backend/'
|
||||||
import * as api from "../api"
|
import * as api from "../api"
|
||||||
import { notifier } from "builderStore/store/notifications"
|
import { notifier } from "builderStore/store/notifications"
|
||||||
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
async function deleteRow() {
|
async function deleteRow() {
|
||||||
await api.deleteRow(row)
|
await api.deleteRow(row)
|
||||||
notifier.success("Row deleted")
|
notifier.success("Row deleted")
|
||||||
backendUiStore.actions.rows.delete(row)
|
rows.delete(row)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue