Skip to content

Commit

Permalink
Merge branch 'develop' into fix/superuser-create-scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
pavish authored Dec 24, 2024
2 parents e41e6c1 + c2ffc44 commit 63390ad
Show file tree
Hide file tree
Showing 31 changed files with 101 additions and 197 deletions.
1 change: 0 additions & 1 deletion mathesar/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
path('administration/users/', views.admin_home, name='admin_users_home'),
path('administration/users/<int:user_id>/', views.admin_home, name='admin_users_edit'),
path('administration/update/', views.admin_home, name='admin_update'),
path('databases/', views.databases_list_route, name='databases_list_route'),
path('i18n/', include('django.conf.urls.i18n')),
re_path(
r'^db/(?P<database_id>\d+)/schemas/(?P<schema_id>\d+)/',
Expand Down
17 changes: 1 addition & 16 deletions mathesar/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import render, redirect
from django.shortcuts import render
from modernrpc.exceptions import RPCException
from modernrpc.views import RPCEntryPoint

Expand Down Expand Up @@ -120,21 +120,6 @@ class MathesarRPCEntryPoint(LoginRequiredMixin, RPCEntryPoint):

@login_required
def home(request):
database_list = get_database_list(request)
number_of_databases = len(database_list)
if number_of_databases > 1:
return redirect('databases_list_route')
elif number_of_databases == 1:
db = database_list[0]
return redirect('database_route', database_id=db['id'])
else:
return render(request, 'mathesar/index.html', {
'common_data': get_common_data(request)
})


@login_required
def databases_list_route(request):
return render(request, 'mathesar/index.html', {
'common_data': get_common_data(request)
})
Expand Down
77 changes: 0 additions & 77 deletions mathesar_ui/src/components/AppHeader.svelte
Original file line number Diff line number Diff line change
@@ -1,41 +1,28 @@
<script lang="ts">
import { _ } from 'svelte-i18n';
import { router } from 'tinro';
import {
iconAddNew,
iconConnection,
iconDatabase,
iconExploration,
iconLogout,
iconSettingsMajor,
iconShortcuts,
iconUser,
} from '@mathesar/icons';
import {
ADMIN_URL,
HOME_URL,
LOGOUT_URL,
USER_PROFILE_URL,
getDataExplorerPageUrl,
getDatabasePageUrl,
getImportPageUrl,
getTablePageUrl,
} from '@mathesar/routes/urls';
import { databasesStore } from '@mathesar/stores/databases';
import { getReleaseDataStoreFromContext } from '@mathesar/stores/releases';
import { currentSchema } from '@mathesar/stores/schemas';
import { createTable } from '@mathesar/stores/tables';
import { getUserProfileStoreFromContext } from '@mathesar/stores/userProfile';
import { preloadCommonData } from '@mathesar/utils/preloadData';
import {
ButtonMenuItem,
DropdownMenu,
Icon,
LinkMenuItem,
MenuDivider,
MenuHeading,
iconLoading,
} from '@mathesar-component-library';
import Breadcrumb from './breadcrumb/Breadcrumb.svelte';
Expand All @@ -46,23 +33,8 @@
const { currentDatabase } = databasesStore;
$: database = $currentDatabase;
$: schema = $currentSchema;
$: upgradable = $releaseDataStore?.value?.upgradeStatus === 'upgradable';
$: isNormalRoutingContext = commonData.routing_context === 'normal';
$: currentRolePrivileges = schema?.currentAccess.currentRolePrivileges;
$: canCreateTable = $currentRolePrivileges?.has('CREATE');
let isCreatingNewEmptyTable = false;
async function handleCreateEmptyTable() {
if (!schema || !database) {
return;
}
isCreatingNewEmptyTable = true;
const table = await createTable({ schema });
isCreatingNewEmptyTable = false;
router.goto(getTablePageUrl(database.id, schema.oid, table.oid), false);
}
</script>

<header class="app-header">
Expand All @@ -72,39 +44,6 @@

{#if isNormalRoutingContext}
<div class="right">
{#if schema && database}
<DropdownMenu
triggerAppearance="ghost"
size="small"
closeOnInnerClick={true}
icon={isCreatingNewEmptyTable ? iconLoading : undefined}
>
<span slot="trigger" class="shortcuts">
<span class="icon"><Icon {...iconShortcuts} /></span>
<span class="text">{$_('shortcuts')}</span>
</span>
<ButtonMenuItem
icon={iconAddNew}
on:click={handleCreateEmptyTable}
disabled={!canCreateTable}
>
{$_('new_table_from_scratch')}
</ButtonMenuItem>
<LinkMenuItem
icon={iconAddNew}
href={getImportPageUrl(database.id, schema.oid)}
disabled={!canCreateTable}
>
{$_('new_table_from_data_import')}
</LinkMenuItem>
<LinkMenuItem
icon={iconExploration}
href={getDataExplorerPageUrl(database.id, schema.oid)}
>
{$_('open_data_explorer')}
</LinkMenuItem>
</DropdownMenu>
{/if}
{#if $userProfile}
<DropdownMenu
triggerAppearance="ghost"
Expand All @@ -130,9 +69,6 @@
{$userProfile.getDisplayName()}
</LinkMenuItem>
<MenuDivider />
<LinkMenuItem icon={iconConnection} href={HOME_URL}>
{$_('databases')}
</LinkMenuItem>
{#if $userProfile.isMathesarAdmin}
<LinkMenuItem
icon={iconSettingsMajor}
Expand Down Expand Up @@ -174,10 +110,6 @@
font-size: var(--text-size-large);
}
.shortcuts .text {
display: none;
}
.shortcuts .icon,
.user-switcher {
background-color: var(--slate-200);
color: var(--slate-800);
Expand All @@ -186,13 +118,4 @@
display: flex;
align-items: center;
}
@media (min-width: 45rem) {
.shortcuts .text {
display: unset;
}
.shortcuts .icon {
display: none;
}
}
</style>
2 changes: 2 additions & 0 deletions mathesar_ui/src/components/breadcrumb/Breadcrumb.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import BreadcrumbItem from './BreadcrumbItem.svelte';
import { getBreadcrumbItemsFromContext } from './breadcrumbUtils';
import DatabaseSelector from './DatabaseSelector.svelte';
import LogoAndNameWithLink from './LogoAndNameWithLink.svelte';
const items = getBreadcrumbItemsFromContext();
Expand All @@ -14,6 +15,7 @@

<div class="breadcrumb">
<LogoAndNameWithLink href="/" {hasResponsiveAbridgement} />
<DatabaseSelector />
{#each $items as item}
<BreadcrumbItem {item} />
{/each}
Expand Down
31 changes: 7 additions & 24 deletions mathesar_ui/src/components/breadcrumb/BreadcrumbItem.svelte
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
<script lang="ts">
import { _ } from 'svelte-i18n';
import { StringOrComponent } from '@mathesar/component-library';
import DatabaseName from '@mathesar/components/DatabaseName.svelte';
import NameWithIcon from '@mathesar/components/NameWithIcon.svelte';
import SchemaName from '@mathesar/components/SchemaName.svelte';
import TableName from '@mathesar/components/TableName.svelte';
import { iconExploration, iconRecord } from '@mathesar/icons';
import {
iconConnectDatabase,
iconExploration,
iconRecord,
} from '@mathesar/icons';
import {
HOME_URL,
getDatabasePageUrl,
getExplorationPageUrl,
getRecordPageUrl,
Expand All @@ -24,38 +17,27 @@
import BreadcrumbPageSeparator from './BreadcrumbPageSeparator.svelte';
import BreadcrumbRecordSelector from './BreadcrumbRecordSelector.svelte';
import type { BreadcrumbItem } from './breadcrumbTypes';
import DatabaseSelector from './DatabaseSelector.svelte';
import EntitySelector from './EntitySelector.svelte';
import SchemaSelector from './SchemaSelector.svelte';
export let item: BreadcrumbItem;
</script>

{#if item.type === 'home'}
<DatabaseSelector />
<div class="breadcrumb-item truncate">
<BreadcrumbLink href={HOME_URL}>
<NameWithIcon icon={{ ...iconConnectDatabase, size: '1.4rem' }}>
{$_('databases')}
</NameWithIcon>
</BreadcrumbLink>
</div>
{:else if item.type === 'database'}
<DatabaseSelector />
{#if item.type === 'database'}
<div class="breadcrumb-item truncate">
<BreadcrumbLink href={getDatabasePageUrl(item.database.id)}>
<DatabaseName database={item.database} />
</BreadcrumbLink>
</div>
{:else if item.type === 'schema'}
<SchemaSelector database={item.database} />
{:else if item.type === 'schema'}
<div class="breadcrumb-item truncate">
<BreadcrumbLink href={getSchemaPageUrl(item.database.id, item.schema.oid)}>
<SchemaName schema={item.schema} />
</BreadcrumbLink>
</div>
{:else if item.type === 'table'}
<EntitySelector database={item.database} schema={item.schema} />
{:else if item.type === 'table'}
<div class="breadcrumb-item truncate">
<BreadcrumbLink
href={getLinkForTableItem(item.database.id, item.schema.oid, item.table)}
Expand All @@ -78,7 +60,6 @@
</BreadcrumbLink>
</div>
{:else if item.type === 'exploration'}
<EntitySelector database={item.database} schema={item.schema} />
<div class="breadcrumb-item truncate">
<BreadcrumbLink
href={getExplorationPageUrl(
Expand All @@ -91,7 +72,9 @@
</BreadcrumbLink>
</div>
{:else if item.type === 'simple'}
<BreadcrumbPageSeparator />
{#if item.prependSeparator}
<BreadcrumbPageSeparator />
{/if}
<div class="breadcrumb-item truncate">
<BreadcrumbLink href={item.href}>
{#if item.icon}
Expand Down
17 changes: 2 additions & 15 deletions mathesar_ui/src/components/breadcrumb/DatabaseSelector.svelte
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script lang="ts">
import { _ } from 'svelte-i18n';
import { iconConnectDatabase, iconDatabase } from '@mathesar/icons';
import { iconDatabase } from '@mathesar/icons';
import type { Database } from '@mathesar/models/Database';
import { HOME_URL, getDatabasePageUrl } from '@mathesar/routes/urls';
import { getDatabasePageUrl } from '@mathesar/routes/urls';
import { databasesStore } from '@mathesar/stores/databases';
import BreadcrumbSelector from './BreadcrumbSelector.svelte';
Expand Down Expand Up @@ -31,17 +31,4 @@
<BreadcrumbSelector
data={new Map([[$_('databases'), breadcrumbEntries]])}
triggerLabel={$_('choose_database')}
persistentLinks={[
{
type: 'simple',
label: $_('manage_databases'),
href: HOME_URL,
icon: {
...iconConnectDatabase,
size: '1.4rem',
},
// TODO: Handle active states for persistent links
isActive: () => false,
},
]}
/>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
function makeBreadcrumbSelectorItem(schema: Schema): BreadcrumbSelectorEntry {
return {
type: 'simple',
// TODO_BETA: Make label a store
// TODO: Make label a store
label: get(schema.name),
href: getSchemaPageUrl(database.id, schema.oid),
icon: iconSchema,
Expand Down
6 changes: 1 addition & 5 deletions mathesar_ui/src/components/breadcrumb/breadcrumbTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ import type { Database } from '@mathesar/models/Database';
import type { Schema } from '@mathesar/models/Schema';
import type { Table } from '@mathesar/models/Table';

export interface BreadcrumbItemHome {
type: 'home';
}

export interface BreadcrumbItemDatabase {
type: 'database';
database: Database;
Expand All @@ -34,6 +30,7 @@ export interface BreadcrumbItemSimple {
href: string;
label: string | ComponentAndProps;
icon?: IconProps;
prependSeparator?: boolean;
}

export interface BreadcrumbItemRecord {
Expand All @@ -55,7 +52,6 @@ export interface BreadcrumbItemExploration {
}

export type BreadcrumbItem =
| BreadcrumbItemHome
| BreadcrumbItemDatabase
| BreadcrumbItemSchema
| BreadcrumbItemTable
Expand Down
6 changes: 6 additions & 0 deletions mathesar_ui/src/components/cell-fabric/data-types/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ const stringType: CellComponentFactory = {
},
};
},
getFilterInput: (column: Column): ComponentAndProps<TextInputProps> => ({
component: TextInput,
props: {
maxlength: optionalNonNullable(column.type_options?.length),
},
}),
getDisplayFormatter: () => String,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,38 @@ export type CellDataType = SimpleCellDataTypes | CompoundCellDataTypes;

export interface CellComponentFactory {
initialInputValue?: unknown;

/**
* Get the component used to render the cell
*/
get(
column: CellColumnLike,
config?: Record<string, unknown>,
): ComponentAndProps;

/** Get the component used to render an input when the user is adding or
* editing a value of this type. This is used on the record page, and default
* value, for example.
*/
getInput(
column: CellColumnLike,
config?: Record<string, unknown>,
): ComponentAndProps;

/**
* Implement this method in order to customize the input used within filter
* conditions. If not implemented, then we fall back to using the `getInput`
* method. Custom filter input components are useful when we want slightly
* different behavior for searching vs data entry. See [issue #4052][4052] for
* an example.
*
* [4052]: https://github.com/mathesar-foundation/mathesar/issues/4052
*/
getFilterInput?(
column: CellColumnLike,
config?: Record<string, unknown>,
): ComponentAndProps;

getDisplayFormatter(
column: CellColumnLike,
config?: Record<string, unknown>,
Expand Down
Loading

0 comments on commit 63390ad

Please sign in to comment.