From ea20d1888dffefc301e071ef8ddce15fa8331d94 Mon Sep 17 00:00:00 2001 From: Matt Henderson Date: Fri, 24 Sep 2021 14:13:23 -0700 Subject: [PATCH] Styling adjustments (#56) * dark mode updates, font sizing, font coloring, button sizing set to better blend with the jupyterlab styling * Added a MutationObserver for theme detection of the data table * theme name should be default --- src/components/JobSubmitForm.tsx | 1 - src/components/SlurmManager.tsx | 23 --------- src/components/SqueueDataTable.tsx | 38 +++++++++++--- style/base.css | 81 +++++++++++++++++++++++++----- 4 files changed, 98 insertions(+), 45 deletions(-) diff --git a/src/components/JobSubmitForm.tsx b/src/components/JobSubmitForm.tsx index e27778d..478c10c 100755 --- a/src/components/JobSubmitForm.tsx +++ b/src/components/JobSubmitForm.tsx @@ -18,7 +18,6 @@ namespace types { submitJob: (input: string, inputType: string) => void; addAlert: (message: string, variant: string) => void; disabled?: boolean; - theme: string; active: boolean; }; diff --git a/src/components/SlurmManager.tsx b/src/components/SlurmManager.tsx index f08312a..3469764 100755 --- a/src/components/SlurmManager.tsx +++ b/src/components/SlurmManager.tsx @@ -38,27 +38,6 @@ namespace types { }; } -function getCurrentTheme() { - const root = document.getElementsByTagName('body')[0]; - const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)'); - - if (root.hasAttribute('data-jp-theme-light')) { - const light = root.getAttribute('data-jp-theme-light'); - - if (light === 'true') { - return 'default'; - } else { - return 'dark'; - } - } else { - if (mediaQuery.matches === true) { - return 'dark'; - } else { - return 'default'; - } - } -} - export default class SlurmManager extends React.Component< types.Props, types.State @@ -306,7 +285,6 @@ export default class SlurmManager extends React.Component< autoReload={this.state.autoReload} itemsPerPage={this.props.settings.itemsPerPage} itemsPerPageOptions={this.props.settings.itemsPerPageOptions} - theme={getCurrentTheme()} /> @@ -315,7 +293,6 @@ export default class SlurmManager extends React.Component< submitJob={this.submitJob.bind(this)} disabled={this.state.jobSubmitDisabled} addAlert={this.addAlert} - theme={getCurrentTheme()} active={this.state.activeTab === 'jobSubmit'} /> diff --git a/src/components/SqueueDataTable.tsx b/src/components/SqueueDataTable.tsx index 96840e4..dbd54ff 100755 --- a/src/components/SqueueDataTable.tsx +++ b/src/components/SqueueDataTable.tsx @@ -36,7 +36,6 @@ namespace types { reloadQueue: boolean; autoReload: boolean; reloadRate: number; - theme: string; processJobAction: ( action: JobAction, rows: Record[] @@ -58,6 +57,8 @@ namespace types { reloadLimit: number; userOnly: boolean; loading: boolean; + theme: string; + observer: MutationObserver; }; } @@ -83,6 +84,20 @@ export default class SqueueDataTable extends Component< ? props.defaultColumns : props.availableColumns; + const body = document.getElementsByTagName('body')[0]; + const observer = new MutationObserver(mutationRecords => { + if (mutationRecords[0].oldValue === 'true') { + this.setState({ theme: 'dark' }); + } else { + this.setState({ theme: 'default' }); + } + }); + observer.observe(body, { + attributes: true, + attributeFilter: ['data-jp-theme-light'], + attributeOldValue: true + }); + this.state = { rows: [], displayRows: [], @@ -99,7 +114,9 @@ export default class SqueueDataTable extends Component< reloadRate: reloadRate, reloadLimit: 5000, userOnly: props.userOnly, - loading: false + loading: false, + theme: 'default', + observer: observer }; } @@ -274,13 +291,11 @@ export default class SqueueDataTable extends Component< }); } - async componentWillMount(): Promise { + async componentDidMount(): Promise { await this.getData().then(async () => { await this.reload(); }); - } - async componentDidMount(): Promise { // if (this.state.autoReload) { // useEffect(() => { // const interval = setInterval(async () => { @@ -322,6 +337,10 @@ export default class SqueueDataTable extends Component< } } + componentWillUnmount(): void { + this.state.observer.disconnect(); + } + async handleFilter(filter: string): Promise { this.setState({ filterQuery: filter }, this.updateDisplayRows); } @@ -343,7 +362,7 @@ export default class SqueueDataTable extends Component< <> - +