Refactor after merge
This commit is contained in:
parent
1e9ce06504
commit
a602dcc5ec
7 changed files with 45 additions and 20 deletions
|
@ -16,7 +16,7 @@
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await viewsStore.save({
|
await viewsStore.create({
|
||||||
name,
|
name,
|
||||||
tableId: $tables.selected._id,
|
tableId: $tables.selected._id,
|
||||||
field,
|
field,
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
selected={$isActive("./view") && $views.selected?.name === viewName}
|
selected={$isActive("./view") && $views.selected?.name === viewName}
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
if (view.version === 2) {
|
if (view.version === 2) {
|
||||||
$goto(`./view/v2/${view._id}`)
|
$goto(`./view/v2/${view.id}`)
|
||||||
} else {
|
} else {
|
||||||
$goto(`./view/${encodeURIComponent(viewName)}`)
|
$goto(`./view/${encodeURIComponent(viewName)}`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,12 +11,12 @@
|
||||||
const stopSyncing = syncURLToState({
|
const stopSyncing = syncURLToState({
|
||||||
urlParam: "id",
|
urlParam: "id",
|
||||||
stateKey: "selectedViewId",
|
stateKey: "selectedViewId",
|
||||||
validate: id => $views.list?.some(view => view._id === id),
|
validate: id => $views.list?.some(view => view.id === id),
|
||||||
update: id => {
|
update: id => {
|
||||||
const view = $views.list.find(v => v._id === id)
|
const view = $views.list.find(v => v.id === id)
|
||||||
views.select(view.name)
|
views.select(view.name)
|
||||||
},
|
},
|
||||||
fallbackUrl: "../",
|
fallbackUrl: "../../",
|
||||||
store: views,
|
store: views,
|
||||||
routify,
|
routify,
|
||||||
decode: decodeURIComponent,
|
decode: decodeURIComponent,
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<Grid
|
<Grid
|
||||||
{API}
|
{API}
|
||||||
tableId={selectedView?._id}
|
tableId={{ tableId: selectedView?.tableId, viewId: selectedView?.id }}
|
||||||
datasourceType="viewV2"
|
datasourceType="viewV2"
|
||||||
showAvatars={false}
|
showAvatars={false}
|
||||||
showControls={false}
|
showControls={false}
|
||||||
|
|
|
@ -40,6 +40,22 @@ export function createViewsStore() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const create = async view => {
|
||||||
|
const savedView = await API.viewV2.create(view.tableId, view)
|
||||||
|
|
||||||
|
// Update tables
|
||||||
|
tables.update(state => {
|
||||||
|
const table = state.list.find(table => table._id === view.tableId)
|
||||||
|
if (table) {
|
||||||
|
if (view.originalName) {
|
||||||
|
delete table.views[view.originalName]
|
||||||
|
}
|
||||||
|
table.views[view.name] = savedView
|
||||||
|
}
|
||||||
|
return { ...state }
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
const save = async view => {
|
const save = async view => {
|
||||||
const savedView = await API.saveView(view)
|
const savedView = await API.saveView(view)
|
||||||
|
|
||||||
|
@ -60,6 +76,7 @@ export function createViewsStore() {
|
||||||
subscribe: derivedStore.subscribe,
|
subscribe: derivedStore.subscribe,
|
||||||
select,
|
select,
|
||||||
delete: deleteView,
|
delete: deleteView,
|
||||||
|
create,
|
||||||
save,
|
save,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +1,29 @@
|
||||||
export const buildViewV2Endpoints = API => ({
|
export const buildViewV2Endpoints = API => ({
|
||||||
/**
|
/**
|
||||||
* Fetches all rows in a view
|
* Create a new view
|
||||||
* @param id the id of the view
|
* @param tableId the id of the table where the view will be created
|
||||||
|
* @param view the view object
|
||||||
*/
|
*/
|
||||||
get: async id => {
|
create: async (tableId, view) => {
|
||||||
return await API.get({ url: `/api/v2/views/${id}` })
|
return await API.post({
|
||||||
|
url: `/api/v2/views/${tableId}`,
|
||||||
|
body: view,
|
||||||
|
})
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Get a view information
|
* Fetches all rows in a view
|
||||||
* @param id the id of the view
|
* @param tableId the id of the table
|
||||||
|
* @param viewId the id of the view
|
||||||
*/
|
*/
|
||||||
fetch: async id => {
|
fetch: async (tableId, viewId) => {
|
||||||
return await API.get({ url: `/api/v2/views/${id}/search` })
|
return await API.get({ url: `/api/v2/views/${tableId}/${viewId}/search` })
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Delete a view
|
* Delete a view
|
||||||
* @param id the id of the view to delete
|
* @param tableId the id of the table
|
||||||
|
* @param viewId the id of the view
|
||||||
*/
|
*/
|
||||||
delete: async id => {
|
delete: async (tableId, viewId) => {
|
||||||
return await API.delete({ url: `/api/v2/views/${id}` })
|
return await API.delete({ url: `/api/v2/views/${tableId}/${viewId}` })
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -7,9 +7,8 @@ export default class ViewV2Fetch extends DataFetch {
|
||||||
|
|
||||||
async getDefinition(datasource) {
|
async getDefinition(datasource) {
|
||||||
try {
|
try {
|
||||||
const viewResponse = await this.API.viewV2.get(datasource.tableId)
|
|
||||||
const result = await this.API.fetchTableDefinition(
|
const result = await this.API.fetchTableDefinition(
|
||||||
viewResponse.data.tableId
|
datasource.tableId.tableId
|
||||||
)
|
)
|
||||||
return result
|
return result
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -24,7 +23,10 @@ export default class ViewV2Fetch extends DataFetch {
|
||||||
async getData() {
|
async getData() {
|
||||||
const { datasource } = this.options
|
const { datasource } = this.options
|
||||||
try {
|
try {
|
||||||
const res = await this.API.viewV2.fetch(datasource.tableId)
|
const res = await this.API.viewV2.fetch(
|
||||||
|
datasource.tableId.tableId,
|
||||||
|
datasource.tableId.viewId
|
||||||
|
)
|
||||||
return { rows: res?.rows || [] }
|
return { rows: res?.rows || [] }
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return { rows: [] }
|
return { rows: [] }
|
||||||
|
|
Loading…
Reference in a new issue