Skip to content

Commit ad13e6d

Browse files
authored
Fixed pages and layouts validation and added No items text when searching (#2715)
1 parent 852cfa9 commit ad13e6d

File tree

4 files changed

+45
-24
lines changed

4 files changed

+45
-24
lines changed

src/admin/pages/pageDetailsModal.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,11 @@ export class PageDetailsModal extends React.Component<PageDetailsModalProps, Pag
139139
const titleError = validateField(REQUIRED, this.state.page.title);
140140

141141
if (permalinkError || titleError) {
142-
this.setState({ errors: { permalink: permalinkError, title: titleError } });
142+
const errors = {};
143+
if (permalinkError) errors['permalink'] = permalinkError;
144+
if (titleError) errors['title'] = titleError;
145+
146+
this.setState({ errors });
143147
return;
144148
}
145149

src/admin/pages/pageLayoutDetailsModal.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ export class PageLayoutDetailsModal extends React.Component<PageLayoutModalProps
111111
const titleError = validateField(REQUIRED, this.state.layout.title);
112112

113113
if (permalinkError || titleError) {
114-
this.setState({ errors: { permalinkTemplate: permalinkError, title: titleError } });
114+
const errors = {};
115+
if (permalinkError) errors['permalink'] = permalinkError;
116+
if (titleError) errors['title'] = titleError;
117+
118+
this.setState({ errors });
115119
return;
116120
}
117121

src/admin/pages/pages.tsx

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,21 @@ export class Pages extends React.Component<PagesProps, PagesState> {
185185
styles={{ root: { marginTop: 20 } }}
186186
/>
187187
<div className="objects-list">
188-
{this.state.isLoading && <Spinner />}
189-
{this.state.pages.map(page =>
190-
<CommandBarButton
191-
iconProps={pageIcon}
192-
text={page.title}
193-
key={page.key}
194-
className="nav-item-list-button"
195-
onRenderText={() => this.renderPageContent(page)}
196-
onClick={async () => await this.router.navigateTo(page.permalink)}
197-
/>
198-
)}
188+
{this.state.isLoading
189+
? <Spinner />
190+
: this.state.pages.length === 0
191+
? <Text className="no-objects-text">No pages found</Text>
192+
: this.state.pages.map(page =>
193+
<CommandBarButton
194+
iconProps={pageIcon}
195+
text={page.title}
196+
key={page.key}
197+
className="nav-item-list-button"
198+
onRenderText={() => this.renderPageContent(page)}
199+
onClick={async () => await this.router.navigateTo(page.permalink)}
200+
/>
201+
)
202+
}
199203
</div>
200204
</PivotItem>
201205
<PivotItem headerText="Layouts" itemKey="layouts">
@@ -216,17 +220,21 @@ export class Pages extends React.Component<PagesProps, PagesState> {
216220
styles={{ root: { marginTop: 20 } }}
217221
/>
218222
<div className="objects-list">
219-
{this.state.isLoading && <Spinner />}
220-
{this.state.layouts.map(layout =>
221-
<CommandBarButton
222-
iconProps={layoutIcon}
223-
text={layout.title}
224-
key={layout.key}
225-
className="nav-item-list-button"
226-
onRenderText={() => this.renderPageLayoutContent(layout)}
227-
onClick={async () => this.viewManager.setHost({ name: 'layout-host', params: { layoutKey: layout.key } })}
228-
/>
229-
)}
223+
{this.state.isLoading
224+
? <Spinner />
225+
: this.state.layouts.length === 0
226+
? <Text className="no-objects-text">No layouts found</Text>
227+
: this.state.layouts.map(layout =>
228+
<CommandBarButton
229+
iconProps={layoutIcon}
230+
text={layout.title}
231+
key={layout.key}
232+
className="nav-item-list-button"
233+
onRenderText={() => this.renderPageLayoutContent(layout)}
234+
onClick={async () => this.viewManager.setHost({ name: 'layout-host', params: { layoutKey: layout.key } })}
235+
/>
236+
)
237+
}
230238
</div>
231239
</PivotItem>
232240
</Pivot>

src/themes/designer/styles/admin.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@
7272
margin: 10px 0 15px;
7373
}
7474

75+
.no-objects-text {
76+
display: block;
77+
padding: 10px 4px;
78+
}
79+
7580
.nav-item-description-container {
7681
margin: 10px 8px 20px;
7782

0 commit comments

Comments
 (0)