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