Skip to content

Commit

Permalink
add tailwind support and refactor dashboard to functional components
Browse files Browse the repository at this point in the history
  • Loading branch information
nezdemkovski committed Jan 26, 2024
1 parent a452e42 commit a9d5cfc
Show file tree
Hide file tree
Showing 11 changed files with 2,387 additions and 1,225 deletions.
3,365 changes: 2,229 additions & 1,136 deletions package-lock.json

Large diffs are not rendered by default.

37 changes: 24 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,43 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@tanstack/eslint-plugin-query": "^4.32.5",
"@tailwindcss/forms": "^0.5.7",
"@tanstack/eslint-plugin-query": "^5.17.20",
"@types/bootstrap": "3.3.32",
"@types/bootstrap-datepicker": "0.0.15",
"@types/d3": "^7.4.0",
"@types/jest": "^29.5.3",
"@types/jest": "^29.5.11",
"@types/jquery": "^3.5.5",
"@types/jqueryui": "1.11.31",
"@typescript-eslint/eslint-plugin": "^5.15.0",
"@typescript-eslint/parser": "^5.15.0",
"@types/react": "^18.2.48",
"@types/react-dom": "^18.2.18",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
"ajv": "^6.12.6",
"ajv-cli": "^5.0.0",
"eslint": "^8.11.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"autoprefixer": "^10.4.17",
"css-loader": "^6.9.1",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-storybook": "^0.6.13",
"eslint-plugin-storybook": "^0.6.15",
"postcss": "^8.4.33",
"postcss-import": "^16.0.0",
"postcss-loader": "^8.0.0",
"postcss-prefix-selector": "^1.16.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"ts-loader": "^9.4.2",
"typescript": "^4.9.5",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1"
"style-loader": "^3.3.4",
"tailwindcss": "^3.4.1",
"ts-loader": "^9.5.1",
"typescript": "^5.3.3",
"webpack": "^5.90.0",
"webpack-cli": "^5.1.4"
},
"dependencies": {
"matrix-requirements-sdk": "^2.4.0-rc.4",
"matrixrequirements-type-declarations": "^2.4.0-rc.0",
"prettier": "^3.0.1"
"prettier": "^3.2.4"
}
}
19 changes: 19 additions & 0 deletions postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/** @type {import('postcss-load-config').Config} */
const config = {
plugins: [
require("postcss-import"),
require("postcss-prefix-selector")({
prefix: ".addon",
transform: function (prefix, selector, prefixedSelector) {
if (selector.startsWith("html") || selector.startsWith("body")) {
return selector;
}
return prefixedSelector;
},
}),
require("tailwindcss"),
require("autoprefixer"),
],
};

module.exports = config;
29 changes: 10 additions & 19 deletions src/BPP/Dashboard/Components/DashboardPageContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
import { Component } from "react";
import { DashboardProps, IProjectSettings } from "../../Interfaces";
import { PageTitle } from "./PageTitle";
import { DashboardProps } from "../../Interfaces";
import { DashboardPageTitle } from "./DashboardPageTitle";
import { Dashboard } from "../DashboardPage";

export class DashboardPageContainer extends Component<DashboardProps> {
settings: IProjectSettings;
export const DashboardPageContainer = ({ dashboard }: DashboardProps) => (
<>
<DashboardPageTitle title={dashboard.header.title} showFullScreen={dashboard.header.showFullScreen} />

render() {
return (
<div>
<div id="itemDetails" className="layoutContainer">
<PageTitle
title={this.props.dashboard.header.title}
showFullScreen={this.props.dashboard.header.showFullScreen}
/>
<Dashboard settings={this.props.dashboard.dashboardContent.settings}></Dashboard>
</div>
</div>
);
}
}
<div className="overflow-y-auto overflow-x-hidden" style={{ height: "calc(100% - 50px)" }}>
<Dashboard settings={dashboard.dashboardContent.settings} />
</div>
</>
);
23 changes: 23 additions & 0 deletions src/BPP/Dashboard/Components/DashboardPageTitle.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { IHeader } from "../../Interfaces";

export const DashboardPageTitle = ({ title, showFullScreen }: IHeader) => (
<div className="py-2.5 px-4 rounded-tl-sm rounded-tr-sm w-full flex justify-between border-b border-gray-200">
<div className="max-w-full flex flex-col gap-2 flex-grow-2">
<span data-cy="title" className="font-light break-words text-[28px]">
{title}
</span>
</div>

<div className="pull-right hidden-print tools-pull-right">
<div className="btn-group toolbarButtons">
{showFullScreen && (
<div className="btn-group btn-dashboard-fullscreen">
<button title="" data-original-title="Fullscreen" className="btn btn-item btn-fullscreen">
<span className="fal fa-expand-arrows-alt"></span>
</button>
</div>
)}
</div>
</div>
</div>
);
35 changes: 0 additions & 35 deletions src/BPP/Dashboard/Components/PageTitle.tsx

This file was deleted.

