Skip to content

Commit

Permalink
/table?name=:name support
Browse files Browse the repository at this point in the history
  • Loading branch information
d9k committed Dec 29, 2023
1 parent 0fdf40e commit 93d888c
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 18 deletions.
13 changes: 11 additions & 2 deletions src/app/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { PageFrameLayoutProviderContextUpdate } from '/~/shared/providers/layout
import { PageFrameLayoutContextCreator } from '/~/shared/providers/layout/page-frame/index.tsx';

import { PageFrameLayout } from '/~/pages/layouts/page-frame.tsx';
import { useUrlParamRetPath } from '/~/shared/lib/react/routing/useUrlParamRetPath.ts';
import { useQueryParamRetPath } from '/~/shared/lib/react/routing/query-params.ts';
import { RedirectIfNoLogin } from '/~/pages/routes-helpers/RedirectIfNoLogin.tsx';
import { useNavigate } from 'react-router-dom';
import LoginPage from '/~/pages/login/index.tsx';
Expand All @@ -23,7 +23,7 @@ const NavbarTables = React.lazy(() => import('/~/pages/navbar/tables.tsx'));

export const AppRoutes = () => {
const supabaseUser = useSupabaseUser();
const retPath = useUrlParamRetPath();
const retPath = useQueryParamRetPath();
const navigate = useNavigate();
console.log('__TEST__: AppRoutes: supabaseUser:', supabaseUser);
console.log('__TEST__: AppRoutes: retPath:', retPath);
Expand Down Expand Up @@ -68,6 +68,15 @@ export const AppRoutes = () => {
path='table/:name'
/>

<Route
element={
<PageFrameLayoutProviderContextUpdate navbarOpened={false}>
<TablePage />
</PageFrameLayoutProviderContextUpdate>
}
path='table'
/>

<Route
element={<TablesPage />}
path='tables'
Expand Down
4 changes: 3 additions & 1 deletion src/features/tables/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export const TablesList = () => {
console.log('TablesList: schemas:', publicSchema);

const list = Object.entries(publicSchema).map(([tableName, _tableSchema]) => {
const href = `/table/${tableName}`;
// TODO uncomment after https://github.com/exhibitionist-digital/ultra/issues/291 is fixed
// const href = `/table/${tableName}`;
const href = `/table?name=${tableName}`;
const caption = upperFirst(tableName);

return (
Expand Down
10 changes: 7 additions & 3 deletions src/pages/table/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { usePageFrameLayoutComponent } from '/~/shared/providers/layout/page-frame/index.tsx';
import { Spinner } from '/~/shared/ui/spinner.tsx';
import useUrlParamName from '/~/shared/lib/react/routing/useUrlParamName.ts';
import { useUrlParamName } from '/~/shared/lib/react/routing/url-params.ts';
import { SupabaseAutogeneratedDataGrid } from '/~/widgets/supabase/autogenerated-data-grid/index.tsx';
import { Suspense } from 'react';

Expand All @@ -16,19 +16,23 @@ import {
//@deno-types="@types/lodash"
import { startCase } from 'lodash';

import { useQueryParamName } from '/~/shared/lib/react/routing/query-params.ts';

const TablePage = () => {
const isBrowser = useRenderOnlyInBrowser();

const [qkey, qkeyRegen] = useQueryKeyUniqueSuffix();
const PageFrameComponent = usePageFrameLayoutComponent();
// const [loading, setLoading] = useState(false);
// const user = useSupabase();
const name = useUrlParamName();
const nameParam = useUrlParamName() || useQueryParamName();

if (!name) {
if (!nameParam) {
return <>Error: can't parse url param "name"</>;
}

const name = `${nameParam}`;

const tableSchema = publicSchema[name];
// console.debug('__TEST__: TablePage: table schema:', tableSchema);

Expand Down
64 changes: 64 additions & 0 deletions src/pages/table/index.tsx.bk
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { usePageFrameLayoutComponent } from '/~/shared/providers/layout/page-frame/index.tsx';
import { Spinner } from '/~/shared/ui/spinner.tsx';
import useUrlParamName from '/~/shared/lib/react/routing/useUrlParamName.ts';
// import { SupabaseAutogeneratedDataGrid } from '/~/widgets/supabase/autogenerated-data-grid/index.tsx';
import { Suspense } from 'react';

// import { publicSchema } from '/~/shared/api/supabase/schemas.ts';
import { useQueryKeyUniqueSuffix } from '/~/shared/lib/react/query/key.ts';
import { useRenderOnlyInBrowser } from '/~/shared/lib/react/useRenderOnlyInBrowser.ts';

import {
COLUMNS_SHOW_FIRST,
COLUMNS_SHOW_LAST,
} from '/~/shared/api/supabase/const.ts';

//@deno-types="@types/lodash"
import { startCase } from 'lodash';

const TablePage = () => {
const isBrowser = useRenderOnlyInBrowser();

const [qkey, qkeyRegen] = useQueryKeyUniqueSuffix();
const PageFrameComponent = usePageFrameLayoutComponent();
// const [loading, setLoading] = useState(false);
// const user = useSupabase();
const name = useUrlParamName();

if (!name) {
return <>Error: can't parse url param "name"</>;
}

// const tableSchema = publicSchema[name];
// console.debug('__TEST__: TablePage: table schema:', tableSchema);

// if (!tableSchema) {
// return <>Error: no schema with dis table</>;
// }

return (
<PageFrameComponent>
<h3>{startCase(name)} table</h3>

{isBrowser
? (
<Suspense fallback={<Spinner />}>
__TEST__
{
/* <SupabaseAutogeneratedDataGrid
columnsNamesFirst={COLUMNS_SHOW_FIRST}
columnsNamesLast={COLUMNS_SHOW_LAST}
onReloadRequired={qkeyRegen}
queryKeyUniqueSuffix={qkey}
tableName={name}
tableSchema={tableSchema}
/> */
}
</Suspense>
)
: <Spinner />}
</PageFrameComponent>
);
};

export default TablePage;
9 changes: 9 additions & 0 deletions src/shared/lib/react/routing/query-params.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { StringParam, useQueryParam } from 'use-query-params';

export function useQueryParamString(name: string): string | undefined {
const [result] = useQueryParam(name, StringParam);

return result || undefined;
}
export const useQueryParamName = () => useQueryParamString('name');
export const useQueryParamRetPath = () => useQueryParamString('retpath');
10 changes: 10 additions & 0 deletions src/shared/lib/react/routing/url-params.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { useParams } from 'react-router-dom';

export function useUrlParamString(paramName: string): string | null {
const value = useParams()[paramName];
return value ? value : null;
}

export function useUrlParamName(): string | null {
return useUrlParamString('name') || null;
}
5 changes: 0 additions & 5 deletions src/shared/lib/react/routing/useUrlParamName.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/shared/lib/react/routing/useUrlParamRetPath.ts

This file was deleted.

0 comments on commit 93d888c

Please sign in to comment.