Skip to content

Commit

Permalink
refactor: change the workspaceName into the prettyName into tenant qu…
Browse files Browse the repository at this point in the history
…ery/sub
  • Loading branch information
Marco Manco committed Dec 14, 2021
1 parent 3743c97 commit a224ed1
Show file tree
Hide file tree
Showing 24 changed files with 118 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ const ActiveViewLogic: FC<{}> = ({ ...props }) => {

const workspaces =
tenantData?.tenant?.spec?.workspaces?.map(workspace => {
const { workspaceWrapperTenantV1alpha2, workspaceId, role } = workspace!;
const { workspaceWrapperTenantV1alpha2, name, role } = workspace!;
const { spec, status } =
workspaceWrapperTenantV1alpha2?.itPolitoCrownlabsV1alpha1Workspace!;
return {
prettyName: spec?.workspaceName as string,
prettyName: spec?.prettyName as string,
role: WorkspaceRole[role!],
namespace: status?.namespace?.workspaceNamespace!,
id: workspaceId!,
namespace: status?.namespace?.name!,
id: name!,
};
}) || [];

Expand All @@ -31,7 +31,7 @@ const ActiveViewLogic: FC<{}> = ({ ...props }) => {
return !tenantLoading && tenantData && !tenantError ? (
<ActiveView
user={{
tenantId: tenantData.tenant?.metadata?.tenantId!,
tenantId: tenantData.tenant?.metadata?.name!,
tenantNamespace: tenantData!.tenant?.status?.personalNamespace?.name!,
}}
managerView={managerWorkspaces.length > 0}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/common/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ const Navbar: FC<INavbarProps> = ({ ...props }) => {
<Title
className="mb-0"
level={5}
>{`${data?.tenant?.metadata?.tenantId}`}</Title>
>{`${data?.tenant?.metadata?.name}`}</Title>
)}
<LogoutButton
logoutHandler={logoutHandler}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface INavbarMenuProps {
const NavbarMenu: FC<INavbarMenuProps> = ({ ...props }) => {
const { routes } = props;
const { data } = useContext(TenantContext);
const tenantId = data?.tenant?.metadata?.tenantId!;
const tenantId = data?.tenant?.metadata?.name!;
const currentPath = useLocation().pathname;

const [visible, setVisible] = useState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ const DashboardLogic: FC<{}> = () => {
return {
workspaceId: workspace?.workspaceWrapperTenantV1alpha2
?.itPolitoCrownlabsV1alpha1Workspace?.spec
?.workspaceName as string,
?.prettyName as string,
role: WorkspaceRole[workspace?.role!],
workspaceNamespace:
workspace?.workspaceWrapperTenantV1alpha2
?.itPolitoCrownlabsV1alpha1Workspace?.status?.namespace
?.workspaceNamespace!,
workspaceName: workspace?.workspaceId!,
?.name!,
workspaceName: workspace?.name!,
};
}) ?? []
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const ModalCreateTemplate: FC<IModalCreateTemplateProps> = ({ ...props }) => {
!errorFetchTemplates &&
!loadingFetchTemplates &&
dataFetchTemplates?.templateList?.templates
?.map(t => t?.spec?.name)
?.map(t => t?.spec?.prettyName)
.includes(formTemplate.name.trim())
) {
setValid(old => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ const TemplatesTableLogic: FC<ITemplateTableLogicProps> = ({ ...props }) => {
getTemplate({
original: t!,
alias: {
id: t?.metadata?.id!,
name: t?.spec?.name!,
id: t?.metadata?.name!,
name: t?.spec?.prettyName!,
},
})
)!
Expand Down
88 changes: 44 additions & 44 deletions frontend/src/generated-types.tsx

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mutation applyTenant(
applicationApplyPatchYamlInput: $patchJson
) {
metadata {
tenantId: name
name
}
spec {
firstName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ mutation createInstance(
templateWrapper {
itPolitoCrownlabsV1alpha2Template {
spec {
templateName: prettyName
templateDescription: description
prettyName
description
environmentList {
guiEnabled
persistent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mutation createTemplate(
}
) {
spec {
name: prettyName
prettyName
description
environmentList {
guiEnabled
Expand All @@ -47,7 +47,7 @@ mutation createTemplate(
}
}
metadata {
id: name
name
namespace
}
}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/graphql-components/query/instances.query.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ query ownedInstances($tenantNamespace: String!) {
templateWrapper {
itPolitoCrownlabsV1alpha2Template {
spec {
templateName: prettyName
templateDescription: description
prettyName
description
environmentList {
guiEnabled
persistent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ query instancesLabelSelector($labels: String) {
running
prettyName
tenantCrownlabsPolitoItTenantRef {
tenantId: name
name
tenantV1alpha2Wrapper {
itPolitoCrownlabsV1alpha2Tenant {
spec {
Expand All @@ -31,8 +31,8 @@ query instancesLabelSelector($labels: String) {
templateWrapper {
itPolitoCrownlabsV1alpha2Template {
spec {
templateName: prettyName
templateDescription: description
prettyName
description
environmentList {
guiEnabled
persistent
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/graphql-components/query/keys.query.graphql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
query sshKeys($tenantId: String!) {
tenant: itPolitoCrownlabsV1alpha2Tenant(name: $tenantId) {
metadata {
tenantId: name
name
}
spec {
email
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/graphql-components/query/templates.query.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ query workspaceTemplates($workspaceNamespace: String!) {
) {
templates: items {
spec {
name: prettyName
prettyName
description
environmentList {
guiEnabled
Expand All @@ -17,7 +17,7 @@ query workspaceTemplates($workspaceNamespace: String!) {
}
}
metadata {
id: name
name
namespace
}
}
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/graphql-components/query/tenant.query.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ query tenant($tenantId: String!) {
lastName
workspaces {
role
workspaceId: name
name
workspaceWrapperTenantV1alpha2 {
itPolitoCrownlabsV1alpha1Workspace {
spec {
workspaceName: prettyName
prettyName
}
status {
namespace {
workspaceNamespace: name
name
}
}
}
}
}
}
metadata {
tenantId: name
name
}
status {
personalNamespace {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ query tenants($labels: String, $retrieveWorkspaces: Boolean = false) {
tenants: itPolitoCrownlabsV1alpha2TenantList(labelSelector: $labels) {
items {
metadata {
tenantId: name
name
}
spec {
firstName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export default gql`
templateWrapper {
itPolitoCrownlabsV1alpha2Template {
spec {
templateName: prettyName
templateDescription: description
prettyName
description
environmentList {
guiEnabled
persistent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default gql`
running
prettyName
tenantCrownlabsPolitoItTenantRef {
tenantId: name
name
tenantV1alpha2Wrapper {
itPolitoCrownlabsV1alpha2Tenant {
spec {
Expand All @@ -37,8 +37,8 @@ export default gql`
templateWrapper {
itPolitoCrownlabsV1alpha2Template {
spec {
templateName: prettyName
templateDescription: description
prettyName
description
environmentList {
guiEnabled
persistent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default gql`
updateType
updatedKeys: payload {
metadata {
tenantId: name
name
}
spec {
email
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default gql`
updateType
template: payload {
spec {
name: prettyName
prettyName
description
environmentList {
guiEnabled
Expand All @@ -25,7 +25,7 @@ export default gql`
}
}
metadata {
id: name
name
namespace
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ export default gql`
lastName
workspaces {
role
workspaceId: name
name
workspaceWrapperTenantV1alpha2 {
itPolitoCrownlabsV1alpha1Workspace {
spec {
workspaceName: prettyName
prettyName
}
status {
namespace {
workspaceNamespace: name
name
}
}
}
}
}
}
metadata {
tenantId: name
name
}
status {
personalNamespace {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
useSshKeysQuery,
useTenantQuery,
} from '../../generated-types';
import { JSONDeepCopy } from '../../utils';
import { workspaceGetName } from '../../utilsLogic';
import { updatedTenant } from '../subscription';

interface ITenantContext {
Expand Down Expand Up @@ -52,7 +54,12 @@ const TenantContextProvider: FC<PropsWithChildren<{}>> = props => {

const { loading, error, subscribeToMore } = useTenantQuery({
variables: { tenantId: userId ?? '' },
onCompleted: setData,
onCompleted: d => {
d!.tenant!.spec?.workspaces!.sort((a, b) =>
workspaceGetName(a!).localeCompare(workspaceGetName(b!))
);
setData(JSONDeepCopy(d));
},
fetchPolicy: 'network-only',
onError: apolloErrorCatcher,
});
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,5 @@ export function makeListToggler<T>(
);
};
}

export const JSONDeepCopy = <T>(obj: T) => JSON.parse(JSON.stringify(obj)) as T;
Loading

0 comments on commit a224ed1

Please sign in to comment.