← Back to team overview

sts-sponsors team mailing list archive

[Merge] ~thorsten-merten/maas-site-manager:1529-add-name-unique-property into maas-site-manager:main

 

Thorsten Merten has proposed merging ~thorsten-merten/maas-site-manager:1529-add-name-unique-property into maas-site-manager:main.

Commit message:
feat: add name_unique property

also remove uniqueness of the name column


Requested reviews:
  MAAS Committers (maas-committers)

For more details, see:
https://code.launchpad.net/~thorsten-merten/maas-site-manager/+git/maas-site-manager/+merge/442834
-- 
Your team MAAS Committers is requested to review the proposed merge of ~thorsten-merten/maas-site-manager:1529-add-name-unique-property into maas-site-manager:main.
diff --git a/backend/msm/db/_tables.py b/backend/msm/db/_tables.py
index 70affca..1fa9662 100644
--- a/backend/msm/db/_tables.py
+++ b/backend/msm/db/_tables.py
@@ -23,7 +23,8 @@ Site = Table(
     Column("country", Text),  # ISO 3166 Alpha2
     Column("latitude", Text),
     Column("longitude", Text),
-    Column("name", Text, unique=True),
+    Column("name", Text),
+    Column("name_unique", Boolean),
     Column("note", Text),
     Column("region", Text),
     Column("street", Text),
diff --git a/backend/msm/db/models.py b/backend/msm/db/models.py
index ec3d032..ff3806f 100644
--- a/backend/msm/db/models.py
+++ b/backend/msm/db/models.py
@@ -26,6 +26,7 @@ class Site(BaseModel):
 
     id: int
     name: str
+    name_unique: bool
     city: str | None
     country: str | None = Field(min_length=2, max_length=2)
     latitude: str | None
diff --git a/backend/msm/db/queries.py b/backend/msm/db/queries.py
index 803aa81..bb2e1a3 100644
--- a/backend/msm/db/queries.py
+++ b/backend/msm/db/queries.py
@@ -150,6 +150,7 @@ async def get_sites(
         select(
             Site.c.id,
             Site.c.name,
+            Site.c.name_unique,
             Site.c.city,
             Site.c.country,
             Site.c.latitude,
diff --git a/backend/tests/user_api/test_handlers.py b/backend/tests/user_api/test_handlers.py
index 348747f..a74ab8f 100644
--- a/backend/tests/user_api/test_handlers.py
+++ b/backend/tests/user_api/test_handlers.py
@@ -28,6 +28,7 @@ def site_details(**extra_details: Any) -> dict[str, Any]:
     """Return sample details for creating a site."""
     details = {
         "name": "LondonHQ",
+        "name_unique": True,
         "url": "https://londoncalling.example.com";,
         "accepted": True,
     }
diff --git a/frontend/src/components/base/PaginationBar/PaginationBar.tsx b/frontend/src/components/base/PaginationBar/PaginationBar.tsx
index 69d8bb4..0c1eefe 100644
--- a/frontend/src/components/base/PaginationBar/PaginationBar.tsx
+++ b/frontend/src/components/base/PaginationBar/PaginationBar.tsx
@@ -49,30 +49,28 @@ const PaginationBar = ({
 
   return (
     <section className="pagination-bar u-flex u-flex--justify-between u-flex--wrap">
-      <div className="p-form p-form--inline">
-        <strong className="pagination-bar__description">
-          Showing {getDisplayedDataCount()} out of {totalItems} {dataContext}
-        </strong>
+      <strong className="pagination-bar__description">
+        Showing {getDisplayedDataCount()} out of {totalItems} {dataContext}
+      </strong>
 
-        <div className="u-flex u-flex--wrap u-flex--column-x-small pagination-bar__right">
-          <TablePagination
-            currentPage={currentPage}
-            isLoading={isLoading}
-            itemsPerPage={itemsPerPage}
-            onNextClick={onNextClick}
-            onPreviousClick={onPreviousClick}
-            setCurrentPage={setCurrentPage}
-            totalItems={totalItems}
-          />
+      <div className="u-flex u-flex--wrap u-flex--column-x-small pagination-bar__right">
+        <TablePagination
+          currentPage={currentPage}
+          isLoading={isLoading}
+          itemsPerPage={itemsPerPage}
+          onNextClick={onNextClick}
+          onPreviousClick={onPreviousClick}
+          setCurrentPage={setCurrentPage}
+          totalItems={totalItems}
+        />
 
-          <Select
-            aria-label="Tokens per page"
-            name="Tokens per page"
-            onChange={handleSizeChange}
-            options={pageOptions}
-            value={itemsPerPage}
-          />
-        </div>
+        <Select
+          aria-label="Tokens per page"
+          name="Tokens per page"
+          onChange={handleSizeChange}
+          options={pageOptions}
+          value={itemsPerPage}
+        />
       </div>
     </section>
   );
diff --git a/frontend/src/components/base/PaginationBar/_PaginationBar.scss b/frontend/src/components/base/PaginationBar/_PaginationBar.scss
index 4227570..7ee6678 100644
--- a/frontend/src/components/base/PaginationBar/_PaginationBar.scss
+++ b/frontend/src/components/base/PaginationBar/_PaginationBar.scss
@@ -5,14 +5,6 @@
   padding: $spv--small 0;
   margin-bottom: $spv--large;
 
-  .p-form--inline {
-      width: 100%;
-  }
-  
-  label {
-    margin-bottom: 0;
-  }
-
   .pagination-bar__description {
     margin: 0;
     padding: 0;
@@ -20,8 +12,6 @@
 
   .pagination-bar__right {
     width: 100%;
-    margin-left: auto;
-    margin-right: 0;
 
     @media screen and (min-width: $breakpoint-small) {
       width: auto;
diff --git a/frontend/src/components/base/TablePagination/TablePagination.tsx b/frontend/src/components/base/TablePagination/TablePagination.tsx
index ce8d599..b5887f1 100644
--- a/frontend/src/components/base/TablePagination/TablePagination.tsx
+++ b/frontend/src/components/base/TablePagination/TablePagination.tsx
@@ -70,9 +70,7 @@ const TablePagination = ({
       >
         <Icon className="u__left-rotate" name="chevron-down" />
       </Button>
-      <label>
-        <strong>Page</strong>
-      </label>
+      <strong>Page</strong>
       <Input
         aria-label="current page"
         className="current-page"
@@ -84,9 +82,7 @@ const TablePagination = ({
         type="number"
         value={pageNumber}
       />
-      <label>
-        <strong className="u-no-wrap"> of {totalPages}</strong>
-      </label>
+      <strong className="u-no-wrap"> of {totalPages}</strong>
       <Button
         appearance="base"
         aria-label="next page"
diff --git a/frontend/src/components/base/TablePagination/_TablePagination.scss b/frontend/src/components/base/TablePagination/_TablePagination.scss
index 7c23942..1291e8c 100644
--- a/frontend/src/components/base/TablePagination/_TablePagination.scss
+++ b/frontend/src/components/base/TablePagination/_TablePagination.scss
@@ -3,7 +3,9 @@
   margin: 0 $sph--x-large $spv--large 0;
   display: flex;
   gap: $sph--small;
+  align-items: center;
   list-style: none;
+  padding: 0;
 
   @media screen and (min-width: $breakpoint-small) {
     margin-bottom: 0;
@@ -11,7 +13,6 @@
 
   button {
     margin: 0;
-    align-self: flex-start;
   }
 
   .u__left-rotate {
@@ -27,7 +28,7 @@
     margin-bottom: 0;
 
     .current-page {
-      width: 3rem;
+      width: 100%;
       min-width: 1.625rem;
       margin-bottom: 0;
       text-align: center;
@@ -48,9 +49,10 @@
     }
 
     .p-form-validation__message {
-      width: max-content;
-      margin-top: $sph--small;
-      margin-bottom: 0;
+      position: absolute;
+      left: 0.625rem;
+      margin-top: 0;
+      white-space: nowrap;
     }
   }
 }
diff --git a/test-data/import.sh b/test-data/import.sh
index da238be..f0163b1 100755
--- a/test-data/import.sh
+++ b/test-data/import.sh
@@ -35,7 +35,7 @@ EOF
 fi
 
 (
-    copy_cmd sites.csv 'site(id, city, country, latitude, longitude, name, note, region, street, timezone, url, accepted, created)'
+    copy_cmd sites.csv 'site(id, city, country, latitude, longitude, name, name_unique, note, region, street, timezone, url, accepted, created)'
     copy_cmd tokens.csv 'token(site_id, value, expired, created)'
     copy_cmd users.csv '"user"(email, full_name, password)'
     copy_cmd site_data.csv 'site_data(site_id, allocated_machines, deployed_machines, ready_machines, error_machines, last_seen)'
diff --git a/test-data/sites.csv b/test-data/sites.csv
index b25a675..f83ba96 100644
--- a/test-data/sites.csv
+++ b/test-data/sites.csv
@@ -1,9 +1,10 @@
-id,city,country,latitude,longitude,name,note,region,street,timezone,url,accepted,created
-1,London,GB,51.501990,-0.092200,Canonical Group Limited,4th Floor,,201 Borough High Street,Europe/London,https://london.canonical.example.com,t,2023-04-19 14:01:40.107611
-2,Austin,US,30.269612,-97.741057,Canonical USA Inc.,Perry Brooks Building - Suite 300,,720 Brazos Street,America/Chicago,https://austin.canonical.example.com,t,2023-04-28 14:01:34.229025
-3,Boston,US,42.358859,-71.059615,Canonical USA Inc. 001,Suite 210,,18 Tremont Street,America/Chicago,https://boston.canonical.example.com,t,2023-05-04 14:01:49.706886
-4,Shanghai,CN,31.187270,121.436829,Canonical China,上海市漕溪北路331号12楼1246室,,No. 331 North Caoxi Road,Asia/Shanghai,https://shanghai.canonical.example.com,f,2023-04-03 14:01:27.419476
-5,Beijing,CN,39.908447,116.448690,Canonical China 001,China World Office 1; 北京市朝阳区建国门外大街1号国贸写字楼1座11层1118-19室 100004,Chaoyang District,1 Jianguomenwai Avenue,Asia/Shanghai,https://shanghai.canonical.example.com,t,2023-05-03 15:02:11.107339
-6,Taipei City,TW,25.058098,121.543406,Canonical Group Limited - Taiwan Branch,105402 台北市松山區民生東路三段100號12樓,Songshan Dist.,"12F.,No. 100,Sec. 3,Minsheng E. Rd.",Asia/Taipei,https://taiwan.canonical.example.com,t,2023-05-04 14:02:24.156508
-7,Douglas,IM,54.153072,-4.481012,Canonical Limited,2nd Floor - Clarendon House,,Victoria Street,Europe/London,https://canonical.example.com,f,2023-04-13 14:02:31.611254
-8,Tokyo,JP,35.673242,139.740669,Canonical Japan K.K,3rd Floor - Sanno Park Tower,,2-11-1 Nagata-cho Chiyoda-ku,Japan,https://japan.canonical.example.com,t,2022-05-03 14:02:42.955134
+id,city,country,latitude,longitude,name,name_unique,note,region,street,timezone,url,accepted,created
+1,London,GB,51.501990,-0.092200,Canonical Group Limited,t,4th Floor,,201 Borough High Street,Europe/London,https://london.canonical.example.com,t,2023-04-19 14:01:40.107611
+2,Austin,US,30.269612,-97.741057,Canonical USA Inc.,t,Perry Brooks Building - Suite 300,,720 Brazos Street,America/Chicago,https://austin.canonical.example.com,t,2023-04-28 14:01:34.229025
+3,Boston,US,42.358859,-71.059615,Canonical USA Inc. 001,t,Suite 210,,18 Tremont Street,America/Chicago,https://boston.canonical.example.com,t,2023-05-04 14:01:49.706886
+4,Shanghai,CN,31.187270,121.436829,Canonical China,t,上海市漕溪北路331号12楼1246室,,No. 331 North Caoxi Road,Asia/Shanghai,https://shanghai.canonical.example.com,f,2023-04-03 14:01:27.419476
+5,Beijing,CN,39.908447,116.448690,Canonical China 001,t,China World Office 1; 北京市朝阳区建国门外大街1号国贸写字楼1座11层1118-19室 100004,Chaoyang District,1 Jianguomenwai Avenue,Asia/Shanghai,https://shanghai.canonical.example.com,t,2023-05-03 15:02:11.107339
+6,Taipei City,TW,25.058098,121.543406,Canonical Group Limited - Taiwan Branch,t,105402 台北市松山區民生東路三段100號12樓,Songshan Dist.,"12F.,No. 100,Sec. 3,Minsheng E. Rd.",Asia/Taipei,https://taiwan.canonical.example.com,t,2023-05-04 14:02:24.156508
+7,Douglas,IM,54.153072,-4.481012,Canonical Limited,t,2nd Floor - Clarendon House,,ictoria Street,Europe/London,https://canonical.example.com,f,2023-04-13 14:02:31.611254
+8,Tokyo,JP,35.673242,139.740669,Canonical Japan K.K,f,3rd Floor - Sanno Park Tower,,2-11-1 Nagata-cho Chiyoda-ku,Japan,https://japan.canonical.example.com,t,2022-05-03 14:02:42.955134
+9,Tokyo,JP,35.673242,139.740669,Canonical Japan K.K,f,Duplicate,,2-11-1 Nagata-cho Chiyoda-ku,Japan,https://japan.canonical.example.com,t,2022-05-03 14:02:42.955134

Follow ups