-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add ui debug page controller * Add build time tooling to bundle stories * Add ui debug page frontend * Add missing types * Migrate all stories, refactor directory structure * Fix lint * Add changes
- Loading branch information
Showing
220 changed files
with
2,263 additions
and
1,306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
java/code/src/com/suse/manager/webui/controllers/StorybookController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2024 SUSE LLC | ||
* | ||
* This software is licensed to you under the GNU General Public License, | ||
* version 2 (GPLv2). There is NO WARRANTY for this software, express or | ||
* implied, including the implied warranties of MERCHANTABILITY or FITNESS | ||
* FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 | ||
* along with this software; if not, see | ||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. | ||
* | ||
* Red Hat trademarks are not licensed under GPLv2. No permission is | ||
* granted to use or replicate Red Hat trademarks that are incorporated | ||
* in this software or its documentation. | ||
*/ | ||
|
||
package com.suse.manager.webui.controllers; | ||
|
||
import static com.suse.manager.webui.utils.SparkApplicationHelper.withCsrfToken; | ||
import static com.suse.manager.webui.utils.SparkApplicationHelper.withUser; | ||
import static com.suse.manager.webui.utils.SparkApplicationHelper.withUserPreferences; | ||
import static spark.Spark.get; | ||
|
||
import com.redhat.rhn.domain.user.User; | ||
|
||
import java.util.HashMap; | ||
|
||
import spark.ModelAndView; | ||
import spark.Request; | ||
import spark.Response; | ||
import spark.template.jade.JadeTemplateEngine; | ||
|
||
public class StorybookController { | ||
private StorybookController() { } | ||
|
||
/** | ||
* Initialize routes | ||
* | ||
* @param jade the Jade engine to use to render the pages | ||
*/ | ||
public static void initRoutes(JadeTemplateEngine jade) { | ||
get("/manager/storybook", | ||
withUserPreferences(withCsrfToken(withUser(StorybookController::view))), jade); | ||
} | ||
|
||
/** | ||
* Returns the ui debug page | ||
* | ||
* @param req the request object | ||
* @param res the response object | ||
* @param user the authorized user | ||
* @return the model and view | ||
*/ | ||
public static ModelAndView view(Request req, Response res, User user) { | ||
return new ModelAndView(new HashMap<String, Object>(), "templates/storybook/storybook.jade"); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
java/code/src/com/suse/manager/webui/templates/storybook/storybook.jade
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
include ../common.jade | ||
|
||
#storybook | ||
|
||
script(type='text/javascript'). | ||
window.csrfToken = "#{csrf_token}"; | ||
|
||
script(type='text/javascript'). | ||
spaImportReactPage('storybook') | ||
.then(function(module) { module.renderer('storybook') }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Integrate ui debugging stories |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
const fs = require("fs").promises; | ||
const path = require("path"); | ||
|
||
/** Automatically gather all imports for story files */ | ||
module.exports = class GenerateStoriesPlugin { | ||
didApply = false; | ||
outputFile = undefined; | ||
|
||
constructor({ outputFile }) { | ||
if (!outputFile) { | ||
throw new Error("GenerateStoriesPlugin: `outputFile` is not set"); | ||
} | ||
this.outputFile = outputFile; | ||
} | ||
|
||
/** | ||
* @param {import("webpack").Compiler} compiler | ||
*/ | ||
apply(compiler) { | ||
// See https://webpack.js.org/api/compiler-hooks/#hooks | ||
compiler.hooks.watchRun.tapAsync("GenerateStoriesPlugin", async (params, callback) => | ||
this.beforeOrWatchRun(params, callback) | ||
); | ||
compiler.hooks.beforeRun.tapAsync("GenerateStoriesPlugin", async (params, callback) => | ||
this.beforeOrWatchRun(params, callback) | ||
); | ||
} | ||
|
||
/** | ||
* | ||
* @param {import("webpack").Compiler} compiler | ||
* @param {Function} callback | ||
*/ | ||
async beforeOrWatchRun(compiler, callback) { | ||
if (this.didApply) { | ||
callback(); | ||
return; | ||
} | ||
this.didApply = true; | ||
|
||
/** Source directory for the compilation, an absolute path to `/web/html/src` */ | ||
const webHtmlSrc = compiler.context; | ||
if (!this.outputFile.startsWith(webHtmlSrc)) { | ||
throw new RangeError("GenerateStoriesPlugin: `outputFile` is outside of the source code directory"); | ||
} | ||
|
||
const files = await fs.readdir(webHtmlSrc, { recursive: true }); | ||
const storyFilePaths = files | ||
.filter( | ||
(item) => !item.startsWith("node_modules") && (item.endsWith(".stories.ts") || item.endsWith(".stories.tsx")) | ||
) | ||
.sort(); | ||
|
||
const stories = storyFilePaths.map((filePath) => { | ||
const safeName = this.wordify(filePath); | ||
// We use the parent directory name as the group name | ||
const groupName = path.dirname(filePath).split("/").pop() ?? "Unknown"; | ||
return storyTemplate(filePath, safeName, groupName); | ||
}); | ||
|
||
const output = fileTemplate(stories.join("")); | ||
await fs.writeFile(this.outputFile, output, "utf-8"); | ||
console.log(`GenerateStoriesPlugin: wrote ${storyFilePaths.length} stories to ${this.outputFile}`); | ||
callback(); | ||
} | ||
|
||
wordify(input) { | ||
return input.replace(/[\W_]+/g, "_"); | ||
} | ||
}; | ||
|
||
const storyTemplate = (filePath, safeName, groupName) => | ||
` | ||
import ${safeName}_component from "${filePath}"; | ||
import ${safeName}_raw from "${filePath}?raw"; | ||
export const ${safeName} = { | ||
path: "${filePath}", | ||
title: "${path.basename(filePath)}", | ||
groupName: "${groupName}", | ||
component: ${safeName}_component, | ||
raw: ${safeName}_raw, | ||
}; | ||
`; | ||
|
||
const fileTemplate = (content) => | ||
` | ||
/** | ||
* NB! This is a generated file! | ||
* Any changes you make here will be lost. | ||
* See: web/html/src/build/plugins/generate-stories-plugin.js | ||
*/ | ||
/* eslint-disable */ | ||
${content} | ||
`.trim(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { ActionStatus } from "./ActionStatus"; | ||
|
||
export default () => { | ||
return ( | ||
<> | ||
<ActionStatus serverId="server123" actionId="456" status="Queued" />, | ||
<ActionStatus serverId="server123" actionId="456" status="Picked Up" />, | ||
<ActionStatus serverId="server123" actionId="456" status="Failed" />, | ||
<ActionStatus serverId="server123" actionId="456" status="Completed" />, | ||
</> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { StoryRow, StripedStorySection } from "manager/storybook/layout"; | ||
|
||
import { Button } from "components/buttons"; | ||
|
||
export default () => { | ||
return ( | ||
<StripedStorySection> | ||
<StoryRow> | ||
<Button><Button /></Button> | ||
<Button disabled><Button disabled /></Button> | ||
</StoryRow> | ||
<StoryRow> | ||
<Button className="btn-link"><Button className="btn-link" /></Button> | ||
<Button className="btn-link" disabled> | ||
<Button className="btn-link" disabled /> | ||
</Button> | ||
</StoryRow> | ||
<StoryRow> | ||
<Button className="btn-default"><Button className="btn-default" /></Button> | ||
<Button className="btn-default" disabled> | ||
<Button className="btn-default" disabled /> | ||
</Button> | ||
</StoryRow> | ||
<StoryRow> | ||
<Button className="btn-primary"><Button className="btn-primary" /></Button> | ||
<Button className="btn-primary" disabled> | ||
<Button className="btn-primary" disabled /> | ||
</Button> | ||
</StoryRow> | ||
<StoryRow> | ||
<Button className="btn-success"><Button className="btn-success" /></Button> | ||
<Button className="btn-success" disabled> | ||
<Button className="btn-success" disabled /> | ||
</Button> | ||
</StoryRow> | ||
<StoryRow> | ||
<Button className="btn-info"><Button className="btn-info" /></Button> | ||
<Button className="btn-info" disabled> | ||
<Button className="btn-info" disabled /> | ||
</Button> | ||
</StoryRow> | ||
<StoryRow> | ||
<Button className="btn-warning"><Button className="btn-warning" /></Button> | ||
<Button className="btn-warning" disabled> | ||
<Button className="btn-warning" disabled /> | ||
</Button> | ||
</StoryRow> | ||
<StoryRow> | ||
<Button className="btn-danger"><Button className="btn-danger" /></Button> | ||
<Button className="btn-danger" disabled> | ||
<Button className="btn-danger" disabled /> | ||
</Button> | ||
</StoryRow> | ||
</StripedStorySection> | ||
); | ||
}; |
Oops, something went wrong.