fixes: slugs issues for released an public apps (#8119)

This commit is contained in:
Arpit 2023-11-07 16:35:07 +05:30 committed by GitHub
parent 6f8f6b260b
commit c1618d7343
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 22 deletions

View file

@ -722,7 +722,7 @@ const EditorComponent = (props) => {
slug: data.slug,
isMaintenanceOn: data?.is_maintenance_on,
organizationId: currentOrgId,
isPublic: data?.is_public,
isPublic: data?.is_public || data?.isPublic,
appName: data?.name,
userId: data?.user_id,
appId: data?.id,

View file

@ -59,6 +59,7 @@ export const GlobalSettings = ({
special chars or spaces in their app slugs
*/
const existedSlugErrors = validateName(oldSlug, 'App slug', true, false, false, false);
setSlug({ value: oldSlug, error: existedSlugErrors.errorMsg });
}, [oldSlug]);
@ -166,6 +167,7 @@ export const GlobalSettings = ({
delayedSlugChange(e.target.value, 'slug');
}}
data-cy="app-slug-input-field"
value={oldSlug}
defaultValue={oldSlug}
/>
{isSlugUpdated && (

View file

@ -117,10 +117,6 @@ class ManageAppUsersComponent extends React.Component {
.then(() => {
this.setState({
ischangingVisibility: false,
app: {
...this.state.app,
is_public: newState,
},
});
if (newState) {
@ -137,10 +133,6 @@ class ManageAppUsersComponent extends React.Component {
});
};
//here
handleSlugChange = (newSlug) => {
useAppDataStore.actions.updateState({ slug: newSlug });
};
delayedSlugChange = debounce((e) => {
this.handleInputChange(e.target.value, 'slug');
}, 500);
@ -171,8 +163,9 @@ class ManageAppUsersComponent extends React.Component {
isSlugVerificationInProgress: false,
isSlugUpdated: true,
});
this.handleSlugChange(value);
replaceEditorURL(value, this.props.pageHandle);
useAppDataStore.getState().actions.updateState({ slug: value });
})
.catch(({ error }) => {
this.setState({

View file

@ -279,8 +279,9 @@ class ViewerComponent extends React.Component {
appService
.fetchAppBySlug(slug)
.then((data) => {
if (authentication_failed && !data.current_version_id) {
redirectToErrorPage(ERROR_TYPES.URL_UNAVAILABLE, {});
const isAppPublic = data?.is_public;
if (authentication_failed && !isAppPublic) {
return redirectToErrorPage(ERROR_TYPES.URL_UNAVAILABLE, {});
}
this.setStateForApp(data, true);
this.setStateForContainer(data);
@ -393,9 +394,13 @@ class ViewerComponent extends React.Component {
handlePageSwitchingBasedOnURLparam() {
const handleOnURL = this.props.params.pageHandle;
const pageIdCorrespondingToHandleOnURL = handleOnURL
? this.findPageIdFromHandle(handleOnURL)
: this.state.appDefinition.homePageId;
const shouldShowPage = handleOnURL ? this.validatePageHandle(handleOnURL) : true;
if (!shouldShowPage) return this.switchPage(this.state.appDefinition.homePageId);
const pageIdCorrespondingToHandleOnURL =
handleOnURL && shouldShowPage ? this.findPageIdFromHandle(handleOnURL) : this.state.appDefinition.homePageId;
const currentPageId = this.state.currentPageId;
if (pageIdCorrespondingToHandleOnURL != this.state.currentPageId) {
@ -441,6 +446,11 @@ class ViewerComponent extends React.Component {
}
}
validatePageHandle(handle) {
const allPages = this.state.appDefinition.pages;
return Object.values(allPages).some((page) => page.handle === handle && !page.disabled);
}
findPageIdFromHandle(handle) {
return (
Object.entries(this.state.appDefinition.pages).filter(([_id, page]) => page.handle === handle)?.[0]?.[0] ??

View file

@ -92,13 +92,6 @@ export class AppsControllerV2 {
response['pages'] = pagesForVersion;
response['events'] = eventsForVersion;
//! if editing version exists, camelize the definition
if (app.editingVersion && app.editingVersion.definition) {
response['editing_version'] = {
...response['editing_version'],
definition: camelizeKeys(app.editingVersion.definition),
};
}
return response;
}