23 changes: 12 additions & 11 deletions src/BPP/Dashboard/DashboardPage.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
// @flow
// import {IProjectSettings} from "./Interfaces";
import { Plugin } from "../Plugin";

import { Component } from "react";
import * as ReactDOM from "react-dom";
import { DashboardPageContainer } from "./Components/DashboardPageContainer";
import { DashboardProps, DashboardState, IDashboard, IDashboardContent, IProjectSettings } from "../Interfaces";
import { IDashboard, IDashboardContent, IProjectSettings } from "../Interfaces";
import { Project, IDataStorage, IItem, IDashboardPage, IDashboardParametersBase } from "matrix-requirements-sdk/client";
import { sdkInstance } from "./../Instance";
import { sdkInstance } from "../Instance";

export interface IDashboardParameters extends IDashboardParametersBase {}

export class Dashboard extends Component<IDashboardContent, DashboardState> {
render() {
return <div className="itemDetails"></div>;
}
}
type DashboardProps = {
settings: IProjectSettings;
};

export const Dashboard = (props: DashboardProps) => (
<div className="w-auto p-4">Hello from the Matrix dashboard plugin!</div>
);

// Glue code to support the IDashboardPage interface
// eslint-disable-next-line no-unused-vars
Expand All @@ -37,6 +36,8 @@ export class DashboardPage implements IDashboardPage<IDashboardParameters> {
/** Add interactive element in this function */
renderProjectPage() {
const element = document.createElement("div");
element.classList.add("addon");
element.style.overflow = "hidden";
let dashboard: IDashboard = {
header: { title: "Dashboard", showFullScreen: false },
dashboardContent: { settings: this.settings },
Expand All @@ -46,6 +47,6 @@ export class DashboardPage implements IDashboardPage<IDashboardParameters> {
}

onResize() {
/* Will be triggered when resizing. */
console.log({ resize: "resizing the plugin page" });
}
}
2 changes: 2 additions & 0 deletions src/BPP/Plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { Tool } from "./Tools/Tools";
import { IPluginFieldValue, IProjectSettings, IServerSettings } from "./Interfaces";
import { FieldHandler } from "./Control/FieldHandler";

import "./styles.css";

/** This class is allows you to configure the features of your plugin.
*
* You can also implement functions to into the plugin (at start in the constructor, when loading a project, when loading an item)
Expand Down
13 changes: 13 additions & 0 deletions src/BPP/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* You can add global styles to this file, and also import other style files */

@tailwind base;
@tailwind components;
@tailwind utilities;

/* just a hack to rewrite the bootstrap 10px base font-size */
/* don't even know why it's 10px cause in bootstrap v3 it was also 16px */
/* looks like a bug in bootstrap file */
/* looks like it's not breaking any styles in the app */
html {
font-size: 16px;
}
10 changes: 10 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const plugin = require("tailwindcss/plugin");

/** @type {import('tailwindcss').Config} */
module.exports = {
content: ["src/**/*!(*.stories|*.spec).{ts,tsx,html}"],
theme: {
extend: {},
},
plugins: [require("@tailwindcss/forms")],
};
56 changes: 45 additions & 11 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const webpack = require("webpack"); //to access built-in plugins

module.exports = {
externals: {
'react': 'React',
'react-dom': 'ReactDOM'
react: "React",
"react-dom": "ReactDOM",
},
// bundling mode
mode: "none",
Expand All @@ -22,35 +22,69 @@ module.exports = {
path: __dirname + "/dist/",
},


// file resolutions
resolve: {
extensions: [".ts", ".js",".tsx",".jsx"]
extensions: [".ts", ".js", ".tsx", ".jsx"],
},

// loaders
module: {
rules: [
{
test: /\.tsx?$/,
use: 'ts-loader',
use: "ts-loader",
exclude: /(node_modules)|(ts\/types)/,
},
{ test: /\.d.ts$/, use: "raw-loader" },
{
test: /\.css$/,
exclude: /node_modules/,
use: [
{
loader: "style-loader",
},
{
loader: "css-loader",
options: {
importLoaders: 1,
},
},
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [
require("postcss-import"),
require("postcss-prefix-selector")({
// that's for tailwind not to mess with bootstrap styles
prefix: ".addon",
transform: function (prefix, selector, prefixedSelector) {
if (selector.startsWith("html") || selector.startsWith("body")) {
return selector;
}
return prefixedSelector;
},
}),
require("tailwindcss"),
require("autoprefixer"),
],
},
},
},
],
},
],
},
optimization: {
minimize: false,
nodeEnv: "production"
nodeEnv: "production",
},
//We can ignore these warnings.
ignoreWarnings: [
/possible exports/
],
//We can ignore these warnings.
ignoreWarnings: [/possible exports/],
plugins: [
new webpack.ProgressPlugin(),
new webpack.SourceMapDevToolPlugin({
filename: "[name].js.map",
}),
]
],
};

0 comments on commit a9d5cfc

Please sign in to comment.