Repository: mathesar-foundation/mathesar

Issue:
Implement adding a new empty table
## Problem
<!-- Please provide a clear and concise description of the problem that this feature request is designed to solve.-->
Users may want to create an empty table.

## Proposed solution
<!-- A clear and concise description of your proposed solution or feature. -->
The ["Basic Table Operations" design spec](https://wiki.mathesar.org/design/specs/table-operations) has a solution for this, which we need to implement on the frontend. We will be implementing a different design than the one in the spec, which will need to be improvised.

This issue involves the following portions of the spec:
- _User Experience_: 
  - User adds a new table
  - User edits a new table name
  - User adds an empty table
- _Interactions_: 
  - Sequential Table Names
 
Please note that we'll need to generate and display a default name of the table that the user can use. Following the logic in #449 is recommended.

## Additional context
<!-- Add any other context or screenshots about the feature request here.-->
- Backend work: #184 
- Design issue: #185
- #449 is related.

Logs of conversation on Matrix from @pavish:

> For adding an empty table, instead of showing Empty table option within the tab, I think it might be better to show it on the top.
> 
> The Add new table button can be changed to a dropdown with two options. 1. Empty table, 2. Import data.
> 
> On clicking empty table, it would just send a create table request and create the table. Then the user can rename it if they want.
> 
> This will have clean separation of concerns. Because Import data, involves importing from csv, remote file import and then copy/paste from spreadsheet..
> 
> Empty table, would just create a new empty table.


Discussion:
I'll take this one

Resolving patch:
diff --git a/mathesar/api/viewsets/tables.py b/mathesar/api/viewsets/tables.py
--- a/mathesar/api/viewsets/tables.py
+++ b/mathesar/api/viewsets/tables.py
@@ -31,26 +31,15 @@ def create(self, request):
         serializer = TableSerializer(data=request.data, context={'request': request})
         serializer.is_valid(raise_exception=True)
 
-        if not serializer.validated_data['name']:
-            name = gen_table_name(
-                serializer.validated_data['schema'],
-                serializer.validated_data['data_files'],
-            )
-        else:
-            name = serializer.validated_data['name']
+        schema = serializer.validated_data['schema']
+        data_files = serializer.validated_data.get('data_files')
+        name = serializer.validated_data.get('name') or gen_table_name(schema, data_files)
 
         try:
-            if serializer.validated_data['data_files']:
-                table = create_table_from_datafile(
-                    serializer.validated_data['data_files'],
-                    name,
-                    serializer.validated_data['schema'],
-                )
+            if data_files:
+                table = create_table_from_datafile(data_files, name, schema)
             else:
-                table = create_empty_table(
-                    name,
-                    serializer.validated_data['schema']
-                )
+                table = create_empty_table(name, schema)
         except ProgrammingError as e:
             if type(e.orig) == DuplicateTable:
                 raise ValidationError(


Test patch: