Skip to content

Commit

Permalink
chore: Restructure store to match standardised architecture (#4646)
Browse files Browse the repository at this point in the history
* chore: Remove old store JS

* chore: Restructure store to match standardised architecture
  • Loading branch information
steverydz authored May 23, 2024
1 parent c0b0e97 commit 808f26c
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 112 deletions.
52 changes: 0 additions & 52 deletions static/js/public/store-categories.js

This file was deleted.

3 changes: 0 additions & 3 deletions static/js/public/store.js

This file was deleted.

2 changes: 1 addition & 1 deletion static/js/store/components/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import { QueryClient, QueryClientProvider } from "react-query";

import Packages from "../Packages";
import Packages from "../../pages/Packages";

function App() {
const queryClient = new QueryClient({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,16 @@ import {
} from "@canonical/react-components";
import { DefaultCard, LoadingCard, Filters } from "@canonical/store-components";

import Banner from "../Banner";
import Banner from "../../components/Banner";

import type { Package, Category } from "../../types/shared";
import { getArchitectures, getCategoryOrder } from "../../utils";

import type { Package, Category } from "../../types";

function Packages() {
const ITEMS_PER_PAGE = 15;
const SHOW_MORE_COUNT = 10;
const CATEGORY_ORDER = [
"development",
"games",
"social",
"productivity",
"utilities",
"music-and-audio",
"art-and-design",
"photo-and-video",
"server-and-cloud",
];
const CATEGORY_ORDER = getCategoryOrder();

const getData = async () => {
let queryString = search;
Expand Down Expand Up @@ -207,36 +199,7 @@ function Packages() {
searchParams.delete("page");
setSearchParams(searchParams);
}}
architectures={[
{
name: "",
display_name: "All",
},
{
name: "amd64",
display_name: "AMD64",
},
{
name: "arm64",
display_name: "ARM64",
},
{
name: "armhf",
display_name: "ARMHF",
},
{
name: "i386",
display_name: "I386",
},
{
name: "ppc64el",
display_name: "PPC64EL",
},
{
name: "s390x",
display_name: "S390X",
},
]}
architectures={getArchitectures()}
selectedArchitecture={
searchParams.get("architecture") || ""
}
Expand Down
File renamed without changes.
6 changes: 6 additions & 0 deletions static/js/store/types/components/Category.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type Category = {
display_name: string;
name: string;
};

export default Category;
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export type Package = {
import type { Category } from "./Category";

type Package = {
id?: string;
package: {
description: string;
Expand All @@ -24,7 +26,4 @@ export type Package = {
};
};

export type Category = {
display_name: string;
name: string;
};
export default Package;
4 changes: 4 additions & 0 deletions static/js/store/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Category from "./components/Category";
import Package from "./components/Package";

export { Category, Package };
34 changes: 34 additions & 0 deletions static/js/store/utils/getArchitectures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
function getArchitectures() {
return [
{
name: "",
display_name: "All",
},
{
name: "amd64",
display_name: "AMD64",
},
{
name: "arm64",
display_name: "ARM64",
},
{
name: "armhf",
display_name: "ARMHF",
},
{
name: "i386",
display_name: "I386",
},
{
name: "ppc64el",
display_name: "PPC64EL",
},
{
name: "s390x",
display_name: "S390X",
},
];
}

export default getArchitectures;
15 changes: 15 additions & 0 deletions static/js/store/utils/getCategoryOrder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function getCategoryOrder() {
return [
"development",
"games",
"social",
"productivity",
"utilities",
"music-and-audio",
"art-and-design",
"photo-and-video",
"server-and-cloud",
];
}

export default getCategoryOrder;
4 changes: 4 additions & 0 deletions static/js/store/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import getArchitectures from "./getArchitectures";
import getCategoryOrder from "./getCategoryOrder";

export { getArchitectures, getCategoryOrder };
2 changes: 1 addition & 1 deletion templates/store/store.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@

{% block content %}
<main id="root"></main>
<script src="{{ versioned_static('js/dist/beta-store.js') }}" defer></script>
<script src="{{ versioned_static('js/dist/store.js') }}" defer></script>
{% endblock %}
3 changes: 1 addition & 2 deletions webpack.config.entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module.exports = {
publisher: "./static/js/publisher/publisher.js",
homepage: "./static/js/public/homepage.js",
blog: "./static/js/public/blog.js",
store: "./static/js/public/store.js",
"store-details": "./static/js/public/store-details.js",
fsf: "./static/js/public/fsf.js",
search: "./static/js/public/search.js",
Expand All @@ -23,5 +22,5 @@ module.exports = {
"publisher-settings": "./static/js/publisher/settings/index.tsx",
"publisher-collaboration": "./static/js/publisher/collaboration/index.tsx",
"about-listing": "./static/js/public/about/listing.ts",
"beta-store": "./static/js/store/index.tsx",
store: "./static/js/store/index.tsx",
};
7 changes: 2 additions & 5 deletions webpack.config.rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ module.exports = [
// except some that use ES6 modules and need to be transpiled:
// such as swiper http://idangero.us/swiper/get-started/
// and also react-dnd related
exclude: /node_modules\/(?!(dom7|ssr-window|swiper|dnd-core|react-dnd|react-dnd-html5-backend)\/).*/,
exclude:
/node_modules\/(?!(dom7|ssr-window|swiper|dnd-core|react-dnd|react-dnd-html5-backend)\/).*/,
use: {
loader: "babel-loader",
},
Expand Down Expand Up @@ -55,10 +56,6 @@ module.exports = [
test: require.resolve(__dirname + "/static/js/public/blog.js"),
use: ["expose-loader?exposes=snapcraft.public.blog", "babel-loader"],
},
{
test: require.resolve(__dirname + "/static/js/public/store.js"),
use: ["expose-loader?exposes=snapcraft.public.store", "babel-loader"],
},
{
test: require.resolve(__dirname + "/static/js/public/store-details.js"),
use: [
Expand Down

0 comments on commit 808f26c

Please sign in to comment.