ToolJet/frontend/src/TooljetDatabase/index.jsx
Akshay c6fe0aa45e
Feature: Import export tjdb schema (#5752)
* add ability to import export app and tjdb schema

* init

* feat ::global settings popover new ui

* feat :: ui for version export modal

* fix :: import export modal

* cleanup

* ui updates

* header footer style fixes

* closing settings modal while showing export modal

* style fix header

* feat :: added button to download table schema

* fix :: styling for fx

* add ability to import and export apps with tjdb schema

* handle duplicate table in workspace

* fix table rename

* fix selected table on edit and delete

* fix invalid toast on table delete

* fix column default value

* handle exports to strip '::' and quotes

* make import/export backward compatible

* handle page redirects based on resource import

* handle import without tjdb schema

* fix column delete and addition

* make data migrations to be run per organizations

* wip

* update migration

* fix credentials to be included

* fix specific version export

* make use of apps ability for import export resource

* fix import navigation

* fix lint

* fix failing tests

* fix lint

* enable tjdb for public apps

* update export error message on tjdb table blank

* fix table not selected after creation

* fix :: styling for imp exp modal , and functionality bug fixes after dev merge

* fixes blank slate and columns selection

* fix table delete

* fix invalid toast on table edit

* fix column information missing tjdb query manager

* make ds imports to either reuse global or create

* export only unique table ids

* create default datasources if not present in export data

* reuse existing table on imports

* add timestamp to table name if name already exists

* add ability to clone with tjdb

* make imports work with marketplace plugin

* skip dataqueries for which plugins are not installed

* fix filter input width

* fix failing spec

* fix marketplace plugin installation in diff workspaces

* fix check for plugin installed in workspace

* fix export when table name is empty

---------

Co-authored-by: stepinfwd <stepinfwd@gmail.com>
2023-08-28 21:23:15 +05:30

120 lines
3.2 KiB
JavaScript

import React, { createContext, useState, useMemo, useEffect, useContext } from 'react';
import Layout from '@/_ui/Layout';
import TooljetDatabasePage from './TooljetDatabasePage';
import { usePostgrestQueryBuilder } from './usePostgrestQueryBuilder';
import { authenticationService } from '../_services/authentication.service';
import { BreadCrumbContext } from '@/App/App';
export const TooljetDatabaseContext = createContext({
organizationId: null,
setOrganizationId: () => {},
selectedTable: '',
setSelectedTable: () => {},
searchParam: '',
setSearchParam: () => {},
selectedTableData: [],
setSelectedTableData: () => {},
tables: [],
setTables: () => {},
columns: [],
setColumns: () => {},
totalRecords: 0,
setTotalRecords: () => {},
handleBuildFilterQuery: () => {},
handleBuildSortQuery: () => {},
buildPaginationQuery: () => {},
resetSortQuery: () => {},
resetFilterQuery: () => {},
queryFilters: {},
setQueryFilters: () => {},
sortFilters: {},
setSortFilters: () => {},
});
export const TooljetDatabase = (props) => {
const [organizationId, setOrganizationId] = useState(
authenticationService?.currentSessionValue?.current_organization_id
);
const [columns, setColumns] = useState([]);
const [tables, setTables] = useState([]);
const [searchParam, setSearchParam] = useState('');
const [selectedTable, setSelectedTable] = useState({});
const [selectedTableData, setSelectedTableData] = useState([]);
const [totalRecords, setTotalRecords] = useState(0);
const [queryFilters, setQueryFilters] = useState({});
const [sortFilters, setSortFilters] = useState({});
const {
handleBuildFilterQuery,
handleBuildSortQuery,
buildPaginationQuery,
resetSortQuery,
resetFilterQuery,
resetAll,
} = usePostgrestQueryBuilder({
organizationId,
selectedTable,
setSelectedTableData,
setTotalRecords,
});
const value = useMemo(
() => ({
searchParam,
setSearchParam,
organizationId,
setOrganizationId,
tables,
setTables,
columns,
setColumns,
selectedTable,
setSelectedTable,
selectedTableData,
setSelectedTableData,
totalRecords,
setTotalRecords,
handleBuildFilterQuery,
handleBuildSortQuery,
buildPaginationQuery,
resetSortQuery,
resetFilterQuery,
queryFilters,
setQueryFilters,
sortFilters,
setSortFilters,
resetAll,
}),
// eslint-disable-next-line react-hooks/exhaustive-deps
[
searchParam,
organizationId,
tables,
columns,
selectedTable,
selectedTableData,
totalRecords,
queryFilters,
sortFilters,
]
);
const { updateSidebarNAV } = useContext(BreadCrumbContext);
useEffect(() => {
updateSidebarNAV('');
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return (
<Layout switchDarkMode={props.switchDarkMode} darkMode={props.darkMode}>
<div className="page-wrapper tooljet-database">
<TooljetDatabaseContext.Provider value={value}>
<TooljetDatabasePage totalTables={tables.length || 0} />
</TooljetDatabaseContext.Provider>
</div>
</Layout>
);
};