Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Check for version control, display notice #145

Merged
merged 39 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
8021294
Create `get-version-control` wp-module
mike-day Apr 20, 2023
70ac8a1
Hydrate `app` using `check_for_git_in_theme`
mike-day Apr 20, 2023
cbd407c
Update global type with `themename`, `versionControl`
mike-day Apr 20, 2023
e352cc8
Create VersionControlNotice component
mike-day Apr 20, 2023
c92dcae
Remove margin-right for notice__content
mike-day Apr 20, 2023
8ca4bc5
Use `VersionControlNotice` in `Patterns`
mike-day Apr 20, 2023
e8e2c71
Update AppTest
mike-day Apr 20, 2023
a8dbda1
Remove unused check for git in theme root
mike-day Apr 20, 2023
1527f1c
Setup a test-theme fixture
mike-day Apr 20, 2023
f3b450c
Create unit tests for get-verison-control (not passing)
mike-day Apr 20, 2023
3e22e49
Simplify the phpunit tests, delete unneeded fixture theme files
mike-day Apr 20, 2023
8031eec
Use a param for main vc checker function so testing is easier
mike-day Apr 20, 2023
d3f6d6b
Make the notice dismissible; adjust notice style to go full-width
mike-day Apr 20, 2023
f52085a
Remove invalid max-width property
mike-day Apr 21, 2023
ba16aca
Use `info` status for notice; adjust styles after talking through UX
mike-day Apr 21, 2023
7379ab4
Try a `warning` status for the notice
mike-day Apr 21, 2023
dbe4758
Tweak the verbiage in notice; linting for component
mike-day Apr 27, 2023
2c7f9c0
Add the update-dismissed-themes endpoint
mike-day Apr 27, 2023
c4b39f7
Hydrate app with new endpoint, query for dismissedThemes
mike-day Apr 27, 2023
7db5b54
Update types
mike-day Apr 27, 2023
36641de
Add a new `useVersionControl` hook
mike-day Apr 27, 2023
ae0d0aa
Call the new hook, then add to context provider
mike-day Apr 27, 2023
c8e0b03
Simplify VersionControlNotice; use the updated context in `Patterns`
mike-day Apr 27, 2023
1697e26
Update ApiDataTest
mike-day Apr 27, 2023
3a394e2
Update AppTest
mike-day Apr 27, 2023
d785692
Move getting of usermeta to get-version-control, return empty array i…
mike-day Apr 27, 2023
e96e8a1
Add empty array test for get_dismissed_themes
mike-day Apr 27, 2023
a9b9ef6
Translate the notification message
mike-day Apr 27, 2023
4e8188e
Merge branch 'main' of https://github.com/studiopress/pattern-manager…
mike-day Apr 27, 2023
126e83f
Pass themeName in PatternProps
mike-day Apr 27, 2023
06172f2
Pass versionControl bool, handler as props in Patterns instead of usi…
mike-day Apr 27, 2023
b50b045
Add get_current_user_id() to setUp, tearDown in unit test
mike-day Apr 27, 2023
af0ada1
Pass `Notice` as an optional prop to `Patterns`
mike-day Apr 27, 2023
37afb1a
Simplify the logic and just hydrate with a boolean to show or hide no…
mike-day Apr 27, 2023
54f8656
Bugfix from sending empty `themeName`; remove the POST body
mike-day Apr 27, 2023
1463614
Tweak the notice message, add space
mike-day Apr 28, 2023
fff8336
Add more test assertions for GetVersionControlTest
mike-day May 1, 2023
19437ed
Delete testing usermeta, user on tearDown
mike-day May 1, 2023
6c3907c
Remove the link to `Git Guide` in the notice message
mike-day May 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions wp-modules/app/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace PatternManager\App;

use function PatternManager\GetVersionControl\check_for_git_in_theme;

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand All @@ -29,6 +31,8 @@ function get_app_state() {
),
'siteUrl' => get_bloginfo( 'url' ),
'adminUrl' => admin_url(),
'themeName' => wp_get_theme()->get( 'Name' ),
'versionControl' => check_for_git_in_theme(),
);
}

Expand Down
15 changes: 15 additions & 0 deletions wp-modules/app/css/src/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,21 @@ html body.toplevel_page_pattern-manager {
}
}

.patternmanager-version-control-notice {
margin-bottom: 3rem;
padding-right: 12px;
text-align: center;

.components-notice__content {
line-height: 2.5;
margin-right: 0;

span {
font-weight: 600;
}
}
}

.patternmanager-pattern-editor-columns {
width: 100%;
height: calc(100vh - 64px - 32px);
Expand Down
2 changes: 2 additions & 0 deletions wp-modules/app/js/src/components/Patterns/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import usePmContext from '../../hooks/usePmContext';
import PatternCategories from './PatternCategories';
import PatternGrid from './PatternGrid';
import SearchCount from './SearchCount';
import VersionControlNotice from '../VersionControlNotice';

// Utils
import createPatternsWithUncategorized from '../../utils/createPatternsWithUncategorized';
Expand Down Expand Up @@ -39,6 +40,7 @@ export default function Patterns() {
return (
<div className="patternmanager-theme-patterns">
<div className="patterns-container-inner">
<VersionControlNotice />
{ ! Object.entries( patterns.data ?? {} ).length ? (
<div className="grid-empty">
{ createInterpolateElement(
Expand Down
22 changes: 22 additions & 0 deletions wp-modules/app/js/src/components/VersionControlNotice/index.tsx
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With a light refactor to pass in versionControl and themeName as props, this component could be a good candidate for moving to common if we do something like #141.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea!

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// WP dependencies
import { Notice } from '@wordpress/components';

// Globals
import { patternManager } from '../../globals';

/** Display a non-dismissible notice if no version control is detected in the theme. */
export default function VersionControlNotice() {
return (
! patternManager.versionControl && (
<Notice
className="patternmanager-version-control-notice"
isDismissible={ false }
status="error"
>
No version control detected for this theme. Please{ ' ' }
<a href="https://github.com/git-guides">initialize git</a> in
the <span>{ patternManager.themeName }</span> theme folder.
</Notice>
)
);
}
2 changes: 2 additions & 0 deletions wp-modules/app/js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export type InitialPatternManager = {
patternCategories: QueriedCategories;
patterns: Patterns;
siteUrl: string;
themeName: string;
versionControl: '' | 1;
mike-day marked this conversation as resolved.
Show resolved Hide resolved
};

export type Pattern = {
Expand Down
2 changes: 2 additions & 0 deletions wp-modules/app/tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public function test_get_app_state() {
'apiEndpoints',
'siteUrl',
'adminUrl',
'themeName',
'versionControl',
],
array_keys( get_app_state() )
);
Expand Down
22 changes: 22 additions & 0 deletions wp-modules/get-version-control/get-version-control.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Module Name: Get Version Control
* Description: Checks the current theme directory for version control.
* Namespace: GetVersionControl
*
* @package pattern-manager
*/

declare(strict_types=1);

namespace PatternManager\GetVersionControl;

/**
* Checks for a .git folder in the current theme.
*
* @return boolean
*/
function check_for_git_in_theme() {
$theme_git_dir = get_template_directory() . '/.git';
return file_exists( $theme_git_dir );
mike-day marked this conversation as resolved.
Show resolved Hide resolved
}