forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moves styleSheetPath to uiExports (elastic#23007)
This was previously defined in uiExports.app, which limited plugins which are not an app of providing a stylesheet. This allows any plugin to define a stylesheet which will be available on page load.
- Loading branch information
1 parent
fe1b90f
commit 519cefc
Showing
28 changed files
with
253 additions
and
162 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
@import 'ui/public/styles/styling_constants'; | ||
|
||
// SASSTODO: Remove when K7 applies background color to body | ||
.stsPage { | ||
#status_page-app .stsPage { | ||
min-height: 100vh; | ||
} |
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 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 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,67 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import path from 'path'; | ||
import { flatConcatAtType } from './reduce'; | ||
import { mapSpec, wrap } from './modify_reduce'; | ||
|
||
const OK_EXTNAMES = ['.css', '.scss']; | ||
|
||
function normalize(localPath, type, pluginSpec) { | ||
const pluginId = pluginSpec.getId(); | ||
const publicDir = pluginSpec.getPublicDir(); | ||
const extname = path.extname(localPath); | ||
|
||
if (!OK_EXTNAMES.includes(extname)) { | ||
throw new Error( | ||
`[plugin:${pluginId}] uiExports.styleSheetPaths supported extensions [${OK_EXTNAMES.join(', ')}], got "${extname}"` | ||
); | ||
} | ||
|
||
if (!path.isAbsolute(localPath)) { | ||
throw new Error( | ||
`[plugin:${pluginId}] uiExports.styleSheetPaths must be an absolute path, got "${localPath}"` | ||
); | ||
} | ||
|
||
if (!localPath.startsWith(publicDir)) { | ||
throw new Error( | ||
`[plugin:${pluginId}] uiExports.styleSheetPaths must be child of publicDir [${publicDir}]` | ||
); | ||
} | ||
|
||
// get the path of the stylesheet relative to the public dir for the plugin | ||
let relativePath = path.relative(publicDir, localPath); | ||
|
||
// replace back slashes on windows | ||
relativePath = relativePath.split('\\').join('/'); | ||
|
||
// replace the extension of relativePath to be .css | ||
// publicPath will always point to the css file | ||
relativePath = relativePath.slice(0, -extname.length) + '.css'; | ||
|
||
const publicPath = `plugins/${pluginSpec.getId()}/${relativePath}`; | ||
|
||
return { | ||
localPath, | ||
publicPath | ||
}; | ||
} | ||
|
||
export const styleSheetPaths = wrap(mapSpec(normalize), flatConcatAtType); |
60 changes: 60 additions & 0 deletions
60
src/ui/ui_exports/ui_export_types/style_sheet_paths.test.js
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,60 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { styleSheetPaths } from './style_sheet_paths'; | ||
|
||
describe('uiExports.styleSheetPaths', () => { | ||
const pluginSpec = { | ||
getId: () => 'test', | ||
getPublicDir: () => '/kibana/public' | ||
}; | ||
|
||
it('does not support relative paths', () => { | ||
expect(() => styleSheetPaths([], 'public/bar.css', 'styleSheetPaths', pluginSpec)) | ||
.toThrowError('[plugin:test] uiExports.styleSheetPaths must be an absolute path, got "public/bar.css"'); | ||
}); | ||
|
||
it('path must be child of public path', () => { | ||
expect(() => styleSheetPaths([], '/another/public/bar.css', 'styleSheetPaths', pluginSpec)) | ||
.toThrowError('[plugin:test] uiExports.styleSheetPaths must be child of publicDir [/kibana/public]'); | ||
}); | ||
|
||
it('only supports css or scss extensions', () => { | ||
expect(() => styleSheetPaths([], '/kibana/public/bar.bad', 'styleSheetPaths', pluginSpec)) | ||
.toThrowError('[plugin:test] uiExports.styleSheetPaths supported extensions [.css, .scss], got ".bad"'); | ||
}); | ||
|
||
it('provides publicPath for scss extensions', () => { | ||
const localPath = '/kibana/public/bar.scss'; | ||
const uiExports = styleSheetPaths([], localPath, 'styleSheetPaths', pluginSpec); | ||
|
||
expect(uiExports.styleSheetPaths).toHaveLength(1); | ||
expect(uiExports.styleSheetPaths[0].localPath).toEqual(localPath); | ||
expect(uiExports.styleSheetPaths[0].publicPath).toEqual('plugins/test/bar.css'); | ||
}); | ||
|
||
it('provides publicPath for css extensions', () => { | ||
const localPath = '/kibana/public/bar.css'; | ||
const uiExports = styleSheetPaths([], localPath, 'styleSheetPaths', pluginSpec); | ||
|
||
expect(uiExports.styleSheetPaths).toHaveLength(1); | ||
expect(uiExports.styleSheetPaths[0].localPath).toEqual(localPath); | ||
expect(uiExports.styleSheetPaths[0].publicPath).toEqual('plugins/test/bar.css'); | ||
}); | ||
}); |
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
Oops, something went wrong.